Skip to content

Commit 3aab5c0

Browse files
committed
stop supporting setting of dataset type via DDI #10517
Maybe someday but we're not confident about which field to use and we're not even sure if there is any interest in this because DDI usually represents data, not software or workflows.
1 parent cfac9dc commit 3aab5c0

File tree

5 files changed

+1
-284
lines changed

5 files changed

+1
-284
lines changed
-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
### Initial Support for Dataset Types (Dataset, Software, Workflow)
22

33
Datasets now have types. By default the dataset type will be "dataset" but if you turn on support for additional types, datasets can have a type of "software" or "workflow" as well. For more details see <https://dataverse-guide--10694.org.readthedocs.build/en/10694/user/dataset-types.html> and #10517. Please note that this feature is highly experimental.
4-
5-
next:
6-
7-
- create with DDI

doc/sphinx-guides/source/_static/api/dataset-create-software-ddi.xml

-196
This file was deleted.

doc/sphinx-guides/source/user/dataset-types.rst

-7
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,3 @@ Import with Native JSON
3535
-----------------------
3636

3737
The same native JSON file as above can be used when importing a dataset: :download:`dataset-create-software.json <../_static/api/dataset-create-software.json>`
38-
39-
Import with DDI
40-
---------------
41-
42-
An example DDI file is available at :download:`dataset-create-software-ddi.xml <../_static/api/dataset-create-software-ddi.xml>`
43-
44-
Note that for DDI import to work ``dataKind`` must be set to one of the valid types. The first valid type wins.

src/main/java/edu/harvard/iq/dataverse/api/Dataverses.java

+1-30
Original file line numberDiff line numberDiff line change
@@ -430,13 +430,8 @@ public Response importDatasetDdi(@Context ContainerRequestContext crc, String xm
430430
Dataverse owner = findDataverseOrDie(parentIdtf);
431431
Dataset ds = null;
432432
try {
433-
JsonObject jsonObject = importService.ddiToJson(xml);
434-
ds = jsonParser().parseDataset(jsonObject);
433+
ds = jsonParser().parseDataset(importService.ddiToJson(xml));
435434
DataverseUtil.checkMetadataLangauge(ds, owner, settingsService.getBaseMetadataLanguageMap(null, true));
436-
DatasetType datasetType = getDatasetTypeFromJson(jsonObject);
437-
if (datasetType != null) {
438-
ds.setDatasetType(datasetType);
439-
}
440435
} catch (JsonParseException jpe) {
441436
return badRequest("Error parsing data as Json: "+jpe.getMessage());
442437
} catch (ImportException e) {
@@ -498,30 +493,6 @@ public Response importDatasetDdi(@Context ContainerRequestContext crc, String xm
498493
}
499494
}
500495

501-
public DatasetType getDatasetTypeFromJson(JsonObject jsonObject) {
502-
JsonArray citationFields = jsonObject.getJsonObject("datasetVersion")
503-
.getJsonObject("metadataBlocks")
504-
.getJsonObject("citation")
505-
.getJsonArray("fields");
506-
for (JsonValue citationField : citationFields) {
507-
JsonObject field = (JsonObject) citationField;
508-
String name = field.getString("typeName");
509-
if (name.equals(DatasetFieldConstant.kindOfData)) {
510-
JsonArray values = field.getJsonArray("value");
511-
for (JsonString value : values.getValuesAs(JsonString.class)) {
512-
try {
513-
// return the first DatasetType you find
514-
DatasetType.Type type = DatasetType.Type.fromString(value.getString());
515-
return new DatasetType(type);
516-
} catch (IllegalArgumentException ex) {
517-
// No worries, it's just some other kind of data.
518-
}
519-
}
520-
}
521-
}
522-
return null;
523-
}
524-
525496
@POST
526497
@AuthRequired
527498
@Path("{identifier}/datasets/:startmigration")

src/test/java/edu/harvard/iq/dataverse/api/DatasetTypesIT.java

-47
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package edu.harvard.iq.dataverse.api;
22

3-
import edu.harvard.iq.dataverse.search.SearchFields;
43
import io.restassured.RestAssured;
54
import io.restassured.path.json.JsonPath;
65
import io.restassured.response.Response;
76
import static jakarta.ws.rs.core.Response.Status.CREATED;
87
import static jakarta.ws.rs.core.Response.Status.OK;
98
import org.hamcrest.CoreMatchers;
10-
import static org.hamcrest.CoreMatchers.equalTo;
119
import static org.junit.jupiter.api.Assertions.assertEquals;
1210
import org.junit.jupiter.api.BeforeAll;
1311
import org.junit.jupiter.api.Test;
@@ -137,49 +135,4 @@ public void testImportJson() {
137135

138136
}
139137

140-
@Test
141-
public void testImportDdiWorkflow() {
142-
Response createUser = UtilIT.createRandomUser();
143-
createUser.then().assertThat().statusCode(OK.getStatusCode());
144-
String username = UtilIT.getUsernameFromResponse(createUser);
145-
String apiToken = UtilIT.getApiTokenFromResponse(createUser);
146-
147-
UtilIT.setSuperuserStatus(username, true).then().assertThat().statusCode(OK.getStatusCode());
148-
149-
Response createDataverse = UtilIT.createRandomDataverse(apiToken);
150-
createDataverse.then().assertThat().statusCode(CREATED.getStatusCode());
151-
String dataverseAlias = UtilIT.getAliasFromResponse(createDataverse);
152-
Integer dataverseId = UtilIT.getDataverseIdFromResponse(createDataverse);
153-
154-
UtilIT.publishDataverseViaNativeApi(dataverseAlias, apiToken).then().assertThat().statusCode(OK.getStatusCode());
155-
156-
String jsonIn = UtilIT.getDatasetJson("doc/sphinx-guides/source/_static/api/dataset-create-software-ddi.xml");
157-
158-
String randomString = UtilIT.getRandomString(6);
159-
160-
Response importJson = UtilIT.importDatasetDDIViaNativeApi(apiToken, dataverseAlias, jsonIn, "doi:10.5072/FK2/" + randomString, "yes");
161-
importJson.prettyPrint();
162-
importJson.then().assertThat().statusCode(CREATED.getStatusCode());
163-
164-
Integer datasetId = JsonPath.from(importJson.getBody().asString()).getInt("data.id");
165-
String datasetPid = JsonPath.from(importJson.getBody().asString()).getString("data.persistentId");
166-
167-
Response getDatasetJson = UtilIT.nativeGet(datasetId, apiToken);
168-
getDatasetJson.prettyPrint();
169-
getDatasetJson.then().assertThat().statusCode(OK.getStatusCode());
170-
String datasetType = JsonPath.from(getDatasetJson.getBody().asString()).getString("data.datasetType");
171-
System.out.println("datasetType: " + datasetType);
172-
assertEquals("workflow", datasetType);
173-
174-
Response search = UtilIT.searchAndShowFacets("id:dataset_" + datasetId, apiToken);
175-
search.prettyPrint();
176-
search.then().assertThat()
177-
.body("data.total_count", CoreMatchers.is(1))
178-
.body("data.count_in_response", CoreMatchers.is(1))
179-
.body("data.facets[0].datasetType_s.friendly", CoreMatchers.is("Dataset Type"))
180-
.body("data.facets[0].datasetType_s.labels[0].workflow", CoreMatchers.is(1))
181-
.statusCode(OK.getStatusCode());
182-
183-
}
184-
185138
}

0 commit comments

Comments
 (0)