Search in sources :

Example 11 with PagedMetadata

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);
    }
}
Also used : PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) RestServerError(org.entando.entando.aps.system.exception.RestServerError) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) Lang(com.agiletec.aps.system.services.lang.Lang)

Example 12 with PagedMetadata

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;
}
Also used : Role(com.agiletec.aps.system.services.role.Role) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) UserDto(org.entando.entando.aps.system.services.user.model.UserDto) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)

Example 13 with 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;
}
Also used : FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) Filter(org.entando.entando.web.common.model.Filter) PermissionDto(org.entando.entando.aps.system.services.role.model.PermissionDto) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) Permission(com.agiletec.aps.system.services.role.Permission) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)

Example 14 with 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);
}
Also used : PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) ArrayList(java.util.ArrayList) RestListRequest(org.entando.entando.web.common.model.RestListRequest) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) PageModelDto(org.entando.entando.aps.system.services.pagemodel.model.PageModelDto) UserDetails(com.agiletec.aps.system.services.user.UserDetails) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 15 with PagedMetadata

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;
}
Also used : User(com.agiletec.aps.system.services.user.User) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) UserDto(org.entando.entando.aps.system.services.user.model.UserDto) ArrayList(java.util.ArrayList) RestListRequest(org.entando.entando.web.common.model.RestListRequest) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) Date(java.util.Date) UserDetails(com.agiletec.aps.system.services.user.UserDetails) UserDtoBuilder(org.entando.entando.aps.system.services.user.model.UserDtoBuilder)

Aggregations

PagedMetadata (org.entando.entando.web.common.model.PagedMetadata)16 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)15 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)8 ArrayList (java.util.ArrayList)8 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)8 RestListRequest (org.entando.entando.web.common.model.RestListRequest)7 RestServerError (org.entando.entando.aps.system.exception.RestServerError)6 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)5 List (java.util.List)5 IDtoBuilder (org.entando.entando.aps.system.services.IDtoBuilder)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 UserDetails (com.agiletec.aps.system.services.user.UserDetails)4 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)4 Map (java.util.Map)3 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Group (com.agiletec.aps.system.services.group.Group)2 GroupUtilizer (com.agiletec.aps.system.services.group.GroupUtilizer)2 IGroupManager (com.agiletec.aps.system.services.group.IGroupManager)2