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