Search in sources :

Example 11 with SearcherDaoPaginatedResult

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;
}
Also used : FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) Filter(org.entando.entando.web.common.model.Filter) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) LabelDto(org.entando.entando.aps.system.services.label.model.LabelDto) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 12 with SearcherDaoPaginatedResult

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);
    }
}
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 13 with SearcherDaoPaginatedResult

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;
}
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 14 with SearcherDaoPaginatedResult

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;
}
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 15 with SearcherDaoPaginatedResult

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

Aggregations

SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)16 PagedMetadata (org.entando.entando.web.common.model.PagedMetadata)15 ArrayList (java.util.ArrayList)9 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)8 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)8 RestServerError (org.entando.entando.aps.system.exception.RestServerError)7 RestListRequest (org.entando.entando.web.common.model.RestListRequest)7 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 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)4 UserDetails (com.agiletec.aps.system.services.user.UserDetails)3 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