Skip to content

Commit

Permalink
Closes #2533: Allow to uningest multiple files at once (#2543)
Browse files Browse the repository at this point in the history
  • Loading branch information
diasf authored Sep 5, 2024
1 parent d49edbe commit b866e25
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -33,7 +39,7 @@ public class UningestPage implements Serializable {
private UningestInfoService uningestInfoService;

private List<UningestableItem> uningestableFiles = new ArrayList<>();
private UningestableItem toUningest;
private List<UningestableItem> selectedFiles = new ArrayList<>();

private Long datasetId;
private Dataset dataset;
Expand All @@ -51,9 +57,9 @@ public Dataset getDataset() {
public List<UningestableItem> getUningestableFiles() {
return uningestableFiles;
}
public UningestableItem getToUningest() {
return toUningest;

public List<UningestableItem> getSelectedFiles() {
return selectedFiles;
}

// -------------------- CONSTRUCTORS --------------------
Expand Down Expand Up @@ -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<String> 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() {
Expand All @@ -127,8 +149,8 @@ public void setDatasetId(Long datasetId) {
this.datasetId = datasetId;
}

public void setToUningest(UningestableItem toUningest) {
this.toUningest = toUningest;
public void setSelectedFiles(List<UningestableItem> selectedFiles) {
this.selectedFiles = selectedFiles;
}

// -------------------- INNER CLASSES --------------------
Expand Down
31 changes: 20 additions & 11 deletions dataverse-webapp/src/main/webapp/uningest.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,20 @@
<h:form id="uningestForm">
<p:outputPanel>
<p:fragment id="uningestList">
<p:dataTable var="item" value="#{UningestPage.uningestableFiles}"
<p:dataTable id="uningestTable" var="item"
value="#{UningestPage.uningestableFiles}"
selection="#{UningestPage.selectedFiles}"
rowKey="${item.dataFile.id}"
style="word-break: break-all">

<p:ajax event="rowSelect" update="uningestForm" />
<p:ajax event="rowSelectCheckbox" update="uningestForm" />
<p:ajax event="rowUnselectCheckbox" update="uningestForm" />
<p:ajax event="toggleSelect" update="uningestForm" />

<p:column selectionMode="multiple" style="width:20px !important;">
</p:column>

<p:column headerText="#{bundle['uningest.table.filename']}">
<h:outputText value="#{item.fileName}" />
</p:column>
Expand All @@ -54,18 +66,17 @@
<h:outputText value="#{item.unf}" styleClass="text-monospace" />
</p:column>

<p:column headerText="#{bundle['uningest.table.actions']}" style="text-align: center">
<p:commandButton value="#{bundle['uningest.table.uningest.button']}"
ajax="true"
oncomplete="primeFacesShowModal('uningestConfirm', this)"
update=":uningestConfirm"
action="#{UningestPage.setToUningest(item)}"/>
</p:column>
</p:dataTable>
</p:fragment>
</p:outputPanel>
<div class="button-block">
<p:outputPanel>
<p:commandButton value="#{bundle['uningest.table.uningest.button']}"
ajax="true"
disabled="${UningestPage.selectedFiles.isEmpty()}"
oncomplete="primeFacesShowModal('uningestConfirm', this)"
update=":uningestConfirm"/>

<p:commandButton id="cancel" value="#{bundle.cancel}" action="#{UningestPage.cancel}"/>
</p:outputPanel>
</div>
Expand All @@ -74,9 +85,7 @@
<p:dialog id="uningestConfirm" styleClass="smallPopUp" header="#{bundle['uningest.dialog.title']}" widgetVar="uningestConfirm" modal="true">
<p class="text-warning">
<span class="glyphicon glyphicon-warning-sign"/>
<h:outputFormat value="#{bundle['uningest.dialog.text']}">
<f:param value="#{UningestPage.toUningest.fileName}" />
</h:outputFormat>
<h:outputText value="#{bundle['uningest.dialog.text']}" />
</p>
<div class="button-block">
<p:commandButton value="#{bundle.continue}"
Expand Down

0 comments on commit b866e25

Please sign in to comment.