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;
}
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;
}
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");
}
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);
}
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;
}
Aggregations