Created
January 9, 2017 16:24
-
-
Save raprasad/c962ce00217a169238f5461138326135 to your computer and use it in GitHub Desktop.
Endpoint to update a single file's metadata (non-working start point)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @PUT | |
| @Path("{id}/metadata") | |
| public Response updateFileMetadata( | |
| @PathParam("id") Long fileToUpdateId, | |
| String jsonData | |
| ){ | |
| // ------------------------------------- | |
| // (1) Get the user from the API key | |
| // ------------------------------------- | |
| User authUser; | |
| try { | |
| authUser = this.findUserOrDie(); | |
| } catch (AbstractApiBean.WrappedResponse ex) { | |
| return error(Response.Status.FORBIDDEN, | |
| ResourceBundle.getBundle("Bundle").getString("file.addreplace.error.auth") | |
| ); | |
| } | |
| // ------------------------------------- | |
| // (2) Check/Parse the JSON | |
| // ------------------------------------- | |
| if (jsonData == null){ | |
| logger.log(Level.SEVERE, "jsonData is null"); | |
| return error( Response.Status.BAD_REQUEST, "No JSON data"); | |
| } | |
| JsonObject jsonObj = new Gson().fromJson(jsonData, JsonObject.class); | |
| // (2d) Load up optional params via JSON | |
| // - Will skip extra attributes which includes fileToReplaceId and forceReplace | |
| //--------------------------------------- | |
| OptionalFileParams optionalFileParams = null; | |
| try { | |
| optionalFileParams = new OptionalFileParams(jsonData); | |
| } catch (DataFileTagException ex) { | |
| return error( Response.Status.BAD_REQUEST, ex.getMessage()); | |
| } | |
| DataverseRequest dvRequest = createDataverseRequest(authUser); | |
| UpdateFileMetadataHelper updateFileMetadataHelper = new UpdateFileMetadataHelper(dvRequest, | |
| this.datasetService, | |
| this.fileService, | |
| this.permissionSvc, | |
| this.commandEngine, | |
| this.systemConfig); | |
| updateFileMetadataHelper.updateFileMetadata(fileToUpdateId, optionalFileParams); | |
| if (updateFileMetadataHelper.hasError()){ | |
| msg("yes, has error"); | |
| return error(updateFileMetadataHelper.getHttpErrorCode(), updateFileMetadataHelper.getErrorMessagesAsString("\n")); | |
| }else{ | |
| msg("no error"); | |
| String successMsg = ResourceBundle.getBundle("Bundle").getString("file.addreplace.success.replace"); | |
| msgt("as String: " + updateFileMetadataHelper.getSuccessResult()); | |
| return ok(successMsg, | |
| updateFileMetadataHelper.getSuccessResultAsJsonObjectBuilder()); | |
| } | |
| } // end: updateFileMetadata | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment