Skip to content

Commit

Permalink
#2438 Clean up FindFileOrDie calls
Browse files Browse the repository at this point in the history
  • Loading branch information
sekmiller committed May 14, 2018
1 parent 5836612 commit fa3a55f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
15 changes: 10 additions & 5 deletions src/main/java/edu/harvard/iq/dataverse/api/Files.java
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,14 @@ public Response getMapLayerMetadatas(@PathParam("id") Long idSupplied) {

@Path("{id}/uningest")
@POST
public Response uningestDatafile(@PathParam("id") Long idSupplied) {

DataFile dataFile = fileService.find(idSupplied);
public Response uningestDatafile(@PathParam("id") String id) {

DataFile dataFile;
try {
dataFile = findDataFileOrDie(id);
} catch (WrappedResponse ex) {
return error(BAD_REQUEST, "Could not find datafile with id " + id);
}
if (dataFile == null) {
return error(Response.Status.NOT_FOUND, "File not found for given id.");
}
Expand All @@ -315,10 +319,11 @@ public Response uningestDatafile(@PathParam("id") Long idSupplied) {
try {
DataverseRequest req = createDataverseRequest(findUserOrDie());
execCommand(new UningestFileCommand(req, dataFile));
dataFile = fileService.find(idSupplied);
Long dataFileId = dataFile.getId();
dataFile = fileService.find(dataFileId);
Dataset theDataset = dataFile.getOwner();
exportMetadata(settingsService, theDataset);
return ok("Datafile " + idSupplied + " uningested.");
return ok("Datafile " + dataFileId + " uningested.");
} catch (WrappedResponse wr) {
return wr.getResponse();
}
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/edu/harvard/iq/dataverse/api/Prov.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,4 @@ public Response getProvJson(String body, @PathParam("id") String idSupplied) {
}
}


/** Helper Methods */
// FIXME: Delete this and switch to the version in AbstractApiBean.java once this is merged: https://github.com/IQSS/dataverse/pull/4350
private DataFile findDataFileOrDie(String idSupplied) throws WrappedResponse {
long idSuppliedAsLong;
try {
idSuppliedAsLong = new Long(idSupplied);
} catch (NumberFormatException ex) {
throw new WrappedResponse(badRequest(BundleUtil.getStringFromBundle("api.prov.error.badDataFileId")));
}
DataFile dataFile = fileSvc.find(idSuppliedAsLong);
if (dataFile == null) {
throw new WrappedResponse(badRequest(BundleUtil.getStringFromBundle("api.prov.error.noDataFileFound")));
}
return dataFile;
}
}

0 comments on commit fa3a55f

Please sign in to comment.