Search in sources :

Example 6 with ChildAssocElement

use of org.alfresco.service.cmr.repository.Path.ChildAssocElement in project alfresco-repository by Alfresco.

the class PathUtil method getNodeIdsInReverse.

/**
 * Return the node ids from the specified node Path, so that
 * the first element is the immediate parent.
 *
 * @param path     the node's path object
 * @param showLeaf whether to process the final leaf element of the path
 * @return list of node ids
 */
public static List<String> getNodeIdsInReverse(Path path, boolean showLeaf) {
    int count = path.size() - (showLeaf ? 1 : 2);
    if (count < 0) {
        return Collections.emptyList();
    }
    List<String> nodeIds = new ArrayList<>(count);
    // Add in reverse order (so the first element is the immediate parent)
    for (int i = count; i >= 0; i--) {
        Path.Element element = path.get(i);
        if (element instanceof ChildAssocElement) {
            ChildAssocElement childAssocElem = (ChildAssocElement) element;
            NodeRef childNodeRef = childAssocElem.getRef().getChildRef();
            nodeIds.add(childNodeRef.getId());
        }
    }
    return nodeIds;
}
Also used : Path(org.alfresco.service.cmr.repository.Path) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ChildAssocElement(org.alfresco.service.cmr.repository.Path.ChildAssocElement) ArrayList(java.util.ArrayList)

Example 7 with ChildAssocElement

use of org.alfresco.service.cmr.repository.Path.ChildAssocElement in project alfresco-repository by Alfresco.

the class AbstractEventsService method getNodeIds.

/**
 * For each path, construct a list of ancestor node ids starting with the leaf path element node id first.
 *
 * @param nodePaths
 * @return
 */
protected List<List<String>> getNodeIds(List<Path> nodePaths) {
    // TODO use fileFolderService.getNamePath instead?
    List<List<String>> pathNodeIds = new ArrayList<List<String>>(nodePaths.size());
    for (Path path : nodePaths) {
        List<String> nodeIds = new ArrayList<String>(path.size());
        // add in reverse order (so the first element is the immediate parent)
        for (int i = path.size() - 1; i >= 0; i--) {
            Path.Element element = path.get(i);
            if (element instanceof ChildAssocElement) {
                ChildAssocElement childAssocElem = (ChildAssocElement) element;
                NodeRef childNodeRef = childAssocElem.getRef().getChildRef();
                nodeIds.add(childNodeRef.getId());
            }
        }
        pathNodeIds.add(nodeIds);
    }
    return pathNodeIds;
}
Also used : Path(org.alfresco.service.cmr.repository.Path) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ChildAssocElement(org.alfresco.service.cmr.repository.Path.ChildAssocElement) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 8 with ChildAssocElement

use of org.alfresco.service.cmr.repository.Path.ChildAssocElement in project alfresco-repository by Alfresco.

the class VirtualStoreImpl method getPath.

@Override
public Path getPath(Reference reference) throws VirtualizationException {
    Reference virtualPathElement = reference;
    Reference virtualPathParent = reference.execute(new GetParentReferenceMethod());
    Path virtualPath = new Path();
    while (virtualPathElement != null && virtualPathParent != null) {
        NodeRef parentNodeRef;
        parentNodeRef = virtualPathParent.toNodeRef();
        NodeRef parent = parentNodeRef;
        NodeRef virtualPathNodeRef = virtualPathElement.toNodeRef();
        // TODO: extract node reference name into protocol method in order
        // to enforce path processing code reuse and consistency
        String templatePath = virtualPathElement.execute(new GetTemplatePathMethod()).trim();
        final String pathSeparator = "/";
        if (pathSeparator.equals(templatePath)) {
            // found root
            break;
        } else if (templatePath.endsWith(pathSeparator)) {
            templatePath = templatePath.substring(0, templatePath.length() - 1);
        }
        int lastSeparator = templatePath.lastIndexOf(pathSeparator);
        String childId = templatePath.substring(lastSeparator + 1);
        VirtualFolderDefinition structure = resolveVirtualFolderDefinition(virtualPathParent);
        VirtualFolderDefinition child = structure.findChildById(childId);
        if (child == null) {
            throw new VirtualizationException("Invalid reference: " + reference.encode());
        }
        String childName = child.getName();
        QName childQName = QName.createQName(VirtualContentModel.VIRTUAL_CONTENT_MODEL_1_0_URI, childName);
        ChildAssociationRef assocRef = new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, parent, childQName, virtualPathNodeRef, true, -1);
        ChildAssocElement assocRefElement = new ChildAssocElement(assocRef);
        virtualPath.prepend(assocRefElement);
        virtualPathElement = virtualPathParent;
        virtualPathParent = virtualPathParent.execute(new GetParentReferenceMethod());
    }
    return virtualPath;
}
Also used : GetParentReferenceMethod(org.alfresco.repo.virtual.ref.GetParentReferenceMethod) Path(org.alfresco.service.cmr.repository.Path) NodeRef(org.alfresco.service.cmr.repository.NodeRef) GetTemplatePathMethod(org.alfresco.repo.virtual.ref.GetTemplatePathMethod) ChildAssocElement(org.alfresco.service.cmr.repository.Path.ChildAssocElement) PermissionReference(org.alfresco.repo.security.permissions.PermissionReference) Reference(org.alfresco.repo.virtual.ref.Reference) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NamePatternPropertyValueConstraint(org.alfresco.repo.virtual.template.NamePatternPropertyValueConstraint) PropertyValueConstraint(org.alfresco.repo.virtual.template.PropertyValueConstraint) FilesFoldersConstraint(org.alfresco.repo.virtual.template.FilesFoldersConstraint) VirtualQueryConstraint(org.alfresco.repo.virtual.template.VirtualQueryConstraint) BasicConstraint(org.alfresco.repo.virtual.template.BasicConstraint) VirtualFolderDefinition(org.alfresco.repo.virtual.template.VirtualFolderDefinition) VirtualizationException(org.alfresco.repo.virtual.VirtualizationException)

Aggregations

NodeRef (org.alfresco.service.cmr.repository.NodeRef)8 Path (org.alfresco.service.cmr.repository.Path)8 ChildAssocElement (org.alfresco.service.cmr.repository.Path.ChildAssocElement)8 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)5 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)3 List (java.util.List)2 QName (org.alfresco.service.namespace.QName)2 Serializable (java.io.Serializable)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Collection (java.util.Collection)1 CRC32 (java.util.zip.CRC32)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 ChildAssocRefQueryCallback (org.alfresco.repo.domain.node.NodeDAO.ChildAssocRefQueryCallback)1 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)1 PermissionReference (org.alfresco.repo.security.permissions.PermissionReference)1 VirtualizationException (org.alfresco.repo.virtual.VirtualizationException)1 GetParentReferenceMethod (org.alfresco.repo.virtual.ref.GetParentReferenceMethod)1 GetTemplatePathMethod (org.alfresco.repo.virtual.ref.GetTemplatePathMethod)1 Reference (org.alfresco.repo.virtual.ref.Reference)1