Search in sources :

Example 1 with Node

use of org.alfresco.rest.api.model.Node 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 2 with Node

use of org.alfresco.rest.api.model.Node in project alfresco-remote-api by Alfresco.

the class AbstractNodeRelation method listNodeChildAssocs.

protected CollectionWithPagingInfo<Node> listNodeChildAssocs(List<ChildAssociationRef> childAssocRefs, Parameters parameters, Boolean isPrimary, boolean returnChild) {
    Map<QName, String> qnameMap = new HashMap<>(3);
    Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
    List<String> includeParam = parameters.getInclude();
    List<Node> collection = new ArrayList<Node>(childAssocRefs.size());
    for (ChildAssociationRef childAssocRef : childAssocRefs) {
        if (isPrimary == null || (isPrimary == childAssocRef.isPrimary())) {
            // minimal info by default (unless "include"d otherwise)
            NodeRef nodeRef = (returnChild ? childAssocRef.getChildRef() : childAssocRef.getParentRef());
            Node node = nodes.getFolderOrDocument(nodeRef, null, null, includeParam, mapUserInfo);
            QName assocTypeQName = childAssocRef.getTypeQName();
            if (!EXCLUDED_NS.contains(assocTypeQName.getNamespaceURI())) {
                String assocType = qnameMap.get(assocTypeQName);
                if (assocType == null) {
                    assocType = assocTypeQName.toPrefixString(namespaceService);
                    qnameMap.put(assocTypeQName, assocType);
                }
                node.setAssociation(new AssocChild(assocType, childAssocRef.isPrimary()));
                collection.add(node);
            }
        }
    }
    return listPage(collection, parameters.getPaging());
}
Also used : HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) Node(org.alfresco.rest.api.model.Node) ArrayList(java.util.ArrayList) AssocChild(org.alfresco.rest.api.model.AssocChild) UserInfo(org.alfresco.rest.api.model.UserInfo) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef)

Example 3 with Node

use of org.alfresco.rest.api.model.Node in project alfresco-remote-api by Alfresco.

the class AbstractNodeRelation method listNodePeerAssocs.

protected CollectionWithPagingInfo<Node> listNodePeerAssocs(List<AssociationRef> assocRefs, Parameters parameters, boolean returnTarget) {
    Map<QName, String> qnameMap = new HashMap<>(3);
    Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
    List<String> includeParam = parameters.getInclude();
    List<Node> collection = new ArrayList<Node>(assocRefs.size());
    for (AssociationRef assocRef : assocRefs) {
        // minimal info by default (unless "include"d otherwise)
        NodeRef nodeRef = (returnTarget ? assocRef.getTargetRef() : assocRef.getSourceRef());
        Node node = nodes.getFolderOrDocument(nodeRef, null, null, includeParam, mapUserInfo);
        QName assocTypeQName = assocRef.getTypeQName();
        if (!EXCLUDED_NS.contains(assocTypeQName.getNamespaceURI())) {
            String assocType = qnameMap.get(assocTypeQName);
            if (assocType == null) {
                assocType = assocTypeQName.toPrefixString(namespaceService);
                qnameMap.put(assocTypeQName, assocType);
            }
            node.setAssociation(new Assoc(assocType));
            collection.add(node);
        }
    }
    return listPage(collection, parameters.getPaging());
}
Also used : HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) Node(org.alfresco.rest.api.model.Node) ArrayList(java.util.ArrayList) UserInfo(org.alfresco.rest.api.model.UserInfo) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Assoc(org.alfresco.rest.api.model.Assoc)

Example 4 with Node

use of org.alfresco.rest.api.model.Node in project alfresco-remote-api by Alfresco.

the class NodeVersionsRelation method readById.

@Override
@WebApiDescription(title = "Get version node info", description = "Return metadata for a specific version node")
public Node readById(String nodeId, String versionId, Parameters parameters) {
    Version v = findVersion(nodeId, versionId);
    if (v != null) {
        Node node = nodes.getFolderOrDocumentFullInfo(v.getFrozenStateNodeRef(), null, null, parameters, null);
        mapVersionInfo(v, node);
        return node;
    }
    throw new EntityNotFoundException(nodeId + "-" + versionId);
}
Also used : Version(org.alfresco.service.cmr.version.Version) Node(org.alfresco.rest.api.model.Node) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 5 with Node

use of org.alfresco.rest.api.model.Node in project alfresco-remote-api by Alfresco.

the class NodeVersionsRelation method revertById.

@Operation("revert")
@WebApiDescription(title = "Revert Version", description = "Reverts (ie. promotes) specified version to become a new, most recent, version", successStatus = HttpServletResponse.SC_OK)
public Node revertById(String nodeId, String versionId, VersionOptions versionOptions, Parameters parameters, WithResponse withResponse) {
    Version v = findVersion(nodeId, versionId);
    if (v != null) {
        CheckOutCheckInService cociService = sr.getCheckOutCheckInService();
        NodeRef nodeRef = v.getVersionedNodeRef();
        String versionComment = versionOptions.getComment();
        VersionType versionType = VersionType.MINOR;
        Boolean versionMajor = versionOptions.getMajorVersion();
        if ((versionMajor != null) && (versionMajor)) {
            versionType = VersionType.MAJOR;
        }
        Map<String, Serializable> versionProperties = new HashMap<>(2);
        versionProperties.put(VersionModel.PROP_VERSION_TYPE, versionType);
        if (versionComment != null) {
            versionProperties.put(VersionModel.PROP_DESCRIPTION, versionComment);
        }
        // cancel editing if we want to revert
        if (sr.getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY)) {
            nodeRef = cociService.cancelCheckout(nodeRef);
        }
        // TODO review default for deep and/or whether we should make it an option
        versionService.revert(nodeRef, v, false);
        // Checkout/Checkin the node - to store the new version in version history
        NodeRef wcNodeRef = cociService.checkout(nodeRef);
        cociService.checkin(wcNodeRef, versionProperties);
        // get latest version
        v = versionService.getVersionHistory(nodeRef).getHeadVersion();
        Node node = nodes.getFolderOrDocumentFullInfo(v.getFrozenStateNodeRef(), null, null, parameters, null);
        mapVersionInfo(v, node);
        return node;
    }
    throw new EntityNotFoundException(nodeId + "-" + versionId);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) CheckOutCheckInService(org.alfresco.service.cmr.coci.CheckOutCheckInService) Version(org.alfresco.service.cmr.version.Version) HashMap(java.util.HashMap) Node(org.alfresco.rest.api.model.Node) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) VersionType(org.alfresco.service.cmr.version.VersionType) WebApiDescription(org.alfresco.rest.framework.WebApiDescription) Operation(org.alfresco.rest.framework.Operation)

Aggregations

Node (org.alfresco.rest.api.model.Node)21 NodeRef (org.alfresco.service.cmr.repository.NodeRef)14 HashMap (java.util.HashMap)12 QName (org.alfresco.service.namespace.QName)10 Serializable (java.io.Serializable)7 UserInfo (org.alfresco.rest.api.model.UserInfo)7 ArrayList (java.util.ArrayList)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)4 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)4 FilterPropBoolean (org.alfresco.repo.node.getchildren.FilterPropBoolean)3 SearchRequestContext (org.alfresco.rest.api.search.context.SearchRequestContext)3 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)3 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)3 Version (org.alfresco.service.cmr.version.Version)3 List (java.util.List)2 Map (java.util.Map)2 PagingRequest (org.alfresco.query.PagingRequest)2 EmptyResultSet (org.alfresco.repo.search.EmptyResultSet)2 SolrJSONResultSet (org.alfresco.repo.search.impl.lucene.SolrJSONResultSet)2