Skip to content

Commit

Permalink
export multiple rows for siarddk working (#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonioG70 authored Dec 17, 2024
1 parent 5097857 commit 8edf325
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ protected void writeToZipFile(ZipFile siardArchive, ZipArchiveOutputStream out,

if (binaryColumn != null) {
if (isSiardDK) {
handleWriteSIARDDKLobs(out, cellEntry.getValue());
handleWriteSIARDDKLobs(out, cellEntry.getValue(), binaryColumn, row);
} else {
if (ViewerType.dbTypes.CLOB.equals(binaryColumn.getType())) {
handleWriteClob(out, binaryColumn, row);
Expand Down Expand Up @@ -193,18 +193,27 @@ private void handleWriteExternalLobs(ZipArchiveOutputStream out, ColumnStatus bi
addEntryToZip(out, inputStream, templateFilename);
}

private void handleWriteSIARDDKLobs(ZipArchiveOutputStream out, ViewerCell cell) throws IOException {
private void handleWriteSIARDDKLobs(ZipArchiveOutputStream out, ViewerCell cell, ColumnStatus binaryColumn,
ViewerRow row) throws IOException {
final String lobLocation = cell.getValue();
final Path lobPath = Paths.get(lobLocation);

if (lobPath.toFile().isDirectory()) {
int index = 0;
for (File file : Objects.requireNonNull(lobPath.toFile().listFiles())) {
InputStream inputStream = Files.newInputStream(file.toPath());
addEntryToZip(out, inputStream, file.getName());
String extension = file.getName().substring(file.getName().lastIndexOf(".") + 1);
String templateFilename = index + "_" + FilenameUtils.getTemplateFilename(row, configTable, binaryColumn,
lobPath.getFileName().toString());
String templateFilenameWithActualExtension = templateFilename.replace(ExtraMediaType.ZIP_FILE_EXTENSION, "." + extension);
addEntryToZip(out, inputStream, templateFilenameWithActualExtension);
index++;
}
} else {
InputStream inputStream = Files.newInputStream(lobPath);
addEntryToZip(out, inputStream, lobPath.getFileName().toString());
final String templateFilename = FilenameUtils.getTemplateFilename(row, configTable, binaryColumn,
lobPath.getFileName().toString());
addEntryToZip(out, inputStream, templateFilename);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.stream.Stream;
import java.util.zip.ZipFile;

import com.databasepreservation.common.client.ViewerConstants;
import org.apache.commons.compress.archivers.zip.Zip64Mode;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
Expand Down Expand Up @@ -53,7 +54,6 @@ public ZipOutputStreamMultiRow(final CollectionStatus configurationCollection, f

@Override
public void consumeOutputStream(OutputStream out) throws IOException {
ZipFile siardArchive = new ZipFile(getDatabase().getPath());

boolean all = false;
if (sublist == null) {
Expand All @@ -76,7 +76,13 @@ public void consumeOutputStream(OutputStream out) throws IOException {
nIndex++;
continue;
} else {
writeToZipFile(siardArchive, zipArchiveOutputStream, row, lobColumns);
if (getDatabase().getVersion().equals(ViewerConstants.SIARD_DK_1007)
|| getDatabase().getVersion().equals(ViewerConstants.SIARD_DK_128)) {
writeToZipFile(null, zipArchiveOutputStream, row, lobColumns, true);
} else {
ZipFile siardArchive = new ZipFile(getDatabase().getPath());
writeToZipFile(siardArchive, zipArchiveOutputStream, row, lobColumns);
}
}
nIndex++;
}
Expand Down

0 comments on commit 8edf325

Please sign in to comment.