Search in sources :

Example 1 with MapBasedQueryWalker

use of org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker in project records-management by Alfresco.

the class FilePlanComponentsApiUtils method getListChildrenFilterProps.

/**
 * Returns a List of filter properties specified by request parameters.
 * @param parameters The {@link Parameters} object to get the parameters passed into the request
 *        including:
 *        - filter, sort & paging params (where, orderBy, skipCount, maxItems)
 * @return The list of {@link FilterProp}. Can be null.
 */
public List<FilterProp> getListChildrenFilterProps(Parameters parameters, Set<String> listFolderChildrenEqualsQueryProperties) {
    List<FilterProp> filterProps = null;
    Query q = parameters.getQuery();
    if (q != null) {
        MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(listFolderChildrenEqualsQueryProperties, null);
        QueryHelper.walk(q, propertyWalker);
        Boolean isPrimary = propertyWalker.getProperty(RMNode.PARAM_ISPRIMARY, WhereClauseParser.EQUALS, Boolean.class);
        if (isPrimary != null) {
            filterProps = new ArrayList<>(1);
            filterProps.add(new FilterPropBoolean(GetChildrenCannedQuery.FILTER_QNAME_NODE_IS_PRIMARY, isPrimary));
        }
        Boolean isClosed = propertyWalker.getProperty(RMNode.PARAM_IS_CLOSED, WhereClauseParser.EQUALS, Boolean.class);
        if (isClosed != null) {
            filterProps = new ArrayList<>(1);
            filterProps.add(new FilterPropBoolean(RecordsManagementModel.PROP_IS_CLOSED, isClosed));
        }
    // TODO see how we can filter for categories that have retention schedule
    // Boolean hasRetentionSchedule = propertyWalker.getProperty(RMNode.PARAM_HAS_RETENTION_SCHEDULE, WhereClauseParser.EQUALS, Boolean.class);
    // if (hasRetentionSchedule != null)
    // {
    // filterProps = new ArrayList<>(1);
    // }
    }
    return filterProps;
}
Also used : Query(org.alfresco.rest.framework.resource.parameters.where.Query) GetChildrenCannedQuery(org.alfresco.repo.node.getchildren.GetChildrenCannedQuery) FilterProp(org.alfresco.repo.node.getchildren.FilterProp) MapBasedQueryWalker(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker) FilterPropBoolean(org.alfresco.repo.node.getchildren.FilterPropBoolean) FilterPropBoolean(org.alfresco.repo.node.getchildren.FilterPropBoolean)

Example 2 with MapBasedQueryWalker

use of org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker in project alfresco-remote-api by Alfresco.

the class SitesImpl method getSiteMembers.

public CollectionWithPagingInfo<SiteMember> getSiteMembers(String siteId, Parameters parameters) {
    SiteInfo siteInfo = validateSite(siteId);
    if (siteInfo == null) {
        // site does not exist
        throw new EntityNotFoundException(siteId);
    }
    // set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
    siteId = siteInfo.getShortName();
    Paging paging = parameters.getPaging();
    PagingRequest pagingRequest = Util.getPagingRequest(paging);
    pagingRequest.setRequestTotalCountMax(100);
    MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(new HashSet<>(Collections.singletonList(PARAM_IS_MEMBER_OF_GROUP)), null);
    ;
    QueryHelper.walk(parameters.getQuery(), propertyWalker);
    Boolean expandGroups = propertyWalker.getProperty(PARAM_IS_MEMBER_OF_GROUP, WhereClauseParser.EQUALS, Boolean.class);
    if (expandGroups == null) {
        expandGroups = true;
    }
    final List<Pair<SiteService.SortFields, Boolean>> sort = new ArrayList<Pair<SiteService.SortFields, Boolean>>();
    sort.add(new Pair<SiteService.SortFields, Boolean>(SiteService.SortFields.LastName, Boolean.TRUE));
    sort.add(new Pair<SiteService.SortFields, Boolean>(SiteService.SortFields.FirstName, Boolean.TRUE));
    sort.add(new Pair<SiteService.SortFields, Boolean>(SiteService.SortFields.Role, Boolean.TRUE));
    sort.add(new Pair<SiteService.SortFields, Boolean>(SiteService.SortFields.Username, Boolean.TRUE));
    PagingResults<SiteMembership> pagedResults = siteService.listMembersPaged(siteId, expandGroups, sort, pagingRequest);
    List<SiteMember> ret = pagedResults.getPage().stream().map((siteMembership) -> new SiteMember(siteMembership.getPersonId(), siteMembership.getRole(), siteMembership.isMemberOfGroup())).collect(Collectors.toList());
    return CollectionWithPagingInfo.asPaged(paging, ret, pagedResults.hasMoreItems(), pagedResults.getTotalResultCount().getFirst());
}
Also used : Arrays(java.util.Arrays) Sites(org.alfresco.rest.api.Sites) MapBasedQueryWalkerOrSupported(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalkerOrSupported) Query(org.alfresco.rest.framework.resource.parameters.where.Query) org.alfresco.repo.site(org.alfresco.repo.site) AuthorityService(org.alfresco.service.cmr.security.AuthorityService) Paging(org.alfresco.rest.framework.resource.parameters.Paging) AbstractList(java.util.AbstractList) FileInfo(org.alfresco.service.cmr.model.FileInfo) ImporterContentCache(org.alfresco.service.cmr.view.ImporterContentCache) SiteVisibility(org.alfresco.service.cmr.site.SiteVisibility) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) PagingRequest(org.alfresco.query.PagingRequest) WhereClauseParser(org.alfresco.rest.antlr.WhereClauseParser) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) PermissionService(org.alfresco.service.cmr.security.PermissionService) Map(java.util.Map) ContentModel(org.alfresco.model.ContentModel) PageDetails(org.alfresco.query.PageDetails) FilterProp(org.alfresco.repo.node.getchildren.FilterProp) NodeService(org.alfresco.service.cmr.repository.NodeService) Set(java.util.Set) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) ImporterService(org.alfresco.service.cmr.view.ImporterService) ImporterBinding(org.alfresco.service.cmr.view.ImporterBinding) SiteService(org.alfresco.service.cmr.site.SiteService) List(java.util.List) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) CollectionWithPagingInfo(org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo) AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) Entry(java.util.Map.Entry) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) Nodes(org.alfresco.rest.api.Nodes) LogFactory(org.apache.commons.logging.LogFactory) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString) Parameters(org.alfresco.rest.framework.resource.parameters.Parameters) PreferenceService(org.alfresco.service.cmr.preference.PreferenceService) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FavouritesService(org.alfresco.service.cmr.favourites.FavouritesService) HashMap(java.util.HashMap) org.alfresco.rest.api.model(org.alfresco.rest.api.model) TreeSet(java.util.TreeSet) AccessStatus(org.alfresco.service.cmr.security.AccessStatus) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) PagingResults(org.alfresco.query.PagingResults) People(org.alfresco.rest.api.People) QueryHelper(org.alfresco.rest.framework.resource.parameters.where.QueryHelper) QName(org.alfresco.service.namespace.QName) BeanPropertiesFilter(org.alfresco.rest.framework.jacksonextensions.BeanPropertiesFilter) Collator(java.text.Collator) UnknownAuthorityException(org.alfresco.repo.security.authority.UnknownAuthorityException) AuthorityType(org.alfresco.service.cmr.security.AuthorityType) Iterator(java.util.Iterator) Location(org.alfresco.service.cmr.view.Location) SortColumn(org.alfresco.rest.framework.resource.parameters.SortColumn) Pair(org.alfresco.util.Pair) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ImportPackageHandler(org.alfresco.service.cmr.view.ImportPackageHandler) FilterPropBoolean(org.alfresco.repo.node.getchildren.FilterPropBoolean) RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) MapBasedQueryWalker(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) SortOrder(org.alfresco.query.CannedQuerySortDetails.SortOrder) Log(org.apache.commons.logging.Log) Comparator(java.util.Comparator) SiteMemberInfo(org.alfresco.service.cmr.site.SiteMemberInfo) Collections(java.util.Collections) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) Paging(org.alfresco.rest.framework.resource.parameters.Paging) ArrayList(java.util.ArrayList) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) PagingRequest(org.alfresco.query.PagingRequest) SiteService(org.alfresco.service.cmr.site.SiteService) MapBasedQueryWalker(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker) FilterPropBoolean(org.alfresco.repo.node.getchildren.FilterPropBoolean) Pair(org.alfresco.util.Pair)

Example 3 with MapBasedQueryWalker

use of org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker in project alfresco-remote-api by Alfresco.

the class NodesImpl method listChildren.

@Override
public CollectionWithPagingInfo<Node> listChildren(String parentFolderNodeId, Parameters parameters) {
    String path = parameters.getParameter(PARAM_RELATIVE_PATH);
    final NodeRef parentNodeRef = validateOrLookupNode(parentFolderNodeId, path);
    final List<String> includeParam = parameters.getInclude();
    QName assocTypeQNameParam = null;
    Query q = parameters.getQuery();
    if (q != null) {
        // filtering via "where" clause
        MapBasedQueryWalker propertyWalker = createListChildrenQueryWalker();
        QueryHelper.walk(q, propertyWalker);
        String assocTypeQNameStr = propertyWalker.getProperty(PARAM_ASSOC_TYPE, WhereClauseParser.EQUALS, String.class);
        if (assocTypeQNameStr != null) {
            assocTypeQNameParam = getAssocType(assocTypeQNameStr);
        }
    }
    List<Pair<QName, Boolean>> sortProps = getListChildrenSortProps(parameters);
    List<FilterProp> filterProps = getListChildrenFilterProps(parameters);
    Paging paging = parameters.getPaging();
    PagingRequest pagingRequest = Util.getPagingRequest(paging);
    final PagingResults<FileInfo> pagingResults;
    Pair<Set<QName>, Set<QName>> pair = buildSearchTypesAndIgnoreAspects(parameters);
    Set<QName> searchTypeQNames = pair.getFirst();
    Set<QName> ignoreAspectQNames = pair.getSecond();
    Set<QName> assocTypeQNames = buildAssocTypes(assocTypeQNameParam);
    // call GetChildrenCannedQuery (via FileFolderService)
    if (((filterProps == null) || (filterProps.size() == 0)) && ((assocTypeQNames == null) || (assocTypeQNames.size() == 0)) && (smartStore.isVirtual(parentNodeRef) || (smartStore.canVirtualize(parentNodeRef)))) {
        pagingResults = fileFolderService.list(parentNodeRef, searchTypeQNames, ignoreAspectQNames, sortProps, pagingRequest);
    } else {
        // TODO smart folders (see REPO-1173)
        pagingResults = fileFolderService.list(parentNodeRef, assocTypeQNames, searchTypeQNames, ignoreAspectQNames, sortProps, filterProps, pagingRequest);
    }
    final Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
    final List<FileInfo> page = pagingResults.getPage();
    List<Node> nodes = new AbstractList<Node>() {

        @Override
        public Node get(int index) {
            FileInfo fInfo = page.get(index);
            // minimal info by default (unless "include"d otherwise)
            // (pass in null as parentNodeRef to force loading of primary
            // parent node as parentId)
            Node node = getFolderOrDocument(fInfo.getNodeRef(), null, fInfo.getType(), includeParam, mapUserInfo);
            if (node.getPath() != null) {
                calculateRelativePath(parentFolderNodeId, node);
            }
            return node;
        }

        private void calculateRelativePath(String parentFolderNodeId, Node node) {
            NodeRef rootNodeRef = validateOrLookupNode(parentFolderNodeId, null);
            try {
                // get the path elements
                List<String> pathInfos = fileFolderService.getNameOnlyPath(rootNodeRef, node.getNodeRef());
                int sizePathInfos = pathInfos.size();
                if (sizePathInfos > 1) {
                    // remove the current child
                    pathInfos.remove(sizePathInfos - 1);
                    // build the path string
                    StringBuilder sb = new StringBuilder(pathInfos.size() * 20);
                    for (String fileInfo : pathInfos) {
                        sb.append("/");
                        sb.append(fileInfo);
                    }
                    node.getPath().setRelativePath(sb.toString());
                }
            } catch (FileNotFoundException e) {
            // NOTE: return null as relativePath
            }
        }

        @Override
        public int size() {
            return page.size();
        }
    };
    Node sourceEntity = null;
    if (parameters.includeSource()) {
        sourceEntity = getFolderOrDocumentFullInfo(parentNodeRef, null, null, null, mapUserInfo);
    }
    return CollectionWithPagingInfo.asPaged(paging, nodes, pagingResults.hasMoreItems(), pagingResults.getTotalResultCount().getFirst(), sourceEntity);
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) Query(org.alfresco.rest.framework.resource.parameters.where.Query) GetChildrenCannedQuery(org.alfresco.repo.node.getchildren.GetChildrenCannedQuery) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Node(org.alfresco.rest.api.model.Node) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) UserInfo(org.alfresco.rest.api.model.UserInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) MapBasedQueryWalker(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker) Pair(org.alfresco.util.Pair) AbstractList(java.util.AbstractList) FilterProp(org.alfresco.repo.node.getchildren.FilterProp) QName(org.alfresco.service.namespace.QName) Paging(org.alfresco.rest.framework.resource.parameters.Paging) PagingRequest(org.alfresco.query.PagingRequest)

Example 4 with MapBasedQueryWalker

use of org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker in project alfresco-remote-api by Alfresco.

the class RenditionsImpl method getStatus.

private String getStatus(Parameters parameters) {
    Query query = parameters.getQuery();
    String status = null;
    if (query != null) {
        // Filtering via "where" clause
        MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(RENDITION_STATUS_COLLECTION_EQUALS_QUERY_PROPERTIES, null);
        QueryHelper.walk(query, propertyWalker);
        status = propertyWalker.getProperty(PARAM_STATUS, WhereClauseParser.EQUALS);
    }
    return status;
}
Also used : Query(org.alfresco.rest.framework.resource.parameters.where.Query) MapBasedQueryWalker(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker)

Example 5 with MapBasedQueryWalker

use of org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker in project alfresco-remote-api by Alfresco.

the class NodesImpl method buildSearchTypesAndIgnoreAspects.

protected Pair<Set<QName>, Set<QName>> buildSearchTypesAndIgnoreAspects(final Parameters parameters) {
    // filters
    Boolean includeFolders = null;
    Boolean includeFiles = null;
    QName filterNodeTypeQName = null;
    // note: for files/folders, include subtypes by default (unless filtering by a specific nodeType - see below)
    boolean filterIncludeSubTypes = true;
    Query q = parameters.getQuery();
    if (q != null) {
        // filtering via "where" clause
        MapBasedQueryWalker propertyWalker = createListChildrenQueryWalker();
        QueryHelper.walk(q, propertyWalker);
        Boolean isFolder = propertyWalker.getProperty(PARAM_ISFOLDER, WhereClauseParser.EQUALS, Boolean.class);
        Boolean isFile = propertyWalker.getProperty(PARAM_ISFILE, WhereClauseParser.EQUALS, Boolean.class);
        if (isFolder != null) {
            includeFolders = isFolder;
        }
        if (isFile != null) {
            includeFiles = isFile;
        }
        if (Boolean.TRUE.equals(includeFiles) && Boolean.TRUE.equals(includeFolders)) {
            throw new InvalidArgumentException("Invalid filter (isFile=true and isFolder=true) - a node cannot be both a file and a folder");
        }
        String nodeTypeStr = propertyWalker.getProperty(PARAM_NODETYPE, WhereClauseParser.EQUALS, String.class);
        if ((nodeTypeStr != null) && (!nodeTypeStr.isEmpty())) {
            if ((isFile != null) || (isFolder != null)) {
                throw new InvalidArgumentException("Invalid filter - nodeType and isFile/isFolder are mutually exclusive");
            }
            Pair<QName, Boolean> pair = parseNodeTypeFilter(nodeTypeStr);
            filterNodeTypeQName = pair.getFirst();
            filterIncludeSubTypes = pair.getSecond();
        }
    }
    if (filterNodeTypeQName == null) {
        if ((includeFiles == null) && (includeFolders == null)) {
            // no additional filtering
            filterNodeTypeQName = ContentModel.TYPE_CMOBJECT;
        } else if ((includeFiles != null) && (includeFolders != null)) {
            if ((!includeFiles) && (!includeFolders)) {
                // no files or folders
                filterNodeTypeQName = ContentModel.TYPE_CMOBJECT;
            }
        } else if ((includeFiles != null) && (!includeFiles)) {
            // no files
            filterNodeTypeQName = ContentModel.TYPE_CMOBJECT;
        } else if ((includeFolders != null) && (!includeFolders)) {
            // no folders
            filterNodeTypeQName = ContentModel.TYPE_CMOBJECT;
        }
    }
    return buildSearchTypesAndIgnoreAspects(filterNodeTypeQName, filterIncludeSubTypes, ignoreQNames, includeFiles, includeFolders);
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) Query(org.alfresco.rest.framework.resource.parameters.where.Query) GetChildrenCannedQuery(org.alfresco.repo.node.getchildren.GetChildrenCannedQuery) QName(org.alfresco.service.namespace.QName) MapBasedQueryWalker(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker) FilterPropBoolean(org.alfresco.repo.node.getchildren.FilterPropBoolean)

Aggregations

Query (org.alfresco.rest.framework.resource.parameters.where.Query)12 MapBasedQueryWalker (org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker)12 QName (org.alfresco.service.namespace.QName)5 HashSet (java.util.HashSet)4 FilterProp (org.alfresco.repo.node.getchildren.FilterProp)4 FilterPropBoolean (org.alfresco.repo.node.getchildren.FilterPropBoolean)4 GetChildrenCannedQuery (org.alfresco.repo.node.getchildren.GetChildrenCannedQuery)4 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)4 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 PagingRequest (org.alfresco.query.PagingRequest)3 Paging (org.alfresco.rest.framework.resource.parameters.Paging)3 InvalidParameterException (java.security.InvalidParameterException)2 AbstractList (java.util.AbstractList)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2 FileInfo (org.alfresco.service.cmr.model.FileInfo)2 QNamePattern (org.alfresco.service.namespace.QNamePattern)2 RegexQNamePattern (org.alfresco.service.namespace.RegexQNamePattern)2 Pair (org.alfresco.util.Pair)2