Search in sources :

Example 21 with Filter

use of org.entando.entando.web.common.model.Filter in project entando-core by entando.

the class RoleService method updateRole.

@Override
public RoleDto updateRole(RoleRequest roleRequest) {
    try {
        Role role = this.getRoleManager().getRole(roleRequest.getCode());
        if (null == role) {
            logger.warn("no role found with code {}", roleRequest.getCode());
            throw new ResourceNotFoundException(RoleValidator.ERRCODE_ROLE_NOT_FOUND, "role", roleRequest.getCode());
        }
        role.setDescription(roleRequest.getName());
        role.getPermissions().clear();
        if (null != roleRequest.getPermissions()) {
            roleRequest.getPermissions().entrySet().stream().filter(entry -> null != entry.getValue() && entry.getValue().booleanValue()).forEach(i -> role.addPermission(i.getKey()));
        }
        BeanPropertyBindingResult validationResult = this.validateRoleForUpdate(role);
        if (validationResult.hasErrors()) {
            throw new ValidationGenericException(validationResult);
        }
        this.getRoleManager().updateRole(role);
        RoleDto dto = this.getDtoBuilder().toDto(role, this.getRoleManager().getPermissionsCodes());
        return dto;
    } catch (ApsSystemException e) {
        logger.error("Error updating a role", e);
        throw new RestServerError("error in update role", e);
    }
}
Also used : Role(com.agiletec.aps.system.services.role.Role) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) JsonPatchService(org.entando.entando.aps.system.services.jsonpatch.JsonPatchService) UserDto(org.entando.entando.aps.system.services.user.model.UserDto) LoggerFactory(org.slf4j.LoggerFactory) Role(com.agiletec.aps.system.services.role.Role) RoleValidator(org.entando.entando.web.role.validator.RoleValidator) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) RestServerError(org.entando.entando.aps.system.exception.RestServerError) IRoleManager(com.agiletec.aps.system.services.role.IRoleManager) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) JsonNode(com.fasterxml.jackson.databind.JsonNode) IAuthorizationService(com.agiletec.aps.system.services.authorization.IAuthorizationService) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RoleRequest(org.entando.entando.web.role.model.RoleRequest) Permission(com.agiletec.aps.system.services.role.Permission) Logger(org.slf4j.Logger) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) DtoBuilder(org.entando.entando.aps.system.services.DtoBuilder) Collectors(java.util.stream.Collectors) List(java.util.List) RestListRequest(org.entando.entando.web.common.model.RestListRequest) PermissionDto(org.entando.entando.aps.system.services.role.model.PermissionDto) RoleDto(org.entando.entando.aps.system.services.role.model.RoleDto) Filter(org.entando.entando.web.common.model.Filter) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) PostConstruct(javax.annotation.PostConstruct) Comparator(java.util.Comparator) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) RoleDto(org.entando.entando.aps.system.services.role.model.RoleDto) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException)

Example 22 with Filter

use of org.entando.entando.web.common.model.Filter in project entando-core by entando.

the class RoleService method getPermissions.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public PagedMetadata<PermissionDto> getPermissions(RestListRequest requestList) {
    List<Permission> permissions = this.getRoleManager().getPermissions();
    permissions = sortPermissionList(requestList, permissions);
    if (null != requestList.getFilters()) {
        for (Filter f : requestList.getFilters()) {
            if (f.getAttributeName().equals(KEY_FILTER_PERMISSION_CODE)) {
                permissions = permissions.stream().filter(i -> i.getName().toLowerCase().contains(f.getValue().toLowerCase())).collect(Collectors.toList());
            }
            if (f.getAttributeName().equals(KEY_FILTER_PERMISSION_DESCR)) {
                permissions = permissions.stream().filter(i -> i.getDescription().toLowerCase().contains(f.getValue().toLowerCase())).collect(Collectors.toList());
            }
        }
    }
    List<Permission> subList = requestList.getSublist(permissions);
    List<PermissionDto> dtoSlice = this.getPermissionDtoBuilder().convert(subList);
    SearcherDaoPaginatedResult<PermissionDto> paginatedResult = new SearcherDaoPaginatedResult(permissions.size(), dtoSlice);
    PagedMetadata<PermissionDto> pagedMetadata = new PagedMetadata<>(requestList, paginatedResult);
    pagedMetadata.setBody(dtoSlice);
    return pagedMetadata;
}
Also used : FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) Filter(org.entando.entando.web.common.model.Filter) PermissionDto(org.entando.entando.aps.system.services.role.model.PermissionDto) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) Permission(com.agiletec.aps.system.services.role.Permission) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)

Example 23 with Filter

use of org.entando.entando.web.common.model.Filter in project entando-core by entando.

the class WidgetServiceTest method shouldFilterByGroup.

@Test
public void shouldFilterByGroup() {
    RestListRequest requestList = new RestListRequest();
    Filter filter = new Filter();
    filter.setAttribute("group");
    filter.setValue("group2");
    requestList.addFilter(filter);
    PagedMetadata<WidgetDto> result = widgetService.getWidgets(requestList);
    assertThat(result.getBody()).hasSize(1);
    assertThat(result.getBody().get(0).getCode()).isEqualTo(WIDGET_2_CODE);
}
Also used : Filter(org.entando.entando.web.common.model.Filter) RestListRequest(org.entando.entando.web.common.model.RestListRequest) WidgetDto(org.entando.entando.aps.system.services.widgettype.model.WidgetDto) Test(org.junit.Test)

Example 24 with Filter

use of org.entando.entando.web.common.model.Filter in project entando-core by entando.

the class WidgetServiceTest method shouldFilterByCode.

@Test
public void shouldFilterByCode() {
    RestListRequest requestList = new RestListRequest();
    Filter filter = new Filter();
    filter.setAttribute("code");
    filter.setValue(WIDGET_1_CODE);
    requestList.addFilter(filter);
    PagedMetadata<WidgetDto> result = widgetService.getWidgets(requestList);
    assertThat(result.getBody()).hasSize(1);
    assertThat(result.getBody().get(0).getCode()).isEqualTo(WIDGET_1_CODE);
}
Also used : Filter(org.entando.entando.web.common.model.Filter) RestListRequest(org.entando.entando.web.common.model.RestListRequest) WidgetDto(org.entando.entando.aps.system.services.widgettype.model.WidgetDto) Test(org.junit.Test)

Example 25 with Filter

use of org.entando.entando.web.common.model.Filter in project entando-core by entando.

the class GroupServiceIntegrationTest method testGetGroups_filter_and_pagination.

@Test
public void testGetGroups_filter_and_pagination() throws JsonProcessingException {
    RestListRequest restListRequest = new RestListRequest();
    restListRequest.setPageSize(2);
    restListRequest.addFilter(new Filter("groupname", "s"));
    PagedMetadata<GroupDto> res = this.groupService.getGroups(restListRequest);
    assertThat(res.getPage(), is(1));
    assertThat(res.getPageSize(), is(2));
    assertThat(res.getLastPage(), is(2));
    assertThat(res.getTotalItems(), is(3));
    restListRequest.setPage(1);
    res = this.groupService.getGroups(restListRequest);
    assertThat(res.getPage(), is(1));
    assertThat(res.getPageSize(), is(2));
    assertThat(res.getLastPage(), is(2));
    assertThat(res.getTotalItems(), is(3));
    restListRequest.setPage(2);
    res = this.groupService.getGroups(restListRequest);
    assertThat(res.getPage(), is(2));
    assertThat(res.getPageSize(), is(2));
    assertThat(res.getLastPage(), is(2));
    assertThat(res.getTotalItems(), is(3));
}
Also used : Filter(org.entando.entando.web.common.model.Filter) RestListRequest(org.entando.entando.web.common.model.RestListRequest) GroupDto(org.entando.entando.aps.system.services.group.model.GroupDto) Test(org.junit.Test)

Aggregations

Filter (org.entando.entando.web.common.model.Filter)38 RestListRequest (org.entando.entando.web.common.model.RestListRequest)30 Test (org.junit.Test)26 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)16 PagedMetadata (org.entando.entando.web.common.model.PagedMetadata)9 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)8 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)5 UserDetails (com.agiletec.aps.system.services.user.UserDetails)4 ResultActions (org.springframework.test.web.servlet.ResultActions)4 Permission (com.agiletec.aps.system.services.role.Permission)3 Role (com.agiletec.aps.system.services.role.Role)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)3 RestServerError (org.entando.entando.aps.system.exception.RestServerError)3 GroupDto (org.entando.entando.aps.system.services.group.model.GroupDto)3 LabelDto (org.entando.entando.aps.system.services.label.model.LabelDto)3 RoleDto (org.entando.entando.aps.system.services.role.model.RoleDto)3 WidgetDto (org.entando.entando.aps.system.services.widgettype.model.WidgetDto)3 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)3