Skip to content

Commit

Permalink
name of dataset type cannot be only digits #10517
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Aug 26, 2024
1 parent eabe8e2 commit 04f1c7c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/sphinx-guides/source/api/native-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3123,7 +3123,7 @@ Add Dataset Type
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.
With all that said, we'll add a "software" type in the example below. This API endpoint is superuser only. The "name" of a type cannot be only digits.
.. code-block:: bash
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/api/Datasets.java
Original file line number Diff line number Diff line change
Expand Up @@ -5139,6 +5139,10 @@ public Response addDatasetType(@Context ContainerRequestContext crc, String json
if (nameIn == null) {
return error(BAD_REQUEST, "A name for the dataset type is required");
}
if (StringUtils.isNumeric(nameIn)) {
// getDatasetTypes supports id or name so we don't want a names that looks like an id
return error(BAD_REQUEST, "The name of the type cannot be only digits.");
}

try {
DatasetType datasetType = new DatasetType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ public void testAddAndDeleteDatasetType() {
badJson.prettyPrint();
badJson.then().assertThat().statusCode(BAD_REQUEST.getStatusCode());

String numbersOnlyIn = Json.createObjectBuilder().add("name", "12345").build().toString();
Response numbersOnly = UtilIT.addDatasetType(numbersOnlyIn, apiToken);
numbersOnly.prettyPrint();
numbersOnly.then().assertThat().statusCode(BAD_REQUEST.getStatusCode());

String randomName = UUID.randomUUID().toString().substring(0, 8);
String jsonIn = Json.createObjectBuilder().add("name", randomName).build().toString();

Expand Down

0 comments on commit 04f1c7c

Please sign in to comment.