Skip to content
Closed
Show file tree
Hide file tree
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
108 changes: 108 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/SettingsWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public class SettingsWrapper implements java.io.Serializable {
private static final Set<String> TRUE_VALUES = Collections.unmodifiableSet(
new TreeSet<>( Arrays.asList("1","yes", "true","allow")));

/**
*
* @return setting value as string, or null if no setting is specified (JSF test `empty`
* works for null values`)
*/
public String get(String settingKey) {
if (settingsMap == null) {
initSettingsMap();
Expand All @@ -62,6 +67,109 @@ private void initSettingsMap() {
}
}

/**
* default separator "," for settings list
*/
public static String defaultListSeparator = ",";

/**
* check if a given value is present in a setting list using the default separator.
* @param settingKey setting list to search
* @param queryValue value to search for
* @return true if a given value is present in a setting list, false if the value or key is
* absent
*/
public boolean valueInSettingList(String settingKey, String queryValue )
{
return valueInSettingList( settingKey, queryValue, defaultListSeparator);
}

/**
* check if a given value is present in a setting list.
* @param settingKey setting list to search
* @param queryValue value to search for
* @param sep list separator
* @return true if a given value is present in a setting list, false if the value or key is
* absent
*/
public boolean valueInSettingList(String settingKey, String queryValue, String sep)
{
if ( null == settingsMap )
{
initSettingsMap();
}
String xs = settingsMap.get( settingKey );
if ( null == xs )
{
return false;
}
String[] ys = xs.split( sep );
if ( 0 == ys.length )
{
return false;
}
for( String y : ys )
{
if ( queryValue.equals(y) )
{
return true;
}
}
return false;
}

/**
* if this key is present in the downloadMethods or uploadMethods list, allow native
* (http) uploads / downloads (if either list has been set).
*/
public static String nativeProtocol = "native/http";

/**
* default string for uploadMethods; may belong elsewhere.
*/
private static String uploadMethodsList = "uploadMethods";
/**
* default string for downloadMethods; may belong elsewhere.
*/
private static String downloadMethodsList = "downloadMethods";

/**
* wrapper to see if the native file upload options should be shown.
* @return true if `nativeProtocol` is in the `uploadMethods` list, or if `uploadMethods`
* has not been set; false otherwise.
*/
public boolean allowNativeUploads()
{
return nativeTransferCheck( uploadMethodsList );
}

/**
* wrapper to see if the native file download options should be shown.
* @return true if `nativeProtocol` is in the `downloadMethods` list, or if `downloadMethods`
* has not been set; false otherwise.
*/
public boolean allowNativeDownloads()
{
return nativeTransferCheck( downloadMethodsList );
}

/**
* centralize logic for check if setting absent, or value present in setting list
*/
private boolean nativeTransferCheck( String transferDirection )
{
if ( null == settingsMap )
{
initSettingsMap();
}
Set keys = settingsMap.keySet();
if ( ! keys.contains( (Object) transferDirection ) )
{
return true;
}
return valueInSettingList( transferDirection, nativeProtocol );
}

private String guidesBaseUrl = null;

public String getGuidesBaseUrl() {
Expand Down
14 changes: 11 additions & 3 deletions src/main/webapp/dataset.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,9 @@
</tr>
</ui:repeat>
</table>
<div class="button-block">
<div class="button-block">
<!-- PM start edit -->
<c:if test="#{ settingsWrapper.allowNativeDownloads() }">
<p class="help-block"><span class="glyphicon glyphicon-info-sign"/> #{bundle['dataset.downloadUnrestricted']}</p>
<ui:fragment rendered="#{!DatasetPage.downloadPopupRequired}">
<p:commandButton value="#{bundle.continue}" onclick="PF('downloadMixed').hide()" action="#{DatasetPage.startMultipleFileDownload(false)}" />
Expand All @@ -606,7 +608,9 @@
action="#{DatasetPage.modifyGuestbookMultipleResponse()}" update="@form" />
</ui:fragment>
<p:commandButton value="#{bundle.cancel}" onclick="PF('downloadMixed').hide();" type="button" />
</div>
</c:if>
<!-- PM end edit -->
</div>
</p:dialog>
<p:dialog styleClass="smallPopUp" header="#{bundle['file.deleteDialog.header']}" widgetVar="deleteConfirmation" modal="true">
<p class="text-danger"><span class="glyphicon glyphicon-warning-sign"/> #{bundle['file.deleteDialog.tip']}</p>
Expand Down Expand Up @@ -1073,6 +1077,8 @@
</p:dialog>
<!-- END: Request Access Sign Up/Log In Button -->

<!-- PM start edit -->
<c:if test="#{ settingsWrapper.allowNativeDownloads() }">
<p:dialog id="downloadPopup" styleClass="largePopUp" header="#{bundle['file.downloadDialog.header']}" widgetVar="downloadPopup" modal="true">
<o:importFunctions type="edu.harvard.iq.dataverse.util.MarkupChecker" />

Expand All @@ -1086,7 +1092,9 @@
<ui:param name="twoRavensHelper" value="#{DatasetPage.twoRavensHelper}"/>
</ui:include>

</p:dialog>
</p:dialog>
</c:if>
<!-- PM end edit -->

<p:dialog id="downloadDataSubsetPopup" styleClass="smallPopUp" header="Download Data Subset" widgetVar="downloadDataSubsetPopup"
rendered="#{empty DatasetPage.editMode}" modal="true">
Expand Down
30 changes: 25 additions & 5 deletions src/main/webapp/editFilesFragment.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
</li>
</ul>
<div class="ui-tabs-panels">
<div aria-hidden="false" role="tabpanel" class="ui-tabs-panel ui-widget-content ui-corner-bottom" id="datasetForm:tabView:dataFilesTab">
<div aria-hidden="false" role="tabpanel" class="ui-tabs-panel ui-widget-content ui-corner-bottom" id="datasetForm:tabView:dataFilesTab">
<!--PM start edit -->
<c:if test="#{ settingsWrapper.allowNativeUploads() }">
<!-- Upload -->
<ui:fragment id="fileUploadFragment" rendered="#{datasetPage || EditDatafilesPage.showFileUploadFragment()}">
<script>
Expand Down Expand Up @@ -99,7 +101,9 @@
<p:commandButton id="uploadStarted" action="#{EditDatafilesPage.uploadStarted()}" update="" style="display:none"/>
<p:commandButton id="AllUploadsFinished" action="#{EditDatafilesPage.uploadFinished()}" update="datasetForm:fileUpload,datasetForm:dropBoxUserButton,datasetForm:uploadMessage,datasetForm:filesTable" style="display:none"/>
<p:commandButton id="dropBoxUploadFinished" action="#{EditDatafilesPage.uploadFinished()}" update="datasetForm:fileUpload,datasetForm:dropBoxUserButton,datasetForm:dropBoxUploadMessage,datasetForm:filesTable" style="display:none"/>
</ui:fragment>
</ui:fragment>
</c:if>
<!--PM end edit -->

<!-- Files Table -->
<p:dataTable id="filesTable"
Expand Down Expand Up @@ -270,9 +274,13 @@
<p:dialog styleClass="smallPopUp" header="#{bundle['file.addreplace.content_type.header']}" widgetVar="fileTypeDifferentPopup" id="fileTypeDifferentPopup" modal="true">
<p class="text-info"><span class="glyphicon glyphicon-info-sign"/> #{EditDatafilesPage.warningMessageForPopUp}</p>
<div class="button-block">
<!--PM start edit -->
<c:if test="#{ settingsWrapper.allowNativeUploads() }">
<p:commandButton value="#{bundle['file.delete']}" onclick="PF('fileTypeDifferentPopup').hide()"
action="#{EditDatafilesPage.deleteFiles()}"
update=":#{p:component('filesTable')},:messagePanel,:#{p:component('fileUpload')},uploadMessage"/>
update=":#{p:component('filesTable')},:messagePanel,:#{p:component('fileUpload')},uploadMessage"/>
</c:if>
<!--PM end edit -->
<p:commandButton value="#{bundle.continue}" onclick="PF('fileTypeDifferentPopup').hide()" type="button" />
</div>
</p:dialog>
Expand All @@ -283,9 +291,13 @@
<p class="text-danger"><span class="glyphicon glyphicon-warning-sign"/> #{bundle['file.deleteFileDialog.failed.tip']}</p>
</ui:fragment>
<div class="button-block">
<!--PM start edit -->
<c:if test="#{ settingsWrapper.allowNativeUploads() }">
<p:commandButton value="#{bundle.continue}" onclick="PF('deleteFileConfirmation').hide()" oncomplete="window.scrollTo(0, 0);"
update=":#{p:component('filesTable')},:messagePanel,:#{p:component('fileUpload')},uploadMessage" action="#{EditDatafilesPage.deleteFiles()}" />
<p:commandButton value="#{bundle.cancel}" onclick="PF('deleteFileConfirmation').hide()" type="button" />
</c:if>
<!--PM end edit -->
</div>
</p:dialog>
<p:dialog id="editFileAccessPopup" header="File Restrictions" widgetVar="editFileAccessPopup" modal="true">
Expand Down Expand Up @@ -482,6 +494,8 @@
</div>
<!-- ODUM-style extra variable labels for SPSS-POR files (this option is only available during ingest) -->
<div class="form-group" jsf:rendered="#{!(empty EditDatafilesPage.fileMetadataSelectedForIngestOptionsPopup) and (empty EditDatafilesPage.fileMetadataSelectedForIngestOptionsPopup.id) and dataFileServiceBean.isSpssPorFile(EditDatafilesPage.fileMetadataSelectedForIngestOptionsPopup.dataFile)}">
<!--PM start edit -->
<c:if test="#{ settingsWrapper.allowNativeUploads() }">
<label for="labelsFileUpload" class="col-sm-4 control-label">
#{bundle['file.spss-porExtraLabels']}
</label>
Expand All @@ -490,6 +504,8 @@
<p:growl id="messageForLabelsFileUpload" showDetail="true" />
<p:fileUpload id="labelsFileUpload" label="#{bundle['file.spss-porExtraLabels.selectToAddBtn']}" update="messageForLabelsFileUpload" mode="advanced" auto="true" fileUploadListener="#{EditDatafilesPage.handleLabelsFileUpload}"/>
</div>
</c:if>
<!--PM end edit -->
</div>
</div>
<div class="button-block">
Expand Down Expand Up @@ -641,6 +657,8 @@
}
}
function openDropboxChooser() {
<!--PM start edit -->
<c:if test="#{ settingsWrapper.allowNativeUploads() }">
options = {
// Required. Called when a user selects an item in the Chooser.
success: function (files) {
Expand All @@ -656,7 +674,9 @@
linkType: "direct",
multiselect: "#{datasetPage || EditDatafilesPage.allowMultipleFileUpload()}",
};
Dropbox.choose(options);
Dropbox.choose(options);
</c:if>
<!--PM end edit -->
}
</script>
</ui:composition>
</ui:composition>
5 changes: 4 additions & 1 deletion src/main/webapp/file-download-button-fragment.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
xmlns:cc="http://java.sun.com/jsf/composite"
xmlns:o="http://omnifaces.org/ui"
xmlns:iqbs="http://xmlns.jcp.org/jsf/composite/iqbs">

<c:if test="#{ settingsWrapper.allowNativeDownloads() }">

<ui:fragment rendered="#{fileMetadata.dataFile.ingestProblem and canUpdateDataset}">
<!-- Ingest Problem - this is the infamous "red triangle" error. As of 4.2, we only want to show it to the owner of the dataset: -->
Expand Down Expand Up @@ -284,5 +286,6 @@
#{bundle.close}
</button>
</div>
</p:dialog>
</p:dialog>
</c:if>
</ui:composition>