use of org.entando.entando.web.common.model.PagedMetadata 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 org.entando.entando.web.common.model.PagedMetadata 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 org.entando.entando.web.common.model.PagedMetadata 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 org.entando.entando.web.common.model.PagedMetadata 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);
}
use of org.entando.entando.web.common.model.PagedMetadata in project entando-core by entando.
the class UserControllerUnitTest method mockUsers.
private PagedMetadata<UserDto> mockUsers() {
List<UserDetails> users = new ArrayList<>();
User user1 = new User();
user1.setUsername("admin");
user1.setDisabled(false);
user1.setLastAccess(new Date());
user1.setLastPasswordChange(new Date());
user1.setMaxMonthsSinceLastAccess(2);
user1.setMaxMonthsSinceLastPasswordChange(1);
User user2 = new User();
user2.setUsername("user2");
user2.setDisabled(false);
user2.setLastAccess(new Date());
user1.setLastPasswordChange(new Date());
user2.setMaxMonthsSinceLastAccess(2);
user2.setMaxMonthsSinceLastPasswordChange(1);
User user3 = new User();
user3.setUsername("user3");
user3.setDisabled(false);
user3.setLastAccess(new Date());
user3.setLastPasswordChange(new Date());
user3.setMaxMonthsSinceLastAccess(2);
user3.setMaxMonthsSinceLastPasswordChange(1);
users.add(user1);
users.add(user2);
users.add(user3);
List<UserDto> dtoList = new UserDtoBuilder().convert(users);
SearcherDaoPaginatedResult<UserDetails> result = new SearcherDaoPaginatedResult<>(users.size(), users);
PagedMetadata<UserDto> pagedMetadata = new PagedMetadata<>(new RestListRequest(), result);
pagedMetadata.setBody(dtoList);
return pagedMetadata;
}
Aggregations