From b866e25b01ab7462a7a60a5c4f121bb69cc9b984 Mon Sep 17 00:00:00 2001 From: Filipe Dias Lewandowski Date: Thu, 5 Sep 2024 08:49:15 +0200 Subject: [PATCH] Closes #2533: Allow to uningest multiple files at once (#2543) --- .../src/main/resources/Bundle_en.properties | 3 +- .../src/main/resources/Bundle_pl.properties | 3 +- .../harvard/iq/dataverse/UningestPage.java | 40 ++++++++++++++----- .../src/main/webapp/uningest.xhtml | 31 +++++++++----- 4 files changed, 55 insertions(+), 22 deletions(-) diff --git a/dataverse-persistence/src/main/resources/Bundle_en.properties b/dataverse-persistence/src/main/resources/Bundle_en.properties index c3856607f8b..cb3da7470ee 100755 --- a/dataverse-persistence/src/main/resources/Bundle_en.properties +++ b/dataverse-persistence/src/main/resources/Bundle_en.properties @@ -3078,7 +3078,8 @@ uningest.table.unf=UNF of ingested file uningest.table.actions=Action uningest.table.uningest.button=Uningest uningest.dialog.title=Confirm uningest -uningest.dialog.text=Do you really want to uningest the file named "{0}"? +uningest.dialog.text=Do you really want to uningest the selected files? +uningest.error=Could not uningest the following files add.dataset.button=Add dataset add.dataset.dialog.header=Select dataverse diff --git a/dataverse-persistence/src/main/resources/Bundle_pl.properties b/dataverse-persistence/src/main/resources/Bundle_pl.properties index e7c5d42e826..e5ab93944fa 100644 --- a/dataverse-persistence/src/main/resources/Bundle_pl.properties +++ b/dataverse-persistence/src/main/resources/Bundle_pl.properties @@ -3029,7 +3029,8 @@ uningest.table.unf=UNF zanalizowanego pliku uningest.table.actions=Akcje uningest.table.uningest.button=Cofnij analiz\u0119 uningest.dialog.title=Potwierd\u017A cofni\u0119cie analizy -uningest.dialog.text=Czy na pewno chcesz cofn\u0105\u0107 analiz\u0119 pliku o nazwie "{0}"? +uningest.dialog.text=Czy na pewno chcesz cofn\u0105\u0107 analiz\u0119 dla zaznaczonych plik\u00F3w? +uningest.error=Nie uda\u0142o si\u0119 cofn\u0105\u0107 analiz\u0119 dla nast\u0119puj\u0105cych plik\u00F3w add.dataset.button=Dodaj zbi\u00F3r danych add.dataset.dialog.header=Wybierz kolekcj\u0119 diff --git a/dataverse-webapp/src/main/java/edu/harvard/iq/dataverse/UningestPage.java b/dataverse-webapp/src/main/java/edu/harvard/iq/dataverse/UningestPage.java index 5ca876b95ab..8753ba4998c 100644 --- a/dataverse-webapp/src/main/java/edu/harvard/iq/dataverse/UningestPage.java +++ b/dataverse-webapp/src/main/java/edu/harvard/iq/dataverse/UningestPage.java @@ -1,5 +1,6 @@ package edu.harvard.iq.dataverse; +import edu.harvard.iq.dataverse.common.BundleUtil; import edu.harvard.iq.dataverse.ingest.UningestInfoService; import edu.harvard.iq.dataverse.ingest.UningestService; import edu.harvard.iq.dataverse.persistence.datafile.DataFile; @@ -11,7 +12,11 @@ import edu.harvard.iq.dataverse.util.SystemConfig; import org.apache.commons.lang.StringUtils; import org.omnifaces.cdi.ViewScoped; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.faces.application.FacesMessage; +import javax.faces.context.FacesContext; import javax.inject.Inject; import javax.inject.Named; import java.io.Serializable; @@ -23,6 +28,7 @@ @Named("UningestPage") public class UningestPage implements Serializable { + private static final Logger log = LoggerFactory.getLogger(UningestPage.class); private UningestService uningestService; private DatasetRepository datasetRepository; private DataverseSession dataverseSession; @@ -33,7 +39,7 @@ public class UningestPage implements Serializable { private UningestInfoService uningestInfoService; private List uningestableFiles = new ArrayList<>(); - private UningestableItem toUningest; + private List selectedFiles = new ArrayList<>(); private Long datasetId; private Dataset dataset; @@ -51,9 +57,9 @@ public Dataset getDataset() { public List getUningestableFiles() { return uningestableFiles; } - - public UningestableItem getToUningest() { - return toUningest; + + public List getSelectedFiles() { + return selectedFiles; } // -------------------- CONSTRUCTORS -------------------- @@ -96,17 +102,33 @@ public String init() { return permissionsWrapper.notFound(); } uningestableFiles.addAll(prepareItemList()); + selectedFiles.clear(); return StringUtils.EMPTY; } public void uningest() { - if (toUningest == null || !dataverseSession.getUser().isAuthenticated()) { + if (selectedFiles.isEmpty() || !dataverseSession.getUser().isAuthenticated()) { return; } + AuthenticatedUser user = (AuthenticatedUser) dataverseSession.getUser(); - uningestService.uningest(toUningest.getDataFile(), user); + List uningestFailedFileNames = new ArrayList<>(); + selectedFiles.forEach(toUningest -> { + try { + uningestService.uningest(toUningest.getDataFile(), user); + } catch (Exception e) { + log.error("Could not uningest data file: {}", toUningest.getDataFile().getId(), e); + uningestFailedFileNames.add(toUningest.getFileName()); + } + }); uningestableFiles = prepareItemList(); - toUningest = null; + selectedFiles.clear(); + + if (!uningestFailedFileNames.isEmpty()) { + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, + BundleUtil.getStringFromBundle("uningest.error"), + uningestFailedFileNames.stream().collect(Collectors.joining(", ", "[", "]. ")))); + } } public String cancel() { @@ -127,8 +149,8 @@ public void setDatasetId(Long datasetId) { this.datasetId = datasetId; } - public void setToUningest(UningestableItem toUningest) { - this.toUningest = toUningest; + public void setSelectedFiles(List selectedFiles) { + this.selectedFiles = selectedFiles; } // -------------------- INNER CLASSES -------------------- diff --git a/dataverse-webapp/src/main/webapp/uningest.xhtml b/dataverse-webapp/src/main/webapp/uningest.xhtml index b78b0fa0370..b2def5d0973 100644 --- a/dataverse-webapp/src/main/webapp/uningest.xhtml +++ b/dataverse-webapp/src/main/webapp/uningest.xhtml @@ -36,8 +36,20 @@ - + + + + + + + + + @@ -54,18 +66,17 @@ - - -
+ +
@@ -74,9 +85,7 @@

- - - +