Skip to content

Commit

Permalink
Merge branch 'develop' into 3153-2419-lockuser
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Aug 4, 2016
2 parents becc694 + 054cafb commit 4f05d67
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 47 deletions.
7 changes: 7 additions & 0 deletions doc/sphinx-guides/source/api/native-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,13 @@ Shibboleth Groups

Management of Shibboleth groups via API is documented in the :doc:`/installation/shibboleth` section of the Installation Guide.

Info
~~~~

For now, only the value for the ``:DatasetPublishPopupCustomText`` setting from the :doc:`/installation/config` section of the Installation Guide is exposed::

GET http://$SERVER/api/info/settings/:DatasetPublishPopupCustomText

Metadata Blocks
~~~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion doc/sphinx-guides/source/installation/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ For Development only. Set ``GeoconnectDebug`` to true to allow a user to see SQ
:DatasetPublishPopupCustomText
++++++++++++++++++++++++++++++

Set custom text a user will view when publishing a dataset.
Set custom text a user will view when publishing a dataset. Note that this text is exposed via the "Info" endpoint of the :doc:`/api/native-api`.

``curl -X PUT -d "Deposit License Requirements" http://localhost:8080/api/admin/settings/:DatasetPublishPopupCustomText``

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/Dataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ private DatasetVersion createNewDatasetVersion(Template template) {
dsv.updateDefaultValuesFromTemplate(template);
} else {
latestVersion = getLatestVersionForCopy();

if (latestVersion.getUNF() != null){
dsv.setUNF(latestVersion.getUNF());
}

if (latestVersion.getDatasetFields() != null && !latestVersion.getDatasetFields().isEmpty()) {
dsv.setDatasetFields(dsv.copyDatasetFields(latestVersion.getDatasetFields()));
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2678,6 +2678,12 @@ public void deleteFiles() {
successMessage = successMessage.replace("{0}", fileNames);
JsfHelper.addFlashMessage(successMessage);
}

/*
Do note that if we are deleting any files that have UNFs (i.e.,
tabular files), we DO NEED TO RECALCULATE the UNF of the version!
- but we will do this inside the UpdateDatasetCommand.
*/
}

public String save() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import edu.harvard.iq.dataverse.engine.command.DataverseRequest;
import edu.harvard.iq.dataverse.engine.command.exception.CommandException;
import edu.harvard.iq.dataverse.engine.command.exception.PermissionException;
import edu.harvard.iq.dataverse.ingest.IngestServiceBean;
import edu.harvard.iq.dataverse.privateurl.PrivateUrlServiceBean;
import edu.harvard.iq.dataverse.search.IndexServiceBean;
import edu.harvard.iq.dataverse.search.SearchServiceBean;
Expand Down Expand Up @@ -73,6 +74,9 @@ public class EjbDataverseEngine {

@EJB
SearchServiceBean searchService;

@EJB
IngestServiceBean ingestService;

@EJB
PermissionServiceBean permissionService;
Expand Down Expand Up @@ -289,6 +293,11 @@ public SearchServiceBean search() {
return searchService;
}

@Override
public IngestServiceBean ingest() {
return ingestService;
}

@Override
public PermissionServiceBean permissions() {
return permissionService;
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/api/Info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package edu.harvard.iq.dataverse.api;

import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
import javax.ejb.EJB;
import javax.json.Json;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;

@Path("info")
public class Info extends AbstractApiBean {

@EJB
SettingsServiceBean settingsService;

@GET
@Path("settings/:DatasetPublishPopupCustomText")
public Response getDatasetPublishPopupCustomText() {
String setting = settingsService.getValueForKey(SettingsServiceBean.Key.DatasetPublishPopupCustomText);
if (setting != null) {
return okResponse(Json.createObjectBuilder().add("message", setting));
} else {
return notFound("Setting " + SettingsServiceBean.Key.DatasetPublishPopupCustomText + " not found");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import edu.harvard.iq.dataverse.authorization.AuthenticationServiceBean;
import edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroupServiceBean;
import edu.harvard.iq.dataverse.engine.DataverseEngine;
import edu.harvard.iq.dataverse.ingest.IngestServiceBean;
import edu.harvard.iq.dataverse.privateurl.PrivateUrlServiceBean;
import edu.harvard.iq.dataverse.search.SolrIndexServiceBean;
import edu.harvard.iq.dataverse.search.savedsearch.SavedSearchServiceBean;
Expand All @@ -39,70 +40,72 @@
* @author michael
*/
public interface CommandContext {

/**
* Note: While this method is not deprecated *yet*, please consider not using it,
* and using a method on the service bean instead. Using the em directly makes
* the command less testable.
*
* Note: While this method is not deprecated *yet*, please consider not
* using it, and using a method on the service bean instead. Using the em
* directly makes the command less testable.
*
* @return the entity manager
*/
public EntityManager em();
public DataverseEngine engine();
public DvObjectServiceBean dvObjects();
public DatasetServiceBean datasets();
public DataverseServiceBean dataverses();
public DataverseRoleServiceBean roles();
public BuiltinUserServiceBean builtinUsers();
public IndexServiceBean index();
public EntityManager em();

public DataverseEngine engine();

public DvObjectServiceBean dvObjects();

public DatasetServiceBean datasets();

public DataverseServiceBean dataverses();

public DataverseRoleServiceBean roles();

public BuiltinUserServiceBean builtinUsers();

public IndexServiceBean index();

public SolrIndexServiceBean solrIndex();

public SearchServiceBean search();

public PermissionServiceBean permissions();

public SearchServiceBean search();

public IngestServiceBean ingest();

public PermissionServiceBean permissions();

public RoleAssigneeServiceBean roleAssignees();
public DataverseFacetServiceBean facets();
public FeaturedDataverseServiceBean featuredDataverses();
public DataFileServiceBean files();

public DataverseFacetServiceBean facets();

public FeaturedDataverseServiceBean featuredDataverses();

public DataFileServiceBean files();

public TemplateServiceBean templates();

public SavedSearchServiceBean savedSearches();

public DataverseFieldTypeInputLevelServiceBean fieldTypeInputLevels();

public DOIEZIdServiceBean doiEZId();

public DOIDataCiteServiceBean doiDataCite();

public HandlenetServiceBean handleNet();

public GuestbookServiceBean guestbooks();

public GuestbookResponseServiceBean responses();

public DataverseLinkingServiceBean dvLinking();

public DatasetLinkingServiceBean dsLinking();
public SettingsServiceBean settings();

public SettingsServiceBean settings();

public ExplicitGroupServiceBean explicitGroups();

public UserNotificationServiceBean notifications();

public AuthenticationServiceBean authentication();

public SystemConfig systemConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,23 @@ public Dataset save(CommandContext ctxt) throws CommandException {
}

// Remove / delete any files that were removed

// If any of the files that we are deleting has a UNF, we will need to
// re-calculate the UNF of the version - since that is the product
// of the UNFs of the individual files.
boolean recalculateUNF = false;

for (FileMetadata fmd : filesToDelete) {
// check if this file is being used as the default thumbnail
if (fmd.getDataFile().equals(theDataset.getThumbnailFile())) {
logger.info("deleting the dataset thumbnail designation");
theDataset.setThumbnailFile(null);
}

if (fmd.getDataFile().getUnf() != null) {
recalculateUNF = true;
}

if (!fmd.getDataFile().isReleased()) {
// if file is draft (ie. new to this version, delete; otherwise just remove filemetadata object)
ctxt.engine().submit(new DeleteDataFileCommand(fmd.getDataFile(), getRequest()));
Expand All @@ -163,6 +173,10 @@ public Dataset save(CommandContext ctxt) throws CommandException {
}
}

if (recalculateUNF) {
ctxt.ingest().recalculateDatasetVersionUNF(theDataset.getEditVersion());
}

String nonNullDefaultIfKeyNotFound = "";
String doiProvider = ctxt.settings().getValueForKey(SettingsServiceBean.Key.DoiProvider, nonNullDefaultIfKeyNotFound);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,12 @@ public void recalculateDatasetVersionUNF(DatasetVersion version) {
version.setUNF(datasetUnfValue);
logger.fine("Recalculated the UNF for the dataset version id="+version.getId()+", new signature: "+datasetUnfValue);
}
} else {
// Of course if no files in the version have UNFs, we need to make sure
// that the version has the NULL UNF too.
// Otherwise, the version will still have a UNF if the user deletes
// all the tabular files from the version!
version.setUNF(null);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/resources/css/structure.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ body .ui-widget {font-size: inherit;}
#navbarFixed li.dropdown.open > span.dropdown-toggle {background-color: #e7e7e7;}

#footer {margin-top:3em; padding-bottom:4em; color:#808080;}
#footer.widget-view {position:fixed; left:0px; bottom:0px; margin:0; padding:4px 0 0 0; height:44px; width:100%; background:#fff;}
#footer.widget-view {position:fixed; left:0px; bottom:0px; margin:0; padding:4px 0 0 0; min-height:44px; width:100%; background:#fff;}
#footer span.socicon-twitter {color:#55acee; font-size:1.3em; vertical-align: top;}
#footer span.socicon-github {color:#000; font-size:1.3em; vertical-align: top;}
#footer .poweredbylogo {text-align:right;}
Expand Down
37 changes: 37 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/api/InfoIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package edu.harvard.iq.dataverse.api;

import static com.jayway.restassured.RestAssured.given;
import com.jayway.restassured.response.Response;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.equalTo;

public class InfoIT {

@Test
public void testGetDatasetPublishPopupCustomText() {

given().urlEncodingEnabled(false)
.body("Hello world!")
.put("/api/admin/settings/"
+ SettingsServiceBean.Key.DatasetPublishPopupCustomText);

Response response = given().urlEncodingEnabled(false)
.get("/api/info/settings/" + SettingsServiceBean.Key.DatasetPublishPopupCustomText);
response.prettyPrint();
response.then().assertThat().statusCode(200)
.body("data.message", equalTo("Hello world!"));

given().urlEncodingEnabled(false)
.delete("/api/admin/settings/"
+ SettingsServiceBean.Key.DatasetPublishPopupCustomText);

response = given().urlEncodingEnabled(false)
.get("/api/info/settings/" + SettingsServiceBean.Key.DatasetPublishPopupCustomText);
response.prettyPrint();
response.then().assertThat().statusCode(404)
.body("message", equalTo("Setting "
+ SettingsServiceBean.Key.DatasetPublishPopupCustomText
+ " not found"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import edu.harvard.iq.dataverse.authorization.AuthenticationServiceBean;
import edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroupServiceBean;
import edu.harvard.iq.dataverse.engine.command.CommandContext;
import edu.harvard.iq.dataverse.ingest.IngestServiceBean;
import edu.harvard.iq.dataverse.privateurl.PrivateUrlServiceBean;
import edu.harvard.iq.dataverse.search.IndexServiceBean;
import edu.harvard.iq.dataverse.search.SearchServiceBean;
Expand Down Expand Up @@ -57,6 +58,11 @@ public SearchServiceBean search() {
return null;
}

@Override
public IngestServiceBean ingest() {
return null;
}

@Override
public PermissionServiceBean permissions() {
return null;
Expand Down

0 comments on commit 4f05d67

Please sign in to comment.