Skip to content

Commit

Permalink
Merge pull request #10451 from GlobalDataverseCommunityConsortium/Glo…
Browse files Browse the repository at this point in the history
…busDownload

IQSS/10450 - Fixes for Globus download (transfer out) and related info messages
  • Loading branch information
landreev committed Apr 19, 2024
2 parents 447d576 + af4f918 commit 516a73f
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 59 deletions.
70 changes: 46 additions & 24 deletions src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Expand Up @@ -1234,8 +1234,17 @@ public boolean canDownloadFiles() {
canDownloadFiles = false;
for (FileMetadata fmd : workingVersion.getFileMetadatas()) {
if (fileDownloadHelper.canDownloadFile(fmd)) {
canDownloadFiles = true;
break;
if (isVersionHasGlobus()) {
String driverId = DataAccess
.getStorageDriverFromIdentifier(fmd.getDataFile().getStorageIdentifier());
if (StorageIO.isDataverseAccessible(driverId)) {
canDownloadFiles = true;
break;
}
} else {
canDownloadFiles = true;
break;
}
}
}
}
Expand Down Expand Up @@ -3260,7 +3269,7 @@ public void startDownloadSelectedOriginal() {

private void startDownload(boolean downloadOriginal){
boolean guestbookRequired = isDownloadPopupRequired();
boolean validate = validateFilesForDownload(downloadOriginal);
boolean validate = validateFilesForDownload(downloadOriginal, false);
if (validate) {
updateGuestbookResponse(guestbookRequired, downloadOriginal, false);
if(!guestbookRequired && !getValidateFilesOutcome().equals("Mixed")){
Expand All @@ -3283,7 +3292,7 @@ public void setValidateFilesOutcome(String validateFilesOutcome) {
this.validateFilesOutcome = validateFilesOutcome;
}

public boolean validateFilesForDownload(boolean downloadOriginal){
public boolean validateFilesForDownload(boolean downloadOriginal, boolean isGlobusTransfer){
if (this.selectedFiles.isEmpty()) {
PrimeFaces.current().executeScript("PF('selectFilesForDownload').show()");
return false;
Expand All @@ -3300,33 +3309,39 @@ public boolean validateFilesForDownload(boolean downloadOriginal){
return false;
}

for (FileMetadata fmd : getSelectedDownloadableFiles()) {
DataFile dataFile = fmd.getDataFile();
if (downloadOriginal && dataFile.isTabularData()) {
bytes += dataFile.getOriginalFileSize() == null ? 0 : dataFile.getOriginalFileSize();
} else {
bytes += dataFile.getFilesize();
if (!isGlobusTransfer) {
for (FileMetadata fmd : getSelectedDownloadableFiles()) {
DataFile dataFile = fmd.getDataFile();
if (downloadOriginal && dataFile.isTabularData()) {
bytes += dataFile.getOriginalFileSize() == null ? 0 : dataFile.getOriginalFileSize();
} else {
bytes += dataFile.getFilesize();
}
}
}

//if there are two or more files, with a total size
//over the zip limit, post a "too large" popup
if (bytes > settingsWrapper.getZipDownloadLimit() && selectedDownloadableFiles.size() > 1) {
setValidateFilesOutcome("FailSize");
return false;
// if there are two or more files, with a total size
// over the zip limit, post a "too large" popup
if (bytes > settingsWrapper.getZipDownloadLimit() && selectedDownloadableFiles.size() > 1) {
setValidateFilesOutcome("FailSize");
return false;
}
}

// If some of the files were restricted and we had to drop them off the
// list, and NONE of the files are left on the downloadable list
// - we show them a "you're out of luck" popup:
if (getSelectedDownloadableFiles().isEmpty() && getSelectedGlobusTransferableFiles().isEmpty() && !getSelectedNonDownloadableFiles().isEmpty()) {
// - we show them a "you're out of luck" popup
// Same for globus transfer
if ((!isGlobusTransfer
&& (getSelectedDownloadableFiles().isEmpty() && !getSelectedNonDownloadableFiles().isEmpty()))
|| (isGlobusTransfer && (getSelectedGlobusTransferableFiles().isEmpty()
&& !getSelectedNonGlobusTransferableFiles().isEmpty()))) {
setValidateFilesOutcome("FailRestricted");
return false;
}

//Some are selected and there are non-downloadable ones or there are both downloadable and globus transferable files
if ((!(getSelectedDownloadableFiles().isEmpty() && getSelectedGlobusTransferableFiles().isEmpty())
&& (!getSelectedNonDownloadableFiles().isEmpty()) || (!getSelectedDownloadableFiles().isEmpty() && !getSelectedGlobusTransferableFiles().isEmpty()))) {
//For download or transfer, there are some that can be downloaded/transferred and some that can't
if ((!isGlobusTransfer && (!getSelectedNonDownloadableFiles().isEmpty() && !getSelectedDownloadableFiles().isEmpty())) ||
(isGlobusTransfer && (!getSelectedNonGlobusTransferableFiles().isEmpty() && !getSelectedGlobusTransferableFiles().isEmpty()))) {
setValidateFilesOutcome("Mixed");
return true;
}
Expand Down Expand Up @@ -6284,12 +6299,18 @@ public void clearSelectionEmbargo() {
PrimeFaces.current().resetInputs("datasetForm:embargoInputs");
}

public boolean isCantDownloadDueToEmbargo() {
public boolean isCantDownloadDueToEmbargoOrDVAccess() {
if (getSelectedNonDownloadableFiles() != null) {
for (FileMetadata fmd : getSelectedNonDownloadableFiles()) {
if (FileUtil.isActivelyEmbargoed(fmd)) {
return true;
}
if (isVersionHasGlobus()) {
if (StorageIO.isDataverseAccessible(
DataAccess.getStorageDriverFromIdentifier(fmd.getDataFile().getStorageIdentifier()))) {
return true;
}
}
}
}
return false;
Expand Down Expand Up @@ -6381,7 +6402,8 @@ public void startGlobusTransfer(boolean transferAll, boolean popupShown) {
}
boolean guestbookRequired = isDownloadPopupRequired();

boolean validated = validateFilesForDownload(true);
boolean validated = validateFilesForDownload(true, true);

if (validated) {
globusTransferRequested = true;
boolean mixed = "Mixed".equals(getValidateFilesOutcome());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/edu/harvard/iq/dataverse/api/Datasets.java
Expand Up @@ -3756,11 +3756,11 @@ public Response getGlobusDownloadParams(@Context ContainerRequestContext crc, @P
// -------------------------------------
// (1) Get the user from the ContainerRequestContext
// -------------------------------------
AuthenticatedUser authUser;
AuthenticatedUser authUser = null;
try {
authUser = getRequestAuthenticatedUserOrDie(crc);
} catch (WrappedResponse e) {
return e.getResponse();
logger.fine("guest user globus download");
}
// -------------------------------------
// (2) Get the Dataset Id
Expand Down
Expand Up @@ -985,10 +985,14 @@ public void globusDownload(String jsonData, Dataset dataset, User authUser) thro
if (taskStatus.startsWith("FAILED") || taskStatus.startsWith("INACTIVE")) {
String comment = "Reason : " + taskStatus.split("#")[1] + "<br> Short Description : "
+ taskStatus.split("#")[2];
userNotificationService.sendNotification((AuthenticatedUser) authUser, new Timestamp(new Date().getTime()),
UserNotification.Type.GLOBUSDOWNLOADCOMPLETEDWITHERRORS, dataset.getId(), comment, true);
globusLogger.info("Globus task failed during download process");
} else {
if (authUser != null && authUser instanceof AuthenticatedUser) {
userNotificationService.sendNotification((AuthenticatedUser) authUser, new Timestamp(new Date().getTime()),
UserNotification.Type.GLOBUSDOWNLOADCOMPLETEDWITHERRORS, dataset.getId(), comment, true);
}

globusLogger.info("Globus task failed during download process: "+comment);
} else if (authUser != null && authUser instanceof AuthenticatedUser) {

boolean taskSkippedFiles = (task.getSkip_source_errors() == null) ? false : task.getSkip_source_errors();
if (!taskSkippedFiles) {
userNotificationService.sendNotification((AuthenticatedUser) authUser,
Expand Down Expand Up @@ -1257,11 +1261,11 @@ public void writeGuestbookAndStartTransfer(GuestbookResponse guestbookResponse,
Long fileId = Long.parseLong(idAsString);
// If we need to create a GuestBookResponse record, we have to
// look up the DataFile object for this file:
df = dataFileService.findCheapAndEasy(fileId);
selectedFiles.add(df);
if (!doNotSaveGuestbookResponse) {
df = dataFileService.findCheapAndEasy(fileId);
guestbookResponse.setDataFile(df);
fileDownloadService.writeGuestbookResponseRecord(guestbookResponse);
selectedFiles.add(df);
}
} catch (NumberFormatException nfe) {
logger.warning(
Expand Down
@@ -1,6 +1,7 @@
package edu.harvard.iq.dataverse.util;

import java.util.Arrays;
import java.util.Random;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -261,7 +262,9 @@ public JsonObject getParams(JsonObject toolParameters) {

public static String getScriptForUrl(String url) {
String msg = BundleUtil.getStringFromBundle("externaltools.enable.browser.popups");
String script = "const newWin = window.open('" + url + "', target='_blank'); if (!newWin || newWin.closed || typeof newWin.closed == \"undefined\") {alert(\"" + msg + "\");}";
String newWin = "newWin" + (new Random()).nextInt(1000000000);
//Always use a unique identifier so that more than one script can run (or one can be rerun) without conflicts
String script = String.format("const %1$s = window.open('" + url + "', target='_blank'); if (!%1$s || %1$s.closed || typeof %1$s.closed == \"undefined\") {alert(\"" + msg + "\");}", newWin);
return script;
}

Expand Down
12 changes: 7 additions & 5 deletions src/main/java/propertyFiles/Bundle.properties
Expand Up @@ -1665,17 +1665,19 @@ dataset.noSelectedFiles=Please select one or more files.
dataset.noSelectedFilesForDownload=Please select a file or files to be downloaded.
dataset.noSelectedFilesForRequestAccess=Please select a file or files for access request.
dataset.embargoedSelectedFilesForRequestAccess=Embargoed files cannot be accessed. Please select an unembargoed file or files for your access request.
dataset.inValidSelectedFilesForDownload=Restricted Files Selected
dataset.inValidSelectedFilesForDownloadWithEmbargo=Embargoed and/or Restricted Files Selected
dataset.noValidSelectedFilesForDownload=The selected file(s) may not be downloaded because you have not been granted access.
dataset.inValidSelectedFilesForDownload=Restricted Files, or Files only Acessible Via Globus Selected
dataset.inValidSelectedFilesForDownloadWithEmbargo=Embargoed and/or Restricted Files, or Files only acessible via Globus Selected
dataset.inValidSelectedFilesForTransferWithEmbargo=Embargoed and/or Restricted Files, or Files that are not Globus accessible Selected
dataset.noValidSelectedFilesForDownload=The selected file(s) may not be downloaded because you have not been granted access or the files can only be transferred via Globus.
dataset.noValidSelectedFilesForTransfer=The selected file(s) may not be transferred because you have not been granted access or the files are not Globus accessible.
dataset.mixedSelectedFilesForDownload=The restricted file(s) selected may not be downloaded because you have not been granted access.
dataset.mixedSelectedFilesForDownloadWithEmbargo=The embargoed and/or restricted file(s) selected may not be downloaded because you have not been granted access.
dataset.mixedSelectedFilesForDownloadWithEmbargo=Any embargoed and/or restricted file(s) selected may not be downloaded because you have not been granted access. Some files may only be accessible via Globus.
dataset.mixedSelectedFilesForTransfer=Some file(s) cannot be transferred. (They are restricted, embargoed, or not Globus accessible.)
dataset.inValidSelectedFilesForTransfer=Ineligible Files Selected
dataset.downloadUnrestricted=Click Continue to download the files you have access to download.
dataset.transferUnrestricted=Click Continue to transfer the elligible files.

dataset.requestAccessToRestrictedFiles=You may request access to the restricted file(s) by clicking the Request Access button.
dataset.requestAccessToRestrictedFiles=You may request access to any restricted file(s) by clicking the Request Access button.
dataset.requestAccessToRestrictedFilesWithEmbargo=Embargoed files cannot be accessed during the embargo period. If your selection contains restricted files, you may request access to them by clicking the Request Access button.
dataset.privateurl.infoMessageAuthor=Privately share this dataset before it is published: {0}
dataset.privateurl.infoMessageReviewer=This unpublished dataset is being privately shared.
Expand Down

0 comments on commit 516a73f

Please sign in to comment.