diff --git a/src/main/java/com/researchspace/dataverse/api/v1/DataverseAPI.java b/src/main/java/com/researchspace/dataverse/api/v1/DataverseAPI.java index 38df432..59dabdd 100644 --- a/src/main/java/com/researchspace/dataverse/api/v1/DataverseAPI.java +++ b/src/main/java/com/researchspace/dataverse/api/v1/DataverseAPI.java @@ -44,6 +44,8 @@ public interface DataverseAPI { * @param config */ void configure (DataverseConfig config); + + InfoOperations getInfoOperations(); } \ No newline at end of file diff --git a/src/main/java/com/researchspace/dataverse/api/v1/InfoOperations.java b/src/main/java/com/researchspace/dataverse/api/v1/InfoOperations.java new file mode 100644 index 0000000..c030e19 --- /dev/null +++ b/src/main/java/com/researchspace/dataverse/api/v1/InfoOperations.java @@ -0,0 +1,12 @@ +package com.researchspace.dataverse.api.v1; + +import com.researchspace.dataverse.entities.DataverseResponse; +import com.researchspace.dataverse.entities.DvMessage; + +public interface InfoOperations { + + DvMessage getDatasetPublishPopupCustomText () ; + + DataverseResponse setDatasetPublishPopupCustomText (String text) ; + +} diff --git a/src/main/java/com/researchspace/dataverse/http/DataverseAPIImpl.java b/src/main/java/com/researchspace/dataverse/http/DataverseAPIImpl.java index 40d9393..baf8e0e 100644 --- a/src/main/java/com/researchspace/dataverse/http/DataverseAPIImpl.java +++ b/src/main/java/com/researchspace/dataverse/http/DataverseAPIImpl.java @@ -4,6 +4,7 @@ import com.researchspace.dataverse.api.v1.DataverseAPI; import com.researchspace.dataverse.api.v1.DataverseConfig; import com.researchspace.dataverse.api.v1.DataverseOperations; +import com.researchspace.dataverse.api.v1.InfoOperations; import com.researchspace.dataverse.api.v1.MetadataOperations; /** Copyright 2016 ResearchSpace @@ -43,4 +44,9 @@ public void configure(DataverseConfig config) { dvOperationsImpl.setApiKey(config.getApiKey()); dvOperationsImpl.setServerURL(config.getServerURL().toString()); } + + @Override + public InfoOperations getInfoOperations() { + return dvOperationsImpl; + } } diff --git a/src/main/java/com/researchspace/dataverse/http/DataverseOperationsImplV1.java b/src/main/java/com/researchspace/dataverse/http/DataverseOperationsImplV1.java index 5e1c8eb..d82664e 100644 --- a/src/main/java/com/researchspace/dataverse/http/DataverseOperationsImplV1.java +++ b/src/main/java/com/researchspace/dataverse/http/DataverseOperationsImplV1.java @@ -29,6 +29,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.researchspace.dataverse.api.v1.DatasetOperations; import com.researchspace.dataverse.api.v1.DataverseOperations; +import com.researchspace.dataverse.api.v1.InfoOperations; import com.researchspace.dataverse.api.v1.MetadataOperations; import com.researchspace.dataverse.entities.Dataset; import com.researchspace.dataverse.entities.DatasetVersion; @@ -62,11 +63,12 @@ */ @Slf4j -public class DataverseOperationsImplV1 implements DatasetOperations, MetadataOperations, DataverseOperations { +public class DataverseOperationsImplV1 implements DatasetOperations, MetadataOperations, InfoOperations, DataverseOperations { private String apiKey = ""; private String serverURL = ""; - String serverAPIURL = serverURL +"/api/v1"; + String serverAPIURL = serverURL +"/api"; + String serverAPIv1URL = serverAPIURL +"/v1"; final String apiHeader = "X-Dataverse-key"; public void setApiKey(String apiKey) { @@ -75,7 +77,8 @@ public void setApiKey(String apiKey) { public void setServerURL(String serverURL) { this.serverURL = serverURL; - this.serverAPIURL = this.serverURL +"/api/v1"; + this.serverAPIURL = serverURL + "/api"; + this.serverAPIv1URL = this.serverAPIURL +"/v1"; } @@ -84,7 +87,7 @@ public void setServerURL(String serverURL) { */ @Override public Dataverse getDataverseById(String dataverseAlias) { - String url = createUrl("dataverses" , dataverseAlias); + String url = createV1Url("dataverses" , dataverseAlias); log.debug(url); RestTemplate template = createTemplate(); HttpEntity entity = createHttpEntity(""); @@ -95,7 +98,12 @@ public Dataverse getDataverseById(String dataverseAlias) { return resp.getBody().getData(); } - private String createUrl(String ... pathComponents) { + private String createV1Url(String ... pathComponents) { + String url = serverAPIv1URL + "/" + StringUtils.join(pathComponents, "/") ; + log.info("URL is {}", url); + return url; + } + private String createAdminUrl(String ... pathComponents) { String url = serverAPIURL + "/" + StringUtils.join(pathComponents, "/") ; log.info("URL is {}", url); return url; @@ -103,7 +111,7 @@ private String createUrl(String ... pathComponents) { @Override public DataverseResponse deleteDataverse(String dataverseAlias) { - String url = createUrl("dataverses", dataverseAlias); + String url = createV1Url("dataverses", dataverseAlias); log.debug(url); RestTemplate template = createTemplate(); HttpEntity entity = createHttpEntity(""); @@ -121,7 +129,7 @@ public DataverseResponse createNewDataverse(String parentDv, Datavers isTrue(!isEmpty(toCreate.getName()), "Name must be specified"); noNullElements(toCreate.getDataverseContacts(), "At least 1 email contact must be provided"); isTrue(!isEmpty(toCreate.getAlias()), "Alias must be specified"); - String url = createUrl("dataverses", parentDv); + String url = createV1Url("dataverses", parentDv); RestTemplate template = createTemplate(); String json = marshalDataset(toCreate); @@ -140,7 +148,7 @@ public DataverseResponse createNewDataverse(String parentDv, Datavers */ @Override public Identifier createDataset(DatasetFacade facade, String dataverseAlias) { - String url = createUrl("dataverses", dataverseAlias,"datasets"); + String url = createV1Url("dataverses", dataverseAlias,"datasets"); RestTemplate template = createTemplate(); String json = getJsonFromFacade(facade); @@ -159,7 +167,7 @@ public Identifier createDataset(DatasetFacade facade, String dataverseAlias) { */ @Override public DatasetVersion updateDataset(DatasetFacade facade, Identifier id) { - String url = createUrl("datasets", id.getId() +"", "versions",":draft"); + String url = createV1Url("datasets", id.getId() +"", "versions",":draft"); Dataset ds = new DatasetBuilder().build(facade); String json = marshalDataset(ds.getDatasetVersion()); @@ -180,7 +188,7 @@ public DatasetVersion updateDataset(DatasetFacade facade, Identifier id) { */ @Override public Dataset getDataset(Identifier dsIdentifier) { - String url = createUrl("datasets", dsIdentifier.getId() +""); + String url = createV1Url("datasets", dsIdentifier.getId() +""); RestTemplate template = createTemplate(); HttpEntity entity = createHttpEntity(""); ParameterizedTypeReference> type = new ParameterizedTypeReference>() { @@ -195,7 +203,7 @@ public Dataset getDataset(Identifier dsIdentifier) { */ @Override public List getDatasetVersions (Identifier dsIdentifier) { - String url = createUrl("datasets", dsIdentifier.getId() +"", "versions"); + String url = createV1Url("datasets", dsIdentifier.getId() +"", "versions"); RestTemplate template = createTemplate(); HttpEntity entity = createHttpEntity(""); ParameterizedTypeReference>> type = new ParameterizedTypeReference>>() { @@ -225,7 +233,7 @@ public void uploadFile (String doi, File file) { */ @Override public DvMessage deleteDataset(Identifier dsIdentifier) { - String url = createUrl("datasets", dsIdentifier.getId() +"" ); + String url = createV1Url("datasets", dsIdentifier.getId() +"" ); RestTemplate template = createTemplate(); HttpEntity entity = createHttpEntity(""); ParameterizedTypeReference> type = new ParameterizedTypeReference>() { @@ -263,7 +271,7 @@ private String marshalDataset(Object object) { */ @Override public List getDataverseContents(String dataverseAlias) { - String url = createUrl("dataverses", dataverseAlias, "contents" ); + String url = createV1Url("dataverses", dataverseAlias, "contents" ); RestTemplate template = createTemplate(); HttpEntity entity = createHttpEntity(""); ParameterizedTypeReference>> type = new ParameterizedTypeReference>>() { @@ -292,7 +300,7 @@ private HttpHeaders addAPIKeyToHeader() { */ @Override public List getMetadataBlockInfo() { - String url = createUrl("metadatablocks" ); + String url = createV1Url("metadatablocks" ); RestTemplate template = createTemplate(); HttpHeaders headers = addAPIKeyToHeader(); HttpEntity entity = new HttpEntity("parameters", headers); @@ -309,7 +317,7 @@ public List getMetadataBlockInfo() { */ @Override public MetadataBlock getMetadataById(String name) { - String url = createUrl("metadatablocks", name ); + String url = createV1Url("metadatablocks", name ); RestTemplate template = createTemplate(); HttpHeaders headers = addAPIKeyToHeader(); HttpEntity entity = new HttpEntity("parameters", headers); @@ -343,7 +351,7 @@ RestTemplate createTemplate() { */ @Override public void publishDataset(Identifier dsIdentifier, Version version) { - String url = createUrl("datasets", dsIdentifier.getId() + "", "actions", ":publish") + "?type=" + String url = createV1Url("datasets", dsIdentifier.getId() + "", "actions", ":publish") + "?type=" + version.name().toLowerCase(); RestTemplate template = createTemplate(); HttpEntity entity = createHttpEntity(""); @@ -358,7 +366,7 @@ public void publishDataset(Identifier dsIdentifier, Version version) { @Override public DataverseResponse publishDataverse(String dvName) { - String url = createUrl("dataverses", dvName, "actions", ":publish"); + String url = createV1Url("dataverses", dvName, "actions", ":publish"); RestTemplate template = createTemplate(); HttpEntity entity = createHttpEntity(""); ParameterizedTypeReference> type = new ParameterizedTypeReference>() { @@ -367,5 +375,30 @@ public DataverseResponse publishDataverse(String dvName) { log.debug(resp.getBody().toString()); return resp.getBody(); + } + + @Override + public DvMessage getDatasetPublishPopupCustomText() { + String url = createAdminUrl("admin", "settings", ":DatasetPublishPopupCustomText"); + RestTemplate template = createTemplate(); + HttpEntity entity = createHttpEntity(""); + ParameterizedTypeReference> type = new ParameterizedTypeReference>() { + }; + ResponseEntity> resp = template.exchange(url, HttpMethod.GET, entity, type); + log.debug(resp.getBody().toString()); + return resp.getBody().getData(); + + } + + @Override + public DataverseResponse setDatasetPublishPopupCustomText(String text) { + String url = createAdminUrl("admin", "settings", ":DatasetPublishPopupCustomText"); + RestTemplate template = createTemplate(); + HttpEntity entity = createHttpEntity(text); + ParameterizedTypeReference> type = new ParameterizedTypeReference>() { + }; + ResponseEntity> resp = template.exchange(url, HttpMethod.PUT, entity, type); + log.debug(resp.getBody().toString()); + return resp.getBody(); } } diff --git a/src/test/java/com/researchspace/dataverse/http/AbstractIntegrationTest.java b/src/test/java/com/researchspace/dataverse/http/AbstractIntegrationTest.java index 4a72bea..c6593f6 100644 --- a/src/test/java/com/researchspace/dataverse/http/AbstractIntegrationTest.java +++ b/src/test/java/com/researchspace/dataverse/http/AbstractIntegrationTest.java @@ -17,6 +17,7 @@ import com.researchspace.dataverse.api.v1.DataverseAPI; import com.researchspace.dataverse.api.v1.DataverseConfig; import com.researchspace.dataverse.api.v1.DataverseOperations; +import com.researchspace.dataverse.api.v1.InfoOperations; import com.researchspace.dataverse.api.v1.MetadataOperations; import com.researchspace.dataverse.spring.config.DataverseSpringConfig; @@ -30,6 +31,7 @@ public class AbstractIntegrationTest extends AbstractJUnit4SpringContextTests { DatasetOperations datasetOps; DataverseOperations dataverseOps; MetadataOperations metadataOPs; + InfoOperations infoOps; @Autowired DataverseAPI dataverseAPI; @Value("#{systemProperties['dataverseAlias']}") @@ -56,6 +58,7 @@ public void setUp() throws Exception { datasetOps = dataverseAPI.getDatasetOperations(); dataverseOps = dataverseAPI.getDataverseOperations(); metadataOPs = dataverseAPI.getMetadataOperations(); + infoOps = dataverseAPI.getInfoOperations(); } private void validateServerCredentials() { @@ -67,10 +70,4 @@ private void validateServerCredentials() { Validate.notEmpty(serverURL, "Dataverse server URL must be set via command line -DdataverseServerURL option or in test.properties)"); } - - @Test - public void test() { - assertTrue(1 == 1);// stop complaints about no methods - } - } diff --git a/src/test/java/com/researchspace/dataverse/http/InfoOperationsTest.java b/src/test/java/com/researchspace/dataverse/http/InfoOperationsTest.java new file mode 100644 index 0000000..3be4b78 --- /dev/null +++ b/src/test/java/com/researchspace/dataverse/http/InfoOperationsTest.java @@ -0,0 +1,37 @@ +package com.researchspace.dataverse.http; + +import static org.junit.Assert.*; + +import org.apache.commons.lang.StringUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.researchspace.dataverse.entities.DataverseResponse; +import com.researchspace.dataverse.entities.DvMessage; + +public class InfoOperationsTest extends AbstractIntegrationTest { + + private static final String NEW_TEXT = "Do you want to publish"; + + @Before + public void setUp() throws Exception { + super.setUp(); + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testGetSetDatasetPublishPopupCustomText() { + DvMessage originalText = infoOps.getDatasetPublishPopupCustomText(); + assertTrue("Message text was empty", !StringUtils.isEmpty(originalText.getMessage())); + DataverseResponse response = infoOps.setDatasetPublishPopupCustomText(NEW_TEXT); + assertTrue("New text was not set", response.getData().toString().contains(NEW_TEXT)); + response = infoOps.setDatasetPublishPopupCustomText(originalText.getMessage()); + assertTrue("Originl text was not restored", response.getData().toString().contains(originalText.getMessage())); + } + + +}