MapServersApi { @ApiOperation( value = "Add a mapserver", notes = "Return the id of the newly created mapserver.", authorizations = { @Authorization(value = "basicAuth") }, nickname = "addMapserver" ) @RequestMapping( method = RequestMethod.PUT, produces = { MediaType.APPLICATION_JSON_VALUE }) @PreAuthorize("hasRole('Reviewer')") @ApiResponses(value = { @ApiResponse(code = 201, message = "Mapserver created."), @ApiResponse(code = 400, message = "Bad parameters.") , @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_ONLY_REVIEWER) }) @ResponseStatus(HttpStatus.CREATED) @ResponseBody public ResponseEntity<Integer> addMapserver( @ApiParam( value = API_PARAM_MAPSERVER_DETAILS, required = true ) @RequestBody MapServer mapserver ) throws Exception { MapServer existingMapserver = mapServerRepository.findOneById(mapserver.getId()); if (existingMapserver != null) { throw new IllegalArgumentException(String.format( "Mapserver with id '%d' already exists.", mapserver.getId() )); } else { mapServerRepository.save(mapserver); } return new ResponseEntity<>(mapserver.getId(), HttpStatus.CREATED); }  @ApiOperation( value = "Get mapservers", notes = "Mapservers are used by the catalog to publish record attachments " + "(eg. ZIP file with shape) or record associated resources (eg. " + "database table, file on the local network) in a remote mapserver like " + "GeoServer or MapServer. The catalog communicate with the mapserver using " + "GeoServer REST API.", authorizations = { @Authorization(value = "basicAuth") }, nickname = "getMapservers" ) @RequestMapping( method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE }) @ResponseBody @ResponseStatus(HttpStatus.OK) @PreAuthorize("hasRole('Editor')") @ApiResponses(value = { @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_ONLY_EDITOR) }) List<AnonymousMapserver> getMapservers(); @ApiOperation( value = "Get a mapserver", authorizations = { @Authorization(value = "basicAuth") }, nickname = "getMapserver" ) @RequestMapping(value = "/{mapserverId}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE }) @ResponseBody @PreAuthorize("hasRole('Editor')") @ApiResponses(value = { @ApiResponse(code = 404, message = ApiParams.API_RESPONSE_RESOURCE_NOT_FOUND) , @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_ONLY_EDITOR) }) AnonymousMapserver getMapserver(
        @ApiParam(value = API_PARAM_MAPSERVER_IDENTIFIER,
            required = true,
            example = "")
        @PathVariable String mapserverId
    ); @ApiOperation( value = "Add a mapserver", notes = "Return the id of the newly created mapserver.", authorizations = { @Authorization(value = "basicAuth") }, nickname = "addMapserver" ) @RequestMapping( method = RequestMethod.PUT, produces = { MediaType.APPLICATION_JSON_VALUE }) @PreAuthorize("hasRole('Reviewer')") @ApiResponses(value = { @ApiResponse(code = 201, message = "Mapserver created."), @ApiResponse(code = 400, message = "Bad parameters.") , @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_ONLY_REVIEWER) }) @ResponseStatus(HttpStatus.CREATED) @ResponseBody ResponseEntity<Integer> addMapserver(
        @ApiParam(
            value = API_PARAM_MAPSERVER_DETAILS,
            required = true
        )
        @RequestBody
            MapServer mapserver
    ); @ApiOperation( value = "Update a mapserver", authorizations = { @Authorization(value = "basicAuth") }, nickname = "updateMapserver" ) @RequestMapping( value = "/{mapserverId}", method = RequestMethod.PUT, produces = { MediaType.APPLICATION_JSON_VALUE }) @PreAuthorize("hasRole('Reviewer')") @ApiResponses(value = { @ApiResponse(code = 204, message = "Mapserver updated."), @ApiResponse(code = 404, message = ApiParams.API_RESPONSE_RESOURCE_NOT_FOUND) , @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_ONLY_REVIEWER) }) @ResponseStatus(HttpStatus.NO_CONTENT) @ResponseBody void updateMapserver(
        @ApiParam(value = API_PARAM_MAPSERVER_IDENTIFIER,
            required = true,
            example = "")
        @PathVariable Integer mapserverId,
        @ApiParam(value = API_PARAM_MAPSERVER_DETAILS,
            required = true)
        @RequestBody
            MapServer mapserver
    ); @ApiOperation( value = "Update a mapserver authentication", notes = "The remote mapserver REST API may require basic authentication. " + "This operation set the username and password.", authorizations = { @Authorization(value = "basicAuth") }, nickname = "updateMapserverAuth") @RequestMapping( value = "/{mapserverId}/auth", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE }) @PreAuthorize("hasRole('Reviewer')") @ApiResponses(value = { @ApiResponse(code = 204, message = "Mapserver updated."), @ApiResponse(code = 404, message = ApiParams.API_RESPONSE_RESOURCE_NOT_FOUND) , @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_ONLY_REVIEWER) }) @ResponseStatus(HttpStatus.NO_CONTENT) void updateMapserver(
        @ApiParam(
            value = API_PARAM_MAPSERVER_IDENTIFIER,
            required = true,
            example = "")
        @PathVariable Integer mapserverId,
        @ApiParam(
            value = "User name",
            required = true)
        @RequestParam
            String username,
        @ApiParam(
            value = "Password",
            required = true)
        @RequestParam
            String password
    ); @ApiOperation( value = "Remove a mapserver", authorizations = { @Authorization(value = "basicAuth") }, nickname = "deleteMapserver") @RequestMapping( value = "/{mapserverId}", method = RequestMethod.DELETE, produces = { MediaType.APPLICATION_JSON_VALUE }) @PreAuthorize("hasRole('Reviewer')") @ApiResponses(value = { @ApiResponse(code = 204, message = "Mapserver removed."), @ApiResponse(code = 404, message = ApiParams.API_RESPONSE_RESOURCE_NOT_FOUND) , @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_ONLY_REVIEWER) }) @ResponseStatus(HttpStatus.NO_CONTENT) void deleteMapserver(
        @ApiParam(value = API_PARAM_MAPSERVER_IDENTIFIER,
            required = true
        )
        @PathVariable Integer mapserverId
    ); @ApiOperation( value = "Check metadata mapserver resource is published ", authorizations = { @Authorization(value = "basicAuth") }, nickname = "getMapserverResource" ) @RequestMapping(value = "/{mapserverId}/records/{metadataUuid}", method = RequestMethod.GET, produces = { MediaType.TEXT_PLAIN_VALUE }) @ResponseBody @PreAuthorize("hasRole('Editor')") @ApiResponses(value = { @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_ONLY_EDITOR) }) String getMapserverResource(
        @ApiParam(value = API_PARAM_MAPSERVER_IDENTIFIER,
            required = true,
            example = "")
        @PathVariable String mapserverId,
        @ApiParam(
            value = API_PARAM_RECORD_UUID,
            required = true
        )
        @PathVariable String metadataUuid,
        @ApiParam(
            value = ApiParams.API_PARAM_MAPSERVER_RESOURCE,
            required = true
        )
        @RequestParam String resource,
        @ApiParam(
            value = ApiParams.API_PARAM_METADATA_TITLE
        )
        @RequestParam(
            required = false,
            defaultValue = ""
        )
            String metadataTitle,
        @ApiParam(
            value = ApiParams.API_PARAM_METADATA_ABSTRACT
        )
        @RequestParam(
            required = false,
            defaultValue = ""
        )
            String metadataAbstract,
        HttpServletRequest request
    ); @ApiOperation( value = "Publish a metadata resource in a mapserver", authorizations = { @Authorization(value = "basicAuth") }, nickname = "publishMapserverResource" ) @RequestMapping(value = "/{mapserverId}/records/{metadataUuid}", method = RequestMethod.PUT, produces = { MediaType.TEXT_PLAIN_VALUE }) @PreAuthorize("hasRole('Editor')") @ApiResponses(value = { @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_ONLY_EDITOR) }) @ResponseBody String publishMapserverResource(
        @ApiParam(value = API_PARAM_MAPSERVER_IDENTIFIER,
            required = true,
            example = "")
        @PathVariable String mapserverId,
        @ApiParam(
            value = API_PARAM_RECORD_UUID,
            required = true
        )
        @PathVariable String metadataUuid,
        @ApiParam(
            value = ApiParams.API_PARAM_MAPSERVER_RESOURCE,
            required = true
        )
        @RequestParam String resource,
        @ApiParam(
            value = ApiParams.API_PARAM_METADATA_TITLE
        )
        @RequestParam(
            required = false,
            defaultValue = ""
        )
            String metadataTitle,
        @ApiParam(
            value = ApiParams.API_PARAM_METADATA_ABSTRACT
        )
        @RequestParam(
            required = false,
            defaultValue = ""
        )
            String metadataAbstract,
        HttpServletRequest request
    ); @ApiOperation( value = "Remove a metadata mapserver resource", authorizations = { @Authorization(value = "basicAuth") }, nickname = "deleteMapserverResource") @RequestMapping( value = "/{mapserverId}/records/{metadataUuid}", method = RequestMethod.DELETE, produces = { MediaType.TEXT_PLAIN_VALUE }) @PreAuthorize("hasRole('Editor')") @ApiResponses(value = { @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_ONLY_EDITOR) }) @ResponseBody String deleteMapserverResource(
        @ApiParam(value = API_PARAM_MAPSERVER_IDENTIFIER,
            required = true,
            example = "")
        @PathVariable String mapserverId,
        @ApiParam(
            value = API_PARAM_RECORD_UUID,
            required = true
        )
        @PathVariable String metadataUuid,
        @ApiParam(
            value = ApiParams.API_PARAM_MAPSERVER_RESOURCE,
            required = true
        )
        @RequestParam String resource,
        @ApiParam(
            value = ApiParams.API_PARAM_METADATA_TITLE
        )
        @RequestParam(
            required = false,
            defaultValue = ""
        )
            String metadataTitle,
        @ApiParam(
            value = ApiParams.API_PARAM_METADATA_ABSTRACT
        )
        @RequestParam(
            required = false,
            defaultValue = ""
        )
            String metadataAbstract,
        HttpServletRequest request
    ); static final String API_PARAM_MAPSERVER_IDENTIFIER; static final String API_PARAM_MAPSERVER_DETAILS; static final String MSG_MAPSERVER_WITH_ID_NOT_FOUND; }
@Test public void addMapserver() throws Exception { MapServer mapServerToAdd = new MapServer(); mapServerToAdd.setName("mapserver-toadd"); mapServerToAdd.setConfigurl("http: mapServerToAdd.setDescription("A test mapserver"); mapServerToAdd.setWmsurl("http: Gson gson = new GsonBuilder() .setFieldNamingStrategy(new JsonFieldNamingStrategy()) .setExclusionStrategies(new FieldNameExclusionStrategy("_pushstyleinworkspace")) .create(); String json = gson.toJson(mapServerToAdd); this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); this.mockHttpSession = loginAsAdmin(); this.mockMvc.perform(put("/srv/api/mapservers") .content(json) .contentType(API_JSON_EXPECTED_ENCODING) .session(this.mockHttpSession) .accept(MediaType.parseMediaType("application/json"))) .andExpect(status().is(201)); }