Skip to content

Commit

Permalink
don't add "software" or "workflow" with Flyway #10517
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Aug 12, 2024
1 parent 1beed5d commit 200a45a
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 15 deletions.
6 changes: 4 additions & 2 deletions doc/release-notes/10517-datasetType.md
Original file line number Diff line number Diff line change
@@ -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 <https://dataverse-guide--10694.org.readthedocs.build/en/10694/user/dataset-management.html#dataset-types> 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 <https://dataverse-guide--10694.org.readthedocs.build/en/10694/user/dataset-management.html#dataset-types> and #10517. Please note that this feature is highly experimental and is expected to evolve.

Upgrade instructions
--------------------
Expand Down
14 changes: 10 additions & 4 deletions doc/sphinx-guides/source/api/native-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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>`.

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -3066,21 +3070,23 @@ 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
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions doc/sphinx-guides/source/user/dataset-management.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 1 addition & 3 deletions src/main/resources/db/migration/V6.3.0.2.sql
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/api/DatasetTypesIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 200a45a

Please sign in to comment.