String[] fullName = name.split(", ");
- givenName = fullName[1];
+ givenName = fullName.length > 1 ? fullName[1] : null;
familyName = fullName[0];
}
}
diff --git a/src/main/webapp/dataset-license-terms.xhtml b/src/main/webapp/dataset-license-terms.xhtml
index 255e63fbfc2..03173faf989 100644
--- a/src/main/webapp/dataset-license-terms.xhtml
+++ b/src/main/webapp/dataset-license-terms.xhtml
@@ -12,7 +12,7 @@
or !empty termsOfUseAndAccess.originalArchive or !empty termsOfUseAndAccess.availabilityStatus
or !empty termsOfUseAndAccess.contactForAccess or !empty termsOfUseAndAccess.sizeOfCollection
or !empty termsOfUseAndAccess.studyCompletion
- or termsOfUseAndAccess.fileAccessRequest}"/>
+ }"/>
ids = List.of(dataverse2Id, dataverse3Id);
+ List uniqueids = new ArrayList<>();
+ assertEquals(ids.size(), lst.size());
+ for (int i = 0; i < lst.size(); i++) {
+ int id = lst.getJsonObject(i).getInt("id");
+ assertTrue(ids.contains(id));
+ assertFalse(uniqueids.contains(id));
+ uniqueids.add(id);
+ }
+
//Experimental code for trying to trick test into thinking the dataset has been harvested
/*
createDataset = UtilIT.createRandomDatasetViaNativeApi(dataverse1Alias, apiToken);
diff --git a/src/test/java/edu/harvard/iq/dataverse/api/DataversesIT.java b/src/test/java/edu/harvard/iq/dataverse/api/DataversesIT.java
index 6fbe91c8405..8c6a8244af1 100644
--- a/src/test/java/edu/harvard/iq/dataverse/api/DataversesIT.java
+++ b/src/test/java/edu/harvard/iq/dataverse/api/DataversesIT.java
@@ -646,6 +646,179 @@ public void testImportDDI() throws IOException, InterruptedException {
Response deleteUserResponse = UtilIT.deleteUser(username);
assertEquals(200, deleteUserResponse.getStatusCode());
}
+
+ @Test
+ public void testImport() throws IOException, InterruptedException {
+
+ Response createUser = UtilIT.createRandomUser();
+ String username = UtilIT.getUsernameFromResponse(createUser);
+ Response makeSuperUser = UtilIT.makeSuperUser(username);
+ assertEquals(200, makeSuperUser.getStatusCode());
+ String apiToken = UtilIT.getApiTokenFromResponse(createUser);
+
+ Response createDataverseResponse = UtilIT.createRandomDataverse(apiToken);
+ String dataverseAlias = UtilIT.getAliasFromResponse(createDataverseResponse);
+
+ Response publishDataverse = UtilIT.publishDataverseViaNativeApi(dataverseAlias, apiToken);
+ assertEquals(200, publishDataverse.getStatusCode());
+
+ JsonObjectBuilder datasetJson = Json.createObjectBuilder()
+ .add("datasetVersion", Json.createObjectBuilder()
+ .add("license", Json.createObjectBuilder()
+ .add("name", "CC0 1.0")
+ )
+ .add("metadataBlocks", Json.createObjectBuilder()
+ .add("citation", Json.createObjectBuilder()
+ .add("fields", Json.createArrayBuilder()
+ .add(Json.createObjectBuilder()
+ .add("typeName", "title")
+ .add("value", "Test Dataset")
+ .add("typeClass", "primitive")
+ .add("multiple", false)
+ )
+ .add(Json.createObjectBuilder()
+ .add("value", Json.createArrayBuilder()
+ .add(Json.createObjectBuilder()
+ .add("authorName",
+ Json.createObjectBuilder()
+ .add("value", "Simpson, Homer")
+ .add("typeClass", "primitive")
+ .add("multiple", false)
+ .add("typeName", "authorName"))
+ )
+ )
+ .add("typeClass", "compound")
+ .add("multiple", true)
+ .add("typeName", "author")
+ )
+ .add(Json.createObjectBuilder()
+ .add("value", Json.createArrayBuilder()
+ .add(Json.createObjectBuilder()
+ .add("datasetContactEmail",
+ Json.createObjectBuilder()
+ .add("value", "hsimpson@mailinator.com")
+ .add("typeClass", "primitive")
+ .add("multiple", false)
+ .add("typeName", "datasetContactEmail"))
+ )
+ )
+ .add("typeClass", "compound")
+ .add("multiple", true)
+ .add("typeName", "datasetContact")
+ )
+ .add(Json.createObjectBuilder()
+ .add("value", Json.createArrayBuilder()
+ .add(Json.createObjectBuilder()
+ .add("dsDescriptionValue",
+ Json.createObjectBuilder()
+ .add("value", "This a test dataset.")
+ .add("typeClass", "primitive")
+ .add("multiple", false)
+ .add("typeName", "dsDescriptionValue"))
+ )
+ )
+ .add("typeClass", "compound")
+ .add("multiple", true)
+ .add("typeName", "dsDescription")
+ )
+ .add(Json.createObjectBuilder()
+ .add("value", Json.createArrayBuilder()
+ .add("Other")
+ )
+ .add("typeClass", "controlledVocabulary")
+ .add("multiple", true)
+ .add("typeName", "subject")
+ )
+ )
+ )
+ ));
+
+ String json = datasetJson.build().toString();
+
+ Response importJSONNoPid = UtilIT.importDatasetViaNativeApi(apiToken, dataverseAlias, json, null, "no");
+ logger.info(importJSONNoPid.prettyPrint());
+ assertEquals(400, importJSONNoPid.getStatusCode());
+
+ String body = importJSONNoPid.getBody().asString();
+ String status = JsonPath.from(body).getString("status");
+ assertEquals("ERROR", status);
+
+ String message = JsonPath.from(body).getString("message");
+ assertEquals(
+ "Please provide a persistent identifier, either by including it in the JSON, or by using the pid query parameter.",
+ message
+ );
+
+ Response importJSONNoPidRelease = UtilIT.importDatasetViaNativeApi(apiToken, dataverseAlias, json, null, "yes");
+ logger.info( importJSONNoPidRelease.prettyPrint());
+ assertEquals(400, importJSONNoPidRelease.getStatusCode());
+
+ body = importJSONNoPidRelease.getBody().asString();
+ status = JsonPath.from(body).getString("status");
+ assertEquals("ERROR", status);
+
+ message = JsonPath.from(body).getString("message");
+ assertEquals(
+ "Please provide a persistent identifier, either by including it in the JSON, or by using the pid query parameter.",
+ message
+ );
+
+ Response importJSONUnmanagedPid = UtilIT.importDatasetViaNativeApi(apiToken, dataverseAlias, json, "doi:10.5073/FK2/ABCD11", "no");
+ logger.info(importJSONUnmanagedPid.prettyPrint());
+ assertEquals(400, importJSONUnmanagedPid.getStatusCode());
+
+ body = importJSONUnmanagedPid.getBody().asString();
+ status = JsonPath.from(body).getString("status");
+ assertEquals("ERROR", status);
+
+ message = JsonPath.from(body).getString("message");
+ assertEquals(
+ "Cannot import a dataset that has a PID that doesn't match the server's settings",
+ message
+ );
+
+ // Under normal conditions, you shouldn't need to destroy these datasets.
+ // Uncomment if they're still around from a previous failed run.
+// Response destroy1 = UtilIT.destroyDataset("doi:10.5072/FK2/ABCD11", apiToken);
+// destroy1.prettyPrint();
+// Response destroy2 = UtilIT.destroyDataset("doi:10.5072/FK2/ABCD22", apiToken);
+// destroy2.prettyPrint();
+
+ Response importJSONPid = UtilIT.importDatasetViaNativeApi(apiToken, dataverseAlias, json, "doi:10.5072/FK2/ABCD11", "no");
+ logger.info(importJSONPid.prettyPrint());
+ assertEquals(201, importJSONPid.getStatusCode());
+
+ Response importJSONPidRel = UtilIT.importDatasetViaNativeApi(apiToken, dataverseAlias, json, "doi:10.5072/FK2/ABCD22", "yes");
+ logger.info(importJSONPidRel.prettyPrint());
+ assertEquals(201, importJSONPidRel.getStatusCode());
+
+ Integer datasetIdInt = JsonPath.from(importJSONPid.body().asString()).getInt("data.id");
+
+ Response search1 = UtilIT.search("id:dataset_" + datasetIdInt + "_draft", apiToken); // santity check, can find it
+ search1.prettyPrint();
+ search1.then().assertThat()
+ .body("data.total_count", CoreMatchers.is(1))
+ .body("data.count_in_response", CoreMatchers.is(1))
+ .body("data.items[0].name", CoreMatchers.is("Test Dataset"))
+ .statusCode(OK.getStatusCode());
+
+ //cleanup
+
+ Response destroyDatasetResponse = UtilIT.destroyDataset(datasetIdInt, apiToken);
+ assertEquals(200, destroyDatasetResponse.getStatusCode());
+
+ Integer datasetIdIntPidRel = JsonPath.from(importJSONPidRel.body().asString()).getInt("data.id");
+ Response destroyDatasetResponsePidRel = UtilIT.destroyDataset(datasetIdIntPidRel, apiToken);
+ assertEquals(200, destroyDatasetResponsePidRel.getStatusCode());
+
+ UtilIT.sleepForDeadlock(UtilIT.MAXIMUM_IMPORT_DURATION);
+
+ Response deleteDataverseResponse = UtilIT.deleteDataverse(dataverseAlias, apiToken);
+ assertEquals(200, deleteDataverseResponse.getStatusCode());
+
+ Response deleteUserResponse = UtilIT.deleteUser(username);
+ assertEquals(200, deleteUserResponse.getStatusCode());
+ }
@Test
public void testAttributesApi() throws Exception {
diff --git a/src/test/java/edu/harvard/iq/dataverse/api/MetadataBlocksIT.java b/src/test/java/edu/harvard/iq/dataverse/api/MetadataBlocksIT.java
index 0153d8dc893..6e7061961f0 100644
--- a/src/test/java/edu/harvard/iq/dataverse/api/MetadataBlocksIT.java
+++ b/src/test/java/edu/harvard/iq/dataverse/api/MetadataBlocksIT.java
@@ -51,7 +51,7 @@ void testListMetadataBlocks() {
// onlyDisplayedOnCreate=true and returnDatasetFieldTypes=true
listMetadataBlocksResponse = UtilIT.listMetadataBlocks(true, true);
- expectedNumberOfMetadataFields = 26;
+ expectedNumberOfMetadataFields = 28;
listMetadataBlocksResponse.then().assertThat()
.statusCode(OK.getStatusCode())
.body("data[0].fields", not(equalTo(null)))
diff --git a/src/test/java/edu/harvard/iq/dataverse/api/MoveIT.java b/src/test/java/edu/harvard/iq/dataverse/api/MoveIT.java
index f7135ce7f3b..8951b0bd42e 100644
--- a/src/test/java/edu/harvard/iq/dataverse/api/MoveIT.java
+++ b/src/test/java/edu/harvard/iq/dataverse/api/MoveIT.java
@@ -278,8 +278,8 @@ public void testMoveLinkedDataset() {
.body("message", equalTo("Use the query parameter forceMove=true to complete the move. This dataset is linked to the new host dataverse or one of its parents. This move would remove the link to this dataset. "));
JsonObject linksBeforeData = Json.createReader(new StringReader(getLinksBefore.asString())).readObject();
- assertEquals("OK", linksBeforeData.getString("status"));
- assertEquals(dataverse2Alias + " (id " + dataverse2Id + ")", linksBeforeData.getJsonObject("data").getJsonArray("dataverses that link to dataset id " + datasetId).getString(0));
+ assertEquals(datasetId, linksBeforeData.getJsonObject("data").getInt("id"));
+ assertEquals(dataverse2Id, linksBeforeData.getJsonObject("data").getJsonArray("linked-dataverses").get(0).asJsonObject().getInt("id"));
boolean forceMove = true;
Response forceMoveLinkedDataset = UtilIT.moveDataset(datasetId.toString(), dataverse2Alias, forceMove, superuserApiToken);
@@ -308,8 +308,7 @@ public void testMoveLinkedDataset() {
JsonObject linksAfterData = Json.createReader(new StringReader(getLinksAfter.asString())).readObject();
assertEquals("OK", linksAfterData.getString("status"));
- assertEquals(0, linksAfterData.getJsonObject("data").getJsonArray("dataverses that link to dataset id " + datasetId).size());
-
+ assertEquals(0, linksAfterData.getJsonObject("data").getJsonArray("linked-dataverses").size());
}
@Test
diff --git a/src/test/java/edu/harvard/iq/dataverse/api/UsersIT.java b/src/test/java/edu/harvard/iq/dataverse/api/UsersIT.java
index 0189ffd6e58..1003c1a990c 100644
--- a/src/test/java/edu/harvard/iq/dataverse/api/UsersIT.java
+++ b/src/test/java/edu/harvard/iq/dataverse/api/UsersIT.java
@@ -23,6 +23,8 @@
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.contains;
import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -371,23 +373,33 @@ public void testAPITokenEndpoints() {
.body("data.message", containsString(userApiToken))
.body("data.message", containsString("expires on"));
+ // Recreate given a bad API token
Response recreateToken = UtilIT.recreateToken("BAD-Token-blah-89234");
recreateToken.prettyPrint();
recreateToken.then().assertThat()
.statusCode(UNAUTHORIZED.getStatusCode());
+ // Recreate given a valid API token
recreateToken = UtilIT.recreateToken(userApiToken);
recreateToken.prettyPrint();
recreateToken.then().assertThat()
.statusCode(OK.getStatusCode())
- .body("data.message", containsString("New token for"));
+ .body("data.message", containsString("New token for"))
+ .body("data.message", CoreMatchers.not(containsString("and expires on")));
+ // Recreate given a valid API token and returning expiration
createUser = UtilIT.createRandomUser();
- createUser.prettyPrint();
- assertEquals(200, createUser.getStatusCode());
+ assertEquals(OK.getStatusCode(), createUser.getStatusCode());
+
+ userApiToken = UtilIT.getApiTokenFromResponse(createUser);
+
+ recreateToken = UtilIT.recreateToken(userApiToken, true);
+ recreateToken.prettyPrint();
+ recreateToken.then().assertThat()
+ .statusCode(OK.getStatusCode())
+ .body("data.message", containsString("New token for"))
+ .body("data.message", containsString("and expires on"));
- String userApiTokenForDelete = UtilIT.getApiTokenFromResponse(createUser);
-
/*
Add tests for Private URL
*/
@@ -418,6 +430,10 @@ public void testAPITokenEndpoints() {
getExpiration.then().assertThat()
.statusCode(NOT_FOUND.getStatusCode());
+ createUser = UtilIT.createRandomUser();
+ assertEquals(OK.getStatusCode(), createUser.getStatusCode());
+
+ String userApiTokenForDelete = UtilIT.getApiTokenFromResponse(createUser);
Response deleteToken = UtilIT.deleteToken(userApiTokenForDelete);
deleteToken.prettyPrint();
diff --git a/src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java b/src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java
index 4e20e8e4c33..70f49d81b35 100644
--- a/src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java
+++ b/src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java
@@ -2813,10 +2813,15 @@ static Response getTokenExpiration( String apiToken) {
return response;
}
- static Response recreateToken( String apiToken) {
+ static Response recreateToken(String apiToken) {
+ return recreateToken(apiToken, false);
+ }
+
+ static Response recreateToken(String apiToken, boolean returnExpiration) {
Response response = given()
- .header(API_TOKEN_HTTP_HEADER, apiToken)
- .post("api/users/token/recreate");
+ .header(API_TOKEN_HTTP_HEADER, apiToken)
+ .queryParam("returnExpiration", returnExpiration)
+ .post("api/users/token/recreate");
return response;
}
@@ -3672,6 +3677,35 @@ static Response importDatasetDDIViaNativeApi(String apiToken, String dataverseAl
return importDDI.post(postString);
}
+
+ static Response importDatasetViaNativeApi(String apiToken, String dataverseAlias, String json, String pid, String release) {
+ String postString = "/api/dataverses/" + dataverseAlias + "/datasets/:import";
+ if (pid != null || release != null ) {
+ //postString = postString + "?";
+ if (pid != null) {
+ postString = postString + "?pid=" + pid;
+ if (release != null && release.compareTo("yes") == 0) {
+ postString = postString + "&release=" + release;
+ }
+ } else {
+ if (release != null && release.compareTo("yes") == 0) {
+ postString = postString + "?release=" + release;
+ }
+ }
+ }
+ logger.info("Here importDatasetViaNativeApi");
+ logger.info(postString);
+
+ RequestSpecification importJSON = given()
+ .header(API_TOKEN_HTTP_HEADER, apiToken)
+ .urlEncodingEnabled(false)
+ .body(json)
+ .contentType("application/json");
+
+ return importJSON.post(postString);
+ }
+
+
static Response retrieveMyDataAsJsonString(String apiToken, String userIdentifier, ArrayList roleIds) {
Response response = given()
.header(API_TOKEN_HTTP_HEADER, apiToken)
diff --git a/src/test/java/edu/harvard/iq/dataverse/util/PersonOrOrgUtilTest.java b/src/test/java/edu/harvard/iq/dataverse/util/PersonOrOrgUtilTest.java
index c3d9fd8fcd3..d772ba2b9da 100644
--- a/src/test/java/edu/harvard/iq/dataverse/util/PersonOrOrgUtilTest.java
+++ b/src/test/java/edu/harvard/iq/dataverse/util/PersonOrOrgUtilTest.java
@@ -89,6 +89,8 @@ public void testName() {
verifyIsPerson("kcjim11, kcjim11", "kcjim11", "kcjim11");
verifyIsPerson("Bartholomew 3, James", "James", "Bartholomew 3");
+ verifyIsPerson("Smith, ", null, "Smith");
+ verifyIsPerson("Smith,", null, "Smith");
}
private void verifyIsOrganization(String fullName) {
@@ -106,7 +108,7 @@ private void verifyIsPerson(String fullName, String givenName, String familyName
private void verifyIsPerson(String fullName, String givenName, String familyName, boolean isPerson) {
JsonObject obj = PersonOrOrgUtil.getPersonOrOrganization(fullName, false, isPerson);
System.out.println(JsonUtil.prettyPrint(obj));
- assertEquals(obj.getString("fullName"),fullName);
+ assertEquals(obj.getString("fullName"), StringUtil.normalize(fullName));
assertTrue(obj.getBoolean("isPerson"));
assertEquals(obj.containsKey("givenName"), givenName != null);
if(obj.containsKey("givenName") && givenName != null) {