Skip to content

Commit 04f1c7c

Browse files
committed
name of dataset type cannot be only digits #10517
1 parent eabe8e2 commit 04f1c7c

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

doc/sphinx-guides/source/api/native-api.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -3123,7 +3123,7 @@ Add Dataset Type
31233123
31243124
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.
31253125
3126-
With all that said, we'll add a "software" type in the example below. This API endpoint is superuser only.
3126+
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.
31273127
31283128
.. code-block:: bash
31293129

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

+4
Original file line numberDiff line numberDiff line change
@@ -5139,6 +5139,10 @@ public Response addDatasetType(@Context ContainerRequestContext crc, String json
51395139
if (nameIn == null) {
51405140
return error(BAD_REQUEST, "A name for the dataset type is required");
51415141
}
5142+
if (StringUtils.isNumeric(nameIn)) {
5143+
// getDatasetTypes supports id or name so we don't want a names that looks like an id
5144+
return error(BAD_REQUEST, "The name of the type cannot be only digits.");
5145+
}
51425146

51435147
try {
51445148
DatasetType datasetType = new DatasetType();

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

+5
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ public void testAddAndDeleteDatasetType() {
217217
badJson.prettyPrint();
218218
badJson.then().assertThat().statusCode(BAD_REQUEST.getStatusCode());
219219

220+
String numbersOnlyIn = Json.createObjectBuilder().add("name", "12345").build().toString();
221+
Response numbersOnly = UtilIT.addDatasetType(numbersOnlyIn, apiToken);
222+
numbersOnly.prettyPrint();
223+
numbersOnly.then().assertThat().statusCode(BAD_REQUEST.getStatusCode());
224+
220225
String randomName = UUID.randomUUID().toString().substring(0, 8);
221226
String jsonIn = Json.createObjectBuilder().add("name", randomName).build().toString();
222227

0 commit comments

Comments
 (0)