Search in sources :

Example 1 with ElementInfo

use of org.alfresco.rest.api.model.PathInfo.ElementInfo in project records-management by Alfresco.

the class FilePlanComponentsApiUtils method lookupPathInfo.

protected PathInfo lookupPathInfo(NodeRef nodeRefIn) {
    List<ElementInfo> pathElements = new ArrayList<>();
    Boolean isComplete = Boolean.TRUE;
    final Path nodePath = nodeService.getPath(nodeRefIn);
    ;
    final int pathIndex = 2;
    for (int i = nodePath.size() - pathIndex; i >= 0; i--) {
        Element element = nodePath.get(i);
        if (element instanceof Path.ChildAssocElement) {
            ChildAssociationRef elementRef = ((Path.ChildAssocElement) element).getRef();
            if (elementRef.getParentRef() != null) {
                NodeRef childNodeRef = elementRef.getChildRef();
                if (permissionService.hasPermission(childNodeRef, PermissionService.READ) == AccessStatus.ALLOWED) {
                    Serializable nameProp = nodeService.getProperty(childNodeRef, ContentModel.PROP_NAME);
                    pathElements.add(0, new ElementInfo(childNodeRef.getId(), nameProp.toString()));
                } else {
                    // Just return the pathInfo up to the location where the user has access
                    isComplete = Boolean.FALSE;
                    break;
                }
            }
        }
    }
    String pathStr = null;
    if (!pathElements.isEmpty()) {
        StringBuilder sb = new StringBuilder(120);
        for (PathInfo.ElementInfo e : pathElements) {
            sb.append("/").append(e.getName());
        }
        pathStr = sb.toString();
    } else {
        // There is no path element, so set it to null in order to be
        // ignored by Jackson during serialisation
        isComplete = null;
    }
    return new PathInfo(pathStr, isComplete, pathElements);
}
Also used : Path(org.alfresco.service.cmr.repository.Path) Serializable(java.io.Serializable) ElementInfo(org.alfresco.rest.api.model.PathInfo.ElementInfo) Element(org.alfresco.service.cmr.repository.Path.Element) ElementInfo(org.alfresco.rest.api.model.PathInfo.ElementInfo) ArrayList(java.util.ArrayList) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PathInfo(org.alfresco.rest.api.model.PathInfo) FilterPropBoolean(org.alfresco.repo.node.getchildren.FilterPropBoolean)

Example 2 with ElementInfo

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

the class NodesImpl method lookupPathInfo.

@Override
public PathInfo lookupPathInfo(NodeRef nodeRefIn, ChildAssociationRef archivedParentAssoc) {
    List<ElementInfo> pathElements = new ArrayList<>();
    Boolean isComplete = Boolean.TRUE;
    final Path nodePath;
    final int pathIndex;
    if (archivedParentAssoc != null) {
        if (permissionService.hasPermission(archivedParentAssoc.getParentRef(), PermissionService.READ).equals(AccessStatus.ALLOWED) && nodeService.exists(archivedParentAssoc.getParentRef())) {
            nodePath = nodeService.getPath(archivedParentAssoc.getParentRef());
            // 1 => we want to include the given node in the path as well.
            pathIndex = 1;
        } else {
            // We can't return a valid path
            return null;
        }
    } else {
        nodePath = nodeService.getPath(nodeRefIn);
        // 2 => as we don't want to include the given node in the path as well.
        pathIndex = 2;
    }
    for (int i = nodePath.size() - pathIndex; i >= 0; i--) {
        Element element = nodePath.get(i);
        if (element instanceof Path.ChildAssocElement) {
            ChildAssociationRef elementRef = ((Path.ChildAssocElement) element).getRef();
            if (elementRef.getParentRef() != null) {
                NodeRef childNodeRef = elementRef.getChildRef();
                if (permissionService.hasPermission(childNodeRef, PermissionService.READ) == AccessStatus.ALLOWED) {
                    Serializable nameProp = nodeService.getProperty(childNodeRef, ContentModel.PROP_NAME);
                    String type = getNodeType(childNodeRef).toPrefixString(namespaceService);
                    Set<QName> aspects = nodeService.getAspects(childNodeRef);
                    List<String> aspectNames = mapFromNodeAspects(aspects, EXCLUDED_NS, EXCLUDED_ASPECTS);
                    pathElements.add(0, new ElementInfo(childNodeRef.getId(), nameProp.toString(), type, aspectNames));
                } else {
                    // Just return the pathInfo up to the location where the user has access
                    isComplete = Boolean.FALSE;
                    break;
                }
            }
        }
    }
    String pathStr = null;
    if (pathElements.size() > 0) {
        StringBuilder sb = new StringBuilder(120);
        for (PathInfo.ElementInfo e : pathElements) {
            sb.append("/").append(e.getName());
        }
        pathStr = sb.toString();
    } else {
        // There is no path element, so set it to null in order to be
        // ignored by Jackson during serialisation
        isComplete = null;
    }
    return new PathInfo(pathStr, isComplete, pathElements);
}
Also used : Path(org.alfresco.service.cmr.repository.Path) Serializable(java.io.Serializable) ElementInfo(org.alfresco.rest.api.model.PathInfo.ElementInfo) QName(org.alfresco.service.namespace.QName) Element(org.alfresco.service.cmr.repository.Path.Element) ElementInfo(org.alfresco.rest.api.model.PathInfo.ElementInfo) ArrayList(java.util.ArrayList) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PathInfo(org.alfresco.rest.api.model.PathInfo) FilterPropBoolean(org.alfresco.repo.node.getchildren.FilterPropBoolean)

Aggregations

Serializable (java.io.Serializable)2 ArrayList (java.util.ArrayList)2 FilterPropBoolean (org.alfresco.repo.node.getchildren.FilterPropBoolean)2 PathInfo (org.alfresco.rest.api.model.PathInfo)2 ElementInfo (org.alfresco.rest.api.model.PathInfo.ElementInfo)2 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 Path (org.alfresco.service.cmr.repository.Path)2 Element (org.alfresco.service.cmr.repository.Path.Element)2 QName (org.alfresco.service.namespace.QName)1