Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.databasepreservation.model.structure.ColumnStructure;
import com.databasepreservation.model.structure.SchemaStructure;
import com.databasepreservation.model.structure.TableStructure;
import com.databasepreservation.modules.siard.SIARDDKModuleFactory;
import com.databasepreservation.modules.siard.common.LargeObject;
import com.databasepreservation.modules.siard.common.SIARDArchiveContainer;
import com.databasepreservation.modules.siard.constants.SIARDConstants;
Expand All @@ -49,6 +50,7 @@
import com.databasepreservation.modules.siard.out.output.SIARDDKExportModule;
import com.databasepreservation.modules.siard.out.path.ContentPathExportStrategy;
import com.databasepreservation.modules.siard.out.write.WriteStrategy;
import com.databasepreservation.modules.siard.services.conversion.BypassedLobReporter;
import com.databasepreservation.modules.siard.services.conversion.LobConversionAuditor;
import com.databasepreservation.modules.siard.services.conversion.model.report.ArtifactReport;
import com.databasepreservation.modules.siard.services.conversion.model.report.ConversionReport;
Expand Down Expand Up @@ -79,6 +81,7 @@ public class SIARDDKContentExportStrategy implements ContentExportStrategy {
private final MimetypeHandler mimetypeHandler;

private final LobConversionAuditor auditor;
private final BypassedLobReporter bypassedLobReporter;
private final ObjectMapper mapper;

private Reporter reporter;
Expand All @@ -102,6 +105,10 @@ public SIARDDKContentExportStrategy(SIARDDKExportModule siarddkExportModule) {
Path exportRoot = baseContainer.getPath().getParent();
String archiveName = baseContainer.getPath().getFileName().toString();
this.auditor = new LobConversionAuditor(exportRoot, archiveName);

String targetLobFormat = siarddkExportModule.getExportModuleArgs()
.getOrDefault(SIARDDKModuleFactory.PARAMETER_LOB_CONVERSION_TARGET_FORMAT, "image/tiff");
this.bypassedLobReporter = new BypassedLobReporter(exportRoot, archiveName, targetLobFormat);
}

@Override
Expand Down Expand Up @@ -450,6 +457,7 @@ private void processConvertedLobArchive(BinaryCell binaryCell, long rowIndex, in
ConversionReport enrichedReport = report
.withContext(new DbptkContext(tableCounter, rowIndex, columnIndex, siardPhysicalPaths));
auditor.appendAuditRecord(enrichedReport);
bypassedLobReporter.appendBypassedRecord(enrichedReport);

} catch (Exception e) {
throw new ModuleException().withMessage("Failed to process converted ZIP archive").withCause(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.databasepreservation.modules.siard.services.conversion;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.databasepreservation.modules.siard.services.conversion.model.report.ArtifactReport;
import com.databasepreservation.modules.siard.services.conversion.model.report.BypassedLobEntry;
import com.databasepreservation.modules.siard.services.conversion.model.report.ConversionReport;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
* @author Vitor Leite <vleite@keep.pt>
*/
public class BypassedLobReporter {
private static final Logger logger = LoggerFactory.getLogger(BypassedLobReporter.class);
private static final String REASON_CONVERSION_FAILED = "Conversion failed";
private static final String REASON_FILTERED_FORMAT = "Retained the original format due to SIARD-DK specification";

private final ObjectMapper mapper;
private final Path reportFilePath;
private final String targetLobFormat;

public BypassedLobReporter(Path baseExportDirectory, String archiveName, String targetLobFormat) {
this.mapper = new ObjectMapper();
this.targetLobFormat = targetLobFormat;
String fileName = archiveName + "_bypassed_lob_report.jsonl";
this.reportFilePath = baseExportDirectory.resolve(fileName);
}

public void appendBypassedRecord(ConversionReport report) {
if (report == null || report.artifacts() == null)
return;

for (ArtifactReport artifact : report.artifacts()) {
String reason = resolveBypassReason(artifact);
if (reason == null)
continue;

BypassedLobEntry entry = new BypassedLobEntry(artifact.logicalName(), artifact.originalMimeType(),
artifact.finalMimeType(), artifact.isBypassed(), artifact.errorMessage(), reason, report.dbptkContext());
append(entry);
}
}

private String resolveBypassReason(ArtifactReport artifact) {
if (artifact.isBypassed()) {
return REASON_CONVERSION_FAILED;
}

if (!targetLobFormat.equalsIgnoreCase(artifact.finalMimeType())) {
return REASON_FILTERED_FORMAT;
}

return null;
}

private void append(BypassedLobEntry entry) {
try {
String jsonLine = mapper.writeValueAsString(entry);
Files.writeString(reportFilePath, jsonLine + System.lineSeparator(), StandardOpenOption.CREATE,
StandardOpenOption.APPEND);
} catch (Exception e) {
logger.error("Failed to append bypassed lob entry to report.", e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.databasepreservation.modules.siard.services.conversion.model.report;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
* @author Vitor Leite <vleite@keep.pt>
*/
public record BypassedLobEntry(@JsonProperty("logicalName") String logicalName,
@JsonProperty("originalMimeType") String originalMimeType, @JsonProperty("finalMimeType") String finalMimeType,
@JsonProperty("isBypassed") boolean isBypassed, @JsonProperty("errorMessage") String errorMessage,
@JsonProperty("reason") String reason, @JsonProperty("dbptkContext") DbptkContext dbptkContext) {
}
Loading