Skip to content

Commit

Permalink
Merge branch 'develop' into 3611-custom-dv-names #3611
Browse files Browse the repository at this point in the history
Conflicts (just imports):
src/main/java/edu/harvard/iq/dataverse/SettingsWrapper.java
  • Loading branch information
pdurbin committed Jun 8, 2017
2 parents 55e5053 + 66cb841 commit c349f1b
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 96 deletions.
11 changes: 11 additions & 0 deletions doc/sphinx-guides/source/installation/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ For systems using Postgresql 8.4 or older, the procedural language `plpgsql` sho
We have provided an example :download:`here </_static/util/pg8-createsequence-prep.sql>`.



:ApplicationTermsOfUse
++++++++++++++++++++++

Expand Down Expand Up @@ -541,6 +542,16 @@ Set ``:ExcludeEmailFromExport`` to prevent email addresses for dataset contacts

``curl -X PUT -d true http://localhost:8080/api/admin/settings/:ExcludeEmailFromExport``

:NavbarAboutUrl
+++++++++++++++

Set ``NavbarAboutUrl`` to a fully-qualified url which will be used for the "About" link in the navbar.

Note: The "About" link will not appear in the navbar until this option is set.

``curl -X PUT -d http://dataverse.example.edu http://localhost:8080/api/admin/settings/:NavbarAboutUrl``


:GuidesBaseUrl
++++++++++++++

Expand Down
17 changes: 9 additions & 8 deletions doc/sphinx-guides/source/style/patterns.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,20 @@ When logged in, the account name is a dropdown menu, linking the user to account
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<span id="dataverseSupportLink" class="dropdown-toggle" data-toggle="dropdown">
Guides <b class="caret"></b>
User Name <b class="caret"></b>
</span>
<ul class="dropdown-menu">
<li><a href="#" onclick="return false;">
User Guide
</a>
<li><a href="#" onclick="return false;">My Data</a>
</li>
<li><a href="#" onclick="return false;">Developer Guide</a>
<li><a href="#" onclick="return false;">Notifications</a>
</li>
<li><a href="#" onclick="return false;">Installation Guide</a>
<li><a href="#" onclick="return false;">Account Information</a>
</li>
<li><a href="#" onclick="return false;">API Token</a>
</li>
<li class="divider"></li>
<li class="logout"><a href="#" onclick="return false;">Log Out</a>
</li>
<li><a href="#" onclick="return false;">API Guide</a>
</li><li><a href="#" onclick="return false;">Admin Guide</a></li>
</ul>
</li>
</ul>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ passwdReset.resetBtn=Reset Password

# dataverse.xhtml

dataverse.title=The project, department, university, or professor this dataverse will contain data for.
dataverse.title=The project, department, university, professor, or journal this dataverse will contain data for.
dataverse.enterName=Enter name...
dataverse.host.title=The dataverse which contains this data.
dataverse.identifier.title=Short name used for the URL of this dataverse.
Expand Down Expand Up @@ -666,7 +666,7 @@ dataverse.update.failure=This dataverse was not able to be updated.

# advanced.xhtml
advanced.search.header.dataverses=Dataverses
advanced.search.dataverses.name.tip=The project, department, university, or professor this Dataverse will contain data for.
advanced.search.dataverses.name.tip=The project, department, university, professor, or journal this Dataverse will contain data for.
advanced.search.dataverses.affiliation.tip=The organization with which this Dataverse is affiliated.
advanced.search.dataverses.description.tip=A summary describing the purpose, nature, or scope of this Dataverse.
advanced.search.dataverses.subject.tip=Domain-specific Subject Categories that are topically relevant to this Dataverse.
Expand Down
34 changes: 20 additions & 14 deletions src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,18 @@ public enum DisplayMode {
DataverseRequestServiceBean dvRequestService;
@Inject
DatasetVersionUI datasetVersionUI;
@Inject PermissionsWrapper permissionsWrapper;
@Inject FileDownloadHelper fileDownloadHelper;
@Inject TwoRavensHelper twoRavensHelper;
@Inject WorldMapPermissionHelper worldMapPermissionHelper;
@Inject ThumbnailServiceWrapper thumbnailServiceWrapper;

@Inject
PermissionsWrapper permissionsWrapper;
@Inject
FileDownloadHelper fileDownloadHelper;
@Inject
TwoRavensHelper twoRavensHelper;
@Inject
WorldMapPermissionHelper worldMapPermissionHelper;
@Inject
ThumbnailServiceWrapper thumbnailServiceWrapper;
@Inject
SettingsWrapper settingsWrapper;


private Dataset dataset = new Dataset();
Expand Down Expand Up @@ -428,11 +434,11 @@ public Boolean isSwiftStorage(){
}

public String getComputeUrl() {
return settingsService.getValueForKey(SettingsServiceBean.Key.ComputeBaseUrl) + getSwiftContainerName();
return settingsWrapper.getValueForKey(SettingsServiceBean.Key.ComputeBaseUrl) + getSwiftContainerName();
}

public String getCloudEnvironmentName() {
return settingsService.getValueForKey(SettingsServiceBean.Key.CloudEnvironmentName);
return settingsWrapper.getValueForKey(SettingsServiceBean.Key.CloudEnvironmentName);
}

public DataFile getSelectedDownloadFile() {
Expand Down Expand Up @@ -1077,7 +1083,7 @@ public boolean isGeoconnectDebugAvailable(){
return false;
}

if (settingsService.isTrueForKey(SettingsServiceBean.Key.GeoconnectDebug, false)){
if (settingsWrapper.isTrueForKey(SettingsServiceBean.Key.GeoconnectDebug, false)){
return true;
}
return false;
Expand Down Expand Up @@ -1146,9 +1152,9 @@ private String init(boolean initFull) {
guestbookResponse = new GuestbookResponse();

String nonNullDefaultIfKeyNotFound = "";
protocol = settingsService.getValueForKey(SettingsServiceBean.Key.Protocol, nonNullDefaultIfKeyNotFound);
authority = settingsService.getValueForKey(SettingsServiceBean.Key.Authority, nonNullDefaultIfKeyNotFound);
separator = settingsService.getValueForKey(SettingsServiceBean.Key.DoiSeparator, nonNullDefaultIfKeyNotFound);
protocol = settingsWrapper.getValueForKey(SettingsServiceBean.Key.Protocol, nonNullDefaultIfKeyNotFound);
authority = settingsWrapper.getValueForKey(SettingsServiceBean.Key.Authority, nonNullDefaultIfKeyNotFound);
separator = settingsWrapper.getValueForKey(SettingsServiceBean.Key.DoiSeparator, nonNullDefaultIfKeyNotFound);

if (dataset.getId() != null || versionId != null || persistentId != null) { // view mode for a dataset

Expand Down Expand Up @@ -2723,7 +2729,7 @@ private List<DatasetVersion> resetReleasedVersionTabList() {
}

public String getDatasetPublishCustomText(){
String datasetPublishCustomText = settingsService.getValueForKey(SettingsServiceBean.Key.DatasetPublishPopupCustomText);
String datasetPublishCustomText = settingsWrapper.getValueForKey(SettingsServiceBean.Key.DatasetPublishPopupCustomText);
if( datasetPublishCustomText!= null && !datasetPublishCustomText.isEmpty()){
return datasetPublishCustomText;

Expand All @@ -2732,7 +2738,7 @@ public String getDatasetPublishCustomText(){
}

public Boolean isDatasetPublishPopupCustomTextOnAllVersions(){
return settingsService.isTrueForKey(SettingsServiceBean.Key.DatasetPublishPopupCustomTextOnAllVersions, false);
return settingsWrapper.isTrueForKey(SettingsServiceBean.Key.DatasetPublishPopupCustomTextOnAllVersions, false);
}

public String getVariableMetadataURL(Long fileid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,20 @@
*/
package edu.harvard.iq.dataverse;

import edu.harvard.iq.dataverse.authorization.Permission;
import edu.harvard.iq.dataverse.authorization.groups.Group;
import edu.harvard.iq.dataverse.authorization.groups.GroupServiceBean;
import edu.harvard.iq.dataverse.authorization.users.User;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
import static edu.harvard.iq.dataverse.util.JsfHelper.JH;
import edu.harvard.iq.dataverse.util.StringUtil;
import edu.harvard.iq.dataverse.util.SystemConfig;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;

/**
Expand Down Expand Up @@ -64,7 +54,10 @@ public class DataverseHeaderFragment implements java.io.Serializable {

@Inject
DataverseSession dataverseSession;


@Inject
SettingsWrapper settingsWrapper;

@Inject
NavigationWrapper navigationWrapper;

Expand Down Expand Up @@ -248,13 +241,13 @@ public boolean isSignupAllowed() {
return signupAllowed;
}
boolean safeDefaultIfKeyNotFound = false;
signupAllowed = settingsService.isTrueForKey(SettingsServiceBean.Key.AllowSignUp, safeDefaultIfKeyNotFound);
signupAllowed = settingsWrapper.isTrueForKey(SettingsServiceBean.Key.AllowSignUp, safeDefaultIfKeyNotFound);
return signupAllowed;
}

public String getSignupUrl(String loginRedirect) {
String nonNullDefaultIfKeyNotFound = "";
String signUpUrl = settingsService.getValueForKey(SettingsServiceBean.Key.SignUpUrl, nonNullDefaultIfKeyNotFound);
String signUpUrl = settingsWrapper.getValueForKey(SettingsServiceBean.Key.SignUpUrl, nonNullDefaultIfKeyNotFound);
return signUpUrl + (!signUpUrl.contains("?") ? loginRedirect : loginRedirect.replace("?", "&"));
}

Expand Down
76 changes: 60 additions & 16 deletions src/main/java/edu/harvard/iq/dataverse/SettingsWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@
import edu.harvard.iq.dataverse.branding.BrandingUtil;
import edu.harvard.iq.dataverse.settings.Setting;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean.Key;
import edu.harvard.iq.dataverse.util.MailUtil;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import javax.ejb.EJB;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
Expand All @@ -36,28 +33,74 @@ public class SettingsWrapper implements java.io.Serializable {

private Map<String, String> settingsMap;

/**
* Values that are considered as "true".
* @see #isTrue(java.lang.String, boolean)
*/
private static final Set<String> TRUE_VALUES = Collections.unmodifiableSet(
new TreeSet<>( Arrays.asList("1","yes", "true","allow")));
// Related to a specific setting for guide urls
private String guidesBaseUrl = null;


public String get(String settingKey) {
if (settingsMap == null) {
initSettingsMap();
}

return settingsMap.get(settingKey);
}
/**
* Return value from map, initiating settings map if needed
* @param settingKey
* @param defaultValue
* @return
*/
public String get(String settingKey, String defaultValue) {
if (settingsMap == null) {
initSettingsMap();
}

if (!settingsMap.containsKey(settingKey)){
return defaultValue;
}
return settingsMap.get(settingKey);
}

/**
* Pass the map key as a "Key" object instead of a string
*
* @param key
* @return
*/
public String getValueForKey(Key key){
if (key == null){
return null;
}
return get(key.toString());
}

/**
* Pass the map key as a "Key" object instead of a string
* Allow a default value if null is encountered
*
* @param key
* @param defaultValue
* @return
*/
public String getValueForKey(Key key, String defaultValue){
if (key == null){
return null;
}
return get(key.toString(), defaultValue);
}

public boolean isTrueForKey(Key key, boolean safeDefaultIfKeyNotFound) {

return isTrueForKey(key.toString(), safeDefaultIfKeyNotFound);
}

public boolean isTrueForKey(String settingKey, boolean safeDefaultIfKeyNotFound) {
if (settingsMap == null) {
initSettingsMap();
}

String val = settingsMap.get(settingKey);;
return ( val==null ) ? safeDefaultIfKeyNotFound : TRUE_VALUES.contains(val.trim().toLowerCase() );
String val = get(settingKey);;
return ( val==null ) ? safeDefaultIfKeyNotFound : settingService.TRUE_VALUES.contains(val.trim().toLowerCase() );
}

private void initSettingsMap() {
Expand All @@ -68,13 +111,14 @@ private void initSettingsMap() {
}
}

private String guidesBaseUrl = null;

public String getGuidesBaseUrl() {
if (guidesBaseUrl == null) {
if (true)

if (guidesBaseUrl == null) {
String saneDefault = "http://guides.dataverse.org";

guidesBaseUrl = get(":GuidesBaseUrl");
guidesBaseUrl = getValueForKey(SettingsServiceBean.Key.GuidesBaseUrl);
if (guidesBaseUrl == null) {
guidesBaseUrl = saneDefault + "/en";
} else {
Expand All @@ -90,7 +134,7 @@ public String getGuidesBaseUrl() {
}

public String getSupportTeamName() {
String systemEmail = get(SettingsServiceBean.Key.SystemEmail.toString());
String systemEmail = getValueForKey(SettingsServiceBean.Key.SystemEmail);
InternetAddress systemAddress = MailUtil.parseSystemAddress(systemEmail);
return BrandingUtil.getSupportTeamName(systemAddress, dataverseService.findRootDataverse().getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import edu.harvard.iq.dataverse.DvObject;
import edu.harvard.iq.dataverse.FileMetadata;
import edu.harvard.iq.dataverse.PermissionServiceBean;
import edu.harvard.iq.dataverse.SettingsWrapper;
import edu.harvard.iq.dataverse.authorization.AuthenticationServiceBean;
import edu.harvard.iq.dataverse.authorization.Permission;
import edu.harvard.iq.dataverse.authorization.users.ApiToken;
Expand All @@ -32,7 +33,7 @@
@Named
public class TwoRavensHelper implements java.io.Serializable {

@Inject SettingsServiceBean settingsService;
@Inject SettingsWrapper settingsWrapper;
@Inject PermissionServiceBean permissionService;
@Inject AuthenticationServiceBean authService;

Expand Down Expand Up @@ -125,7 +126,7 @@ public boolean canSeeTwoRavensExploreButton(FileMetadata fm, boolean permissions
// (1) Is TwoRavens active via the "setting" table?
// Nope: get out
//
if (!settingsService.isTrueForKey(SettingsServiceBean.Key.TwoRavensTabularView, false)){
if (!settingsWrapper.isTrueForKey(SettingsServiceBean.Key.TwoRavensTabularView, false)){
this.fileMetadataTwoRavensExploreMap.put(fm.getId(), false);
return false;
}
Expand Down Expand Up @@ -207,7 +208,7 @@ public boolean canSeeTwoRavensExploreButton(FileMetadata fm, boolean permissions
* @return
*/
public String getDataExploreURL() {
String TwoRavensUrl = settingsService.getValueForKey(SettingsServiceBean.Key.TwoRavensUrl);
String TwoRavensUrl = settingsWrapper.getValueForKey(SettingsServiceBean.Key.TwoRavensUrl);

if (TwoRavensUrl != null && !TwoRavensUrl.equals("")) {
return TwoRavensUrl;
Expand All @@ -230,7 +231,7 @@ public String getDataExploreURLComplete(Long fileid) {
}


String TwoRavensUrl = settingsService.getValueForKey(SettingsServiceBean.Key.TwoRavensUrl);
String TwoRavensUrl = settingsWrapper.getValueForKey(SettingsServiceBean.Key.TwoRavensUrl);
String TwoRavensDefaultLocal = "/dataexplore/gui.html?dfId=";

if (TwoRavensUrl != null && !TwoRavensUrl.equals("")) {
Expand Down
Loading

0 comments on commit c349f1b

Please sign in to comment.