Skip to content

Commit

Permalink
issue IQSS#3156 addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksonokuhn committed Jun 10, 2016
1 parent 2935cde commit 072fb3e
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
8 changes: 8 additions & 0 deletions doc/sphinx-guides/source/api/native-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,11 @@ Execute a saved search by database id and make links to dataverses and datasets
Execute all saved searches and make links to dataverses and datasets that are found. ``debug`` works as described above. ::

PUT http://$SERVER/api/admin/savedsearches/makelinks/all?debug=true

System
~~~~~~~~~~~~~~~~
This part of the API exposes settings (namely :DatasetPublishPopupCustomText) necessary for OSF integration.

Get the :DatasetPublishPopupCustomText setting::

GET http://$SERVER/api/system/settings/:DatasetPublishPopupCustomText
46 changes: 46 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/api/Sys.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package edu.harvard.iq.dataverse.api;

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

/**
* API endpoint that returns JSON representations of particular database
* settings.
*
* @author jackson
*/
@Path("system")
public class Sys extends AbstractApiBean {

@EJB
SettingsServiceBean settingsService;

@GET
@Path("settings/:DatasetPublishPopupCustomText")
public Response getDatasetPublishPopupCustomText() {

String setting = settingsService.getValueForKey(
SettingsServiceBean.Key.DatasetPublishPopupCustomText);

JsonObjectBuilder response = Json.createObjectBuilder();

if (setting != null) {
return okResponse(response.add(
"message", setting));
} else {
return notFound("Setting "
+ SettingsServiceBean.Key.DatasetPublishPopupCustomText
+ " not found");
}
}
}
51 changes: 51 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/api/SysIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
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;

/**
*
* @author jacksonokuhn
*/
public class SysIT {

/**
* Test of getDatasetPublishPopupCustomText method, of class Sys.
*/
@Test
public void testGetDatasetPublishPopupCustomText() {

System.out.println("checking getDatasetPublishPopupCustomText");

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

Response response = given().urlEncodingEnabled(false)
.get("/api/system/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/system/settings/" + SettingsServiceBean.Key.DatasetPublishPopupCustomText);
response.prettyPrint();
response.then().assertThat().statusCode(404)
.body("message", equalTo("Setting "
+ SettingsServiceBean.Key.DatasetPublishPopupCustomText
+ " not found"));
}
}

0 comments on commit 072fb3e

Please sign in to comment.