Search in sources :

Example 6 with MapBasedQueryWalker

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

the class AbstractNodeRelation method getAssocTypeFromWhereElseAll.

protected QNamePattern getAssocTypeFromWhereElseAll(Parameters parameters) {
    QNamePattern assocTypeQNamePattern = RegexQNamePattern.MATCH_ALL;
    Query q = parameters.getQuery();
    if (q != null) {
        MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(WHERE_PARAMS_ASSOC_TYPE, null);
        QueryHelper.walk(q, propertyWalker);
        String assocTypeQNameStr = propertyWalker.getProperty(Nodes.PARAM_ASSOC_TYPE, WhereClauseParser.EQUALS, String.class);
        if (assocTypeQNameStr != null) {
            assocTypeQNamePattern = nodes.getAssocType(assocTypeQNameStr);
        }
    }
    return assocTypeQNamePattern;
}
Also used : Query(org.alfresco.rest.framework.resource.parameters.where.Query) MapBasedQueryWalker(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker) RegexQNamePattern(org.alfresco.service.namespace.RegexQNamePattern) QNamePattern(org.alfresco.service.namespace.QNamePattern)

Example 7 with MapBasedQueryWalker

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

the class NodeParentsRelation method readAll.

/**
 * List child node's parent(s) based on (parent ->) child associations.
 * Returns primary parent & also secondary parents, if any.
 *
 * @param childNodeId String id of child node
 */
@Override
@WebApiDescription(title = "Return a list of parent nodes based on child assocs")
public CollectionWithPagingInfo<Node> readAll(String childNodeId, Parameters parameters) {
    NodeRef childNodeRef = nodes.validateOrLookupNode(childNodeId, null);
    QNamePattern assocTypeQNameParam = RegexQNamePattern.MATCH_ALL;
    Boolean isPrimary = null;
    Query q = parameters.getQuery();
    if (q != null) {
        MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(WHERE_PARAMS_PARENTS, null);
        QueryHelper.walk(q, propertyWalker);
        isPrimary = propertyWalker.getProperty(Nodes.PARAM_ISPRIMARY, WhereClauseParser.EQUALS, Boolean.class);
        String assocTypeQNameStr = propertyWalker.getProperty(Nodes.PARAM_ASSOC_TYPE, WhereClauseParser.EQUALS, String.class);
        if (assocTypeQNameStr != null) {
            assocTypeQNameParam = nodes.getAssocType(assocTypeQNameStr);
        }
    }
    List<ChildAssociationRef> childAssocRefs = null;
    if (assocTypeQNameParam.equals(RegexQNamePattern.MATCH_ALL)) {
        childAssocRefs = nodeService.getParentAssocs(childNodeRef);
    } else {
        childAssocRefs = nodeService.getParentAssocs(childNodeRef, assocTypeQNameParam, RegexQNamePattern.MATCH_ALL);
    }
    return listNodeChildAssocs(childAssocRefs, parameters, isPrimary, false);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Query(org.alfresco.rest.framework.resource.parameters.where.Query) MapBasedQueryWalker(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker) RegexQNamePattern(org.alfresco.service.namespace.RegexQNamePattern) QNamePattern(org.alfresco.service.namespace.QNamePattern) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 8 with MapBasedQueryWalker

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

the class SearchTypesFactory method buildSearchTypesCategoriesEndpoint.

/**
 * Helper method to build search types for categories endpoint
 * @param parameters
 * @param listRecordCategoryChildrenEqualsQueryProperties
 * @return
 */
public Set<QName> buildSearchTypesCategoriesEndpoint(Parameters parameters, Set<String> listRecordCategoryChildrenEqualsQueryProperties) {
    Set<QName> searchTypeQNames = new HashSet<>();
    Query q = parameters.getQuery();
    boolean includeRecordFolders = false;
    boolean includeRecordCategories = false;
    if (q != null) {
        // filtering via "where" clause
        MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(listRecordCategoryChildrenEqualsQueryProperties, null);
        QueryHelper.walk(q, propertyWalker);
        Boolean isRecordFolder = propertyWalker.getProperty(RecordCategoryChild.PARAM_IS_RECORD_FOLDER, WhereClauseParser.EQUALS, Boolean.class);
        Boolean isRecordCategory = propertyWalker.getProperty(RecordCategoryChild.PARAM_IS_RECORD_CATEGORY, WhereClauseParser.EQUALS, Boolean.class);
        if ((isRecordFolder != null && isRecordFolder.booleanValue()) || (isRecordCategory != null && !isRecordCategory.booleanValue())) {
            includeRecordFolders = true;
        } else if ((isRecordFolder != null && !isRecordFolder.booleanValue()) || (isRecordCategory != null && isRecordCategory.booleanValue())) {
            includeRecordCategories = true;
        }
        String nodeTypeQNameStr = propertyWalker.getProperty(RecordCategoryChild.PARAM_NODE_TYPE, WhereClauseParser.EQUALS, String.class);
        QName filterNodeTypeQName;
        if (nodeTypeQNameStr != null) {
            if ((isRecordFolder != null) || (isRecordCategory != null)) {
                throw new InvalidArgumentException("Invalid filter - nodeType and isRecordFolder/isRecordCategory are mutually exclusive");
            }
            Pair<QName, Boolean> pair = parseNodeTypeFilter(nodeTypeQNameStr);
            filterNodeTypeQName = pair.getFirst();
            if (nodeTypeQNameStr.equals(RecordsManagementModel.TYPE_RECORD_FOLDER)) {
                includeRecordFolders = true;
            } else if (filterNodeTypeQName.equals(RecordsManagementModel.TYPE_RECORD_CATEGORY)) {
                includeRecordCategories = true;
            } else {
                throw new InvalidParameterException("Filter nodeType: " + nodeTypeQNameStr + " is invalid for this endpoint");
            }
        }
    } else {
        includeRecordCategories = true;
        includeRecordFolders = true;
    }
    if (includeRecordFolders) {
        searchTypeQNames.add(RecordsManagementModel.TYPE_RECORD_FOLDER);
    }
    if (includeRecordCategories) {
        searchTypeQNames.add(RecordsManagementModel.TYPE_RECORD_CATEGORY);
    }
    return searchTypeQNames;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) Query(org.alfresco.rest.framework.resource.parameters.where.Query) QName(org.alfresco.service.namespace.QName) MapBasedQueryWalker(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker) HashSet(java.util.HashSet)

Example 9 with MapBasedQueryWalker

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

the class SearchTypesFactory method buildSearchTypesForUnfiledEndpoint.

/**
 * Helper method to build search types for unfiled container and unfiled record folders endpoints
 * @param parameters
 * @param listFolderChildrenEqualsQueryProperties
 * @return
 */
public Set<QName> buildSearchTypesForUnfiledEndpoint(Parameters parameters, Set<String> listFolderChildrenEqualsQueryProperties) {
    Set<QName> searchTypeQNames = new HashSet<>();
    Query q = parameters.getQuery();
    boolean includeUnfiledRecordFolders = false;
    boolean includeRecords = false;
    boolean includeSubTypes = false;
    if (q != null) {
        // filtering via "where" clause
        MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(listFolderChildrenEqualsQueryProperties, null);
        QueryHelper.walk(q, propertyWalker);
        Boolean isUnfiledRecordFolder = propertyWalker.getProperty(UnfiledChild.PARAM_IS_UNFILED_RECORD_FOLDER, WhereClauseParser.EQUALS, Boolean.class);
        Boolean isRecord = propertyWalker.getProperty(UnfiledChild.PARAM_IS_RECORD, WhereClauseParser.EQUALS, Boolean.class);
        if ((isUnfiledRecordFolder != null && isUnfiledRecordFolder.booleanValue()) || (isRecord != null && !isRecord.booleanValue())) {
            includeUnfiledRecordFolders = true;
        } else if ((isUnfiledRecordFolder != null && !isUnfiledRecordFolder.booleanValue()) || (isRecord != null && isRecord.booleanValue())) {
            includeRecords = true;
        }
        String nodeTypeQNameStr = propertyWalker.getProperty(UnfiledChild.PARAM_NODE_TYPE, WhereClauseParser.EQUALS, String.class);
        QName filterNodeTypeQName;
        if (nodeTypeQNameStr != null) {
            if ((isUnfiledRecordFolder != null) || (isRecord != null)) {
                throw new InvalidArgumentException("Invalid filter - nodeType and isUnfiledRecordFolder/isRecord are mutually exclusive");
            }
            Pair<QName, Boolean> pair = parseNodeTypeFilter(nodeTypeQNameStr);
            filterNodeTypeQName = pair.getFirst();
            includeSubTypes = pair.getSecond();
            if (nodeTypeQNameStr.equals(RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER)) {
                includeUnfiledRecordFolders = true;
            } else if (filterNodeTypeQName.equals(ContentModel.TYPE_CONTENT)) {
                includeRecords = true;
            } else if (dictionaryService.isSubClass(filterNodeTypeQName, ContentModel.TYPE_CONTENT)) {
                searchTypeQNames.add(filterNodeTypeQName);
                if (includeSubTypes) {
                    Collection<QName> qnames = dictionaryService.getSubTypes(filterNodeTypeQName, true);
                    searchTypeQNames.addAll(qnames);
                }
            } else {
                throw new InvalidParameterException("Filter nodeType: " + nodeTypeQNameStr + " is invalid for this endpoint");
            }
        }
    } else {
        includeRecords = true;
        includeUnfiledRecordFolders = true;
        includeSubTypes = true;
    }
    if (includeUnfiledRecordFolders) {
        searchTypeQNames.add(RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER);
    }
    if (includeRecords) {
        if (includeSubTypes) {
            Collection<QName> qnames = dictionaryService.getSubTypes(ContentModel.TYPE_CONTENT, true);
            searchTypeQNames.addAll(qnames);
        } else {
            searchTypeQNames.add(ContentModel.TYPE_CONTENT);
            searchTypeQNames.add(RecordsManagementModel.TYPE_NON_ELECTRONIC_DOCUMENT);
        }
    }
    return searchTypeQNames;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) Query(org.alfresco.rest.framework.resource.parameters.where.Query) QName(org.alfresco.service.namespace.QName) MapBasedQueryWalker(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker) HashSet(java.util.HashSet)

Example 10 with MapBasedQueryWalker

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

the class NodesImpl method getListChildrenFilterProps.

/**
 * <p>Returns a List of filter properties specified by request parameters.</p>
 *
 * @param parameters The {@link Parameters} object to get the parameters passed into the request
 *        including:
 *        - filter, sort & paging params (where, orderBy, skipCount, maxItems)
 *        - incFiles, incFolders (both true by default)
 * @return The list of {@link FilterProp}. Can be null.
 */
protected List<FilterProp> getListChildrenFilterProps(final Parameters parameters) {
    List<FilterProp> filterProps = null;
    Query q = parameters.getQuery();
    if (q != null) {
        MapBasedQueryWalker propertyWalker = createListChildrenQueryWalker();
        QueryHelper.walk(q, propertyWalker);
        Boolean isPrimary = propertyWalker.getProperty(PARAM_ISPRIMARY, WhereClauseParser.EQUALS, Boolean.class);
        if (isPrimary != null) {
            filterProps = new ArrayList<>(1);
            filterProps.add(new FilterPropBoolean(GetChildrenCannedQuery.FILTER_QNAME_NODE_IS_PRIMARY, isPrimary));
        }
    }
    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)

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