Search in sources :

Example 1 with GroupDto

use of org.entando.entando.aps.system.services.group.model.GroupDto in project entando-core by entando.

the class GroupController method getGroups.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getGroups(RestListRequest requestList) throws JsonProcessingException {
    this.getGroupValidator().validateRestListRequest(requestList);
    PagedMetadata<GroupDto> result = this.getGroupService().getGroups(requestList);
    this.getGroupValidator().validateRestListResult(requestList, result);
    logger.debug("Main Response -> {}", result);
    return new ResponseEntity<>(new RestResponse(result.getBody(), null, result), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) RestResponse(org.entando.entando.web.common.model.RestResponse) GroupDto(org.entando.entando.aps.system.services.group.model.GroupDto) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with GroupDto

use of org.entando.entando.aps.system.services.group.model.GroupDto in project entando-core by entando.

the class GroupController method updateGroup.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{groupCode}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> updateGroup(@PathVariable String groupCode, @Valid @RequestBody GroupRequest groupRequest, BindingResult bindingResult) {
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    this.getGroupValidator().validateBodyName(groupCode, groupRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    GroupDto group = this.getGroupService().updateGroup(groupCode, groupRequest.getName());
    return new ResponseEntity<>(new RestResponse(group), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) RestResponse(org.entando.entando.web.common.model.RestResponse) GroupDto(org.entando.entando.aps.system.services.group.model.GroupDto) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with GroupDto

use of org.entando.entando.aps.system.services.group.model.GroupDto in project entando-core by entando.

the class GroupService method getGroups.

@SuppressWarnings("rawtypes")
@Override
public PagedMetadata<GroupDto> getGroups(RestListRequest restListReq) {
    try {
        // transforms the filters by overriding the key specified in the request with the correct one known by the dto
        List<FieldSearchFilter> filters = new ArrayList<FieldSearchFilter>(restListReq.buildFieldSearchFilters());
        filters.stream().filter(i -> i.getKey() != null).forEach(i -> i.setKey(GroupDto.getEntityFieldName(i.getKey())));
        SearcherDaoPaginatedResult<Group> groups = this.getGroupManager().getGroups(filters);
        List<GroupDto> dtoList = dtoBuilder.convert(groups.getList());
        PagedMetadata<GroupDto> pagedMetadata = new PagedMetadata<>(restListReq, groups);
        pagedMetadata.setBody(dtoList);
        return pagedMetadata;
    } catch (Throwable t) {
        logger.error("error in search groups", t);
        throw new RestServerError("error in search groups", t);
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) Group(com.agiletec.aps.system.services.group.Group) ArrayList(java.util.ArrayList) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) RestServerError(org.entando.entando.aps.system.exception.RestServerError) IGroupManager(com.agiletec.aps.system.services.group.IGroupManager) Map(java.util.Map) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) GroupRequest(org.entando.entando.web.group.model.GroupRequest) GroupValidator(org.entando.entando.web.group.validator.GroupValidator) Logger(org.slf4j.Logger) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) GroupDto(org.entando.entando.aps.system.services.group.model.GroupDto) BeansException(org.springframework.beans.BeansException) ApplicationContext(org.springframework.context.ApplicationContext) List(java.util.List) RestListRequest(org.entando.entando.web.common.model.RestListRequest) GroupUtilizer(com.agiletec.aps.system.services.group.GroupUtilizer) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) Optional(java.util.Optional) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) ApplicationContextAware(org.springframework.context.ApplicationContextAware) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) Group(com.agiletec.aps.system.services.group.Group) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ArrayList(java.util.ArrayList) GroupDto(org.entando.entando.aps.system.services.group.model.GroupDto) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter)

Example 4 with GroupDto

use of org.entando.entando.aps.system.services.group.model.GroupDto in project entando-core by entando.

the class GroupService method getGroup.

@Override
public GroupDto getGroup(String groupCode) {
    Group group = this.getGroupManager().getGroup(groupCode);
    if (null == group) {
        logger.warn("no group found with code {}", groupCode);
        throw new RestRourceNotFoundException(GroupValidator.ERRCODE_GROUP_NOT_FOUND, "group", groupCode);
    }
    GroupDto dto = this.getDtoBuilder().convert(group);
    dto.setReferences(this.getReferencesInfo(group));
    return dto;
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) Group(com.agiletec.aps.system.services.group.Group) GroupDto(org.entando.entando.aps.system.services.group.model.GroupDto)

Example 5 with GroupDto

use of org.entando.entando.aps.system.services.group.model.GroupDto in project entando-core by entando.

the class GroupControllerIntegrationTest method testAddExistingGroup.

@Test
public void testAddExistingGroup() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    GroupDto group = this.groupService.getGroup(Group.FREE_GROUP_NAME);
    GroupRequest groupRequest = new GroupRequest();
    groupRequest.setCode(group.getCode());
    groupRequest.setName(group.getName());
    ObjectMapper mapper = new ObjectMapper();
    String payload = mapper.writeValueAsString(groupRequest);
    ResultActions result = mockMvc.perform(post("/groups").content(payload).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
    // System.out.println(result.andReturn().getResponse().getContentAsString());
    result.andExpect(status().isConflict());
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) GroupRequest(org.entando.entando.web.group.model.GroupRequest) GroupDto(org.entando.entando.aps.system.services.group.model.GroupDto) ResultActions(org.springframework.test.web.servlet.ResultActions) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Aggregations

GroupDto (org.entando.entando.aps.system.services.group.model.GroupDto)12 Test (org.junit.Test)7 RestListRequest (org.entando.entando.web.common.model.RestListRequest)6 UserDetails (com.agiletec.aps.system.services.user.UserDetails)4 ResultActions (org.springframework.test.web.servlet.ResultActions)4 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)3 Filter (org.entando.entando.web.common.model.Filter)3 RestResponse (org.entando.entando.web.common.model.RestResponse)3 GroupRequest (org.entando.entando.web.group.model.GroupRequest)3 ResponseEntity (org.springframework.http.ResponseEntity)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Group (com.agiletec.aps.system.services.group.Group)2 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)2 AbstractControllerIntegrationTest (org.entando.entando.web.AbstractControllerIntegrationTest)2 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)2 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)2 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)2 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)1 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)1 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)1