diff --git a/DLCM-Model/src/main/java/ch/dlcm/DLCMConstants.java b/DLCM-Model/src/main/java/ch/dlcm/DLCMConstants.java index f6b047f3f0df0efffc4562a5cabb051c3d2537c9..374c56f79fc4447195cf9c35b171b629ba046163 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/model/preingest/AnonymizedDeposit.java b/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDeposit.java new file mode 100644 index 0000000000000000000000000000000000000000..ba581e52ffb833711376173705eec0f19f7e1579 --- /dev/null +++ b/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDeposit.java @@ -0,0 +1,117 @@ +/*- + * %%---------------------------------------------------------------------------------------------- + * 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; +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 id of the page listing all anonymized deposits of a given deposit") + private String pageId; + + public @NotNull Deposit getDeposit() { + return deposit; + } + + public OffsetDateTime getTimestamp() { + return timestamp; + } + + public String getAggregateChecksum() { + return aggregateChecksum; + } + + public String getPageId() { + return pageId; + } + + 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 setPageId(String linkId) { + this.pageId = 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) && Objects.equals(pageId, that.pageId); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), deposit, timestamp, aggregateChecksum, pageId); + } +} 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 0000000000000000000000000000000000000000..2f53213d04b180b5186334c4896916c1fcfdd557 --- /dev/null +++ b/DLCM-Model/src/main/java/ch/dlcm/model/preingest/AnonymizedDepositEntry.java @@ -0,0 +1,35 @@ +/*- + * %%---------------------------------------------------------------------------------------------- + * 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 { + private final String anonymizedDepositResId; + private final String timestamp; + public AnonymizedDepositEntry(String anonymizedDepositResId, String timestamp) { + this.anonymizedDepositResId = anonymizedDepositResId; + this.timestamp = timestamp; + } + public String getAnonymizedDepositResId() { return anonymizedDepositResId; } + public String getTimestamp() { return timestamp; } +} 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 b723d0c02c618eadb32a1e8dea4a89168eff551a..a35a9a3a5c58346304f47bea190698c937c94854 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 743e8ecdbe49c4e9c0b0fc15b50ed9c5e85a0cf8..cb19fbd28bab25116f6f2c130e980408d5c99c5e 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"; @@ -147,7 +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 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/business/DepositService.java b/DLCM-PreIngest/src/main/java/ch/dlcm/business/DepositService.java index 253f0d5277bc00bbf0ba7e47b3df356846f97ba3..26ab33ba84f2c10a24db2b0ba36b07c56fcc6308 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; @@ -97,6 +98,8 @@ 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.AnonymizedDepositEntry; 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; } /** @@ -1245,37 +1252,64 @@ 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")); } - + 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)) { - if (Files.exists(lastZipFilePath)) { - return depositDatafilesChecksum; + final Path anonymizedDepositFolder = Path.of(this.dlcmProperties.getPreingestLocation(), ANONYMIZED_DEPOSITS_FOLDER); + + // 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 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); } } - 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); + if (lastOptionalAnonymizedDeposit.isPresent()) { + anonymizedDeposit.setPageId(lastOptionalAnonymizedDeposit.get().getPageId()); + } else { + anonymizedDeposit.setPageId(UUID.randomUUID().toString()); + } + this.anonymizedDepositRepository.save(anonymizedDeposit); + new Thread(() -> { + 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(); + + // Delete old anonymized deposit + if (lastOptionalAnonymizedDeposit.isPresent()) { + final String lastAnonymizedDepositId = lastOptionalAnonymizedDeposit.get().getResId(); try { - Files.delete(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); } } - 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.getPageId(); + } + + public List<AnonymizedDepositEntry> buildAnonymizedDepositEntryList(String anonymizedDepositPageId) { + final List<AnonymizedDepositEntry> anonymizedDepositEntryList = new ArrayList<>(); + for (AnonymizedDeposit anonymizedDeposit : + this.anonymizedDepositRepository.findAnonymizedDepositByPageIdOrderByTimestamp(anonymizedDepositPageId)) { + anonymizedDepositEntryList.add(new AnonymizedDepositEntry(anonymizedDeposit.getResId(), anonymizedDeposit.getTimestamp().toString())); + } + 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 5624c91103adfc80c9a9132a33dabd8ec26f8c21..68cb96108d1c779277d851c26f3a5b4acd8e7179 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 @@ -74,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; @@ -81,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; @@ -117,6 +119,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; @@ -386,22 +389,36 @@ 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 ModelAndView getAnonymizedDepositPage(@PathVariable("id") String anonymizedDepositPageId) { + final ModelAndView modelAndView = new ModelAndView("anonymizedDeposit"); + final List<AnonymizedDepositEntry> anonymizedDepositEntryList = + ((DepositService) this.itemService).buildAnonymizedDepositEntryList(anonymizedDepositPageId); + modelAndView.addObject("anonymizedDepositEntryList", anonymizedDepositEntryList); + modelAndView.addObject("preingestPublicUrl", this.config.getModule().getPreingest().getPublicUrl()); + return modelAndView; + } + @GetMapping(SolidifyConstants.URL_ID_PLUS_SEP + DLCMActionName.DOWNLOAD_ANONYMIZED_DEPOSIT) @EveryonePermissions 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))); } - @GetMapping(SolidifyConstants.URL_ID_PLUS_SEP + DLCMActionName.GET_ANONYMIZED_DOWNLOAD_LINK) + @PostMapping(SolidifyConstants.URL_ID_PLUS_SEP + DLCMActionName.GENERATE_ANONYMIZED_DEPOSIT_PAGE) @PreAuthorize("@depositPermissionService.isAllowed(#depositId, 'DOWNLOAD_FILE')") - public HttpEntity<String> getAnonymizedDownloadLink(@PathVariable("id") String depositId) { + public HttpEntity<String> generateAnonymizedDepositPage(@PathVariable("id") String depositId) { final Deposit deposit = this.itemService.findOne(depositId); - final String anonymizedDepositId = ((DepositService) this.itemService).buildAnonymizedDownloadableDeposit(deposit); + final String anonymizedDepositPageId = ((DepositService) this.itemService).buildAnonymizedDeposit(deposit); return new HttpEntity<>(this.config.getModule().getPreingest().getPublicUrl() + "/" + ResourceName.DEPOSIT + "/" + - anonymizedDepositId + "/" + DLCMActionName.DOWNLOAD_ANONYMIZED_DEPOSIT); + 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 new file mode 100644 index 0000000000000000000000000000000000000000..4a03cd2472e6819f2c4ce948911b9d5c82246fbf --- /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> findAnonymizedDepositByPageIdOrderByTimestamp(String pageId); + +} diff --git a/DLCM-PreIngest/src/main/resources/templates/anonymizedDeposit.html b/DLCM-PreIngest/src/main/resources/templates/anonymizedDeposit.html new file mode 100644 index 0000000000000000000000000000000000000000..8d2f5812cf77e2b5d3a46ab21247ed1f95a07a09 --- /dev/null +++ b/DLCM-PreIngest/src/main/resources/templates/anonymizedDeposit.html @@ -0,0 +1,56 @@ +<!DOCTYPE html> +<html xmlns:th="http://www.thymeleaf.org"> +<head> + <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: 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> + +<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>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: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> +</table> + +</body> +</html> \ No newline at end of file