Search in sources :

Example 6 with Paging

use of org.alfresco.rest.framework.resource.parameters.Paging in project alfresco-remote-api by Alfresco.

the class CustomModelsImpl method getCustomModels.

@Override
public CollectionWithPagingInfo<CustomModel> getCustomModels(Parameters parameters) {
    Paging paging = parameters.getPaging();
    PagingRequest pagingRequest = Util.getPagingRequest(paging);
    PagingResults<CustomModelDefinition> results = customModelService.getCustomModels(pagingRequest);
    Integer totalItems = results.getTotalResultCount().getFirst();
    List<CustomModelDefinition> page = results.getPage();
    List<CustomModel> models = new ArrayList<>(page.size());
    for (CustomModelDefinition modelDefinition : page) {
        models.add(new CustomModel(modelDefinition));
    }
    return CollectionWithPagingInfo.asPaged(paging, models, results.hasMoreItems(), (totalItems == null ? null : totalItems.intValue()));
}
Also used : CustomModelDefinition(org.alfresco.service.cmr.dictionary.CustomModelDefinition) Paging(org.alfresco.rest.framework.resource.parameters.Paging) ArrayList(java.util.ArrayList) PagingRequest(org.alfresco.query.PagingRequest) CustomModel(org.alfresco.rest.api.model.CustomModel)

Example 7 with Paging

use of org.alfresco.rest.framework.resource.parameters.Paging in project alfresco-remote-api by Alfresco.

the class CustomModelsImpl method getCustomAspects.

@Override
public CollectionWithPagingInfo<CustomAspect> getCustomAspects(String modelName, Parameters parameters) {
    CustomModelDefinition modelDef = getCustomModelImpl(modelName);
    Collection<AspectDefinition> aspectDefinitions = modelDef.getAspectDefinitions();
    // TODO Should we support paging?
    Paging paging = Paging.DEFAULT;
    List<CustomAspect> customAspects = convertToCustomAspects(aspectDefinitions, false);
    return CollectionWithPagingInfo.asPaged(paging, customAspects, false, aspectDefinitions.size());
}
Also used : CustomModelDefinition(org.alfresco.service.cmr.dictionary.CustomModelDefinition) Paging(org.alfresco.rest.framework.resource.parameters.Paging) CustomAspect(org.alfresco.rest.api.model.CustomAspect) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition)

Example 8 with Paging

use of org.alfresco.rest.framework.resource.parameters.Paging in project alfresco-remote-api by Alfresco.

the class CustomModelsImpl method getCustomModelConstraints.

@Override
public CollectionWithPagingInfo<CustomModelConstraint> getCustomModelConstraints(String modelName, Parameters parameters) {
    CustomModelDefinition modelDef = getCustomModelImpl(modelName);
    Collection<ConstraintDefinition> constraintDefinitions = modelDef.getModelDefinedConstraints();
    // TODO Should we support paging?
    Paging paging = Paging.DEFAULT;
    List<CustomModelConstraint> customModelConstraints = convertToCustomModelConstraints(constraintDefinitions);
    return CollectionWithPagingInfo.asPaged(paging, customModelConstraints, false, constraintDefinitions.size());
}
Also used : CustomModelDefinition(org.alfresco.service.cmr.dictionary.CustomModelDefinition) Paging(org.alfresco.rest.framework.resource.parameters.Paging) CustomModelConstraint(org.alfresco.rest.api.model.CustomModelConstraint) ConstraintDefinition(org.alfresco.service.cmr.dictionary.ConstraintDefinition)

Example 9 with Paging

use of org.alfresco.rest.framework.resource.parameters.Paging in project alfresco-remote-api by Alfresco.

the class GroupsImpl method getGroups.

public CollectionWithPagingInfo<Group> getGroups(final Parameters parameters) {
    final List<String> includeParam = parameters.getInclude();
    Paging paging = parameters.getPaging();
    // Retrieve sort column. This is limited for now to sort column due to
    // v0 api implementation. Should be improved in the future.
    Pair<String, Boolean> sortProp = getGroupsSortProp(parameters);
    // Parse where clause properties.
    Query q = parameters.getQuery();
    Boolean isRootParam = null;
    String zoneFilter = null;
    if (q != null) {
        GroupsQueryWalker propertyWalker = new GroupsQueryWalker();
        QueryHelper.walk(q, propertyWalker);
        isRootParam = propertyWalker.getIsRoot();
        List<String> zonesParam = propertyWalker.getZones();
        if (zonesParam != null) {
            validateZonesParam(zonesParam);
            zoneFilter = zonesParam.get(0);
        }
    }
    final AuthorityType authorityType = AuthorityType.GROUP;
    final Set<String> rootAuthorities = getAllRootAuthorities(authorityType);
    PagingResults<AuthorityInfo> pagingResult;
    try {
        pagingResult = getAuthoritiesInfo(authorityType, isRootParam, zoneFilter, rootAuthorities, sortProp, paging);
    } catch (UnknownAuthorityException e) {
        // Non-existent zone
        pagingResult = new EmptyPagingResults<>();
    }
    // Create response.
    final List<AuthorityInfo> page = pagingResult.getPage();
    int totalItems = pagingResult.getTotalResultCount().getFirst();
    List<Group> groups = new AbstractList<Group>() {

        @Override
        public Group get(int index) {
            AuthorityInfo authorityInfo = page.get(index);
            return getGroup(authorityInfo, includeParam, rootAuthorities);
        }

        @Override
        public int size() {
            return page.size();
        }
    };
    return CollectionWithPagingInfo.asPaged(paging, groups, pagingResult.hasMoreItems(), totalItems);
}
Also used : AbstractList(java.util.AbstractList) Group(org.alfresco.rest.api.model.Group) Query(org.alfresco.rest.framework.resource.parameters.where.Query) Paging(org.alfresco.rest.framework.resource.parameters.Paging) AuthorityType(org.alfresco.service.cmr.security.AuthorityType) AuthorityInfo(org.alfresco.repo.security.authority.AuthorityInfo) UnknownAuthorityException(org.alfresco.repo.security.authority.UnknownAuthorityException) EmptyPagingResults(org.alfresco.query.EmptyPagingResults)

Example 10 with Paging

use of org.alfresco.rest.framework.resource.parameters.Paging 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)

Aggregations

Paging (org.alfresco.rest.framework.resource.parameters.Paging)34 ArrayList (java.util.ArrayList)18 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)11 Query (org.alfresco.rest.framework.resource.parameters.where.Query)10 PagingRequest (org.alfresco.query.PagingRequest)9 SortColumn (org.alfresco.rest.framework.resource.parameters.SortColumn)8 Pair (org.alfresco.util.Pair)8 AbstractList (java.util.AbstractList)7 HashMap (java.util.HashMap)6 List (java.util.List)6 Test (org.junit.Test)6 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)5 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)5 HashSet (java.util.HashSet)4 AuthorityInfo (org.alfresco.repo.security.authority.AuthorityInfo)4 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 Map (java.util.Map)3 Set (java.util.Set)3 EmptyPagingResults (org.alfresco.query.EmptyPagingResults)3 GroupMember (org.alfresco.rest.api.model.GroupMember)3