GroupsApi { @ApiOperation( value = "Update a group", notes = "", authorizations = { @Authorization(value = "basicAuth") }, nickname = "updateGroup") @RequestMapping( value = "/{groupIdentifier}", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.PUT ) @ResponseStatus(value = HttpStatus.NO_CONTENT) @PreAuthorize("hasRole('UserAdmin')") @ApiResponses(value = { @ApiResponse(code = 204, message = "Group updated."), @ApiResponse(code = 404, message = ApiParams.API_RESPONSE_RESOURCE_NOT_FOUND), @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_ONLY_USER_ADMIN) }) @ResponseBody public void updateGroup( @ApiParam( value = API_PARAM_GROUP_IDENTIFIER ) @PathVariable Integer groupIdentifier, @ApiParam( value = API_PARAM_GROUP_DETAILS ) @RequestBody Group group ) throws Exception { final Group existing = groupRepository.findOne(groupIdentifier); if (existing == null) { throw new ResourceNotFoundException(String.format( MSG_GROUP_WITH_IDENTIFIER_NOT_FOUND, groupIdentifier )); } else { try { groupRepository.saveAndFlush(group); } catch (Exception ex) { Log.error(API.LOG_MODULE_NAME, ExceptionUtils.getStackTrace(ex)); throw new RuntimeException(ex.getMessage()); } } }  @ApiOperation(value = "Get the group logo image.", nickname = "get", notes = API_GET_LOGO_NOTE ) @RequestMapping(value = "/{groupId}/logo", method = RequestMethod.GET) void getGroupLogo(
        @ApiParam(value = "Group identifier", required = true) @PathVariable(value = "groupId") final Integer groupId,
        @ApiIgnore final WebRequest webRequest,
        HttpServletRequest request,
        HttpServletResponse response); @ApiOperation( value = "Get groups", notes = "The catalog contains one or more groups. By default, there is 3 reserved groups " + "(Internet, Intranet, Guest) and a sample group.<br/>" + "This service returns all catalog groups when not authenticated or " + "when current is user is an administrator. The list can contains or not " + "reserved groups depending on the parameters.<br/>" + "When authenticated, return user groups " + "optionally filtered on a specific user profile.", nickname = "getGroups") @RequestMapping( produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET) @ResponseStatus(value = HttpStatus.OK) @ResponseBody List<Group> getGroups(
        @ApiParam(
            value = "Including Internet, Intranet, Guest groups or not"
        )
        @RequestParam(
            required = false,
            defaultValue = "false"
        )
            boolean withReservedGroup,
        @ApiParam(
            value = "For a specific profile"
        )
        @RequestParam(
            required = false
        )
            String profile,
        @ApiIgnore
            HttpSession httpSession
    ); @ApiOperation( value = "Add a group", notes = "Return the identifier of the group created.", authorizations = { @Authorization(value = "basicAuth") }, nickname = "addGroup") @RequestMapping( produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.PUT ) @ResponseStatus(value = HttpStatus.OK) @PreAuthorize("hasRole('UserAdmin')") @ApiResponses(value = { @ApiResponse(code = 201, message = "Group created."), @ApiResponse(code = 400, message = "Group with that id or name already exist."), @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_ONLY_USER_ADMIN) }) @ResponseBody ResponseEntity<Integer> addGroup(
        @ApiParam(
            value = API_PARAM_GROUP_DETAILS
        )
        @RequestBody
            Group group
    ); @ApiOperation( value = "Get group", notes = "Return the requested group details.", nickname = "getGroup") @RequestMapping( value = "/{groupIdentifier}", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET) @ResponseStatus(value = HttpStatus.OK) @ApiResponses(value = { @ApiResponse(code = 404, message = ApiParams.API_RESPONSE_RESOURCE_NOT_FOUND) }) @ResponseBody Group getGroup(
        @ApiParam(
            value = API_PARAM_GROUP_IDENTIFIER
        )
        @PathVariable
            Integer groupIdentifier
    ); @ApiOperation( value = "Get group users", notes = "", authorizations = { @Authorization(value = "basicAuth") }, nickname = "getGroupUsers") @RequestMapping( value = "/{groupIdentifier}/users", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET) @ResponseStatus(value = HttpStatus.OK) @PreAuthorize("hasRole('UserAdmin')") @ApiResponses(value = { @ApiResponse(code = 200, message = "List of users in that group."), @ApiResponse(code = 404, message = ApiParams.API_RESPONSE_RESOURCE_NOT_FOUND), @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_ONLY_USER_ADMIN) }) @ResponseBody List<User> getGroupUsers(
        @ApiParam(
            value = API_PARAM_GROUP_IDENTIFIER
        )
        @PathVariable
            Integer groupIdentifier
    ); @ApiOperation( value = "Update a group", notes = "", authorizations = { @Authorization(value = "basicAuth") }, nickname = "updateGroup") @RequestMapping( value = "/{groupIdentifier}", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.PUT ) @ResponseStatus(value = HttpStatus.NO_CONTENT) @PreAuthorize("hasRole('UserAdmin')") @ApiResponses(value = { @ApiResponse(code = 204, message = "Group updated."), @ApiResponse(code = 404, message = ApiParams.API_RESPONSE_RESOURCE_NOT_FOUND), @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_ONLY_USER_ADMIN) }) @ResponseBody void updateGroup(
        @ApiParam(
            value = API_PARAM_GROUP_IDENTIFIER
        )
        @PathVariable
            Integer groupIdentifier,
        @ApiParam(
            value = API_PARAM_GROUP_DETAILS
        )
        @RequestBody
            Group group
    ); @ApiOperation( value = "Remove a group", notes = "Remove a group by first removing sharing settings, link to users and " + "finally reindex all affected records.", authorizations = { @Authorization(value = "basicAuth") }, nickname = "deleteGroup") @RequestMapping(value = "/{groupIdentifier}", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.DELETE) @ResponseStatus(value = HttpStatus.NO_CONTENT) @PreAuthorize("hasRole('Administrator')") @ApiResponses(value = { @ApiResponse(code = 204, message = "Group removed."), @ApiResponse(code = 404, message = ApiParams.API_RESPONSE_RESOURCE_NOT_FOUND), @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_ONLY_USER_ADMIN) }) @ResponseBody void deleteGroup(
        @ApiParam(
            value = "Group identifier."
        )
        @PathVariable
            Integer groupIdentifier,
        @ApiParam(
            value = "Force removal even if records are assigned to that group."
        )
        @RequestParam(defaultValue = "false")
            boolean force,
        @ApiIgnore
            ServletRequest request
    ); static final String LOGGER; static final String API_PARAM_GROUP_DETAILS; static final String API_PARAM_GROUP_IDENTIFIER; static final String MSG_GROUP_WITH_IDENTIFIER_NOT_FOUND; }
@Test public void updateGroup() throws Exception { Group groupToUpdate = _groupRepo.findByName("sample"); Assert.assertNotNull(groupToUpdate); groupToUpdate.setEmail("group@mail.com"); groupToUpdate.setDescription("A test group"); groupToUpdate.setWebsite("http: Gson gson = new GsonBuilder() .setFieldNamingStrategy(new JsonFieldNamingStrategy()) .setExclusionStrategies(new FieldNameExclusionStrategy("_labelTranslations")) .create(); String json = gson.toJson(groupToUpdate); this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); this.mockHttpSession = loginAsAdmin(); this.mockMvc.perform(put("/srv/api/groups/" + groupToUpdate.getId()) .content(json) .contentType(API_JSON_EXPECTED_ENCODING) .session(this.mockHttpSession) .accept(MediaType.parseMediaType("application/json"))) .andExpect(status().is(204)); }