diff --git a/doc/release-notes/10517-datasetType.md b/doc/release-notes/10517-datasetType.md index 12c2eaa46f2..722b2f96321 100644 --- a/doc/release-notes/10517-datasetType.md +++ b/doc/release-notes/10517-datasetType.md @@ -1,6 +1,8 @@ -### Initial Support for Dataset Types (Dataset, Software, Workflow) +### Initial Support for Dataset Types -Datasets now have types. By default the dataset type will be "dataset", but out of the box datasets can have a type of "software" or "workflow" as well. For more details see and #10517. Please note that this feature is highly experimental and is expected to evolve. +Out of the box, all datasets have the type "dataset" but superusers can add additional types. At this time the type can only be set at creation time via API. The types "dataset", "software", and "workflow" will be sent to DataCite when the dataset is published. + +For details see and #10517. Please note that this feature is highly experimental and is expected to evolve. Upgrade instructions -------------------- diff --git a/doc/sphinx-guides/source/api/native-api.rst b/doc/sphinx-guides/source/api/native-api.rst index 6be7706a2a4..b38bc2d1b5f 100644 --- a/doc/sphinx-guides/source/api/native-api.rst +++ b/doc/sphinx-guides/source/api/native-api.rst @@ -788,7 +788,9 @@ You should expect an HTTP 200 ("OK") response and JSON indicating the database I Create a Dataset with a Dataset Type (Software, etc.) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Follow :ref:`api-create-dataset` as normal but include a line like `"datasetType": "software"` in your JSON. You can check which types are supported by your installation using the :ref:`api-list-dataset-types` API endpoint. +By default, datasets are given the type "dataset" but if your installation had added additional types (see :ref:`api-add-dataset-type`), you can specify the type. + +Follow :ref:`api-create-dataset` as normal but include a line like ``"datasetType": "software"`` in your JSON. You can check which types are supported by your installation using the :ref:`api-list-dataset-types` API endpoint. Here is an example JSON file for reference: :download:`dataset-create-software.json <../_static/api/dataset-create-software.json>`. @@ -841,6 +843,8 @@ Before calling the API, make sure the data files referenced by the ``POST``\ ed Import a Dataset with a Dataset Type (Software, etc.) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +By default, datasets are given the type "dataset" but if your installation had added additional types (see :ref:`api-add-dataset-type`), you can specify the type. + The same native JSON file as above under :ref:`api-create-dataset-with-type` can be used when importing a dataset. A file like this is the only difference. Otherwise, follow :ref:`api-import-dataset` as normal. @@ -3066,13 +3070,15 @@ The fully expanded example above (without environment variables) looks like this Add Dataset Type ^^^^^^^^^^^^^^^^ -Superuser only. +Note: Before you add any types of your own, there should be a single type called "dataset". If you add "software" or "workflow", these types will be sent to DataCite (if you use DataCite). Otherwise, the only functionality you gain currently from adding types is an entry in the "Dataset Type" facet but be advised that if you add a type other than "software" or "workflow", you will need to add your new type to your Bundle.properties file for it to appear in Title Case rather than lower case in the "Dataset Type" facet. + +With all that said, we'll add a "software" type in the example below. This API endpoint is superuser only. .. code-block:: bash export API_TOKEN=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx export SERVER_URL=https://demo.dataverse.org - export JSON='{"name": "newType"}' + export JSON='{"name": "software"}' curl -H "X-Dataverse-key:$API_TOKEN" -H "Content-Type: application/json" "$SERVER_URL/api/datasets/datasetTypes" -X POST -d $JSON @@ -3080,7 +3086,7 @@ The fully expanded example above (without environment variables) looks like this .. code-block:: bash - curl -H "X-Dataverse-key:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -H "Content-Type: application/json" "https://demo.dataverse.org/api/datasets/datasetTypes" -X POST -d '{"name": "newType"}' + curl -H "X-Dataverse-key:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -H "Content-Type: application/json" "https://demo.dataverse.org/api/datasets/datasetTypes" -X POST -d '{"name": "software"}' .. _api-delete-dataset-type: diff --git a/doc/sphinx-guides/source/developers/dataset-semantic-metadata-api.rst b/doc/sphinx-guides/source/developers/dataset-semantic-metadata-api.rst index 44188891786..4f374bdc039 100644 --- a/doc/sphinx-guides/source/developers/dataset-semantic-metadata-api.rst +++ b/doc/sphinx-guides/source/developers/dataset-semantic-metadata-api.rst @@ -112,6 +112,8 @@ An example jsonld file is available at :download:`dataset-create.jsonld <../_sta Create a Dataset with a Dataset Type ------------------------------------ +By default, datasets are given the type "dataset" but if your installation had added additional types (see :ref:`api-add-dataset-type`), you can specify the type. + An example JSON-LD file is available at :download:`dataset-create-software.jsonld <../_static/api/dataset-create-software.jsonld>`. You can use this file with the normal :ref:`api-semantic-create-dataset` endpoint above. diff --git a/doc/sphinx-guides/source/user/dataset-management.rst b/doc/sphinx-guides/source/user/dataset-management.rst index 9bf166fae0a..02381000519 100755 --- a/doc/sphinx-guides/source/user/dataset-management.rst +++ b/doc/sphinx-guides/source/user/dataset-management.rst @@ -787,9 +787,9 @@ If you deaccession the most recently published version of the dataset but not al Dataset Types ============= -Datasets can have a dataset type such as "dataset", "software", or "workflow". +Out of the box, all datasets have a dataset type of "dataset". Superusers can add additional types such as "software" or "workflow" using the :ref:`api-add-dataset-type` API endpoint. -When browsing or searching, these types appear under a facet called "Dataset Type". +Once more than one type appears in search results, a facet called "Dataset Type" will appear allowing you to filter down to a certain type. If your installation is configured to use DataCite as a persistent ID (PID) provider, the appropriate type ("Dataset", "Software", "Workflow") will be sent to DataCite when the dataset is published for those three types. diff --git a/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetType.java b/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetType.java index 3333819372d..962799257dc 100644 --- a/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetType.java +++ b/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetType.java @@ -27,7 +27,10 @@ public class DatasetType implements Serializable { - public static final String DEFAULT_DATASET_TYPE = "dataset"; + public static final String DATASET_TYPE_DATASET = "dataset"; + public static final String DATASET_TYPE_SOFTWARE = "software"; + public static final String DATASET_TYPE_WORKFLOW = "workflow"; + public static final String DEFAULT_DATASET_TYPE = DATASET_TYPE_DATASET; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/edu/harvard/iq/dataverse/pidproviders/doi/XmlMetadataTemplate.java b/src/main/java/edu/harvard/iq/dataverse/pidproviders/doi/XmlMetadataTemplate.java index 694c09b8122..fb4e294d246 100644 --- a/src/main/java/edu/harvard/iq/dataverse/pidproviders/doi/XmlMetadataTemplate.java +++ b/src/main/java/edu/harvard/iq/dataverse/pidproviders/doi/XmlMetadataTemplate.java @@ -203,11 +203,11 @@ public String generateXML(DvObject dvObject) { Dataset dataset = (Dataset) dvObject; String datasetTypeName = dataset.getDatasetType().getName(); resourceTypeGeneral = switch (datasetTypeName) { - case "dataset" -> + case DatasetType.DATASET_TYPE_DATASET -> "Dataset"; - case "software" -> + case DatasetType.DATASET_TYPE_SOFTWARE -> "Software"; - case "workflow" -> + case DatasetType.DATASET_TYPE_WORKFLOW -> "Workflow"; default -> "Dataset"; diff --git a/src/main/resources/db/migration/V6.3.0.2.sql b/src/main/resources/db/migration/V6.3.0.2.sql index 610d6899d68..437572f3f0c 100644 --- a/src/main/resources/db/migration/V6.3.0.2.sql +++ b/src/main/resources/db/migration/V6.3.0.2.sql @@ -1,9 +1,7 @@ -- Dataset types have been added. See #10517 and #10694 -- --- Insert some types (dataset is the default). +-- Insert the default dataset type: dataset. INSERT INTO datasettype (name) VALUES ('dataset'); -INSERT INTO datasettype (name) VALUES ('software'); -INSERT INTO datasettype (name) VALUES ('workflow'); -- -- Add the new column (if it doesn't exist). ALTER TABLE dataset ADD COLUMN IF NOT EXISTS datasettype_id bigint; diff --git a/src/test/java/edu/harvard/iq/dataverse/api/DatasetTypesIT.java b/src/test/java/edu/harvard/iq/dataverse/api/DatasetTypesIT.java index 2ff98ecd557..ef24f0102b7 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/DatasetTypesIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/DatasetTypesIT.java @@ -20,6 +20,28 @@ public class DatasetTypesIT { @BeforeAll public static void setUpClass() { RestAssured.baseURI = UtilIT.getRestAssuredBaseUri(); + + Response getSoftwareType = UtilIT.getDatasetTypeByName(DatasetType.DATASET_TYPE_SOFTWARE); + getSoftwareType.prettyPrint(); + + String typeFound = JsonPath.from(getSoftwareType.getBody().asString()).getString("data.name"); + System.out.println("type found: " + typeFound); + if (DatasetType.DATASET_TYPE_SOFTWARE.equals(typeFound)) { + return; + } + + System.out.println("The \"software\" type wasn't found. Create it."); + Response createUser = UtilIT.createRandomUser(); + createUser.then().assertThat().statusCode(OK.getStatusCode()); + String username = UtilIT.getUsernameFromResponse(createUser); + String apiToken = UtilIT.getApiTokenFromResponse(createUser); + UtilIT.setSuperuserStatus(username, true).then().assertThat().statusCode(OK.getStatusCode()); + + String jsonIn = Json.createObjectBuilder().add("name", DatasetType.DATASET_TYPE_SOFTWARE).build().toString(); + + Response typeAdded = UtilIT.addDatasetType(jsonIn, apiToken); + typeAdded.prettyPrint(); + typeAdded.then().assertThat().statusCode(OK.getStatusCode()); } @Test