diff --git a/src/main/java/com/databasepreservation/common/api/v1/CollectionResource.java b/src/main/java/com/databasepreservation/common/api/v1/CollectionResource.java index ef9c336a..13227e56 100644 --- a/src/main/java/com/databasepreservation/common/api/v1/CollectionResource.java +++ b/src/main/java/com/databasepreservation/common/api/v1/CollectionResource.java @@ -623,7 +623,7 @@ private ResponseEntity handleInternalLobDownload(String d String filePath = row.getCells().get(row.getCells().keySet().toArray()[row.getCells().size() - 1]).getValue(); Path path = Paths.get(filePath); if (path.toFile().isDirectory()) { - Path tempZipFile = Files.createTempFile("temp-", ExtraMediaType.ZIP_FILE_EXTENSION); + Path tempZipFile = Files.createTempFile(ViewerConstants.TEMP_PREFIX, ExtraMediaType.ZIP_FILE_EXTENSION); try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(tempZipFile.toFile()))) { Files.walk(path).filter(p -> !Files.isDirectory(p)).forEach(p -> { ZipEntry zipEntry = new ZipEntry(path.relativize(p).toString()); diff --git a/src/main/java/com/databasepreservation/common/api/v1/FileResource.java b/src/main/java/com/databasepreservation/common/api/v1/FileResource.java index bb88391c..c70d5fa7 100644 --- a/src/main/java/com/databasepreservation/common/api/v1/FileResource.java +++ b/src/main/java/com/databasepreservation/common/api/v1/FileResource.java @@ -10,15 +10,13 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Paths; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; +import com.databasepreservation.common.utils.LobManagerUtils; import org.roda.core.data.exceptions.AlreadyExistsException; import org.roda.core.data.exceptions.GenericException; import org.roda.core.data.exceptions.NotFoundException; @@ -95,11 +93,11 @@ public ResponseEntity getSIARDFile(String filename) { java.nio.file.Path siardPath = siardFilesPath.resolve(filename); if (java.nio.file.Files.isDirectory(siardPath)) { - siardPath = zipDirectory(siardPath); + siardPath = LobManagerUtils.zipDirectory(siardPath); } if (java.nio.file.Files.exists(siardPath) && (ViewerConfiguration.checkPathIsWithin(siardPath, siardFilesPath) - || ViewerConfiguration.checkPathIsWithin(siardPath, basePath))) { + || ViewerConfiguration.checkPathIsWithin(siardPath, basePath))) { InputStreamResource resource = new InputStreamResource(new FileInputStream(siardPath.toFile())); return ResponseEntity.ok() @@ -119,24 +117,6 @@ public ResponseEntity getSIARDFile(String filename) { } } - private java.nio.file.Path zipDirectory(java.nio.file.Path dirPath) throws IOException { - java.nio.file.Path zipFilePath = dirPath.resolveSibling(dirPath.getFileName().toString() + ".zip"); - try (FileOutputStream fos = new FileOutputStream(zipFilePath.toFile()); - ZipOutputStream zos = new ZipOutputStream(fos)) { - java.nio.file.Files.walk(dirPath).filter(path -> !java.nio.file.Files.isDirectory(path)).forEach(path -> { - ZipEntry zipEntry = new ZipEntry(dirPath.relativize(path).toString()); - try { - zos.putNextEntry(zipEntry); - java.nio.file.Files.copy(path, zos); - zos.closeEntry(); - } catch (IOException e) { - throw new RuntimeException(e); - } - }); - } - return zipFilePath; - } - @Override public void deleteSiardFile(String filename) { final ControllerAssistant controllerAssistant = new ControllerAssistant() {}; @@ -176,7 +156,7 @@ public ResponseEntity createSIARDFile(MultipartFile resource if (!fileExtension.equals(ViewerConstants.SIARD)) { return ResponseEntity.status(HttpStatus.BAD_REQUEST) - .body(new ApiResponseMessage(ApiResponseMessage.ERROR, "Must be a SIARD file")); + .body(new ApiResponseMessage(ApiResponseMessage.ERROR, "Must be a SIARD file")); } java.nio.file.Path path = Paths.get(ViewerConfiguration.getInstance().getSIARDFilesPath().toString(), filename); diff --git a/src/main/java/com/databasepreservation/common/client/ViewerConstants.java b/src/main/java/com/databasepreservation/common/client/ViewerConstants.java index a11c7b32..bd38104f 100644 --- a/src/main/java/com/databasepreservation/common/client/ViewerConstants.java +++ b/src/main/java/com/databasepreservation/common/client/ViewerConstants.java @@ -554,6 +554,7 @@ public class ViewerConstants { public static final String PROPERTY_PLUGIN_LOAD_ON_ACCESS = "ui.plugin.loadOnAccess"; public static final String ALIAS_PREFIX = "alias-"; + public static final String TEMP_PREFIX = "temp-"; public static final String EMPTY_SEARCH = ""; diff --git a/src/main/java/com/databasepreservation/common/client/common/visualization/browse/RowPanel.java b/src/main/java/com/databasepreservation/common/client/common/visualization/browse/RowPanel.java index d84758e2..e5581ba1 100644 --- a/src/main/java/com/databasepreservation/common/client/common/visualization/browse/RowPanel.java +++ b/src/main/java/com/databasepreservation/common/client/common/visualization/browse/RowPanel.java @@ -421,29 +421,11 @@ private void getNestedHTML(ColumnStatus columnStatus) { null, false, new ArrayList<>()); CollectionService.Util.call((IndexResult result) -> { if (result.getTotalCount() >= 1) { - RowField rowField; String json = JSOUtils.cellsToJson(result.getResults().get(0).getCells(), nestedTable); String s = JavascriptUtils.compileTemplate(template, json); - if (columnStatus.getTypeName().contains("BINARY LARGE OBJECT")) { - String templateLob = "{{download_label}}"; - if ((database.getPath() == null || database.getPath().isEmpty()) - && !status.getConsolidateProperty().equals(LargeObjectConsolidateProperty.CONSOLIDATED)) { - rowField = RowField.createInstance(new Label(s).getText(), new HTML(messages.rowPanelTextForLobUnavailable())); - } else { - SafeHtml safeHtml = SafeHtmlUtils.EMPTY_SAFE_HTML; - json = JSOUtils.cellsToJson(ViewerConstants.TEMPLATE_LOB_DOWNLOAD_LABEL, messages.row_downloadLOB(), - ViewerConstants.TEMPLATE_LOB_DOWNLOAD_LINK, RestUtils.createExportLobUri(database.getUuid(), - nestedTable.getSchemaName(), nestedTable.getName(), "3309", columnStatus.getColumnIndex())); - safeHtml = SafeHtmlUtils.fromSafeConstant(JavascriptUtils.compileTemplate(templateLob, json)); - - - rowField = RowField.createInstance(columnStatus.getCustomName(), new HTML(safeHtml)); - } - } else { - rowField = RowField.createInstance(columnStatus.getCustomName(), new Label(s)); - } - + RowField rowField = RowField.createInstance(columnStatus.getCustomName(), new Label(s)); rowField.addColumnDescription(columnStatus.getCustomDescription()); + panel.add(rowField); } }).findRows(database.getUuid(), database.getUuid(), nestedTable.getSchemaName(), nestedTable.getName(), diff --git a/src/main/java/com/databasepreservation/common/transformers/DenormalizeTransformer.java b/src/main/java/com/databasepreservation/common/transformers/DenormalizeTransformer.java index da64df20..f94f96c3 100644 --- a/src/main/java/com/databasepreservation/common/transformers/DenormalizeTransformer.java +++ b/src/main/java/com/databasepreservation/common/transformers/DenormalizeTransformer.java @@ -243,7 +243,7 @@ private void queryOverRelatedTables(ViewerRow row, RelatedTablesConfiguration re fieldsToReturn.addAll(auxColumns); fieldsToReturn.addAll(columnsToDisplay); - //TODO USE NESTEDORIGINALUUID FOR LINK + IterableIndexResult nestedRows = solrManager.findAllRows(databaseUUID, resultingFilter, null, fieldsToReturn); for (ViewerRow nestedRow : nestedRows) { for (RelatedTablesConfiguration innerRelatedTable : relatedTable.getRelatedTables()) { diff --git a/src/main/java/com/databasepreservation/common/utils/LobManagerUtils.java b/src/main/java/com/databasepreservation/common/utils/LobManagerUtils.java index 4e504882..08ea1dcd 100644 --- a/src/main/java/com/databasepreservation/common/utils/LobManagerUtils.java +++ b/src/main/java/com/databasepreservation/common/utils/LobManagerUtils.java @@ -7,6 +7,7 @@ */ package com.databasepreservation.common.utils; +import java.io.FileOutputStream; import java.io.IOException; import java.io.UncheckedIOException; import java.nio.file.Files; @@ -14,6 +15,7 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; +import com.databasepreservation.common.api.utils.ExtraMediaType; import com.databasepreservation.common.client.ViewerConstants; import com.databasepreservation.common.client.models.status.collection.TableStatus; import com.databasepreservation.common.client.models.structure.ViewerRow; @@ -56,17 +58,18 @@ public static String getZipFilePath(TableStatus configTable, int columnIndex, St } - public static Path createZipFromDirectory(Path directoryPath) throws IOException { - Path zipFilePath = directoryPath.resolveSibling(directoryPath.getFileName().toString() + ".zip"); - try (ZipOutputStream zos = new ZipOutputStream(Files.newOutputStream(zipFilePath))) { - Files.walk(directoryPath).filter(path -> !Files.isDirectory(path)).forEach(path -> { - ZipEntry zipEntry = new ZipEntry(directoryPath.relativize(path).toString()); + public static Path zipDirectory(Path dirPath) throws IOException { + Path zipFilePath = dirPath.resolveSibling(dirPath.getFileName().toString() + ExtraMediaType.ZIP_FILE_EXTENSION); + try (FileOutputStream fos = new FileOutputStream(zipFilePath.toFile()); + ZipOutputStream zos = new ZipOutputStream(fos)) { + Files.walk(dirPath).filter(path -> !Files.isDirectory(path)).forEach(path -> { + ZipEntry zipEntry = new ZipEntry(dirPath.relativize(path).toString()); try { zos.putNextEntry(zipEntry); Files.copy(path, zos); zos.closeEntry(); } catch (IOException e) { - throw new UncheckedIOException(e); + throw new RuntimeException(e); } }); }