diff --git a/doc/release-notes/3913-delete-file-endpoint b/doc/release-notes/3913-delete-file-endpoint new file mode 100644 index 00000000000..b8b0c2f1ec5 --- /dev/null +++ b/doc/release-notes/3913-delete-file-endpoint @@ -0,0 +1 @@ +Support for deleting files using native API: http://preview.guides.gdcc.io/en/develop/api/native-api.html#deleting-files diff --git a/doc/sphinx-guides/source/api/native-api.rst b/doc/sphinx-guides/source/api/native-api.rst index 07cba1efccf..6614b6d0438 100644 --- a/doc/sphinx-guides/source/api/native-api.rst +++ b/doc/sphinx-guides/source/api/native-api.rst @@ -2468,6 +2468,49 @@ The fully expanded example above (without environment variables) looks like this -F 'jsonData={"description":"My description.","categories":["Data"],"forceReplace":false}' \ "https://demo.dataverse.org/api/files/:persistentId/replace?persistentId=doi:10.5072/FK2/AAA000" +Deleting Files +~~~~~~~~~~~~~~ + +Delete an existing file where ``ID`` is the database id of the file to delete or ``PERSISTENT_ID`` is the persistent id (DOI or Handle, if it exists) of the file. + +Note that the behavior of deleting files depends on if the dataset has ever been published or not. + +- If the dataset has never been published, the file will be deleted forever. +- If the dataset has published, the file is deleted from the draft (and future published versions). +- If the dataset has published, the deleted file can still be downloaded because it was part of a published version. + +A curl example using an ``ID`` + +.. code-block:: bash + + export API_TOKEN=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx + export SERVER_URL=https://demo.dataverse.org + export ID=24 + + curl -H "X-Dataverse-key:$API_TOKEN" -X DELETE $SERVER_URL/api/files/$ID + +The fully expanded example above (without environment variables) looks like this: + +.. code-block:: bash + + curl -H "X-Dataverse-key:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -X DELETE https://demo.dataverse.org/api/files/24 + +A curl example using a ``PERSISTENT_ID`` + +.. code-block:: bash + + export API_TOKEN=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx + export SERVER_URL=https://demo.dataverse.org + export PERSISTENT_ID=doi:10.5072/FK2/AAA000 + + curl -H "X-Dataverse-key:$API_TOKEN" -X DELETE "$SERVER_URL/api/files/:persistentId?persistentId=$PERSISTENT_ID" + +The fully expanded example above (without environment variables) looks like this: + +.. code-block:: bash + + curl -H "X-Dataverse-key:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -X DELETE "https://demo.dataverse.org/api/files/:persistentId?persistentId=doi:10.5072/FK2/AAA000" + Getting File Metadata ~~~~~~~~~~~~~~~~~~~~~ diff --git a/src/main/java/edu/harvard/iq/dataverse/api/Files.java b/src/main/java/edu/harvard/iq/dataverse/api/Files.java index 44c7e944556..182e37a193e 100644 --- a/src/main/java/edu/harvard/iq/dataverse/api/Files.java +++ b/src/main/java/edu/harvard/iq/dataverse/api/Files.java @@ -47,6 +47,8 @@ import static edu.harvard.iq.dataverse.util.json.JsonPrinter.json; import edu.harvard.iq.dataverse.util.json.JsonUtil; import edu.harvard.iq.dataverse.util.json.NullSafeJsonBuilder; + +import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; @@ -54,10 +56,12 @@ import java.util.logging.Level; import java.util.logging.Logger; import javax.ejb.EJB; +import javax.ejb.EJBException; import javax.inject.Inject; import javax.json.Json; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PUT; @@ -311,6 +315,54 @@ public Response replaceFileInDataset( } } // end: replaceFileInDataset + + /** + * Delete an Existing File + * + * @param id file ID or peristent ID + */ + @DELETE + @AuthRequired + @Path("{id}") + public Response deleteFileInDataset(@Context ContainerRequestContext crc, @PathParam("id") String fileIdOrPersistentId){ + // (1) Get the user from the API key and create request + User authUser = getRequestUser(crc); + DataverseRequest dvRequest = createDataverseRequest(authUser); + + // (2) Delete + boolean deletePhysicalFile = false; + try { + DataFile dataFile = findDataFileOrDie(fileIdOrPersistentId); + FileMetadata fileToDelete = dataFile.getLatestFileMetadata(); + Dataset dataset = dataFile.getOwner(); + DatasetVersion v = dataset.getOrCreateEditVersion(); + deletePhysicalFile = !dataFile.isReleased(); + + UpdateDatasetVersionCommand update_cmd = new UpdateDatasetVersionCommand(dataset, dvRequest, Arrays.asList(fileToDelete), v); + update_cmd.setValidateLenient(true); + + try { + commandEngine.submit(update_cmd); + } catch (CommandException ex) { + return error(BAD_REQUEST, "Delete failed for file ID " + fileIdOrPersistentId + " (CommandException): " + ex.getMessage()); + } catch (EJBException ex) { + return error(BAD_REQUEST, "Delete failed for file ID " + fileIdOrPersistentId + "(EJBException): " + ex.getMessage()); + } + + if (deletePhysicalFile) { + try { + fileService.finalizeFileDelete(dataFile.getId(), fileService.getPhysicalFileToDelete(dataFile)); + } catch (IOException ioex) { + logger.warning("Failed to delete the physical file associated with the deleted datafile id=" + + dataFile.getId() + ", storage location: " + fileService.getPhysicalFileToDelete(dataFile)); + } + } + } catch (WrappedResponse wr) { + return wr.getResponse(); + } + + return ok(deletePhysicalFile); + } //Much of this code is taken from the replace command, //simplified as we aren't actually switching files diff --git a/src/test/java/edu/harvard/iq/dataverse/api/FilesIT.java b/src/test/java/edu/harvard/iq/dataverse/api/FilesIT.java index dd9ecf26228..ed4d255ab74 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/FilesIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/FilesIT.java @@ -8,6 +8,7 @@ import org.junit.Test; import org.junit.BeforeClass; import com.jayway.restassured.path.json.JsonPath; +import static com.jayway.restassured.path.json.JsonPath.with; import com.jayway.restassured.path.xml.XmlPath; import static edu.harvard.iq.dataverse.api.AccessIT.apiToken; import edu.harvard.iq.dataverse.settings.SettingsServiceBean; @@ -23,6 +24,7 @@ import java.text.MessageFormat; import java.util.Arrays; import java.util.Collections; +import java.util.Map; import java.util.ResourceBundle; import javax.json.Json; import javax.json.JsonObjectBuilder; @@ -64,7 +66,7 @@ private String createUserGetToken(){ String username = UtilIT.getUsernameFromResponse(createUser); String apiToken = UtilIT.getApiTokenFromResponse(createUser); - + System.out.println(apiToken); return apiToken; } @@ -1896,4 +1898,124 @@ public void testAddFileToDatasetSkipTabIngest() throws IOException, InterruptedE } + @Test + public void testDeleteFile() { + msgt("testDeleteFile"); + // Create user + String apiToken = createUserGetToken(); + + // Create user with no permission + String apiTokenNoPerms = createUserGetToken(); + + // Create Dataverse + String dataverseAlias = createDataverseGetAlias(apiToken); + + // Create Dataset + Response createDataset = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias, apiToken); + createDataset.then().assertThat() + .statusCode(CREATED.getStatusCode()); + + Integer datasetId = UtilIT.getDatasetIdFromResponse(createDataset); + String datasetPid = JsonPath.from(createDataset.asString()).getString("data.persistentId"); + + // Upload file 1 + String pathToFile1 = "src/main/webapp/resources/images/dataverseproject.png"; + JsonObjectBuilder json1 = Json.createObjectBuilder() + .add("description", "my description1") + .add("directoryLabel", "data/subdir1") + .add("categories", Json.createArrayBuilder().add("Data")); + Response uploadResponse1 = UtilIT.uploadFileViaNative(datasetId.toString(), pathToFile1, json1.build(), apiToken); + uploadResponse1.then().assertThat().statusCode(OK.getStatusCode()); + + Integer fileId1 = JsonPath.from(uploadResponse1.body().asString()).getInt("data.files[0].dataFile.id"); + + // Check file uploaded + Response downloadResponse1 = UtilIT.downloadFile(fileId1, null, null, null, apiToken); + downloadResponse1.then().assertThat().statusCode(OK.getStatusCode()); + + // Delete file 1 + Response deleteResponseFail = UtilIT.deleteFileApi(fileId1, apiTokenNoPerms); + deleteResponseFail.prettyPrint(); + deleteResponseFail.then().assertThat().statusCode(BAD_REQUEST.getStatusCode()); + + Response deleteResponse1 = UtilIT.deleteFileApi(fileId1, apiToken); + deleteResponse1.then().assertThat().statusCode(OK.getStatusCode()); + + // Check file 1 deleted for good because it was in a draft + Response downloadResponse1notFound = UtilIT.downloadFile(fileId1, null, null, null, apiToken); + downloadResponse1notFound.then().assertThat().statusCode(NOT_FOUND.getStatusCode()); + + // Upload file 2 + String pathToFile2 = "src/main/webapp/resources/images/cc0.png"; + JsonObjectBuilder json2 = Json.createObjectBuilder() + .add("description", "my description2") + .add("directoryLabel", "data/subdir1") + .add("categories", Json.createArrayBuilder().add("Data")); + Response uploadResponse2 = UtilIT.uploadFileViaNative(datasetId.toString(), pathToFile2, json2.build(), apiToken); + uploadResponse2.then().assertThat().statusCode(OK.getStatusCode()); + + Integer fileId2 = JsonPath.from(uploadResponse2.body().asString()).getInt("data.files[0].dataFile.id"); + + // Upload file 3 + String pathToFile3 = "src/main/webapp/resources/images/orcid_16x16.png"; + JsonObjectBuilder json3 = Json.createObjectBuilder() + .add("description", "my description3") + .add("directoryLabel", "data/subdir1") + .add("categories", Json.createArrayBuilder().add("Data")); + Response uploadResponse3 = UtilIT.uploadFileViaNative(datasetId.toString(), pathToFile3, json3.build(), apiToken); + uploadResponse3.then().assertThat().statusCode(OK.getStatusCode()); + + Integer fileId3 = JsonPath.from(uploadResponse3.body().asString()).getInt("data.files[0].dataFile.id"); + + // Publish collection and dataset + UtilIT.publishDataverseViaNativeApi(dataverseAlias, apiToken).then().assertThat().statusCode(OK.getStatusCode()); + UtilIT.publishDatasetViaNativeApi(datasetId, "major", apiToken).then().assertThat().statusCode(OK.getStatusCode()); + + Response deleteResponse2 = UtilIT.deleteFileApi(fileId2, apiToken); + deleteResponse2.then().assertThat().statusCode(OK.getStatusCode()); + + // Check file 2 deleted from post v1.0 draft + Response postv1draft = UtilIT.getDatasetVersion(datasetPid, ":draft", apiToken); + postv1draft.prettyPrint(); + postv1draft.then().assertThat() + .body("data.files.size()", equalTo(1)) + .statusCode(OK.getStatusCode()); + + // Check file 2 still in v1.0 + Response v1 = UtilIT.getDatasetVersion(datasetPid, "1.0", apiToken); + v1.prettyPrint(); + v1.then().assertThat() + .body("data.files[0].dataFile.filename", equalTo("cc0.png")) + .statusCode(OK.getStatusCode()); + + Map v1files1 = with(v1.body().asString()).param("fileToFind", "cc0.png") + .getJsonObject("data.files.find { files -> files.label == fileToFind }"); + assertEquals("cc0.png", v1files1.get("label")); + + // Check file 2 still downloadable (published in in v1.0) + Response downloadResponse2 = UtilIT.downloadFile(fileId2, null, null, null, apiToken); + downloadResponse2.then().assertThat().statusCode(OK.getStatusCode()); + + // Check file 3 still in post v1.0 draft + Response postv1draft2 = UtilIT.getDatasetVersion(datasetPid, ":draft", apiToken); + postv1draft2.prettyPrint(); + postv1draft2.then().assertThat() + .body("data.files[0].dataFile.filename", equalTo("orcid_16x16.png")) + .statusCode(OK.getStatusCode()); + + Map v1files2 = with(postv1draft2.body().asString()).param("fileToFind", "orcid_16x16.png") + .getJsonObject("data.files.find { files -> files.label == fileToFind }"); + assertEquals("orcid_16x16.png", v1files2.get("label")); + + // Delete file 3, the current version is still draft + Response deleteResponse3 = UtilIT.deleteFileApi(fileId3, apiToken); + deleteResponse3.then().assertThat().statusCode(OK.getStatusCode()); + + // Check file 3 deleted from post v1.0 draft + Response postv1draft3 = UtilIT.getDatasetVersion(datasetPid, ":draft", apiToken); + postv1draft3.prettyPrint(); + postv1draft3.then().assertThat() + .body("data.files[0]", equalTo(null)) + .statusCode(OK.getStatusCode()); + } } diff --git a/src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java b/src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java index 4262b709f58..642480cf11c 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java @@ -795,7 +795,7 @@ static Response replaceFile(String fileIdOrPersistentId, String pathToFile, Json static Response replaceFile(String fileIdOrPersistentId, String pathToFile, String jsonAsString, String apiToken) { String idInPath = fileIdOrPersistentId; // Assume it's a number. String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(fileIdOrPersistentId)) { + if (!NumberUtils.isCreatable(fileIdOrPersistentId)) { idInPath = ":persistentId"; optionalQueryParam = "?persistentId=" + fileIdOrPersistentId; } @@ -808,11 +808,17 @@ static Response replaceFile(String fileIdOrPersistentId, String pathToFile, Stri return requestSpecification .post("/api/files/" + idInPath + "/replace" + optionalQueryParam); } + + static Response deleteFileApi(Integer fileId, String apiToken) { + return given() + .header(API_TOKEN_HTTP_HEADER, apiToken) + .delete("/api/files/" + fileId); + } static Response updateFileMetadata(String fileIdOrPersistentId, String jsonAsString, String apiToken) { String idInPath = fileIdOrPersistentId; // Assume it's a number. String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(fileIdOrPersistentId)) { + if (!NumberUtils.isCreatable(fileIdOrPersistentId)) { idInPath = ":persistentId"; optionalQueryParam = "?persistentId=" + fileIdOrPersistentId; } @@ -937,7 +943,7 @@ static Response downloadFiles(String datasetIdOrPersistentId, String datasetVers static Response downloadFiles(String datasetIdOrPersistentId, String datasetVersion, DownloadFormat format, String apiToken) { String idInPath = datasetIdOrPersistentId; // Assume it's a number. String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(datasetIdOrPersistentId)) { + if (!NumberUtils.isCreatable(datasetIdOrPersistentId)) { idInPath = ":persistentId"; optionalQueryParam = "?persistentId=" + datasetIdOrPersistentId; } @@ -970,7 +976,7 @@ static Response subset(String fileId, String variables, String apiToken) { static Response getFileMetadata(String fileIdOrPersistentId, String optionalFormat, String apiToken) { String idInPath = fileIdOrPersistentId; // Assume it's a number. String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(fileIdOrPersistentId)) { + if (!NumberUtils.isCreatable(fileIdOrPersistentId)) { idInPath = ":persistentId"; optionalQueryParam = "&persistentId=" + fileIdOrPersistentId; } @@ -987,7 +993,7 @@ static Response getFileMetadata(String fileIdOrPersistentId, String optionalForm static Response getFileMetadata(String fileIdOrPersistentId, String optionalFormat) { String idInPath = fileIdOrPersistentId; // Assume it's a number. String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(fileIdOrPersistentId)) { + if (!NumberUtils.isCreatable(fileIdOrPersistentId)) { idInPath = ":persistentId"; optionalQueryParam = "?persistentId=" + fileIdOrPersistentId; } @@ -1508,7 +1514,7 @@ static Response migrateBuiltinToOAuth(String data, String apiToken) { static Response restrictFile(String fileIdOrPersistentId, boolean restrict, String apiToken) { String idInPath = fileIdOrPersistentId; // Assume it's a number. String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(fileIdOrPersistentId)) { + if (!NumberUtils.isCreatable(fileIdOrPersistentId)) { idInPath = ":persistentId"; optionalQueryParam = "?persistentId=" + fileIdOrPersistentId; } @@ -1522,7 +1528,7 @@ static Response restrictFile(String fileIdOrPersistentId, boolean restrict, Stri static Response allowAccessRequests(String datasetIdOrPersistentId, boolean allowRequests, String apiToken) { String idInPath = datasetIdOrPersistentId; // Assume it's a number. String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(datasetIdOrPersistentId)) { + if (!NumberUtils.isCreatable(datasetIdOrPersistentId)) { idInPath = ":persistentId"; optionalQueryParam = "?persistentId=" + datasetIdOrPersistentId; } @@ -1538,7 +1544,7 @@ static Response requestFileAccess(String fileIdOrPersistentId, String apiToken) System.out.print ("Reuest file acceess + apiToken: " + apiToken); String idInPath = fileIdOrPersistentId; // Assume it's a number. String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(fileIdOrPersistentId)) { + if (!NumberUtils.isCreatable(fileIdOrPersistentId)) { idInPath = ":persistentId"; optionalQueryParam = "?persistentId=" + fileIdOrPersistentId; } @@ -1556,7 +1562,7 @@ static Response requestFileAccess(String fileIdOrPersistentId, String apiToken) static Response grantFileAccess(String fileIdOrPersistentId, String identifier, String apiToken) { String idInPath = fileIdOrPersistentId; // Assume it's a number. String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(fileIdOrPersistentId)) { + if (!NumberUtils.isCreatable(fileIdOrPersistentId)) { idInPath = ":persistentId"; optionalQueryParam = "?persistentId=" + fileIdOrPersistentId; } @@ -1572,7 +1578,7 @@ static Response grantFileAccess(String fileIdOrPersistentId, String identifier, static Response getAccessRequestList(String fileIdOrPersistentId, String apiToken) { String idInPath = fileIdOrPersistentId; // Assume it's a number. String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(fileIdOrPersistentId)) { + if (!NumberUtils.isCreatable(fileIdOrPersistentId)) { idInPath = ":persistentId"; optionalQueryParam = "?persistentId=" + fileIdOrPersistentId; } @@ -1588,7 +1594,7 @@ static Response getAccessRequestList(String fileIdOrPersistentId, String apiToke static Response rejectFileAccessRequest(String fileIdOrPersistentId, String identifier, String apiToken) { String idInPath = fileIdOrPersistentId; // Assume it's a number. String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(fileIdOrPersistentId)) { + if (!NumberUtils.isCreatable(fileIdOrPersistentId)) { idInPath = ":persistentId"; optionalQueryParam = "?persistentId=" + fileIdOrPersistentId; } @@ -1620,7 +1626,7 @@ static Response moveDataset(String idOrPersistentIdOfDatasetToMove, String desti } String idInPath = idOrPersistentIdOfDatasetToMove; // Assume it's a number. String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(idOrPersistentIdOfDatasetToMove)) { + if (!NumberUtils.isCreatable(idOrPersistentIdOfDatasetToMove)) { idInPath = ":persistentId"; optionalQueryParam = "?persistentId=" + idOrPersistentIdOfDatasetToMove; } @@ -1738,7 +1744,7 @@ static Response getDatasetVersions(String idOrPersistentId, String apiToken) { logger.info("Getting Dataset Versions"); String idInPath = idOrPersistentId; // Assume it's a number. String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(idOrPersistentId)) { + if (!NumberUtils.isCreatable(idOrPersistentId)) { idInPath = ":persistentId"; optionalQueryParam = "?persistentId=" + idOrPersistentId; } @@ -1755,7 +1761,7 @@ static Response getProvJson(String idOrPersistentId, String apiToken) { logger.info("Getting Provenance JSON"); String idInPath = idOrPersistentId; // Assume it's a number. String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(idOrPersistentId)) { + if (!NumberUtils.isCreatable(idOrPersistentId)) { idInPath = ":persistentId"; optionalQueryParam = "?persistentId=" + idOrPersistentId; } @@ -1771,7 +1777,7 @@ static Response getProvFreeForm(String idOrPersistentId, String apiToken) { logger.info("Getting Provenance Free Form"); String idInPath = idOrPersistentId; // Assume it's a number. String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(idOrPersistentId)) { + if (!NumberUtils.isCreatable(idOrPersistentId)) { idInPath = ":persistentId"; optionalQueryParam = "?persistentId=" + idOrPersistentId; } @@ -1787,7 +1793,7 @@ static Response uploadProvJson(String idOrPersistentId, JsonObject jsonObject, S logger.info("Uploading Provenance JSON"); String idInPath = idOrPersistentId; // Assume it's a number. String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(idOrPersistentId)) { + if (!NumberUtils.isCreatable(idOrPersistentId)) { idInPath = ":persistentId"; optionalQueryParam = "?persistentId=" + idOrPersistentId; } @@ -1809,7 +1815,7 @@ static Response deleteProvJson(String idOrPersistentId, String apiToken) { //TODO: Repeated code, refactor String idInPath = idOrPersistentId; // Assume it's a number. String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(idOrPersistentId)) { + if (!NumberUtils.isCreatable(idOrPersistentId)) { idInPath = ":persistentId"; optionalQueryParam = "?persistentId=" + idOrPersistentId; } @@ -1825,7 +1831,7 @@ static Response uploadProvFreeForm(String idOrPersistentId, JsonObject jsonObjec logger.info("Uploading Provenance Free Form"); String idInPath = idOrPersistentId; // Assume it's a number. String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(idOrPersistentId)) { + if (!NumberUtils.isCreatable(idOrPersistentId)) { idInPath = ":persistentId"; optionalQueryParam = "?persistentId=" + idOrPersistentId; } @@ -1846,7 +1852,7 @@ static Response uploadProvFreeForm(String idOrPersistentId, JsonObject jsonObjec // //TODO: Repeated code, refactor // String idInPath = idOrPersistentId; // Assume it's a number. // String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. -// if (!NumberUtils.isNumber(idOrPersistentId)) { +// if (!NumberUtils.isCreatable(idOrPersistentId)) { // idInPath = ":persistentId"; // optionalQueryParam = "?persistentId=" + idOrPersistentId; // } @@ -2126,7 +2132,7 @@ static Response getRsyncScript(String datasetPersistentId, String apiToken) { static Response dataCaptureModuleChecksumValidation(String datasetPersistentId, JsonObject jsonObject, String apiToken) { String persistentIdInPath = datasetPersistentId; // Assume it's a number. String optionalQueryParam = ""; // If datasetPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(datasetPersistentId)) { + if (!NumberUtils.isCreatable(datasetPersistentId)) { persistentIdInPath = ":persistentId"; optionalQueryParam = "?persistentId=" + datasetPersistentId; } @@ -2173,7 +2179,7 @@ static Response deleteExternalTool(long externalToolid) { static Response getExternalToolsForDataset(String idOrPersistentIdOfDataset, String type, String apiToken) { String idInPath = idOrPersistentIdOfDataset; // Assume it's a number. String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(idOrPersistentIdOfDataset)) { + if (!NumberUtils.isCreatable(idOrPersistentIdOfDataset)) { idInPath = ":persistentId"; optionalQueryParam = "&persistentId=" + idOrPersistentIdOfDataset; } @@ -2188,7 +2194,7 @@ static Response getExternalToolsForDataset(String idOrPersistentIdOfDataset, Str static Response getExternalToolsForFile(String idOrPersistentIdOfFile, String type, String apiToken) { String idInPath = idOrPersistentIdOfFile; // Assume it's a number. String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(idOrPersistentIdOfFile)) { + if (!NumberUtils.isCreatable(idOrPersistentIdOfFile)) { idInPath = ":persistentId"; optionalQueryParam = "&persistentId=" + idOrPersistentIdOfFile; } @@ -2564,7 +2570,7 @@ static Response checkDatasetLocks(long datasetId, String lockType, String apiTok static Response checkDatasetLocks(String idOrPersistentId, String lockType, String apiToken) { String idInPath = idOrPersistentId; // Assume it's a number. String queryParams = ""; // If idOrPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(idOrPersistentId)) { + if (!NumberUtils.isCreatable(idOrPersistentId)) { idInPath = ":persistentId"; queryParams = "?persistentId=" + idOrPersistentId; } @@ -2733,7 +2739,7 @@ static Response makeDataCountGetMetricForDataset(String idOrPersistentIdOfDatase System.out.println("metric: " + metric); String idInPath = idOrPersistentIdOfDataset; // Assume it's a number. String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(idOrPersistentIdOfDataset)) { + if (!NumberUtils.isCreatable(idOrPersistentIdOfDataset)) { idInPath = ":persistentId"; optionalQueryParam = "&persistentId=" + idOrPersistentIdOfDataset; } @@ -2749,7 +2755,7 @@ static Response makeDataCountGetMetricForDataset(String idOrPersistentIdOfDatase System.out.println("metric: " + metric); String idInPath = idOrPersistentIdOfDataset; // Assume it's a number. String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(idOrPersistentIdOfDataset)) { + if (!NumberUtils.isCreatable(idOrPersistentIdOfDataset)) { idInPath = ":persistentId"; optionalQueryParam = "&persistentId=" + idOrPersistentIdOfDataset; } @@ -2765,7 +2771,7 @@ static Response makeDataCountGetMetricForDataset(String idOrPersistentIdOfDatase System.out.println("metric: " + metric); String idInPath = idOrPersistentIdOfDataset; // Assume it's a number. String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(idOrPersistentIdOfDataset)) { + if (!NumberUtils.isCreatable(idOrPersistentIdOfDataset)) { idInPath = ":persistentId"; optionalQueryParam = "&persistentId=" + idOrPersistentIdOfDataset; } @@ -2781,7 +2787,7 @@ static Response makeDataCountAddUsageMetricsFromSushiReport(String idOrPersisten String idInPath = idOrPersistentIdOfDataset; // Assume it's a number. String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(idOrPersistentIdOfDataset)) { + if (!NumberUtils.isCreatable(idOrPersistentIdOfDataset)) { idInPath = ":persistentId"; optionalQueryParam = "&persistentId=" + idOrPersistentIdOfDataset; } @@ -2794,7 +2800,7 @@ static Response makeDataCountUpdateCitationsForDataset(String idOrPersistentIdOf String idInPath = idOrPersistentIdOfDataset; // Assume it's a number. String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path. - if (!NumberUtils.isNumber(idOrPersistentIdOfDataset)) { + if (!NumberUtils.isCreatable(idOrPersistentIdOfDataset)) { idInPath = ":persistentId"; optionalQueryParam = "?persistentId=" + idOrPersistentIdOfDataset; } @@ -3076,7 +3082,7 @@ static Response getDatasetVersionArchivalStatus(Integer datasetId, String versio static Response archiveDataset(String idOrPersistentIdOfDataset, String version, String apiToken) { String idInPath = idOrPersistentIdOfDataset; String optionalQueryParam = ""; - if (!NumberUtils.isNumber(idOrPersistentIdOfDataset)) { + if (!NumberUtils.isCreatable(idOrPersistentIdOfDataset)) { idInPath = ":persistentId"; optionalQueryParam = "?persistentId=" + idOrPersistentIdOfDataset; }