Search in sources :

Example 1 with GetParentReferenceMethod

use of org.alfresco.repo.virtual.ref.GetParentReferenceMethod in project alfresco-repository by Alfresco.

the class VirtualNodeServiceExtension method getTargetAssocs.

@Override
public List<AssociationRef> getTargetAssocs(NodeRef sourceRef, QNamePattern qnamePattern) {
    NodeServiceTrait theTrait = getTrait();
    List<AssociationRef> targetAssocs = null;
    Reference reference = Reference.fromNodeRef(sourceRef);
    if (reference != null) {
        if (smartStore.canMaterialize(reference)) {
            NodeRef materializedReferece = smartStore.materialize(reference);
            targetAssocs = theTrait.getTargetAssocs(materializedReferece, qnamePattern);
        } else {
            targetAssocs = new LinkedList<>();
        }
    } else {
        targetAssocs = theTrait.getTargetAssocs(sourceRef, qnamePattern);
    }
    List<AssociationRef> virtualizedIfNeededTargetAssocs = null;
    Reference sourceReference = Reference.fromNodeRef(sourceRef);
    if (sourceReference != null) {
        virtualizedIfNeededTargetAssocs = new LinkedList<>();
        for (AssociationRef associationRef : targetAssocs) {
            NodeRef targetNodeRef = associationRef.getTargetRef();
            Reference targetReference = NodeProtocol.newReference(targetNodeRef, sourceReference.execute(new GetParentReferenceMethod()));
            AssociationRef virtualAssocRef = new AssociationRef(associationRef.getId(), sourceRef, associationRef.getTypeQName(), targetReference.toNodeRef(targetNodeRef.getStoreRef()));
            virtualizedIfNeededTargetAssocs.add(virtualAssocRef);
        }
    } else {
        virtualizedIfNeededTargetAssocs = targetAssocs;
        if (DownloadModel.TYPE_DOWNLOAD.equals(environment.getType(sourceRef))) {
            if (qnamePattern.isMatch(DownloadModel.ASSOC_REQUESTED_NODES)) {
                List<AssociationRef> virtualTargetAssocs = getDownloadTargetAssocs(sourceRef);
                virtualizedIfNeededTargetAssocs.addAll(virtualTargetAssocs);
            }
        }
    }
    return virtualizedIfNeededTargetAssocs;
}
Also used : GetParentReferenceMethod(org.alfresco.repo.virtual.ref.GetParentReferenceMethod) NodeRef(org.alfresco.service.cmr.repository.NodeRef) NodeServiceTrait(org.alfresco.repo.node.db.traitextender.NodeServiceTrait) Reference(org.alfresco.repo.virtual.ref.Reference) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 2 with GetParentReferenceMethod

use of org.alfresco.repo.virtual.ref.GetParentReferenceMethod in project alfresco-repository by Alfresco.

the class VirtualNodeServiceExtension method getSourceAssocs.

@Override
public List<AssociationRef> getSourceAssocs(NodeRef targetRef, QNamePattern qnamePattern) {
    NodeServiceTrait theTrait = getTrait();
    Reference reference = Reference.fromNodeRef(targetRef);
    if (reference != null) {
        List<AssociationRef> materialAssocs = new ArrayList<AssociationRef>();
        if (smartStore.canMaterialize(reference)) {
            List<AssociationRef> sourceAssocs = theTrait.getSourceAssocs(smartStore.materialize(reference), qnamePattern);
            for (AssociationRef associationRef : sourceAssocs) {
                NodeRef sourceRef = associationRef.getSourceRef();
                Reference sourceReference = NodeProtocol.newReference(sourceRef, reference.execute(new GetParentReferenceMethod()));
                AssociationRef virtualAssocRef = new AssociationRef(associationRef.getId(), sourceReference.toNodeRef(), associationRef.getTypeQName(), targetRef);
                materialAssocs.add(virtualAssocRef);
            }
        }
        return materialAssocs;
    } else {
        return theTrait.getSourceAssocs(targetRef, qnamePattern);
    }
}
Also used : GetParentReferenceMethod(org.alfresco.repo.virtual.ref.GetParentReferenceMethod) NodeRef(org.alfresco.service.cmr.repository.NodeRef) NodeServiceTrait(org.alfresco.repo.node.db.traitextender.NodeServiceTrait) Reference(org.alfresco.repo.virtual.ref.Reference) ArrayList(java.util.ArrayList) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 3 with GetParentReferenceMethod

use of org.alfresco.repo.virtual.ref.GetParentReferenceMethod in project alfresco-repository by Alfresco.

the class VirtualNodeServiceExtension method getParentAssocs.

@Override
public List<ChildAssociationRef> getParentAssocs(NodeRef nodeRef, QNamePattern typeQNamePattern, QNamePattern qnamePattern) {
    NodeServiceTrait theTrait = getTrait();
    Reference reference = Reference.fromNodeRef(nodeRef);
    if (reference != null) {
        Reference parent = reference.execute(new GetParentReferenceMethod());
        if (parent == null) {
            return theTrait.getParentAssocs(reference.execute(new GetActualNodeRefMethod(environment)), typeQNamePattern, qnamePattern);
        } else {
            if (typeQNamePattern.isMatch(ContentModel.ASSOC_CONTAINS)) {
                Reference parentsParent = parent.execute(new GetParentReferenceMethod());
                NodeRef parentNodeRef = parent.toNodeRef();
                if (parentsParent == null) {
                    parentNodeRef = parent.execute(new GetActualNodeRefMethod(environment));
                }
                NodeRef referenceNodeRef = reference.toNodeRef();
                Map<QName, Serializable> properties = smartStore.getProperties(reference);
                Serializable name = properties.get(ContentModel.PROP_NAME);
                QName assocChildName = QName.createQNameWithValidLocalName(VirtualContentModel.VIRTUAL_CONTENT_MODEL_1_0_URI, name.toString());
                if (qnamePattern.isMatch(assocChildName)) {
                    ChildAssociationRef assoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, parentNodeRef, assocChildName, referenceNodeRef);
                    return Arrays.asList(assoc);
                } else {
                    return Collections.emptyList();
                }
            } else {
                return Collections.emptyList();
            }
        }
    } else {
        return theTrait.getParentAssocs(nodeRef, typeQNamePattern, qnamePattern);
    }
}
Also used : GetParentReferenceMethod(org.alfresco.repo.virtual.ref.GetParentReferenceMethod) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) NodeServiceTrait(org.alfresco.repo.node.db.traitextender.NodeServiceTrait) Reference(org.alfresco.repo.virtual.ref.Reference) QName(org.alfresco.service.namespace.QName) GetActualNodeRefMethod(org.alfresco.repo.virtual.ref.GetActualNodeRefMethod) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 4 with GetParentReferenceMethod

use of org.alfresco.repo.virtual.ref.GetParentReferenceMethod in project alfresco-repository by Alfresco.

the class VirtualNodeServiceExtension method getPrimaryParent.

@Override
public ChildAssociationRef getPrimaryParent(NodeRef nodeRef) {
    Reference reference = Reference.fromNodeRef(nodeRef);
    if (reference != null) {
        Reference parent = reference.execute(new GetParentReferenceMethod());
        if (parent == null) {
            return getTrait().getPrimaryParent(reference.execute(new GetActualNodeRefMethod(environment)));
        } else {
            Reference parentsParent = parent.execute(new GetParentReferenceMethod());
            NodeRef parentNodeRef = parent.toNodeRef();
            if (parentsParent == null) {
                parentNodeRef = parent.execute(new GetActualNodeRefMethod(environment));
            }
            NodeRef referenceNodeRef = reference.toNodeRef();
            Map<QName, Serializable> refProperties = smartStore.getProperties(reference);
            Serializable childName = refProperties.get(ContentModel.PROP_NAME);
            QName childAssocQName = QName.createQNameWithValidLocalName(VirtualContentModel.VIRTUAL_CONTENT_MODEL_1_0_URI, childName.toString());
            ChildAssociationRef assoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, parentNodeRef, childAssocQName, referenceNodeRef, true, -1);
            return assoc;
        }
    } else {
        return getTrait().getPrimaryParent(nodeRef);
    }
}
Also used : GetParentReferenceMethod(org.alfresco.repo.virtual.ref.GetParentReferenceMethod) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) Reference(org.alfresco.repo.virtual.ref.Reference) QName(org.alfresco.service.namespace.QName) GetActualNodeRefMethod(org.alfresco.repo.virtual.ref.GetActualNodeRefMethod) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 5 with GetParentReferenceMethod

use of org.alfresco.repo.virtual.ref.GetParentReferenceMethod in project alfresco-repository by Alfresco.

the class VirtualCheckOutCheckInServiceExtension method virtualizeOriginalIfNeeded.

private NodeRef virtualizeOriginalIfNeeded(NodeRef workingCopyNodeRef, NodeRef materialOriginalNode) {
    Reference workingCopyReference = Reference.fromNodeRef(workingCopyNodeRef);
    if ((materialOriginalNode != null) && (workingCopyReference != null)) {
        Reference parentReference = workingCopyReference.execute(new GetParentReferenceMethod());
        Reference originalReference = NodeProtocol.newReference(materialOriginalNode, parentReference);
        return originalReference.toNodeRef(materialOriginalNode.getStoreRef());
    } else {
        return materialOriginalNode;
    }
}
Also used : GetParentReferenceMethod(org.alfresco.repo.virtual.ref.GetParentReferenceMethod) Reference(org.alfresco.repo.virtual.ref.Reference)

Aggregations

GetParentReferenceMethod (org.alfresco.repo.virtual.ref.GetParentReferenceMethod)9 Reference (org.alfresco.repo.virtual.ref.Reference)9 NodeRef (org.alfresco.service.cmr.repository.NodeRef)7 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)5 Serializable (java.io.Serializable)3 NodeServiceTrait (org.alfresco.repo.node.db.traitextender.NodeServiceTrait)3 QName (org.alfresco.service.namespace.QName)3 GetActualNodeRefMethod (org.alfresco.repo.virtual.ref.GetActualNodeRefMethod)2 AssociationRef (org.alfresco.service.cmr.repository.AssociationRef)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 PermissionReference (org.alfresco.repo.security.permissions.PermissionReference)1 VersionImpl (org.alfresco.repo.version.common.VersionImpl)1 VirtualizationException (org.alfresco.repo.virtual.VirtualizationException)1 GetTemplatePathMethod (org.alfresco.repo.virtual.ref.GetTemplatePathMethod)1 BasicConstraint (org.alfresco.repo.virtual.template.BasicConstraint)1 FilesFoldersConstraint (org.alfresco.repo.virtual.template.FilesFoldersConstraint)1 NamePatternPropertyValueConstraint (org.alfresco.repo.virtual.template.NamePatternPropertyValueConstraint)1 PropertyValueConstraint (org.alfresco.repo.virtual.template.PropertyValueConstraint)1 VirtualFolderDefinition (org.alfresco.repo.virtual.template.VirtualFolderDefinition)1