Search in sources :

Example 1 with SearcherDaoPaginatedResult

use of com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult in project entando-core by entando.

the class PageModelService method getPageModels.

@Override
public PagedMetadata<PageModelDto> getPageModels(RestListRequest restListReq) {
    try {
        // transforms the filters by overriding the key specified in the request with the correct one known by the dto
        List<FieldSearchFilter> filters = new ArrayList<FieldSearchFilter>(restListReq.buildFieldSearchFilters());
        filters.stream().filter(i -> i.getKey() != null).forEach(i -> i.setKey(PageModelDto.getEntityFieldName(i.getKey())));
        SearcherDaoPaginatedResult<PageModel> pageModels = this.getPageModelManager().searchPageModels(filters);
        List<PageModelDto> dtoList = null;
        if (null != pageModels) {
            dtoList = this.getDtoBuilder().convert(pageModels.getList());
        }
        PagedMetadata<PageModelDto> pagedMetadata = new PagedMetadata<>(restListReq, pageModels);
        pagedMetadata.setBody(dtoList);
        return pagedMetadata;
    } catch (Throwable t) {
        logger.error("error in search pageModels", t);
        throw new RestServerError("error in search pageModels", t);
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) ArrayList(java.util.ArrayList) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) PageModelValidator(org.entando.entando.web.pagemodel.validator.PageModelValidator) RestServerError(org.entando.entando.aps.system.exception.RestServerError) Frame(com.agiletec.aps.system.services.pagemodel.Frame) Service(org.springframework.stereotype.Service) Map(java.util.Map) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) PageModelUtilizer(com.agiletec.aps.system.services.pagemodel.PageModelUtilizer) Logger(org.slf4j.Logger) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) BeansException(org.springframework.beans.BeansException) Collectors(java.util.stream.Collectors) PageModelFrameReq(org.entando.entando.web.pagemodel.model.PageModelFrameReq) PageModelRequest(org.entando.entando.web.pagemodel.model.PageModelRequest) ApplicationContext(org.springframework.context.ApplicationContext) List(java.util.List) RestListRequest(org.entando.entando.web.common.model.RestListRequest) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) IPageModelManager(com.agiletec.aps.system.services.pagemodel.IPageModelManager) PageModelDto(org.entando.entando.aps.system.services.pagemodel.model.PageModelDto) ApplicationContextAware(org.springframework.context.ApplicationContextAware) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ArrayList(java.util.ArrayList) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) PageModelDto(org.entando.entando.aps.system.services.pagemodel.model.PageModelDto)

Example 2 with SearcherDaoPaginatedResult

use of com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult in project entando-core by entando.

the class UserService method getUsers.

@Override
public PagedMetadata<UserDto> getUsers(RestListRequest requestList) {
    try {
        // transforms the filters by overriding the key specified in the request with the correct one known by the dto
        List<FieldSearchFilter> filters = new ArrayList<FieldSearchFilter>(requestList.buildFieldSearchFilters());
        filters.stream().filter(i -> ((i.getKey() != null) && (UserDto.getEntityFieldName(i.getKey()) != null))).forEach(i -> i.setKey(UserDto.getEntityFieldName(i.getKey())));
        List<UserDetails> users = null;
        if (filters.size() > 0) {
            String text = (String) filters.get(0).getValue();
            users = this.getUserManager().searchUsers(text);
        } else {
            users = this.getUserManager().getUsers();
        }
        List<UserDto> dtoList = dtoBuilder.convert(users);
        SearcherDaoPaginatedResult<UserDetails> result = new SearcherDaoPaginatedResult<>(users.size(), users);
        PagedMetadata<UserDto> pagedMetadata = new PagedMetadata<>(requestList, result);
        pagedMetadata.setBody(dtoList);
        return pagedMetadata;
    } catch (Throwable t) {
        logger.error("error in search groups", t);
        throw new RestServerError("error in search groups", t);
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) IAuthenticationProviderManager(com.agiletec.aps.system.services.user.IAuthenticationProviderManager) UserAuthoritiesRequest(org.entando.entando.web.user.model.UserAuthoritiesRequest) Logger(org.slf4j.Logger) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) UserDto(org.entando.entando.aps.system.services.user.model.UserDto) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) UserAuthorityDto(org.entando.entando.aps.system.services.user.model.UserAuthorityDto) UserRequest(org.entando.entando.web.user.model.UserRequest) UserPasswordRequest(org.entando.entando.web.user.model.UserPasswordRequest) ArrayList(java.util.ArrayList) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) List(java.util.List) User(com.agiletec.aps.system.services.user.User) RestListRequest(org.entando.entando.web.common.model.RestListRequest) RestServerError(org.entando.entando.aps.system.exception.RestServerError) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) IUserManager(com.agiletec.aps.system.services.user.IUserManager) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) IAuthorizationManager(com.agiletec.aps.system.services.authorization.IAuthorizationManager) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) UserDto(org.entando.entando.aps.system.services.user.model.UserDto) ArrayList(java.util.ArrayList) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) UserDetails(com.agiletec.aps.system.services.user.UserDetails) RestServerError(org.entando.entando.aps.system.exception.RestServerError) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter)

Example 3 with SearcherDaoPaginatedResult

use of com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult in project entando-core by entando.

the class PageService method getPageReferences.

@Override
public PagedMetadata<?> getPageReferences(String pageCode, String managerName, RestListRequest requestList) {
    IPage page = this.getPageManager().getDraftPage(pageCode);
    if (null == page) {
        logger.warn("no page found with code {}", pageCode);
        throw new ResourceNotFoundException(ERRCODE_PAGE_NOT_FOUND, "page", pageCode);
    }
    PageServiceUtilizer<?> utilizer = this.getPageServiceUtilizer(managerName);
    if (null == utilizer) {
        logger.warn("no references found for {}", managerName);
        throw new ResourceNotFoundException(ERRCODE_PAGE_REFERENCES, "reference", managerName);
    }
    List<?> dtoList = utilizer.getPageUtilizer(pageCode);
    List<?> subList = requestList.getSublist(dtoList);
    SearcherDaoPaginatedResult<?> pagedResult = new SearcherDaoPaginatedResult<>(dtoList.size(), subList);
    PagedMetadata<Object> pagedMetadata = new PagedMetadata<>(requestList, pagedResult);
    pagedMetadata.setBody((List<Object>) subList);
    return pagedMetadata;
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException)

Example 4 with SearcherDaoPaginatedResult

use of com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult in project entando-core by entando.

the class RoleService method getRoles.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public PagedMetadata<RoleDto> getRoles(RestListRequest restRequest) {
    List<Role> roles = this.getRoleManager().getRoles();
    roles = sortRoleList(restRequest, roles);
    if (null != restRequest.getFilters()) {
        for (Filter f : restRequest.getFilters()) {
            if (f.getAttributeName().equals(KEY_FILTER_ROLE_CODE)) {
                roles = roles.stream().filter(i -> i.getName().toLowerCase().contains(f.getValue().toLowerCase())).collect(Collectors.toList());
            }
            if (f.getAttributeName().equals(KEY_FILTER_ROLE_DESCR)) {
                roles = roles.stream().filter(i -> i.getDescription().toLowerCase().contains(f.getValue().toLowerCase())).collect(Collectors.toList());
            }
        }
    }
    List<Role> subList = restRequest.getSublist(roles);
    List<RoleDto> dtoSlice = this.getDtoBuilder().convert(subList);
    SearcherDaoPaginatedResult<RoleDto> paginatedResult = new SearcherDaoPaginatedResult(roles.size(), dtoSlice);
    PagedMetadata<RoleDto> pagedMetadata = new PagedMetadata<>(restRequest, paginatedResult);
    pagedMetadata.setBody(dtoSlice);
    return pagedMetadata;
}
Also used : Role(com.agiletec.aps.system.services.role.Role) RoleDto(org.entando.entando.aps.system.services.role.model.RoleDto) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) Filter(org.entando.entando.web.common.model.Filter) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)

Example 5 with SearcherDaoPaginatedResult

use of com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult in project entando-core by entando.

the class UserService method getUsers.

@Override
public PagedMetadata<UserDto> getUsers(RestListRequest requestList, String withProfile) {
    try {
        // transforms the filters by overriding the key specified in the request with the correct one known by the dto
        List<FieldSearchFilter> filters = new ArrayList<>(requestList.buildFieldSearchFilters());
        List<EntitySearchFilter> entityFilters = new ArrayList<>(requestList.buildEntitySearchFilters());
        filters.stream().filter(i -> ((i.getKey() != null) && (UserDto.getEntityFieldName(i.getKey()) != null))).forEach(i -> i.setKey(UserDto.getEntityFieldName(i.getKey())));
        List<String> userNames = null;
        List<UserDetails> users = new ArrayList<>(), allUsers = new ArrayList<>();
        // username filter
        List<FieldSearchFilter> usernameFilter = filters.stream().filter(filter -> filter.getValue() != null && filter.getKey().equals("username")).collect(Collectors.toList());
        if (usernameFilter.size() > 0) {
            String text = (String) filters.get(0).getValue();
            userNames = this.getUserManager().searchUsernames(text);
        } else {
            userNames = this.getUserManager().getUsernames();
        }
        userNames.forEach(username -> allUsers.add(this.loadUser(username)));
        // Profile and attributes filters
        users.addAll(allUsers.stream().filter(user -> (withProfile == null || withProfile.equals("1")) && checkAttributesFilter(filters, entityFilters, user)).collect(Collectors.toList()));
        List<UserDto> dtoList = dtoBuilder.convert(users);
        SearcherDaoPaginatedResult<UserDetails> result = new SearcherDaoPaginatedResult<>(users.size(), users);
        PagedMetadata<UserDto> pagedMetadata = new PagedMetadata<>(requestList, result);
        pagedMetadata.setBody(dtoList);
        pagedMetadata.imposeLimits();
        return pagedMetadata;
    } catch (Throwable t) {
        logger.error("error in search users", t);
        throw new RestServerError("error in search users", t);
    }
}
Also used : ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) java.util(java.util) UserDto(org.entando.entando.aps.system.services.user.model.UserDto) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) UserAuthorityDto(org.entando.entando.aps.system.services.user.model.UserAuthorityDto) BindingResult(org.springframework.validation.BindingResult) IUserProfileManager(org.entando.entando.aps.system.services.userprofile.IUserProfileManager) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) Authorization(com.agiletec.aps.system.services.authorization.Authorization) IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) RestServerError(org.entando.entando.aps.system.exception.RestServerError) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter) IAuthorizationManager(com.agiletec.aps.system.services.authorization.IAuthorizationManager) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) UserAuthoritiesRequest(org.entando.entando.web.user.model.UserAuthoritiesRequest) Logger(org.slf4j.Logger) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) UserRequest(org.entando.entando.web.user.model.UserRequest) UserPasswordRequest(org.entando.entando.web.user.model.UserPasswordRequest) Collectors(java.util.stream.Collectors) com.agiletec.aps.system.services.user(com.agiletec.aps.system.services.user) RestListRequest(org.entando.entando.web.common.model.RestListRequest) UserValidator(org.entando.entando.web.user.validator.UserValidator) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) IRoleService(org.entando.entando.aps.system.services.role.IRoleService) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) 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) RestServerError(org.entando.entando.aps.system.exception.RestServerError) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter)

Aggregations

SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)19 PagedMetadata (org.entando.entando.web.common.model.PagedMetadata)18 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)8 ArrayList (java.util.ArrayList)8 RestServerError (org.entando.entando.aps.system.exception.RestServerError)8 RestListRequest (org.entando.entando.web.common.model.RestListRequest)8 ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)7 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)5 IDtoBuilder (org.entando.entando.aps.system.services.IDtoBuilder)5 UserDto (org.entando.entando.aps.system.services.user.model.UserDto)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)4 UserDetails (com.agiletec.aps.system.services.user.UserDetails)3 List (java.util.List)3 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)2 IAuthorizationManager (com.agiletec.aps.system.services.authorization.IAuthorizationManager)2 Group (com.agiletec.aps.system.services.group.Group)2