IdentifiersApi { @ApiOperation( value = "Update an identifier template", notes = "", authorizations = { @Authorization(value = "basicAuth") }, nickname = "updateIdentifier") @RequestMapping( path = "/{identifier}", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.PUT ) @ResponseStatus(HttpStatus.NO_CONTENT) @ApiResponses(value = { @ApiResponse(code = 204, message = "Identifier template updated.") , @ApiResponse(code = 404, message = "Resource not found.") , @ApiResponse(code = 403, message = "Operation not allowed. Only Editor can access it.") }) @PreAuthorize("hasRole('Editor') or hasRole('Reviewer') or hasRole('UserAdmin') or hasRole('Administrator')") @ResponseBody public void updateIdentifier( @ApiParam( value = API_PARAM_IDENTIFIER ) @PathVariable Integer identifier, @ApiParam( value = API_PARAM_IDENTIFIER_TEMPLATE_DETAILS ) @RequestBody MetadataIdentifierTemplate metadataIdentifierTemplate ) throws Exception { MetadataIdentifierTemplate existing = metadataIdentifierTemplateRepository.findOne(identifier); if (existing == null) { throw new ResourceNotFoundException(String.format( MSG_NO_METADATA_IDENTIFIER_FOUND_WITH_ID, identifier )); } else { metadataIdentifierTemplateRepository.save(metadataIdentifierTemplate); } }  @ApiOperation( value = "Get identifier templates", notes = "Identifier templates are used to create record UUIDs " + "havind a particular structure. The template will be used " + "when user creates a new record. The template identifier to " + "use is defined in the administration > settings.", authorizations = { @Authorization(value = "basicAuth") }, nickname = "getIdentifiers") @RequestMapping( produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET) @ResponseStatus(value = HttpStatus.OK) @ApiResponses(value = { @ApiResponse(code = 200, message = "List of identifier templates.") , @ApiResponse(code = 403, message = "Operation not allowed. Only Editor can access it.") }) @PreAuthorize("hasRole('Editor') or hasRole('Reviewer') or hasRole('UserAdmin') or hasRole('Administrator')") @ResponseBody List<MetadataIdentifierTemplate> getIdentifiers(
        @ApiParam(
            value = "Only user defined ones",
            required = false
        )
        @RequestParam(
            required = false,
            defaultValue = "false"
        )
            boolean userDefinedOnly
    ); @ApiOperation( value = "Add an identifier template", notes = "", authorizations = { @Authorization(value = "basicAuth") }, nickname = "addIdentifier") @RequestMapping( produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.PUT ) @ResponseStatus(HttpStatus.CREATED) @ApiResponses(value = { @ApiResponse(code = 201, message = "Identifier template created.") , @ApiResponse(code = 403, message = "Operation not allowed. Only Editor can access it.") }) @PreAuthorize("hasRole('Editor') or hasRole('Reviewer') or hasRole('UserAdmin') or hasRole('Administrator')") @ResponseBody ResponseEntity<Integer> addIdentifier(
        @ApiParam(
            value = API_PARAM_IDENTIFIER_TEMPLATE_DETAILS
        )
        @RequestBody
            MetadataIdentifierTemplate metadataIdentifierTemplate
    ); @ApiOperation( value = "Update an identifier template", notes = "", authorizations = { @Authorization(value = "basicAuth") }, nickname = "updateIdentifier") @RequestMapping( path = "/{identifier}", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.PUT ) @ResponseStatus(HttpStatus.NO_CONTENT) @ApiResponses(value = { @ApiResponse(code = 204, message = "Identifier template updated.") , @ApiResponse(code = 404, message = "Resource not found.") , @ApiResponse(code = 403, message = "Operation not allowed. Only Editor can access it.") }) @PreAuthorize("hasRole('Editor') or hasRole('Reviewer') or hasRole('UserAdmin') or hasRole('Administrator')") @ResponseBody void updateIdentifier(
        @ApiParam(
            value = API_PARAM_IDENTIFIER
        )
        @PathVariable
            Integer identifier,
        @ApiParam(
            value = API_PARAM_IDENTIFIER_TEMPLATE_DETAILS
        )
        @RequestBody
            MetadataIdentifierTemplate metadataIdentifierTemplate
    ); @ApiOperation( value = "Remove an identifier template", notes = "", authorizations = { @Authorization(value = "basicAuth") }, nickname = "deleteIdentifier") @RequestMapping( path = "/{identifier}", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.DELETE ) @ResponseStatus(HttpStatus.NO_CONTENT) @ApiResponses(value = { @ApiResponse(code = 204, message = "Template identifier removed.") , @ApiResponse(code = 404, message = "Resource not found.") , @ApiResponse(code = 403, message = "Operation not allowed. Only Editor can access it.") }) @PreAuthorize("hasRole('Editor') or hasRole('Reviewer') or hasRole('UserAdmin') or hasRole('Administrator')") void deleteIdentifier(
        @ApiParam(
            value = API_PARAM_IDENTIFIER,
            required = true
        )
        @PathVariable
            int identifier
    ); static final String MSG_NO_METADATA_IDENTIFIER_FOUND_WITH_ID; }
@Test public void updateIdentifier() throws Exception { MetadataIdentifierTemplate metadataIdentifierTemplateToUpdate = metadataIdentifierTemplateRepo.findOneByName("id-template-1"); Assert.assertNotNull(metadataIdentifierTemplateToUpdate); metadataIdentifierTemplateToUpdate.setTemplate("{AAAA}"); Gson gson = new GsonBuilder() .setFieldNamingStrategy(new JsonFieldNamingStrategy()) .create(); String json = gson.toJson(metadataIdentifierTemplateToUpdate); this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); this.mockHttpSession = loginAsAdmin(); this.mockMvc.perform(put("/srv/api/identifiers/" + metadataIdentifierTemplateToUpdate.getId()) .content(json) .contentType(API_JSON_EXPECTED_ENCODING) .session(this.mockHttpSession) .accept(MediaType.parseMediaType("application/json"))) .andExpect(status().is(204)); MetadataIdentifierTemplate metadataIdentifierTemplateAdded = metadataIdentifierTemplateRepo.findOneByName("id-template-1"); Assert.assertNotNull(metadataIdentifierTemplateAdded); }