From 1ff1538eb0ca72294374950a492a642f2f91adb7 Mon Sep 17 00:00:00 2001 From: Mathieu Vonlanthen <Mathieu.Vonlanthen@unige.ch> Date: Fri, 31 Jan 2025 15:38:58 +0100 Subject: [PATCH 01/14] feat: [DLCM-2825] allow to get a download page with a list of anonymized deposits --- .../model/preingest/AnonymizedDeposit.java | 94 +++++++++++++++++++ .../java/ch/dlcm/model/preingest/Deposit.java | 11 --- .../java/ch/dlcm/rest/DLCMActionName.java | 1 + .../java/ch/dlcm/business/DepositService.java | 74 +++++++++++---- .../preingest/DepositController.java | 14 ++- .../AnonymizedDepositRepository.java | 48 ++++++++++ .../templates/anonymized_deposit.html | 34 +++++++ 7 files changed, 246 insertions(+), 30 deletions(-) create mode 100644 DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDeposit.java create mode 100644 DLCM-PreIngest/src/main/java/ch/dlcm/repository/AnonymizedDepositRepository.java create mode 100644 DLCM-PreIngest/src/main/resources/templates/anonymized_deposit.html diff --git a/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDeposit.java b/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDeposit.java new file mode 100644 index 0000000000..2889db7472 --- /dev/null +++ b/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDeposit.java @@ -0,0 +1,94 @@ +package ch.dlcm.model.preingest; + +import java.time.OffsetDateTime; +import java.util.Objects; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.persistence.Entity; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.validation.constraints.NotNull; + +import ch.unige.solidify.rest.ResourceNormalized; + +import ch.dlcm.DLCMConstants; +import ch.dlcm.rest.ModuleName; + +@Entity +public class AnonymizedDeposit extends ResourceNormalized { + + @Schema(description = "The corresponding non anonymized deposit") + @NotNull + @ManyToOne + @JoinColumn(name = DLCMConstants.DB_PACKAGE_ID, referencedColumnName = DLCMConstants.DB_RES_ID) + private Deposit deposit; + + @Schema(description = "The timestamp when the zip file of the anonymized deposit has been created") + private OffsetDateTime timestamp; + + @Schema(description = "The checksum of the checksums of all data files") + private String aggregateChecksum; + + @Schema(description = "The link id of the page listing all anonymized deposits of a same deposit") + private String linkId; + + public @NotNull Deposit getDeposit() { + return deposit; + } + + public OffsetDateTime getTimestamp() { + return timestamp; + } + + public String getAggregateChecksum() { + return aggregateChecksum; + } + + public String getLinkId() { + return linkId; + } + + public void setDeposit(@NotNull Deposit deposit) { + this.deposit = deposit; + } + + public void setTimestamp(OffsetDateTime timestamp) { + this.timestamp = timestamp; + } + + public void setAggregateChecksum(String aggregateChecksum) { + this.aggregateChecksum = aggregateChecksum; + } + + public void setLinkId(String linkId) { + this.linkId = linkId; + } + + @Override + public void init() { + // Do nothing + } + + @Override + public String managedBy() { + return ModuleName.PREINGEST; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + if (!super.equals(o)) + return false; + AnonymizedDeposit that = (AnonymizedDeposit) o; + return Objects.equals(deposit, that.deposit) && Objects.equals(timestamp, that.timestamp) && Objects.equals( + aggregateChecksum, that.aggregateChecksum); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), deposit, timestamp, aggregateChecksum); + } +} diff --git a/DLCM-Model/src/main/java/ch/dlcm/model/preingest/Deposit.java b/DLCM-Model/src/main/java/ch/dlcm/model/preingest/Deposit.java index b723d0c02c..a35a9a3a5c 100644 --- a/DLCM-Model/src/main/java/ch/dlcm/model/preingest/Deposit.java +++ b/DLCM-Model/src/main/java/ch/dlcm/model/preingest/Deposit.java @@ -333,9 +333,6 @@ public class Deposit extends SearchableResourceNormalized<Deposit> implements Re @JsonIgnore private List<String> subjectAreas = new ArrayList<>(); - @Schema(description = "The identifier of the last anonymized deposit, can be null") - private String lastAnonymizedDepositId; - @Override public <T> boolean addItem(T t) { @@ -497,10 +494,6 @@ public class Deposit extends SearchableResourceNormalized<Deposit> implements Re return this.subjectAreas; } - public String getLastAnonymizedDepositId() { - return this.lastAnonymizedDepositId; - } - /****************************************************************/ @JsonIgnore @@ -1006,10 +999,6 @@ public class Deposit extends SearchableResourceNormalized<Deposit> implements Re this.isObsoletedBy = doi; } - public void setLastAnonymizedDepositId(String lastAnonymizedDepositId) { - this.lastAnonymizedDepositId = lastAnonymizedDepositId; - } - private boolean addAip(ArchivalInfoPackage aip) { this.collection.add(aip.getResId()); return true; diff --git a/DLCM-Model/src/main/java/ch/dlcm/rest/DLCMActionName.java b/DLCM-Model/src/main/java/ch/dlcm/rest/DLCMActionName.java index 743e8ecdbe..78bd8b485a 100644 --- a/DLCM-Model/src/main/java/ch/dlcm/rest/DLCMActionName.java +++ b/DLCM-Model/src/main/java/ch/dlcm/rest/DLCMActionName.java @@ -128,6 +128,7 @@ public class DLCMActionName { public static final String DOWNLOAD_DUA = "download-dua"; public static final String DOWNLOAD_DATASET_FILE = "download-dataset-file"; public static final String DOWNLOAD_ANONYMIZED_DEPOSIT = "download-anonymized-deposit"; + public static final String GET_ANONYMIZED_DEPOSIT_PAGE = "get-anonymized-deposit-page"; public static final String DELETE_DUA = "delete-dua"; public static final String DELETE_DATASET_FILE = "delete-dataset-file"; diff --git a/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java b/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java index 253f0d5277..4742f28232 100644 --- a/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java +++ b/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java @@ -41,6 +41,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; +import java.util.UUID; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,6 +53,7 @@ import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; +import org.springframework.ui.Model; import org.springframework.validation.BindingResult; import org.springframework.validation.FieldError; @@ -97,6 +99,7 @@ import ch.dlcm.model.notification.NotificationType; import ch.dlcm.model.oais.ArchivalInfoPackage; import ch.dlcm.model.policies.PreservationPolicy; import ch.dlcm.model.policies.SubmissionPolicy; +import ch.dlcm.model.preingest.AnonymizedDeposit; import ch.dlcm.model.preingest.Deposit; import ch.dlcm.model.preingest.Deposit.DepositStatus; import ch.dlcm.model.security.User; @@ -108,6 +111,7 @@ import ch.dlcm.model.settings.SubjectArea; import ch.dlcm.model.settings.SubmissionAgreement; import ch.dlcm.model.xml.dlcm.v4.mets.RelationType; import ch.dlcm.preparation.PreparationService; +import ch.dlcm.repository.AnonymizedDepositRepository; import ch.dlcm.repository.DepositDataFileRepository; import ch.dlcm.repository.DepositRepository; import ch.dlcm.service.HistoryService; @@ -199,6 +203,7 @@ public class DepositService extends CompositeResourceService<Deposit> { private final HistoryService historyService; private final PreparationService preparationService; private final ChecksumAlgorithm defaultChecksumAlgorithm; + private final AnonymizedDepositRepository anonymizedDepositRepository; public DepositService(DLCMProperties dlcmProperties, @@ -222,7 +227,8 @@ public class DepositService extends CompositeResourceService<Deposit> { TrustedSubmissionAgreementUserRemoteResourceService trustedSubmissionAgreementUserRemoteResourceService, FallbackSubjectAreaRemoteResourceService subjectAreaService, HistoryService historyService, - @Lazy PreparationService preparationService) { + @Lazy PreparationService preparationService, + AnonymizedDepositRepository anonymizedDepositRepository) { this.dlcmProperties = dlcmProperties; this.depositDataFileRepository = depositDataFileRepository; this.specificationPermissionFilter = specificationPermissionFilter; @@ -246,6 +252,7 @@ public class DepositService extends CompositeResourceService<Deposit> { this.subjectAreaService = subjectAreaService; this.preparationService = preparationService; this.defaultChecksumAlgorithm = ChecksumAlgorithm.valueOf(dlcmProperties.getParameters().getDefaultChecksum()); + this.anonymizedDepositRepository = anonymizedDepositRepository; } /** @@ -1249,33 +1256,66 @@ public class DepositService extends CompositeResourceService<Deposit> { if (deposit.getStatus() != IN_PROGRESS) { throw new IllegalStateException(this.messageService.get("message.deposit.anonymized_download_link_only_for_in_progress")); } - + final Optional<AnonymizedDeposit> lastOptionalAnonymizedDeposit = this.anonymizedDepositRepository.findLastAnonymizedDeposit(deposit); final String depositDatafilesChecksum = this.getDepositDatafilesChecksum(deposit.getResId(), this.defaultChecksumAlgorithm); - final String lastAnonymizedDepositId = deposit.getLastAnonymizedDepositId(); - final Path lastAnonymizedFolder = Path.of(this.dlcmProperties.getPreingestLocation(), ANONYMIZED_DEPOSITS_FOLDER); - final Path lastZipFilePath = lastAnonymizedFolder.resolve(lastAnonymizedDepositId + SolidifyConstants.ZIP_EXT); - if (depositDatafilesChecksum.equals(lastAnonymizedDepositId)) { + final Path anonymizedDepositFolder = Path.of(this.dlcmProperties.getPreingestLocation(), ANONYMIZED_DEPOSITS_FOLDER); + + // Return existing anonymized deposit if no updates has been made + if (lastOptionalAnonymizedDeposit.isPresent() && + depositDatafilesChecksum.equals(lastOptionalAnonymizedDeposit.get().getAggregateChecksum())) { + final String lastAnonymizedDepositId = lastOptionalAnonymizedDeposit.get().getResId(); + final Path lastZipFilePath = anonymizedDepositFolder.resolve(lastAnonymizedDepositId + SolidifyConstants.ZIP_EXT); if (Files.exists(lastZipFilePath)) { - return depositDatafilesChecksum; + return lastOptionalAnonymizedDeposit.get().getLinkId(); } else { log.warn("Anonymized deposit {} is missing. Regenerating it.", lastZipFilePath); } } - deposit.setLastAnonymizedDepositId(depositDatafilesChecksum); - this.save(deposit); - if (lastAnonymizedDepositId != null) { + + // Create a new anonymized deposit + final AnonymizedDeposit anonymizedDeposit = new AnonymizedDeposit(); + anonymizedDeposit.setDeposit(deposit); + anonymizedDeposit.setTimestamp(OffsetDateTime.now()); + anonymizedDeposit.setAggregateChecksum(depositDatafilesChecksum); + anonymizedDeposit.setLinkId(UUID.randomUUID().toString()); + this.anonymizedDepositRepository.save(anonymizedDeposit); + new Thread(() -> { + final Path newZipFilePath = anonymizedDepositFolder.resolve(depositDatafilesChecksum + SolidifyConstants.ZIP_EXT); + final ZipTool zipTool = new ZipTool(newZipFilePath.toString()); + zipTool.zipFiles(Paths.get(this.dlcmProperties.getPreingestLocation() + "/" + deposit.getResId())); + }).start(); + + // Delete old anonymized deposit + if (lastOptionalAnonymizedDeposit.isPresent()) { + final String lastAnonymizedDepositId = lastOptionalAnonymizedDeposit.get().getResId(); try { - Files.delete(lastZipFilePath); + final Path lastZipFilePath = anonymizedDepositFolder.resolve(lastAnonymizedDepositId + SolidifyConstants.ZIP_EXT); + Files.deleteIfExists(lastZipFilePath); } catch (IOException e) { throw new SolidifyRuntimeException("Unable to delete old anonymized deposit " + lastAnonymizedDepositId, e); } } - new Thread(() -> { - final Path newZipFilePath = lastAnonymizedFolder.resolve(depositDatafilesChecksum + SolidifyConstants.ZIP_EXT); - final ZipTool zipTool = new ZipTool(newZipFilePath.toString()); - zipTool.zipFiles(Paths.get(this.dlcmProperties.getPreingestLocation() + "/" + deposit.getResId())); - }).start(); - return depositDatafilesChecksum; + + return anonymizedDeposit.getLinkId(); + } + + public String buildAnonymizedDepositPage(String anonymizedDepositLinkId, Model model) { + class AnonymizedDepositEntry { + private final String anonymizedDepositLink; + private final OffsetDateTime timestamp; + public AnonymizedDepositEntry(String anonymizedDepositLink, OffsetDateTime timestamp) { + this.anonymizedDepositLink = anonymizedDepositLink; + this.timestamp = timestamp; + } + public String getAnonymizedDepositLink() { return anonymizedDepositLink; } + public OffsetDateTime getTimestamp() { return timestamp; } + } + final List<AnonymizedDepositEntry> anonymizedDepositEntryList = new ArrayList<>(); + for (AnonymizedDeposit anonymizedDeposit : this.anonymizedDepositRepository.findAnonymizedDepositByLinkId(anonymizedDepositLinkId)) { + anonymizedDepositEntryList.add(new AnonymizedDepositEntry(anonymizedDeposit.getLinkId(), anonymizedDeposit.getTimestamp())); + } + model.addAttribute("anonymizedDepositEntryList", anonymizedDepositEntryList); + return "anonymizedDeposit"; } public String buildDownloadableDeposit(String depositId, String folder) { diff --git a/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java b/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java index 5624c91103..c1e334206b 100644 --- a/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java +++ b/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java @@ -64,6 +64,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; +import org.springframework.ui.Model; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; @@ -386,6 +387,15 @@ public class DepositController extends AbstractPackageController<DepositDataFile return new ResponseEntity<>(list, HttpStatus.OK); } + @GetMapping(SolidifyConstants.URL_ID_PLUS_SEP + DLCMActionName.GET_ANONYMIZED_DEPOSIT_PAGE) + @EveryonePermissions + public HttpEntity<String> getAnonymizedDepositPage(@PathVariable("id") String anonymizedDepositId, Model model) { + + + + return new HttpEntity<>("Hello"); + } + @GetMapping(SolidifyConstants.URL_ID_PLUS_SEP + DLCMActionName.DOWNLOAD_ANONYMIZED_DEPOSIT) @EveryonePermissions public HttpEntity<FileSystemResource> downloadAnonymizedDeposit(@PathVariable("id") String anonymizedDepositId) { @@ -399,9 +409,9 @@ public class DepositController extends AbstractPackageController<DepositDataFile @PreAuthorize("@depositPermissionService.isAllowed(#depositId, 'DOWNLOAD_FILE')") public HttpEntity<String> getAnonymizedDownloadLink(@PathVariable("id") String depositId) { final Deposit deposit = this.itemService.findOne(depositId); - final String anonymizedDepositId = ((DepositService) this.itemService).buildAnonymizedDownloadableDeposit(deposit); + final String linkIdForAnonymizedDeposit = ((DepositService) this.itemService).buildAnonymizedDownloadableDeposit(deposit); return new HttpEntity<>(this.config.getModule().getPreingest().getPublicUrl() + "/" + ResourceName.DEPOSIT + "/" + - anonymizedDepositId + "/" + DLCMActionName.DOWNLOAD_ANONYMIZED_DEPOSIT); + linkIdForAnonymizedDeposit + "/" + DLCMActionName.DOWNLOAD_ANONYMIZED_DEPOSIT); } @PreAuthorize("@depositPermissionService.isAllowed(#depositId, 'DOWNLOAD_FILE') " diff --git a/DLCM-PreIngest/src/main/java/ch/dlcm/repository/AnonymizedDepositRepository.java b/DLCM-PreIngest/src/main/java/ch/dlcm/repository/AnonymizedDepositRepository.java new file mode 100644 index 0000000000..2b67d9dc3a --- /dev/null +++ b/DLCM-PreIngest/src/main/java/ch/dlcm/repository/AnonymizedDepositRepository.java @@ -0,0 +1,48 @@ +/*- + * %%---------------------------------------------------------------------------------------------- + * DLCM Technology - DLCM PreIngest - DepositRepository.java + * SPDX-License-Identifier: GPL-2.0-or-later + * %----------------------------------------------------------------------------------------------% + * Copyright (C) 2017 - 2022 University of Geneva + * %----------------------------------------------------------------------------------------------% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-2.0.html>. + * ----------------------------------------------------------------------------------------------%% + */ + +package ch.dlcm.repository; + +import java.util.List; +import java.util.Optional; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import ch.unige.solidify.repository.SolidifyRepository; + +import ch.dlcm.controller.PreIngestController; +import ch.dlcm.model.preingest.AnonymizedDeposit; +import ch.dlcm.model.preingest.Deposit; + +@Repository +@ConditionalOnBean(PreIngestController.class) +public interface AnonymizedDepositRepository extends SolidifyRepository<AnonymizedDeposit> { + + @Query("SELECT ad FROM AnonymizedDeposit ad WHERE ad.deposit = :deposit ORDER BY ad.timestamp DESC LIMIT 1") + Optional<AnonymizedDeposit> findLastAnonymizedDeposit(Deposit deposit); + + List<AnonymizedDeposit> findAnonymizedDepositByLinkId(String linkId); + +} diff --git a/DLCM-PreIngest/src/main/resources/templates/anonymized_deposit.html b/DLCM-PreIngest/src/main/resources/templates/anonymized_deposit.html new file mode 100644 index 0000000000..2885d8627a --- /dev/null +++ b/DLCM-PreIngest/src/main/resources/templates/anonymized_deposit.html @@ -0,0 +1,34 @@ +<!DOCTYPE html> +<html xmlns:th="http://www.thymeleaf.org"> +<head> + <meta charset="UTF-8"> + <title>URL List</title> + <style> + body { font-family: Arial, sans-serif; } + table { width: 100%; border-collapse: collapse; margin-top: 20px; } + th, td { border: 1px solid #ddd; padding: 8px; text-align: left; } + th { background-color: #f2f2f2; } + </style> +</head> +<body> + +<h2>Welcome to the anonymized deposit download page</h2> +<table> + <thead> + <tr> + <th>#</th> + <th>URL</th> + <th>Timestamp</th> + </tr> + </thead> + <tbody> + <tr th:each="entry, index : ${anonymizedDepositEntryList}"> + <td th:text="${index.index + 1}"></td> + <td><a th:href="${entry.anonymizedDepositLink}" th:text="${entry.anonymizedDepositLink}" target="_blank"></a></td> + <td th:text="${#dates.format(entry.timestamp, 'yyyy-MM-dd HH:mm:ss')}"></td> + </tr> + </tbody> +</table> + +</body> +</html> \ No newline at end of file -- GitLab From a118104e82361d79e7f90237b5a4ceb8e310f89e Mon Sep 17 00:00:00 2001 From: Mathieu Vonlanthen <Mathieu.Vonlanthen@unige.ch> Date: Fri, 31 Jan 2025 16:44:43 +0100 Subject: [PATCH 02/14] chore: add missing header --- .../model/preingest/AnonymizedDeposit.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDeposit.java b/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDeposit.java index 2889db7472..07c0b350e4 100644 --- a/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDeposit.java +++ b/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDeposit.java @@ -1,3 +1,26 @@ +/*- + * %%---------------------------------------------------------------------------------------------- + * DLCM Technology - DLCM Model - AnonymizedDeposit.java + * SPDX-License-Identifier: GPL-2.0-or-later + * %----------------------------------------------------------------------------------------------% + * Copyright (C) 2017 - 2025 University of Geneva + * %----------------------------------------------------------------------------------------------% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-2.0.html>. + * ----------------------------------------------------------------------------------------------%% + */ + package ch.dlcm.model.preingest; import java.time.OffsetDateTime; -- GitLab From ffc987310ca16d725b1c521144109acad456fbbe Mon Sep 17 00:00:00 2001 From: Mathieu Vonlanthen <Mathieu.Vonlanthen@unige.ch> Date: Mon, 3 Feb 2025 17:39:24 +0100 Subject: [PATCH 03/14] feat(DepositControlelr): implement getAnonymizedDepositPage method --- .../model/preingest/AnonymizedDepositEntry.java | 14 ++++++++++++++ .../java/ch/dlcm/business/DepositService.java | 16 +++------------- .../controller/preingest/DepositController.java | 11 ++++++----- 3 files changed, 23 insertions(+), 18 deletions(-) create mode 100644 DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDepositEntry.java diff --git a/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDepositEntry.java b/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDepositEntry.java new file mode 100644 index 0000000000..8170612658 --- /dev/null +++ b/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDepositEntry.java @@ -0,0 +1,14 @@ +package ch.dlcm.model.preingest; + +import java.time.OffsetDateTime; + +public class AnonymizedDepositEntry { + private final String anonymizedDepositLink; + private final OffsetDateTime timestamp; + public AnonymizedDepositEntry(String anonymizedDepositLink, OffsetDateTime timestamp) { + this.anonymizedDepositLink = anonymizedDepositLink; + this.timestamp = timestamp; + } + public String getAnonymizedDepositLink() { return anonymizedDepositLink; } + public OffsetDateTime getTimestamp() { return timestamp; } +} \ No newline at end of file diff --git a/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java b/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java index 4742f28232..66b17931e0 100644 --- a/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java +++ b/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java @@ -100,6 +100,7 @@ import ch.dlcm.model.oais.ArchivalInfoPackage; import ch.dlcm.model.policies.PreservationPolicy; import ch.dlcm.model.policies.SubmissionPolicy; import ch.dlcm.model.preingest.AnonymizedDeposit; +import ch.dlcm.model.preingest.AnonymizedDepositEntry; import ch.dlcm.model.preingest.Deposit; import ch.dlcm.model.preingest.Deposit.DepositStatus; import ch.dlcm.model.security.User; @@ -1299,23 +1300,12 @@ public class DepositService extends CompositeResourceService<Deposit> { return anonymizedDeposit.getLinkId(); } - public String buildAnonymizedDepositPage(String anonymizedDepositLinkId, Model model) { - class AnonymizedDepositEntry { - private final String anonymizedDepositLink; - private final OffsetDateTime timestamp; - public AnonymizedDepositEntry(String anonymizedDepositLink, OffsetDateTime timestamp) { - this.anonymizedDepositLink = anonymizedDepositLink; - this.timestamp = timestamp; - } - public String getAnonymizedDepositLink() { return anonymizedDepositLink; } - public OffsetDateTime getTimestamp() { return timestamp; } - } + public List<AnonymizedDepositEntry> buildAnonymizedDepositPage(String anonymizedDepositLinkId, Model model) { final List<AnonymizedDepositEntry> anonymizedDepositEntryList = new ArrayList<>(); for (AnonymizedDeposit anonymizedDeposit : this.anonymizedDepositRepository.findAnonymizedDepositByLinkId(anonymizedDepositLinkId)) { anonymizedDepositEntryList.add(new AnonymizedDepositEntry(anonymizedDeposit.getLinkId(), anonymizedDeposit.getTimestamp())); } - model.addAttribute("anonymizedDepositEntryList", anonymizedDepositEntryList); - return "anonymizedDeposit"; + return anonymizedDepositEntryList; } public String buildDownloadableDeposit(String depositId, String folder) { diff --git a/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java b/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java index c1e334206b..72f16eadfa 100644 --- a/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java +++ b/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java @@ -118,6 +118,7 @@ import ch.dlcm.model.notification.NotificationStatus; import ch.dlcm.model.notification.NotificationType; import ch.dlcm.model.policies.SubmissionAgreementType; import ch.dlcm.model.policies.SubmissionPolicy; +import ch.dlcm.model.preingest.AnonymizedDepositEntry; import ch.dlcm.model.preingest.Deposit; import ch.dlcm.model.preingest.Deposit.DepositStatus; import ch.dlcm.model.preingest.DepositDataFile; @@ -389,11 +390,11 @@ public class DepositController extends AbstractPackageController<DepositDataFile @GetMapping(SolidifyConstants.URL_ID_PLUS_SEP + DLCMActionName.GET_ANONYMIZED_DEPOSIT_PAGE) @EveryonePermissions - public HttpEntity<String> getAnonymizedDepositPage(@PathVariable("id") String anonymizedDepositId, Model model) { - - - - return new HttpEntity<>("Hello"); + public String getAnonymizedDepositPage(@PathVariable("id") String anonymizedDepositLinkId, Model model) { + final List<AnonymizedDepositEntry> anonymizedDepositEntryList = + ((DepositService) this.itemService).buildAnonymizedDepositPage(anonymizedDepositLinkId, model); + model.addAttribute("anonymizedDepositEntryList", anonymizedDepositEntryList); + return "anonymizedDeposit"; } @GetMapping(SolidifyConstants.URL_ID_PLUS_SEP + DLCMActionName.DOWNLOAD_ANONYMIZED_DEPOSIT) -- GitLab From 74434ae8251b72c32bcdd12e2c271802b1ae97fa Mon Sep 17 00:00:00 2001 From: Mathieu Vonlanthen <Mathieu.Vonlanthen@unige.ch> Date: Tue, 4 Feb 2025 14:22:37 +0100 Subject: [PATCH 04/14] feat: allow to create an anonymized deposit page --- .../src/main/java/ch/dlcm/DLCMConstants.java | 2 ++ .../main/java/ch/dlcm/rest/DLCMActionName.java | 1 + .../java/ch/dlcm/business/DepositService.java | 3 +-- .../controller/preingest/DepositController.java | 17 +++++++++-------- ...ized_deposit.html => anonymizedDeposit.html} | 2 +- 5 files changed, 14 insertions(+), 11 deletions(-) rename DLCM-PreIngest/src/main/resources/templates/{anonymized_deposit.html => anonymizedDeposit.html} (90%) diff --git a/DLCM-Model/src/main/java/ch/dlcm/DLCMConstants.java b/DLCM-Model/src/main/java/ch/dlcm/DLCMConstants.java index f6b047f3f0..374c56f79f 100644 --- a/DLCM-Model/src/main/java/ch/dlcm/DLCMConstants.java +++ b/DLCM-Model/src/main/java/ch/dlcm/DLCMConstants.java @@ -98,6 +98,8 @@ public class DLCMConstants { "/" + ModuleName.PRES_PLANNING + "/" + ResourceName.MODULE, "/" + ModuleName.ARCHIVALSTORAGE + "/" + ResourceName.AIP + "/*/" + ActionName.DOWNLOAD, "/" + ModuleName.PREINGEST + "/" + ResourceName.DEPOSIT + "/*/" + ActionName.DOWNLOAD, + "/" + ModuleName.PREINGEST + "/" + ResourceName.DEPOSIT + "/*/" + DLCMActionName.GET_ANONYMIZED_DEPOSIT_PAGE, + "/" + ModuleName.PREINGEST + "/" + ResourceName.DEPOSIT + "/*/" + DLCMActionName.DOWNLOAD_ANONYMIZED_DEPOSIT, "/" + ModuleName.PREINGEST + "/" + ResourceName.DEPOSIT + "/*/" + ResourceName.DATAFILE + "/*/" +ActionName.DOWNLOAD, "/" + ModuleName.INGEST + "/" + ResourceName.SIP + "/*/" + ActionName.DOWNLOAD, "/" + ModuleName.INGEST + "/" + ResourceName.SIP + "/*/" + ResourceName.DATAFILE + "/*/" +ActionName.DOWNLOAD, diff --git a/DLCM-Model/src/main/java/ch/dlcm/rest/DLCMActionName.java b/DLCM-Model/src/main/java/ch/dlcm/rest/DLCMActionName.java index 78bd8b485a..718fe861c9 100644 --- a/DLCM-Model/src/main/java/ch/dlcm/rest/DLCMActionName.java +++ b/DLCM-Model/src/main/java/ch/dlcm/rest/DLCMActionName.java @@ -149,6 +149,7 @@ public class DLCMActionName { public static final String GET_MY_ACLS = "get-my-acls"; public static final String GET_MY_APPROBATIONS = "get-my-approbations"; public static final String GET_ANONYMIZED_DOWNLOAD_LINK = "get-anonymized-download-link"; + public static final String CREATE_ANONYMIZED_DEPOSIT_PAGE = "create-anonymized-deposit-page"; public static final String LIST_INHERITED_ROLE = "list-inherited-role"; public static final String LIST_INHERITED_PERSON_ROLES = "list-inherited-person-roles"; diff --git a/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java b/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java index 66b17931e0..fdd05bf0eb 100644 --- a/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java +++ b/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java @@ -53,7 +53,6 @@ import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; -import org.springframework.ui.Model; import org.springframework.validation.BindingResult; import org.springframework.validation.FieldError; @@ -1300,7 +1299,7 @@ public class DepositService extends CompositeResourceService<Deposit> { return anonymizedDeposit.getLinkId(); } - public List<AnonymizedDepositEntry> buildAnonymizedDepositPage(String anonymizedDepositLinkId, Model model) { + public List<AnonymizedDepositEntry> buildAnonymizedDepositEntryList(String anonymizedDepositLinkId) { final List<AnonymizedDepositEntry> anonymizedDepositEntryList = new ArrayList<>(); for (AnonymizedDeposit anonymizedDeposit : this.anonymizedDepositRepository.findAnonymizedDepositByLinkId(anonymizedDepositLinkId)) { anonymizedDepositEntryList.add(new AnonymizedDepositEntry(anonymizedDeposit.getLinkId(), anonymizedDeposit.getTimestamp())); diff --git a/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java b/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java index 72f16eadfa..9f2ec7bc2e 100644 --- a/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java +++ b/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java @@ -64,7 +64,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; -import org.springframework.ui.Model; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; @@ -75,6 +74,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody; import ch.unige.solidify.ChecksumAlgorithm; @@ -390,11 +390,12 @@ public class DepositController extends AbstractPackageController<DepositDataFile @GetMapping(SolidifyConstants.URL_ID_PLUS_SEP + DLCMActionName.GET_ANONYMIZED_DEPOSIT_PAGE) @EveryonePermissions - public String getAnonymizedDepositPage(@PathVariable("id") String anonymizedDepositLinkId, Model model) { + public ModelAndView getAnonymizedDepositPage(@PathVariable("id") String anonymizedDepositLinkId) { + final ModelAndView modelAndView = new ModelAndView("anonymizedDeposit"); final List<AnonymizedDepositEntry> anonymizedDepositEntryList = - ((DepositService) this.itemService).buildAnonymizedDepositPage(anonymizedDepositLinkId, model); - model.addAttribute("anonymizedDepositEntryList", anonymizedDepositEntryList); - return "anonymizedDeposit"; + ((DepositService) this.itemService).buildAnonymizedDepositEntryList(anonymizedDepositLinkId); + modelAndView.addObject("anonymizedDepositEntryList", anonymizedDepositEntryList); + return modelAndView; } @GetMapping(SolidifyConstants.URL_ID_PLUS_SEP + DLCMActionName.DOWNLOAD_ANONYMIZED_DEPOSIT) @@ -406,13 +407,13 @@ public class DepositController extends AbstractPackageController<DepositDataFile SolidifyConstants.ZIP_MIME_TYPE, FileTool.getSize(Paths.get(zipFileLocation))); } - @GetMapping(SolidifyConstants.URL_ID_PLUS_SEP + DLCMActionName.GET_ANONYMIZED_DOWNLOAD_LINK) + @PostMapping(SolidifyConstants.URL_ID_PLUS_SEP + DLCMActionName.CREATE_ANONYMIZED_DEPOSIT_PAGE) @PreAuthorize("@depositPermissionService.isAllowed(#depositId, 'DOWNLOAD_FILE')") - public HttpEntity<String> getAnonymizedDownloadLink(@PathVariable("id") String depositId) { + public HttpEntity<String> createAnonymizedDepositPage(@PathVariable("id") String depositId) { final Deposit deposit = this.itemService.findOne(depositId); final String linkIdForAnonymizedDeposit = ((DepositService) this.itemService).buildAnonymizedDownloadableDeposit(deposit); return new HttpEntity<>(this.config.getModule().getPreingest().getPublicUrl() + "/" + ResourceName.DEPOSIT + "/" + - linkIdForAnonymizedDeposit + "/" + DLCMActionName.DOWNLOAD_ANONYMIZED_DEPOSIT); + linkIdForAnonymizedDeposit + "/" + DLCMActionName.GET_ANONYMIZED_DEPOSIT_PAGE); } @PreAuthorize("@depositPermissionService.isAllowed(#depositId, 'DOWNLOAD_FILE') " diff --git a/DLCM-PreIngest/src/main/resources/templates/anonymized_deposit.html b/DLCM-PreIngest/src/main/resources/templates/anonymizedDeposit.html similarity index 90% rename from DLCM-PreIngest/src/main/resources/templates/anonymized_deposit.html rename to DLCM-PreIngest/src/main/resources/templates/anonymizedDeposit.html index 2885d8627a..a36debb04a 100644 --- a/DLCM-PreIngest/src/main/resources/templates/anonymized_deposit.html +++ b/DLCM-PreIngest/src/main/resources/templates/anonymizedDeposit.html @@ -25,7 +25,7 @@ <tr th:each="entry, index : ${anonymizedDepositEntryList}"> <td th:text="${index.index + 1}"></td> <td><a th:href="${entry.anonymizedDepositLink}" th:text="${entry.anonymizedDepositLink}" target="_blank"></a></td> - <td th:text="${#dates.format(entry.timestamp, 'yyyy-MM-dd HH:mm:ss')}"></td> + <!--<td th:text="${#dates.format(entry.timestamp, 'yyyy-MM-dd HH:mm:ss')}"></td>--> </tr> </tbody> </table> -- GitLab From 5dbd9779e0933e0ce5d029f12d70ac19acbb19d6 Mon Sep 17 00:00:00 2001 From: Mathieu Vonlanthen <Mathieu.Vonlanthen@unige.ch> Date: Tue, 4 Feb 2025 14:41:00 +0100 Subject: [PATCH 05/14] fix: fix anonymized deposit URL in anonymized deposit page --- .../java/ch/dlcm/controller/preingest/DepositController.java | 1 + .../src/main/resources/templates/anonymizedDeposit.html | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java b/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java index 9f2ec7bc2e..aef04533ae 100644 --- a/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java +++ b/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java @@ -395,6 +395,7 @@ public class DepositController extends AbstractPackageController<DepositDataFile final List<AnonymizedDepositEntry> anonymizedDepositEntryList = ((DepositService) this.itemService).buildAnonymizedDepositEntryList(anonymizedDepositLinkId); modelAndView.addObject("anonymizedDepositEntryList", anonymizedDepositEntryList); + modelAndView.addObject("preingestUrl", this.config.getModule().getPreingest().getPublicUrl()); return modelAndView; } diff --git a/DLCM-PreIngest/src/main/resources/templates/anonymizedDeposit.html b/DLCM-PreIngest/src/main/resources/templates/anonymizedDeposit.html index a36debb04a..9307e905b5 100644 --- a/DLCM-PreIngest/src/main/resources/templates/anonymizedDeposit.html +++ b/DLCM-PreIngest/src/main/resources/templates/anonymizedDeposit.html @@ -24,7 +24,7 @@ <tbody> <tr th:each="entry, index : ${anonymizedDepositEntryList}"> <td th:text="${index.index + 1}"></td> - <td><a th:href="${entry.anonymizedDepositLink}" th:text="${entry.anonymizedDepositLink}" target="_blank"></a></td> + <td><a th:href="${preingestUrl} + '/deposits/' + ${entry.anonymizedDepositLink} + '/download-anonymized-deposit'" th:text="${entry.anonymizedDepositLink}" target="_blank"></a></td> <!--<td th:text="${#dates.format(entry.timestamp, 'yyyy-MM-dd HH:mm:ss')}"></td>--> </tr> </tbody> -- GitLab From 04934fb98f0d6413800c0c46e0f7b350ce784d4f Mon Sep 17 00:00:00 2001 From: Mathieu Vonlanthen <Mathieu.Vonlanthen@unige.ch> Date: Tue, 4 Feb 2025 14:51:03 +0100 Subject: [PATCH 06/14] fix: use anonymizedDepositResId in AnonymizedDepositEntry --- .../ch/dlcm/model/preingest/AnonymizedDepositEntry.java | 8 ++++---- .../src/main/java/ch/dlcm/business/DepositService.java | 2 +- .../src/main/resources/templates/anonymizedDeposit.html | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDepositEntry.java b/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDepositEntry.java index 8170612658..fc3dc3c210 100644 --- a/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDepositEntry.java +++ b/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDepositEntry.java @@ -3,12 +3,12 @@ package ch.dlcm.model.preingest; import java.time.OffsetDateTime; public class AnonymizedDepositEntry { - private final String anonymizedDepositLink; + private final String anonymizedDepositResId; private final OffsetDateTime timestamp; - public AnonymizedDepositEntry(String anonymizedDepositLink, OffsetDateTime timestamp) { - this.anonymizedDepositLink = anonymizedDepositLink; + public AnonymizedDepositEntry(String anonymizedDepositResId, OffsetDateTime timestamp) { + this.anonymizedDepositResId = anonymizedDepositResId; this.timestamp = timestamp; } - public String getAnonymizedDepositLink() { return anonymizedDepositLink; } + public String getAnonymizedDepositResId() { return anonymizedDepositResId; } public OffsetDateTime getTimestamp() { return timestamp; } } \ No newline at end of file diff --git a/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java b/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java index fdd05bf0eb..72021723f3 100644 --- a/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java +++ b/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java @@ -1302,7 +1302,7 @@ public class DepositService extends CompositeResourceService<Deposit> { public List<AnonymizedDepositEntry> buildAnonymizedDepositEntryList(String anonymizedDepositLinkId) { final List<AnonymizedDepositEntry> anonymizedDepositEntryList = new ArrayList<>(); for (AnonymizedDeposit anonymizedDeposit : this.anonymizedDepositRepository.findAnonymizedDepositByLinkId(anonymizedDepositLinkId)) { - anonymizedDepositEntryList.add(new AnonymizedDepositEntry(anonymizedDeposit.getLinkId(), anonymizedDeposit.getTimestamp())); + anonymizedDepositEntryList.add(new AnonymizedDepositEntry(anonymizedDeposit.getResId(), anonymizedDeposit.getTimestamp())); } return anonymizedDepositEntryList; } diff --git a/DLCM-PreIngest/src/main/resources/templates/anonymizedDeposit.html b/DLCM-PreIngest/src/main/resources/templates/anonymizedDeposit.html index 9307e905b5..197a0fb4b0 100644 --- a/DLCM-PreIngest/src/main/resources/templates/anonymizedDeposit.html +++ b/DLCM-PreIngest/src/main/resources/templates/anonymizedDeposit.html @@ -24,7 +24,7 @@ <tbody> <tr th:each="entry, index : ${anonymizedDepositEntryList}"> <td th:text="${index.index + 1}"></td> - <td><a th:href="${preingestUrl} + '/deposits/' + ${entry.anonymizedDepositLink} + '/download-anonymized-deposit'" th:text="${entry.anonymizedDepositLink}" target="_blank"></a></td> + <td><a th:href="${preingestUrl} + '/deposits/' + ${entry.anonymizedDepositResId} + '/download-anonymized-deposit'" th:text="${entry.anonymizedDepositResId}" target="_blank"></a></td> <!--<td th:text="${#dates.format(entry.timestamp, 'yyyy-MM-dd HH:mm:ss')}"></td>--> </tr> </tbody> -- GitLab From 1159fe519a0a36d54ee9d08f93e7339f6d698f66 Mon Sep 17 00:00:00 2001 From: Mathieu Vonlanthen <Mathieu.Vonlanthen@unige.ch> Date: Tue, 4 Feb 2025 14:58:11 +0100 Subject: [PATCH 07/14] refactor: renaming --- .../src/main/java/ch/dlcm/business/DepositService.java | 2 +- .../java/ch/dlcm/controller/preingest/DepositController.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java b/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java index 72021723f3..395d1f7c43 100644 --- a/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java +++ b/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java @@ -1260,7 +1260,7 @@ public class DepositService extends CompositeResourceService<Deposit> { final String depositDatafilesChecksum = this.getDepositDatafilesChecksum(deposit.getResId(), this.defaultChecksumAlgorithm); final Path anonymizedDepositFolder = Path.of(this.dlcmProperties.getPreingestLocation(), ANONYMIZED_DEPOSITS_FOLDER); - // Return existing anonymized deposit if no updates has been made + // Return existing anonymized deposit link id if no updates has been made if (lastOptionalAnonymizedDeposit.isPresent() && depositDatafilesChecksum.equals(lastOptionalAnonymizedDeposit.get().getAggregateChecksum())) { final String lastAnonymizedDepositId = lastOptionalAnonymizedDeposit.get().getResId(); diff --git a/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java b/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java index aef04533ae..6aa1d37700 100644 --- a/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java +++ b/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java @@ -412,9 +412,9 @@ public class DepositController extends AbstractPackageController<DepositDataFile @PreAuthorize("@depositPermissionService.isAllowed(#depositId, 'DOWNLOAD_FILE')") public HttpEntity<String> createAnonymizedDepositPage(@PathVariable("id") String depositId) { final Deposit deposit = this.itemService.findOne(depositId); - final String linkIdForAnonymizedDeposit = ((DepositService) this.itemService).buildAnonymizedDownloadableDeposit(deposit); + final String anonymizedDepositLinkId = ((DepositService) this.itemService).buildAnonymizedDownloadableDeposit(deposit); return new HttpEntity<>(this.config.getModule().getPreingest().getPublicUrl() + "/" + ResourceName.DEPOSIT + "/" + - linkIdForAnonymizedDeposit + "/" + DLCMActionName.GET_ANONYMIZED_DEPOSIT_PAGE); + anonymizedDepositLinkId + "/" + DLCMActionName.GET_ANONYMIZED_DEPOSIT_PAGE); } @PreAuthorize("@depositPermissionService.isAllowed(#depositId, 'DOWNLOAD_FILE') " -- GitLab From f763c6d9ad80be0e7ef0e74049bd68d13527acbf Mon Sep 17 00:00:00 2001 From: Mathieu Vonlanthen <Mathieu.Vonlanthen@unige.ch> Date: Tue, 4 Feb 2025 15:44:23 +0100 Subject: [PATCH 08/14] refactor: renaming --- .../model/preingest/AnonymizedDeposit.java | 12 ++++---- .../java/ch/dlcm/business/DepositService.java | 28 +++++++++++-------- .../preingest/DepositController.java | 10 +++---- .../AnonymizedDepositRepository.java | 2 +- .../templates/anonymizedDeposit.html | 2 +- 5 files changed, 29 insertions(+), 25 deletions(-) diff --git a/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDeposit.java b/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDeposit.java index 07c0b350e4..e7786ac0a8 100644 --- a/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDeposit.java +++ b/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDeposit.java @@ -52,8 +52,8 @@ public class AnonymizedDeposit extends ResourceNormalized { @Schema(description = "The checksum of the checksums of all data files") private String aggregateChecksum; - @Schema(description = "The link id of the page listing all anonymized deposits of a same deposit") - private String linkId; + @Schema(description = "The id of the page listing all anonymized deposits of a given deposit") + private String pageId; public @NotNull Deposit getDeposit() { return deposit; @@ -67,8 +67,8 @@ public class AnonymizedDeposit extends ResourceNormalized { return aggregateChecksum; } - public String getLinkId() { - return linkId; + public String getPageId() { + return pageId; } public void setDeposit(@NotNull Deposit deposit) { @@ -83,8 +83,8 @@ public class AnonymizedDeposit extends ResourceNormalized { this.aggregateChecksum = aggregateChecksum; } - public void setLinkId(String linkId) { - this.linkId = linkId; + public void setPageId(String linkId) { + this.pageId = linkId; } @Override diff --git a/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java b/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java index 395d1f7c43..ec876b9a4e 100644 --- a/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java +++ b/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java @@ -1252,7 +1252,7 @@ public class DepositService extends CompositeResourceService<Deposit> { + " approved by user " + userInfo; } - public String buildAnonymizedDownloadableDeposit(Deposit deposit) { + public String buildAnonymizedDeposit(Deposit deposit) { if (deposit.getStatus() != IN_PROGRESS) { throw new IllegalStateException(this.messageService.get("message.deposit.anonymized_download_link_only_for_in_progress")); } @@ -1260,15 +1260,15 @@ public class DepositService extends CompositeResourceService<Deposit> { final String depositDatafilesChecksum = this.getDepositDatafilesChecksum(deposit.getResId(), this.defaultChecksumAlgorithm); final Path anonymizedDepositFolder = Path.of(this.dlcmProperties.getPreingestLocation(), ANONYMIZED_DEPOSITS_FOLDER); - // Return existing anonymized deposit link id if no updates has been made + // Return the existing anonymized deposit page id if no updates has been made and anonymized deposit is still present if (lastOptionalAnonymizedDeposit.isPresent() && depositDatafilesChecksum.equals(lastOptionalAnonymizedDeposit.get().getAggregateChecksum())) { final String lastAnonymizedDepositId = lastOptionalAnonymizedDeposit.get().getResId(); - final Path lastZipFilePath = anonymizedDepositFolder.resolve(lastAnonymizedDepositId + SolidifyConstants.ZIP_EXT); - if (Files.exists(lastZipFilePath)) { - return lastOptionalAnonymizedDeposit.get().getLinkId(); + final Path lastAnonymizedDepositPath = anonymizedDepositFolder.resolve(lastAnonymizedDepositId + SolidifyConstants.ZIP_EXT); + if (Files.exists(lastAnonymizedDepositPath)) { + return lastOptionalAnonymizedDeposit.get().getPageId(); } else { - log.warn("Anonymized deposit {} is missing. Regenerating it.", lastZipFilePath); + log.warn("Anonymized deposit {} is missing. Regenerating it.", lastAnonymizedDepositPath); } } @@ -1277,7 +1277,11 @@ public class DepositService extends CompositeResourceService<Deposit> { anonymizedDeposit.setDeposit(deposit); anonymizedDeposit.setTimestamp(OffsetDateTime.now()); anonymizedDeposit.setAggregateChecksum(depositDatafilesChecksum); - anonymizedDeposit.setLinkId(UUID.randomUUID().toString()); + if (lastOptionalAnonymizedDeposit.isPresent()) { + anonymizedDeposit.setPageId(lastOptionalAnonymizedDeposit.get().getPageId()); + } else { + anonymizedDeposit.setPageId(UUID.randomUUID().toString()); + } this.anonymizedDepositRepository.save(anonymizedDeposit); new Thread(() -> { final Path newZipFilePath = anonymizedDepositFolder.resolve(depositDatafilesChecksum + SolidifyConstants.ZIP_EXT); @@ -1289,19 +1293,19 @@ public class DepositService extends CompositeResourceService<Deposit> { if (lastOptionalAnonymizedDeposit.isPresent()) { final String lastAnonymizedDepositId = lastOptionalAnonymizedDeposit.get().getResId(); try { - final Path lastZipFilePath = anonymizedDepositFolder.resolve(lastAnonymizedDepositId + SolidifyConstants.ZIP_EXT); - Files.deleteIfExists(lastZipFilePath); + final Path lastAnonymizedDepositPath = anonymizedDepositFolder.resolve(lastAnonymizedDepositId + SolidifyConstants.ZIP_EXT); + Files.deleteIfExists(lastAnonymizedDepositPath); } catch (IOException e) { throw new SolidifyRuntimeException("Unable to delete old anonymized deposit " + lastAnonymizedDepositId, e); } } - return anonymizedDeposit.getLinkId(); + return anonymizedDeposit.getPageId(); } - public List<AnonymizedDepositEntry> buildAnonymizedDepositEntryList(String anonymizedDepositLinkId) { + public List<AnonymizedDepositEntry> buildAnonymizedDepositEntryList(String anonymizedDepositPageId) { final List<AnonymizedDepositEntry> anonymizedDepositEntryList = new ArrayList<>(); - for (AnonymizedDeposit anonymizedDeposit : this.anonymizedDepositRepository.findAnonymizedDepositByLinkId(anonymizedDepositLinkId)) { + for (AnonymizedDeposit anonymizedDeposit : this.anonymizedDepositRepository.findAnonymizedDepositByPageId(anonymizedDepositPageId)) { anonymizedDepositEntryList.add(new AnonymizedDepositEntry(anonymizedDeposit.getResId(), anonymizedDeposit.getTimestamp())); } return anonymizedDepositEntryList; diff --git a/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java b/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java index 6aa1d37700..121b3f1f6d 100644 --- a/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java +++ b/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java @@ -390,12 +390,12 @@ public class DepositController extends AbstractPackageController<DepositDataFile @GetMapping(SolidifyConstants.URL_ID_PLUS_SEP + DLCMActionName.GET_ANONYMIZED_DEPOSIT_PAGE) @EveryonePermissions - public ModelAndView getAnonymizedDepositPage(@PathVariable("id") String anonymizedDepositLinkId) { + public ModelAndView getAnonymizedDepositPage(@PathVariable("id") String anonymizedDepositPageId) { final ModelAndView modelAndView = new ModelAndView("anonymizedDeposit"); final List<AnonymizedDepositEntry> anonymizedDepositEntryList = - ((DepositService) this.itemService).buildAnonymizedDepositEntryList(anonymizedDepositLinkId); + ((DepositService) this.itemService).buildAnonymizedDepositEntryList(anonymizedDepositPageId); modelAndView.addObject("anonymizedDepositEntryList", anonymizedDepositEntryList); - modelAndView.addObject("preingestUrl", this.config.getModule().getPreingest().getPublicUrl()); + modelAndView.addObject("preingestPublicUrl", this.config.getModule().getPreingest().getPublicUrl()); return modelAndView; } @@ -412,9 +412,9 @@ public class DepositController extends AbstractPackageController<DepositDataFile @PreAuthorize("@depositPermissionService.isAllowed(#depositId, 'DOWNLOAD_FILE')") public HttpEntity<String> createAnonymizedDepositPage(@PathVariable("id") String depositId) { final Deposit deposit = this.itemService.findOne(depositId); - final String anonymizedDepositLinkId = ((DepositService) this.itemService).buildAnonymizedDownloadableDeposit(deposit); + final String anonymizedDepositPageId = ((DepositService) this.itemService).buildAnonymizedDeposit(deposit); return new HttpEntity<>(this.config.getModule().getPreingest().getPublicUrl() + "/" + ResourceName.DEPOSIT + "/" + - anonymizedDepositLinkId + "/" + DLCMActionName.GET_ANONYMIZED_DEPOSIT_PAGE); + anonymizedDepositPageId + "/" + DLCMActionName.GET_ANONYMIZED_DEPOSIT_PAGE); } @PreAuthorize("@depositPermissionService.isAllowed(#depositId, 'DOWNLOAD_FILE') " diff --git a/DLCM-PreIngest/src/main/java/ch/dlcm/repository/AnonymizedDepositRepository.java b/DLCM-PreIngest/src/main/java/ch/dlcm/repository/AnonymizedDepositRepository.java index 2b67d9dc3a..8ecb6e3e26 100644 --- a/DLCM-PreIngest/src/main/java/ch/dlcm/repository/AnonymizedDepositRepository.java +++ b/DLCM-PreIngest/src/main/java/ch/dlcm/repository/AnonymizedDepositRepository.java @@ -43,6 +43,6 @@ public interface AnonymizedDepositRepository extends SolidifyRepository<Anonymiz @Query("SELECT ad FROM AnonymizedDeposit ad WHERE ad.deposit = :deposit ORDER BY ad.timestamp DESC LIMIT 1") Optional<AnonymizedDeposit> findLastAnonymizedDeposit(Deposit deposit); - List<AnonymizedDeposit> findAnonymizedDepositByLinkId(String linkId); + List<AnonymizedDeposit> findAnonymizedDepositByPageId(String pageId); } diff --git a/DLCM-PreIngest/src/main/resources/templates/anonymizedDeposit.html b/DLCM-PreIngest/src/main/resources/templates/anonymizedDeposit.html index 197a0fb4b0..02fb07f52b 100644 --- a/DLCM-PreIngest/src/main/resources/templates/anonymizedDeposit.html +++ b/DLCM-PreIngest/src/main/resources/templates/anonymizedDeposit.html @@ -24,7 +24,7 @@ <tbody> <tr th:each="entry, index : ${anonymizedDepositEntryList}"> <td th:text="${index.index + 1}"></td> - <td><a th:href="${preingestUrl} + '/deposits/' + ${entry.anonymizedDepositResId} + '/download-anonymized-deposit'" th:text="${entry.anonymizedDepositResId}" target="_blank"></a></td> + <td><a th:href="${preingestPublicUrl} + '/deposits/' + ${entry.anonymizedDepositResId} + '/download-anonymized-deposit'" th:text="${entry.anonymizedDepositResId}" target="_blank"></a></td> <!--<td th:text="${#dates.format(entry.timestamp, 'yyyy-MM-dd HH:mm:ss')}"></td>--> </tr> </tbody> -- GitLab From 6488cbd6ccaf454b2bab0822134d3661cf36103b Mon Sep 17 00:00:00 2001 From: Mathieu Vonlanthen <Mathieu.Vonlanthen@unige.ch> Date: Tue, 4 Feb 2025 15:55:03 +0100 Subject: [PATCH 09/14] fix: fix: anonymized deposit path --- .../src/main/java/ch/dlcm/business/DepositService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java b/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java index ec876b9a4e..6cd2b56658 100644 --- a/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java +++ b/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java @@ -1284,8 +1284,8 @@ public class DepositService extends CompositeResourceService<Deposit> { } this.anonymizedDepositRepository.save(anonymizedDeposit); new Thread(() -> { - final Path newZipFilePath = anonymizedDepositFolder.resolve(depositDatafilesChecksum + SolidifyConstants.ZIP_EXT); - final ZipTool zipTool = new ZipTool(newZipFilePath.toString()); + final Path newAnonymizedDepositPath = anonymizedDepositFolder.resolve(anonymizedDeposit.getResId() + SolidifyConstants.ZIP_EXT); + final ZipTool zipTool = new ZipTool(newAnonymizedDepositPath.toString()); zipTool.zipFiles(Paths.get(this.dlcmProperties.getPreingestLocation() + "/" + deposit.getResId())); }).start(); -- GitLab From 689e448b3a920c0ca5b552f573cf0ea4989f3ad8 Mon Sep 17 00:00:00 2001 From: Mathieu Vonlanthen <Mathieu.Vonlanthen@unige.ch> Date: Tue, 4 Feb 2025 16:23:21 +0100 Subject: [PATCH 10/14] fix: timestamp problem --- .../ch/dlcm/model/preingest/AnonymizedDepositEntry.java | 8 +++----- .../src/main/java/ch/dlcm/business/DepositService.java | 2 +- .../src/main/resources/templates/anonymizedDeposit.html | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDepositEntry.java b/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDepositEntry.java index fc3dc3c210..ab880a9bf2 100644 --- a/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDepositEntry.java +++ b/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDepositEntry.java @@ -1,14 +1,12 @@ package ch.dlcm.model.preingest; -import java.time.OffsetDateTime; - public class AnonymizedDepositEntry { private final String anonymizedDepositResId; - private final OffsetDateTime timestamp; - public AnonymizedDepositEntry(String anonymizedDepositResId, OffsetDateTime timestamp) { + private final String timestamp; + public AnonymizedDepositEntry(String anonymizedDepositResId, String timestamp) { this.anonymizedDepositResId = anonymizedDepositResId; this.timestamp = timestamp; } public String getAnonymizedDepositResId() { return anonymizedDepositResId; } - public OffsetDateTime getTimestamp() { return timestamp; } + public String getTimestamp() { return timestamp; } } \ No newline at end of file diff --git a/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java b/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java index 6cd2b56658..02cab48730 100644 --- a/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java +++ b/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java @@ -1306,7 +1306,7 @@ public class DepositService extends CompositeResourceService<Deposit> { public List<AnonymizedDepositEntry> buildAnonymizedDepositEntryList(String anonymizedDepositPageId) { final List<AnonymizedDepositEntry> anonymizedDepositEntryList = new ArrayList<>(); for (AnonymizedDeposit anonymizedDeposit : this.anonymizedDepositRepository.findAnonymizedDepositByPageId(anonymizedDepositPageId)) { - anonymizedDepositEntryList.add(new AnonymizedDepositEntry(anonymizedDeposit.getResId(), anonymizedDeposit.getTimestamp())); + anonymizedDepositEntryList.add(new AnonymizedDepositEntry(anonymizedDeposit.getResId(), anonymizedDeposit.getTimestamp().toString())); } return anonymizedDepositEntryList; } diff --git a/DLCM-PreIngest/src/main/resources/templates/anonymizedDeposit.html b/DLCM-PreIngest/src/main/resources/templates/anonymizedDeposit.html index 02fb07f52b..47a6868b7e 100644 --- a/DLCM-PreIngest/src/main/resources/templates/anonymizedDeposit.html +++ b/DLCM-PreIngest/src/main/resources/templates/anonymizedDeposit.html @@ -25,7 +25,7 @@ <tr th:each="entry, index : ${anonymizedDepositEntryList}"> <td th:text="${index.index + 1}"></td> <td><a th:href="${preingestPublicUrl} + '/deposits/' + ${entry.anonymizedDepositResId} + '/download-anonymized-deposit'" th:text="${entry.anonymizedDepositResId}" target="_blank"></a></td> - <!--<td th:text="${#dates.format(entry.timestamp, 'yyyy-MM-dd HH:mm:ss')}"></td>--> + <td th:text="${entry.timestamp}"></td> </tr> </tbody> </table> -- GitLab From 727ab6f38afa7377a010d83e28ed0335f3d0c405 Mon Sep 17 00:00:00 2001 From: Mathieu Vonlanthen <Mathieu.Vonlanthen@unige.ch> Date: Tue, 4 Feb 2025 16:30:47 +0100 Subject: [PATCH 11/14] refactor: renaming --- DLCM-Model/src/main/java/ch/dlcm/rest/DLCMActionName.java | 3 +-- .../java/ch/dlcm/controller/preingest/DepositController.java | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/DLCM-Model/src/main/java/ch/dlcm/rest/DLCMActionName.java b/DLCM-Model/src/main/java/ch/dlcm/rest/DLCMActionName.java index 718fe861c9..cb19fbd28b 100644 --- a/DLCM-Model/src/main/java/ch/dlcm/rest/DLCMActionName.java +++ b/DLCM-Model/src/main/java/ch/dlcm/rest/DLCMActionName.java @@ -148,8 +148,7 @@ public class DLCMActionName { public static final String GET_ALL_APPROBATIONS = "get-all-approbations"; public static final String GET_MY_ACLS = "get-my-acls"; public static final String GET_MY_APPROBATIONS = "get-my-approbations"; - public static final String GET_ANONYMIZED_DOWNLOAD_LINK = "get-anonymized-download-link"; - public static final String CREATE_ANONYMIZED_DEPOSIT_PAGE = "create-anonymized-deposit-page"; + public static final String GENERATE_ANONYMIZED_DEPOSIT_PAGE = "generate-anonymized-deposit-page"; public static final String LIST_INHERITED_ROLE = "list-inherited-role"; public static final String LIST_INHERITED_PERSON_ROLES = "list-inherited-person-roles"; diff --git a/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java b/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java index 121b3f1f6d..3aa0304529 100644 --- a/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java +++ b/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java @@ -408,9 +408,9 @@ public class DepositController extends AbstractPackageController<DepositDataFile SolidifyConstants.ZIP_MIME_TYPE, FileTool.getSize(Paths.get(zipFileLocation))); } - @PostMapping(SolidifyConstants.URL_ID_PLUS_SEP + DLCMActionName.CREATE_ANONYMIZED_DEPOSIT_PAGE) + @PostMapping(SolidifyConstants.URL_ID_PLUS_SEP + DLCMActionName.GENERATE_ANONYMIZED_DEPOSIT_PAGE) @PreAuthorize("@depositPermissionService.isAllowed(#depositId, 'DOWNLOAD_FILE')") - public HttpEntity<String> createAnonymizedDepositPage(@PathVariable("id") String depositId) { + public HttpEntity<String> generateAnonymizedDepositPage(@PathVariable("id") String depositId) { final Deposit deposit = this.itemService.findOne(depositId); final String anonymizedDepositPageId = ((DepositService) this.itemService).buildAnonymizedDeposit(deposit); return new HttpEntity<>(this.config.getModule().getPreingest().getPublicUrl() + "/" + ResourceName.DEPOSIT + "/" + -- GitLab From 9c162cf8018ffa1bfa39960270160471d529030a Mon Sep 17 00:00:00 2001 From: Mathieu Vonlanthen <Mathieu.Vonlanthen@unige.ch> Date: Tue, 4 Feb 2025 17:20:18 +0100 Subject: [PATCH 12/14] feat: improve anonymized download page --- .../java/ch/dlcm/business/DepositService.java | 3 +- .../preingest/DepositController.java | 4 +++ .../AnonymizedDepositRepository.java | 2 +- .../templates/anonymizedDeposit.html | 32 ++++++++++++++++--- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java b/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java index 02cab48730..26ab33ba84 100644 --- a/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java +++ b/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java @@ -1305,7 +1305,8 @@ public class DepositService extends CompositeResourceService<Deposit> { public List<AnonymizedDepositEntry> buildAnonymizedDepositEntryList(String anonymizedDepositPageId) { final List<AnonymizedDepositEntry> anonymizedDepositEntryList = new ArrayList<>(); - for (AnonymizedDeposit anonymizedDeposit : this.anonymizedDepositRepository.findAnonymizedDepositByPageId(anonymizedDepositPageId)) { + for (AnonymizedDeposit anonymizedDeposit : + this.anonymizedDepositRepository.findAnonymizedDepositByPageIdOrderByTimestamp(anonymizedDepositPageId)) { anonymizedDepositEntryList.add(new AnonymizedDepositEntry(anonymizedDeposit.getResId(), anonymizedDeposit.getTimestamp().toString())); } return anonymizedDepositEntryList; diff --git a/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java b/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java index 3aa0304529..68cb96108d 100644 --- a/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java +++ b/DLCM-PreIngest/src/main/java/ch/dlcm/controller/preingest/DepositController.java @@ -82,6 +82,7 @@ import ch.unige.solidify.SolidifyConstants; import ch.unige.solidify.auth.service.ApplicationRoleListService; import ch.unige.solidify.config.SolidifyEventPublisher; import ch.unige.solidify.exception.SolidifyHttpErrorException; +import ch.unige.solidify.exception.SolidifyResourceNotFoundException; import ch.unige.solidify.exception.SolidifyRuntimeException; import ch.unige.solidify.exception.SolidifyValidationException; import ch.unige.solidify.rest.ActionName; @@ -404,6 +405,9 @@ public class DepositController extends AbstractPackageController<DepositDataFile public HttpEntity<FileSystemResource> downloadAnonymizedDeposit(@PathVariable("id") String anonymizedDepositId) { final String zipFileLocation = this.config.getPreingestLocation() + "/" + ANONYMIZED_DEPOSITS_FOLDER + "/" + anonymizedDepositId + SolidifyConstants.ZIP_EXT; + if (Files.notExists(Paths.get(zipFileLocation))) { + throw new SolidifyResourceNotFoundException("Anonymized deposit " + anonymizedDepositId + " not found"); + } return this.buildDownloadResponseEntity(zipFileLocation, anonymizedDepositId + SolidifyConstants.ZIP_EXT, SolidifyConstants.ZIP_MIME_TYPE, FileTool.getSize(Paths.get(zipFileLocation))); } diff --git a/DLCM-PreIngest/src/main/java/ch/dlcm/repository/AnonymizedDepositRepository.java b/DLCM-PreIngest/src/main/java/ch/dlcm/repository/AnonymizedDepositRepository.java index 8ecb6e3e26..4a03cd2472 100644 --- a/DLCM-PreIngest/src/main/java/ch/dlcm/repository/AnonymizedDepositRepository.java +++ b/DLCM-PreIngest/src/main/java/ch/dlcm/repository/AnonymizedDepositRepository.java @@ -43,6 +43,6 @@ public interface AnonymizedDepositRepository extends SolidifyRepository<Anonymiz @Query("SELECT ad FROM AnonymizedDeposit ad WHERE ad.deposit = :deposit ORDER BY ad.timestamp DESC LIMIT 1") Optional<AnonymizedDeposit> findLastAnonymizedDeposit(Deposit deposit); - List<AnonymizedDeposit> findAnonymizedDepositByPageId(String pageId); + List<AnonymizedDeposit> findAnonymizedDepositByPageIdOrderByTimestamp(String pageId); } diff --git a/DLCM-PreIngest/src/main/resources/templates/anonymizedDeposit.html b/DLCM-PreIngest/src/main/resources/templates/anonymizedDeposit.html index 47a6868b7e..8d2f5812cf 100644 --- a/DLCM-PreIngest/src/main/resources/templates/anonymizedDeposit.html +++ b/DLCM-PreIngest/src/main/resources/templates/anonymizedDeposit.html @@ -4,27 +4,49 @@ <meta charset="UTF-8"> <title>URL List</title> <style> + h1 {text-align: center;} body { font-family: Arial, sans-serif; } - table { width: 100%; border-collapse: collapse; margin-top: 20px; } + table { width: 100%; border-collapse: collapse; margin: 30px; } th, td { border: 1px solid #ddd; padding: 8px; text-align: left; } th { background-color: #f2f2f2; } + .centered-div { + width: 50%; + margin: 20px auto; + text-align: center; + line-height: 1.8; + padding: 20px; + border: 1px solid #ddd; + background-color: #f9f9f9; + } </style> </head> <body> -<h2>Welcome to the anonymized deposit download page</h2> +<h1>Welcome to the anonymized deposit download page</h1> +<div class="centered-div"> +The most recent anonymized deposit for the dataset under review is available for download.<br> +Please note that all content is for review purposes only and should not be shared or distributed. +</div> <table> <thead> <tr> <th>#</th> - <th>URL</th> - <th>Timestamp</th> + <th>Anonymized Deposit</th> + <th>Generation Timestamp</th> </tr> </thead> <tbody> <tr th:each="entry, index : ${anonymizedDepositEntryList}"> <td th:text="${index.index + 1}"></td> - <td><a th:href="${preingestPublicUrl} + '/deposits/' + ${entry.anonymizedDepositResId} + '/download-anonymized-deposit'" th:text="${entry.anonymizedDepositResId}" target="_blank"></a></td> + <td> + <a th:if="${index.last}" + th:href="${preingestPublicUrl} + '/deposits/' + ${entry.anonymizedDepositResId} + '/download-anonymized-deposit'" + th:text="${entry.anonymizedDepositResId}"> + + </a> + <span th:unless="${index.last}" + th:text="${entry.anonymizedDepositResId}"></span> + </td> <td th:text="${entry.timestamp}"></td> </tr> </tbody> -- GitLab From ef18a3f2776e13bd5eefdeae293191621b4ff443 Mon Sep 17 00:00:00 2001 From: Mathieu Vonlanthen <Mathieu.Vonlanthen@unige.ch> Date: Wed, 5 Feb 2025 11:59:00 +0100 Subject: [PATCH 13/14] fix: MR --- .../main/java/ch/dlcm/model/preingest/AnonymizedDeposit.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDeposit.java b/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDeposit.java index e7786ac0a8..ba581e52ff 100644 --- a/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDeposit.java +++ b/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDeposit.java @@ -107,11 +107,11 @@ public class AnonymizedDeposit extends ResourceNormalized { return false; AnonymizedDeposit that = (AnonymizedDeposit) o; return Objects.equals(deposit, that.deposit) && Objects.equals(timestamp, that.timestamp) && Objects.equals( - aggregateChecksum, that.aggregateChecksum); + aggregateChecksum, that.aggregateChecksum) && Objects.equals(pageId, that.pageId); } @Override public int hashCode() { - return Objects.hash(super.hashCode(), deposit, timestamp, aggregateChecksum); + return Objects.hash(super.hashCode(), deposit, timestamp, aggregateChecksum, pageId); } } -- GitLab From f938a8236265107c793f19cda0ec5895c15619a2 Mon Sep 17 00:00:00 2001 From: Mathieu Vonlanthen <Mathieu.Vonlanthen@unige.ch> Date: Wed, 5 Feb 2025 12:01:16 +0100 Subject: [PATCH 14/14] Add missing header --- .../preingest/AnonymizedDepositEntry.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDepositEntry.java b/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDepositEntry.java index ab880a9bf2..2f53213d04 100644 --- a/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDepositEntry.java +++ b/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDepositEntry.java @@ -1,3 +1,26 @@ +/*- + * %%---------------------------------------------------------------------------------------------- + * DLCM Technology - DLCM Model - AnonymizedDepositEntry.java + * SPDX-License-Identifier: GPL-2.0-or-later + * %----------------------------------------------------------------------------------------------% + * Copyright (C) 2017 - 2025 University of Geneva + * %----------------------------------------------------------------------------------------------% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-2.0.html>. + * ----------------------------------------------------------------------------------------------%% + */ + package ch.dlcm.model.preingest; public class AnonymizedDepositEntry { @@ -9,4 +32,4 @@ public class AnonymizedDepositEntry { } public String getAnonymizedDepositResId() { return anonymizedDepositResId; } public String getTimestamp() { return timestamp; } -} \ No newline at end of file +} -- GitLab