Skip to content

Commit

Permalink
include object metadata to blob store when uploading blobs during exp…
Browse files Browse the repository at this point in the history
…ort process

This can be later on extended to support other values as well, at this point there is need for name only.
  • Loading branch information
esuomi committed Oct 14, 2024
1 parent 0dd951b commit 60ade20
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions src/main/java/no/entur/uttu/export/ExportService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@

package no.entur.uttu.export;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.List;
import no.entur.uttu.error.codedexception.CodedIllegalArgumentException;
import no.entur.uttu.export.linestatistics.ExportedLineStatisticsService;
import no.entur.uttu.export.messaging.spi.MessagingService;
Expand All @@ -29,15 +26,27 @@
import no.entur.uttu.model.job.SeverityEnumeration;
import no.entur.uttu.util.ExportUtil;
import org.apache.commons.io.IOUtils;
import org.rutebanken.helper.storage.model.BlobDescriptor;
import org.rutebanken.helper.storage.repository.BlobStoreRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.Optional;

@Component
public class ExportService {

/**
* Object metadata key prefix to categorize where the possibly attached metadata originates from.
*/
public static final String EXPORT_METADATA_PREFIX = "no.entur.uttu.export.";

private final Logger logger = LoggerFactory.getLogger(this.getClass());

private final NetexExporter exporter;
Expand Down Expand Up @@ -82,13 +91,20 @@ public void exportDataSet(Export export) {
byte[] bytes = IOUtils.toByteArray(dataSetStream);
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);

Map<String, String> metadata = Map.of(
EXPORT_METADATA_PREFIX + "name",
export.getName()
);

if (!export.isDryRun() && !exportHasErrors(export)) {
String exportedDataSetFilename = ExportUtil.createExportedDataSetFilename(
export.getProvider(),
exportedFilenameSuffix
);
String blobName = exportFolder + exportedDataSetFilename;
blobStoreRepository.uploadBlob(blobName, bis);
blobStoreRepository.uploadBlob(
new BlobDescriptor(blobName, bis, Optional.empty(), Optional.of(metadata))
);
bis.reset();
// notify Marduk that a new export is available
messagingService.notifyExport(
Expand All @@ -101,7 +117,14 @@ public void exportDataSet(Export export) {
.forEach(export::addExportedLineStatistics);
}
export.setFileName(exportFolder + ExportUtil.createBackupDataSetFilename(export));
blobStoreRepository.uploadBlob(export.getFileName(), bis);
blobStoreRepository.uploadBlob(
new BlobDescriptor(
export.getFileName(),
bis,
Optional.empty(),
Optional.of(metadata)
)
);
} catch (CodedIllegalArgumentException iae) {
ExportMessage msg = new ExportMessage(SeverityEnumeration.ERROR, iae.getCode());
export.addMessage(msg);
Expand Down

0 comments on commit 60ade20

Please sign in to comment.