Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 33 additions & 41 deletions src/main/java/edu/harvard/iq/dataverse/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -1471,73 +1471,65 @@ public static String getCiteDataFileFilename(String fileTitle, FileCitationExten
* elaborate on the text "This file cannot be downloaded publicly."
*/
public static boolean isDownloadPopupRequired(DatasetVersion datasetVersion) {
// Each of these conditions is sufficient reason to have to
// present the user with the popup:
if (datasetVersion == null) {
logger.fine("Download popup required because datasetVersion is null.");
return false;
}
//0. if version is draft then Popup "not required"
if (!datasetVersion.isReleased()) {
logger.fine("Download popup required because datasetVersion has not been released.");
return false;
}
// 1. License and Terms of Use:
if (datasetVersion.getTermsOfUseAndAccess() != null) {
License license = datasetVersion.getTermsOfUseAndAccess().getLicense();
if ((license == null && StringUtils.isNotBlank(datasetVersion.getTermsOfUseAndAccess().getTermsOfUse()))
|| (license != null && !license.isDefault())) {
logger.fine("Download popup required because of license or terms of use.");
return true;
}

// 2. Terms of Access:
if (!(datasetVersion.getTermsOfUseAndAccess().getTermsOfAccess() == null) && !datasetVersion.getTermsOfUseAndAccess().getTermsOfAccess().equals("")) {
logger.fine("Download popup required because of terms of access.");
return true;
}
logger.fine("Checking if download popup is required.");
Boolean answer = popupDueToStateOrTerms(datasetVersion);
if (answer != null) {
return answer;
}

// 3. Guest Book:
if (datasetVersion.getDataset() != null && datasetVersion.getDataset().getGuestbook() != null && datasetVersion.getDataset().getGuestbook().isEnabled() && datasetVersion.getDataset().getGuestbook().getDataverse() != null) {
logger.fine("Download popup required because of guestbook.");
return true;
}

logger.fine("Download popup is not required.");
return false;
}

public static boolean isRequestAccessPopupRequired(DatasetVersion datasetVersion){
// Each of these conditions is sufficient reason to have to
// present the user with the popup:
public static boolean isRequestAccessPopupRequired(DatasetVersion datasetVersion) {

Boolean answer = popupDueToStateOrTerms(datasetVersion);
if (answer != null) {
return answer;
}
logger.fine("Request access popup is not required.");
return false;
}

/* Code shared by isDownloadPopupRequired and isRequestAccessPopupRequired.
*
* Returns Boolean to allow null = no decision. This allows the isDownloadPopupRequired method to then add another check w.r.t. guestbooks before returning its value.
*
*/
private static Boolean popupDueToStateOrTerms(DatasetVersion datasetVersion) {

// Each of these conditions is sufficient reason to have to
// present the user with the popup:
if (datasetVersion == null) {
logger.fine("Download popup required because datasetVersion is null.");
logger.fine("Popup not required because datasetVersion is null.");
return false;
}
//0. if version is draft then Popup "not required"
// 0. if version is draft then Popup "not required"
if (!datasetVersion.isReleased()) {
logger.fine("Download popup required because datasetVersion has not been released.");
logger.fine("Popup not required because datasetVersion has not been released.");
return false;
}
// 1. License and Terms of Use:
if (datasetVersion.getTermsOfUseAndAccess() != null) {
if (!datasetVersion.getTermsOfUseAndAccess().getLicense().isDefault()
&& !(datasetVersion.getTermsOfUseAndAccess().getTermsOfUse() == null
|| datasetVersion.getTermsOfUseAndAccess().getTermsOfUse().equals(""))) {
logger.fine("Download popup required because of license or terms of use.");
License license = datasetVersion.getTermsOfUseAndAccess().getLicense();
if ((license == null && StringUtils.isNotBlank(datasetVersion.getTermsOfUseAndAccess().getTermsOfUse()))
|| (license != null && !license.isDefault())) {
logger.fine("Popup required because of license or terms of use.");
return true;
}

// 2. Terms of Access:
if (!(datasetVersion.getTermsOfUseAndAccess().getTermsOfAccess() == null) && !datasetVersion.getTermsOfUseAndAccess().getTermsOfAccess().equals("")) {
logger.fine("Download popup required because of terms of access.");
logger.fine("Popup required because of terms of access.");
return true;
}
}

logger.fine("Download popup is not required.");
return false;
//No decision based on the criteria above
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found the use of null here a little confusing, but looking at the rest of the code I see that it means "leave it up to Guestbook if applicable"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a method header comment and a comment at this line.

}

/**
Expand Down