Search in sources :

Example 1 with FilterProp

use of org.alfresco.repo.node.getchildren.FilterProp in project records-management by Alfresco.

the class RecordCategoryChildrenRelation method readAll.

@Override
@WebApiDescription(title = "Return a paged list of record category children for the container identified by 'recordCategoryId'")
public CollectionWithPagingInfo<RecordCategoryChild> readAll(String recordCategoryId, Parameters parameters) {
    checkNotBlank("recordCategoryId", recordCategoryId);
    mandatory("parameters", parameters);
    String relativePath = parameters.getParameter(Nodes.PARAM_RELATIVE_PATH);
    NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(recordCategoryId, RecordsManagementModel.TYPE_RECORD_CATEGORY, relativePath, true);
    // list record categories and record folders
    Set<QName> searchTypeQNames = searchTypesFactory.buildSearchTypesCategoriesEndpoint(parameters, LIST_RECORD_CATEGORY_CHILDREN_EQUALS_QUERY_PROPERTIES);
    Set<QName> assocTypeQNames = Collections.singleton(ContentModel.ASSOC_CONTAINS);
    List<FilterProp> filterProps = apiUtils.getListChildrenFilterProps(parameters, LIST_RECORD_CATEGORY_CHILDREN_EQUALS_QUERY_PROPERTIES);
    final PagingResults<FileInfo> pagingResults = fileFolderService.list(parentNodeRef, assocTypeQNames, searchTypeQNames, null, apiUtils.getSortProperties(parameters), filterProps, Util.getPagingRequest(parameters.getPaging()));
    final List<FileInfo> page = pagingResults.getPage();
    Map<String, UserInfo> mapUserInfo = new HashMap<>();
    List<RecordCategoryChild> nodes = new AbstractList<RecordCategoryChild>() {

        @Override
        public RecordCategoryChild get(int index) {
            FileInfo info = page.get(index);
            return nodesModelFactory.createRecordCategoryChild(info, parameters, mapUserInfo, true);
        }

        @Override
        public int size() {
            return page.size();
        }
    };
    RecordCategory sourceEntity = null;
    if (parameters.includeSource()) {
        FileInfo info = fileFolderService.getFileInfo(parentNodeRef);
        sourceEntity = nodesModelFactory.createRecordCategory(info, parameters, mapUserInfo, true);
    }
    return CollectionWithPagingInfo.asPaged(parameters.getPaging(), nodes, pagingResults.hasMoreItems(), pagingResults.getTotalResultCount().getFirst(), sourceEntity);
}
Also used : AbstractList(java.util.AbstractList) FilterProp(org.alfresco.repo.node.getchildren.FilterProp) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) RecordCategoryChild(org.alfresco.rm.rest.api.model.RecordCategoryChild) UserInfo(org.alfresco.rest.api.model.UserInfo) RecordCategory(org.alfresco.rm.rest.api.model.RecordCategory) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 2 with FilterProp

use of org.alfresco.repo.node.getchildren.FilterProp in project records-management by Alfresco.

the class UnfiledContainerChildrenRelation method readAll.

@Override
@WebApiDescription(title = "Return a paged list of unfiled container children for the container identified by 'unfiledContainerId'")
public CollectionWithPagingInfo<UnfiledContainerChild> readAll(String unfiledContainerId, Parameters parameters) {
    // validate parameters
    checkNotBlank("unfiledContainerId", unfiledContainerId);
    mandatory("parameters", parameters);
    NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(unfiledContainerId, RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER);
    // list unfiled record folders and records
    Set<QName> searchTypeQNames = searchTypesFactory.buildSearchTypesForUnfiledEndpoint(parameters, LIST_UNFILED_CONTAINER_CHILDREN_EQUALS_QUERY_PROPERTIES);
    List<FilterProp> filterProps = apiUtils.getListChildrenFilterProps(parameters, LIST_UNFILED_CONTAINER_CHILDREN_EQUALS_QUERY_PROPERTIES);
    final PagingResults<FileInfo> pagingResults = fileFolderService.list(parentNodeRef, null, searchTypeQNames, null, apiUtils.getSortProperties(parameters), filterProps, Util.getPagingRequest(parameters.getPaging()));
    final List<FileInfo> page = pagingResults.getPage();
    Map<String, UserInfo> mapUserInfo = new HashMap<>();
    List<UnfiledContainerChild> nodes = new AbstractList<UnfiledContainerChild>() {

        @Override
        public UnfiledContainerChild get(int index) {
            FileInfo info = page.get(index);
            return nodesModelFactory.createUnfiledContainerChild(info, parameters, mapUserInfo, true);
        }

        @Override
        public int size() {
            return page.size();
        }
    };
    UnfiledContainer sourceEntity = null;
    if (parameters.includeSource()) {
        FileInfo info = fileFolderService.getFileInfo(parentNodeRef);
        sourceEntity = nodesModelFactory.createUnfiledContainer(info, parameters, mapUserInfo, true);
    }
    return CollectionWithPagingInfo.asPaged(parameters.getPaging(), nodes, pagingResults.hasMoreItems(), pagingResults.getTotalResultCount().getFirst(), sourceEntity);
}
Also used : AbstractList(java.util.AbstractList) FilterProp(org.alfresco.repo.node.getchildren.FilterProp) HashMap(java.util.HashMap) UnfiledContainerChild(org.alfresco.rm.rest.api.model.UnfiledContainerChild) QName(org.alfresco.service.namespace.QName) UserInfo(org.alfresco.rest.api.model.UserInfo) UnfiledContainer(org.alfresco.rm.rest.api.model.UnfiledContainer) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 3 with FilterProp

use of org.alfresco.repo.node.getchildren.FilterProp 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 4 with FilterProp

use of org.alfresco.repo.node.getchildren.FilterProp 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 5 with FilterProp

use of org.alfresco.repo.node.getchildren.FilterProp in project alfresco-remote-api by Alfresco.

the class SitesImpl method getFilterPropListOfSites.

private List<FilterProp> getFilterPropListOfSites(final Parameters parameters) {
    List<FilterProp> filterProps = new ArrayList<FilterProp>();
    Query q = parameters.getQuery();
    if (q != null) {
        MapBasedQueryWalkerOrSupported propertyWalker = new MapBasedQueryWalkerOrSupported(LIST_SITES_EQUALS_QUERY_PROPERTIES, null);
        QueryHelper.walk(q, propertyWalker);
        String siteVisibilityStr = propertyWalker.getProperty(PARAM_VISIBILITY, WhereClauseParser.EQUALS, String.class);
        if (siteVisibilityStr != null && !siteVisibilityStr.isEmpty()) {
            SiteVisibility siteVisibility = getSiteVisibilityFromParam(siteVisibilityStr);
            filterProps.add(new FilterPropString(SiteModel.PROP_SITE_VISIBILITY, siteVisibility.name(), FilterPropString.FilterTypeString.EQUALS));
        }
        String sitePreset = propertyWalker.getProperty(PARAM_PRESET, WhereClauseParser.EQUALS, String.class);
        if (sitePreset != null && !sitePreset.isEmpty()) {
            filterProps.add(new FilterPropString(SiteModel.PROP_SITE_PRESET, sitePreset, FilterPropString.FilterTypeString.EQUALS));
        }
    }
    // expected null or non-empty list
    return filterProps.isEmpty() ? null : filterProps;
}
Also used : Query(org.alfresco.rest.framework.resource.parameters.where.Query) FilterProp(org.alfresco.repo.node.getchildren.FilterProp) ArrayList(java.util.ArrayList) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString) MapBasedQueryWalkerOrSupported(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalkerOrSupported) SiteVisibility(org.alfresco.service.cmr.site.SiteVisibility) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString)

Aggregations

FilterProp (org.alfresco.repo.node.getchildren.FilterProp)12 QName (org.alfresco.service.namespace.QName)6 AbstractList (java.util.AbstractList)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 FilterPropString (org.alfresco.repo.node.getchildren.FilterPropString)5 FilterPropBoolean (org.alfresco.repo.node.getchildren.FilterPropBoolean)4 UserInfo (org.alfresco.rest.api.model.UserInfo)4 Query (org.alfresco.rest.framework.resource.parameters.where.Query)4 FileInfo (org.alfresco.service.cmr.model.FileInfo)4 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 Pair (org.alfresco.util.Pair)4 PagingRequest (org.alfresco.query.PagingRequest)3 GetChildrenCannedQuery (org.alfresco.repo.node.getchildren.GetChildrenCannedQuery)3 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)3 Paging (org.alfresco.rest.framework.resource.parameters.Paging)3 MapBasedQueryWalker (org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker)3 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)3 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 SortColumn (org.alfresco.rest.framework.resource.parameters.SortColumn)2