/* * Create a new data source (metadata entry). * If there is another one with the same identifier, then - error. */ @RequestMapping( value = "/admin/datasources", consumes = "application/json", method = RequestMethod.PUT) public void put( @RequestBody @Valid Metadata metadata, BindingResult bindingResult, HttpServletResponse response) throws IOException { if (bindingResult != null && bindingResult.hasErrors()) { log.error( Status.BAD_REQUEST.getErrorCode() + "; " + Status.BAD_REQUEST.getErrorMsg() + "; " + errorFromBindingResult(bindingResult)); response.sendError( Status.BAD_REQUEST.getErrorCode(), Status.BAD_REQUEST.getErrorMsg() + "; " + errorFromBindingResult(bindingResult)); } Metadata existing = service.metadata().findByIdentifier(metadata.identifier); if (existing == null) { service.save(metadata); } else { response.sendError( Status.BAD_REQUEST.getErrorCode(), "PUT failed: Metadata already exists for pk: " + metadata.identifier + " (use POST to update instead)"); } }
/* * Update a data source definition (metadata entry) */ @RequestMapping( value = "/admin/datasources", consumes = "application/json", method = RequestMethod.POST) public void update( @RequestBody @Valid Metadata metadata, BindingResult bindingResult, HttpServletResponse response) throws IOException { if (bindingResult != null && bindingResult.hasErrors()) { log.error( Status.BAD_REQUEST.getErrorCode() + "; " + Status.BAD_REQUEST.getErrorMsg() + "; " + errorFromBindingResult(bindingResult)); response.sendError( Status.BAD_REQUEST.getErrorCode(), Status.BAD_REQUEST.getErrorMsg() + "; " + errorFromBindingResult(bindingResult)); } service.save(metadata); }