Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonioG70 committed Nov 25, 2024
1 parent 9b3dc3e commit 9740af0
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ private ResponseEntity<StreamingResponseBody> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -95,11 +93,11 @@ public ResponseEntity<Resource> 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()
Expand All @@ -119,24 +117,6 @@ public ResponseEntity<Resource> 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() {};
Expand Down Expand Up @@ -176,7 +156,7 @@ public ResponseEntity<ApiResponseMessage> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,29 +421,11 @@ private void getNestedHTML(ColumnStatus columnStatus) {
null, false, new ArrayList<>());
CollectionService.Util.call((IndexResult<ViewerRow> 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 = "<a href=\"{{download_link}}\">{{download_label}}</a>";
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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
*/
package com.databasepreservation.common.utils;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
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;
Expand Down Expand Up @@ -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);
}
});
}
Expand Down

0 comments on commit 9740af0

Please sign in to comment.