use of com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult in project entando-core by entando.
the class LabelService method getLabelGroups.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public PagedMetadata<LabelDto> getLabelGroups(RestListRequest restRequest) {
Map<String, ApsProperties> result = this.i18nManager.getLabelGroups();
List<LabelDto> dtoList = this.getDtoBuilder().convert(result);
if (restRequest.getDirection().equals(FieldSearchFilter.DESC_ORDER)) {
dtoList = dtoList.stream().sorted(Comparator.comparing(LabelDto::getKey).reversed()).collect(Collectors.toList());
} else {
dtoList = dtoList.stream().sorted(Comparator.comparing(LabelDto::getKey)).collect(Collectors.toList());
}
if (null != restRequest.getFilters()) {
for (Filter f : restRequest.getFilters()) {
if (f.getAttributeName().equals(LABEL_KEY_FILTER_KEY)) {
dtoList = dtoList.stream().filter(i -> i.getKey().toLowerCase().contains(f.getValue().toLowerCase())).collect(Collectors.toList());
}
if (f.getAttributeName().equals(LABEL_KEY_FILTER_VALUE)) {
dtoList = dtoList.stream().filter(i -> i.getTitles().values().stream().filter(k -> k.contains(f.getValue())).collect(Collectors.toList()).size() > 0).collect(Collectors.toList());
}
}
}
List<?> subList = restRequest.getSublist(dtoList);
SearcherDaoPaginatedResult<LabelDto> resultx = new SearcherDaoPaginatedResult(dtoList.size(), subList);
PagedMetadata<LabelDto> pagedMetadata = new PagedMetadata<>(restRequest, resultx);
pagedMetadata.setBody((List<LabelDto>) subList);
return pagedMetadata;
}
use of com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult in project entando-core by entando.
the class LanguageService method getLanguages.
@Override
public PagedMetadata<LanguageDto> getLanguages(RestListRequest requestList) {
try {
List<Lang> langs = this.getLangManager().getAssignableLangs();
Collections.sort(langs, (o1, o2) -> o1.getCode().compareTo(o2.getCode()));
SearcherDaoPaginatedResult<Lang> langsResult = new SearcherDaoPaginatedResult<>(langs.size(), langs);
List<LanguageDto> dtoList = this.getLanguageDtoBuilder().convert(langsResult.getList());
langsResult.setCount(langs.size());
requestList.setPageSize(langs.size());
PagedMetadata<LanguageDto> pagedMetadata = new PagedMetadata<>(requestList, langsResult);
pagedMetadata.setBody(dtoList);
return pagedMetadata;
} catch (Throwable t) {
logger.error("error in search langs", t);
throw new RestServerError("error in search langs", t);
}
}
use of com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult in project entando-core by entando.
the class RoleService method getRoleReferences.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public PagedMetadata<UserDto> getRoleReferences(String roleCode, RestListRequest restRequest) {
Role role = this.getRoleManager().getRole(roleCode);
if (null == role) {
logger.warn("no role found with code {}", roleCode);
throw new RestRourceNotFoundException(RoleValidator.ERRCODE_ROLE_NOT_FOUND, "role", roleCode);
}
List<UserDto> dtoList = this.getAuthorizationService().getRoleUtilizer(roleCode);
List<UserDto> subList = restRequest.getSublist(dtoList);
SearcherDaoPaginatedResult<UserDto> pagedResult = new SearcherDaoPaginatedResult(dtoList.size(), subList);
PagedMetadata<UserDto> pagedMetadata = new PagedMetadata<>(restRequest, pagedResult);
pagedMetadata.setBody(subList);
return pagedMetadata;
}
use of com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult 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.getFilter()) {
for (Filter f : requestList.getFilter()) {
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 com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult in project entando-core by entando.
the class PageModelControllerTest method should_load_the_list_of_pageModels_1.
@Test
public void should_load_the_list_of_pageModels_1() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
PageModelDto singleDto = new PageModelDto();
List<PageModelDto> dtos = new ArrayList<>();
dtos.add(singleDto);
PageModel model = new PageModel();
List<PageModel> models = new ArrayList<>();
models.add(model);
SearcherDaoPaginatedResult<PageModel> sdpr = new SearcherDaoPaginatedResult<>(1, models);
PagedMetadata<PageModelDto> meta = new PagedMetadata<>(new RestListRequest(), sdpr);
meta.setBody(dtos);
when(pageModelService.getPageModels(any(RestListRequest.class))).thenReturn(meta);
ResultActions result = mockMvc.perform(get("/pagemodels").header("Authorization", "Bearer " + accessToken));
System.out.println(result.andReturn().getResponse().getContentAsString());
result.andExpect(status().isOk());
RestListRequest restListReq = new RestListRequest();
Mockito.verify(pageModelService, Mockito.times(1)).getPageModels(restListReq);
}
Aggregations