SourcesApi { @ApiOperation( value = "Update a source", notes = "", nickname = "updateSource") @RequestMapping( value = "/{sourceIdentifier}", method = RequestMethod.PUT) @PreAuthorize("hasRole('UserAdmin')") @ResponseStatus(HttpStatus.NO_CONTENT) @ApiResponses(value = { @ApiResponse(code = 204, message = "Source updated."), @ApiResponse(code = 404, message = "Source not found."), @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_ONLY_USER_ADMIN) }) public ResponseEntity updateSource( @ApiParam( value = "Source identifier", required = true ) @PathVariable String sourceIdentifier, @ApiParam( name = "source" ) @RequestBody Source source, @ApiIgnore HttpServletRequest request) throws Exception { Source existingSource = sourceRepository.findOne(sourceIdentifier); if (existingSource != null) { updateSource(sourceIdentifier, source, sourceRepository); copySourceLogo(source, request); } else { throw new ResourceNotFoundException(String.format( "Source with uuid '%s' does not exist.", sourceIdentifier )); } return new ResponseEntity(HttpStatus.NO_CONTENT); }  @ApiOperation( value = "Get all sources", notes = "Sources are the local catalogue, subportal, external catalogue (when importing MEF files) or harvesters.", nickname = "getSources") @RequestMapping( produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) @ApiResponses(value = { @ApiResponse(code = 200, message = "List of source catalogues.") }) @ResponseBody List<Source> getSources(
        @ApiParam(
            value = "Group owner of the source (only applies to subportal)."
        )
        @RequestParam(
            value = "group",
            required = false)
        Integer group
    ); @ApiOperation( value = "Get portal list", notes = "List all subportal available.", nickname = "getSubPortal") @RequestMapping( produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) @ApiResponses(value = { @ApiResponse(code = 200, message = "List of portals.") }) @ResponseBody void getSubPortal(
        @ApiIgnore
            HttpServletResponse response
    ); @ApiOperation( value = "Add a source", notes = "", nickname = "addSource") @RequestMapping( method = RequestMethod.PUT, produces = { MediaType.TEXT_PLAIN_VALUE }) @PreAuthorize("hasRole('Administrator')") @ResponseStatus(HttpStatus.CREATED) @ApiResponses(value = { @ApiResponse(code = 201, message = "Source created."), @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_ONLY_ADMIN) }) ResponseEntity addSource(
        @ApiParam(
            name = "source"
        )
        @RequestBody
            Source source,
        @ApiIgnore
        HttpServletRequest request); @ApiOperation( value = "Update a source", notes = "", nickname = "updateSource") @RequestMapping( value = "/{sourceIdentifier}", method = RequestMethod.PUT) @PreAuthorize("hasRole('UserAdmin')") @ResponseStatus(HttpStatus.NO_CONTENT) @ApiResponses(value = { @ApiResponse(code = 204, message = "Source updated."), @ApiResponse(code = 404, message = "Source not found."), @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_ONLY_USER_ADMIN) }) ResponseEntity updateSource(
        @ApiParam(
            value = "Source identifier",
            required = true
        )
        @PathVariable
            String sourceIdentifier,
        @ApiParam(
            name = "source"
        )
        @RequestBody
            Source source,
        @ApiIgnore
        HttpServletRequest request); @ApiOperation( value = "Remove a source", notes = "", nickname = "deleteSource") @RequestMapping( value = "/{sourceIdentifier}", method = RequestMethod.DELETE ) @PreAuthorize("hasRole('Administrator')") @ResponseStatus(HttpStatus.NO_CONTENT) @ApiResponses(value = { @ApiResponse(code = 201, message = "Source deleted."), @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_ONLY_ADMIN) }) ResponseEntity deleteSource(
        @ApiParam(
            value = "Source identifier",
            required = true
        )
        @PathVariable
            String sourceIdentifier,
        @ApiIgnore
            HttpServletRequest request
    );  }
@Test public void updateSource() throws Exception { Source source = sourceRepo.findOneByName("source-test"); Assert.assertNotNull(source); source.setName("source-test-updated"); Gson gson = new GsonBuilder() .setFieldNamingStrategy(new JsonFieldNamingStrategy()) .setExclusionStrategies(new FieldNameExclusionStrategy("_labelTranslations", "creationDate")) .create(); String json = gson.toJson(source); this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); this.mockHttpSession = loginAsAdmin(); this.mockMvc.perform(put("/srv/api/sources/" + source.getUuid()) .content(json) .contentType(API_JSON_EXPECTED_ENCODING) .session(this.mockHttpSession) .accept(MediaType.parseMediaType("text/plain"))) .andExpect(status().is(204)); }