Search in sources :

Example 1 with Filter

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

the class RoleService method createRole.

protected Role createRole(RoleRequest roleRequest) {
    Role role = new Role();
    role.setName(roleRequest.getCode());
    role.setDescription(roleRequest.getName());
    if (null != roleRequest.getPermissions()) {
        roleRequest.getPermissions().entrySet().stream().filter(entry -> null != entry.getValue() && entry.getValue().booleanValue()).forEach(i -> role.addPermission(i.getKey()));
    }
    return role;
}
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)

Example 2 with Filter

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

the class RoleService method getRoles.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public PagedMetadata<RoleDto> getRoles(RestListRequest restRequest) {
    List<Role> roles = this.getRoleManager().getRoles();
    roles = sortRoleList(restRequest, roles);
    if (null != restRequest.getFilters()) {
        for (Filter f : restRequest.getFilters()) {
            if (f.getAttributeName().equals(KEY_FILTER_ROLE_CODE)) {
                roles = roles.stream().filter(i -> i.getName().toLowerCase().contains(f.getValue().toLowerCase())).collect(Collectors.toList());
            }
            if (f.getAttributeName().equals(KEY_FILTER_ROLE_DESCR)) {
                roles = roles.stream().filter(i -> i.getDescription().toLowerCase().contains(f.getValue().toLowerCase())).collect(Collectors.toList());
            }
        }
    }
    List<Role> subList = restRequest.getSublist(roles);
    List<RoleDto> dtoSlice = this.getDtoBuilder().convert(subList);
    SearcherDaoPaginatedResult<RoleDto> paginatedResult = new SearcherDaoPaginatedResult(roles.size(), dtoSlice);
    PagedMetadata<RoleDto> pagedMetadata = new PagedMetadata<>(restRequest, paginatedResult);
    pagedMetadata.setBody(dtoSlice);
    return pagedMetadata;
}
Also used : Role(com.agiletec.aps.system.services.role.Role) RoleDto(org.entando.entando.aps.system.services.role.model.RoleDto) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) Filter(org.entando.entando.web.common.model.Filter) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)

Example 3 with Filter

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

the class LanguageServiceTest method shouldFilterByIsDefault.

@Test
public void shouldFilterByIsDefault() {
    RestListRequest requestList = new RestListRequest();
    Filter filter = new Filter();
    filter.setAttribute("isDefault");
    filter.setOperator(FilterOperator.EQUAL.getValue());
    filter.setValue("true");
    requestList.addFilter(filter);
    PagedMetadata<LanguageDto> result = languageService.getLanguages(requestList);
    assertThat(result.getBody()).hasSize(1);
    assertThat(result.getBody().get(0).getCode()).isEqualTo("en");
}
Also used : Filter(org.entando.entando.web.common.model.Filter) RestListRequest(org.entando.entando.web.common.model.RestListRequest) Test(org.junit.Test)

Example 4 with Filter

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

the class WidgetServiceTest method shouldFilterByUsed.

@Test
public void shouldFilterByUsed() {
    RestListRequest requestList = new RestListRequest();
    Filter filter = new Filter();
    filter.setAttribute("used");
    filter.setValue("2");
    filter.setOperator(FilterOperator.EQUAL.getValue());
    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 5 with Filter

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

the class FilterUtilsTest method getFilter.

private Filter getFilter(FilterOperator operator, String[] allowedValues) {
    Filter filter = new Filter();
    filter.setOperator(operator.getValue());
    filter.setAllowedValues(allowedValues);
    return filter;
}
Also used : Filter(org.entando.entando.web.common.model.Filter)

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