Search in sources :

Example 1 with NodeServiceTrait

use of org.alfresco.repo.node.db.traitextender.NodeServiceTrait 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 NodeServiceTrait

use of org.alfresco.repo.node.db.traitextender.NodeServiceTrait in project alfresco-repository by Alfresco.

the class VirtualNodeServiceExtension method removeSecondaryChildAssociation.

@Override
public boolean removeSecondaryChildAssociation(ChildAssociationRef childAssocRef) {
    NodeServiceTrait theTrait = getTrait();
    NodeRef childRef = childAssocRef.getChildRef();
    if (Reference.fromNodeRef(childRef) != null) {
        List<ChildAssociationRef> assocsToRemove = revertVirtualAssociation(childAssocRef, theTrait, childRef);
        boolean removed = false;
        if (!assocsToRemove.isEmpty()) {
            for (ChildAssociationRef assoc : assocsToRemove) {
                removed = removed || theTrait.removeSecondaryChildAssociation(assoc);
            }
        }
        return removed;
    } else {
        return theTrait.removeSecondaryChildAssociation(childAssocRef);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) NodeServiceTrait(org.alfresco.repo.node.db.traitextender.NodeServiceTrait) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 3 with NodeServiceTrait

use of org.alfresco.repo.node.db.traitextender.NodeServiceTrait in project alfresco-repository by Alfresco.

the class VirtualNodeServiceExtension method getChildAssocsByPropertyValue.

@Override
public List<ChildAssociationRef> getChildAssocsByPropertyValue(NodeRef nodeRef, QName propertyQName, Serializable value) {
    NodeServiceTrait theTrait = getTrait();
    boolean canVirtualize = canVirtualizeAssocNodeRef(nodeRef);
    if (canVirtualize) {
        Reference reference = smartStore.virtualize(nodeRef);
        List<ChildAssociationRef> virtualAssociations = smartStore.getChildAssocsByPropertyValue(reference, propertyQName, value);
        List<ChildAssociationRef> associations = new LinkedList<>(virtualAssociations);
        if (smartStore.canMaterialize(reference)) {
            NodeRef materialReference = smartStore.materialize(reference);
            List<ChildAssociationRef> actualAssociations = theTrait.getChildAssocsByPropertyValue(materialReference, propertyQName, value);
            associations.addAll(actualAssociations);
        }
        return associations;
    } else {
        return theTrait.getChildAssocsByPropertyValue(nodeRef, propertyQName, value);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) NodeServiceTrait(org.alfresco.repo.node.db.traitextender.NodeServiceTrait) Reference(org.alfresco.repo.virtual.ref.Reference) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) LinkedList(java.util.LinkedList)

Example 4 with NodeServiceTrait

use of org.alfresco.repo.node.db.traitextender.NodeServiceTrait in project alfresco-repository by Alfresco.

the class VirtualNodeServiceExtension method createNode.

@Override
public ChildAssociationRef createNode(NodeRef parentRef, QName assocTypeQName, QName assocQName, QName nodeTypeQName, Map<QName, Serializable> properties) {
    NodeServiceTrait theTrait = getTrait();
    if ((Reference.fromNodeRef(parentRef) != null) && !isVirtualContextFolder(parentRef, environment)) {
        // (repo)
        if (environment.isSubClass(nodeTypeQName, ContentModel.TYPE_FOLDER)) {
            throw new VirtualizationException("The creation of folders within virtual folders is disabled.");
        }
        try {
            Reference parentReference = Reference.fromNodeRef(parentRef);
            FilingData filingData = smartStore.createFilingData(parentReference, assocTypeQName, assocQName, nodeTypeQName, properties);
            NodeRef childParentNodeRef = filingData.getFilingNodeRef();
            if (childParentNodeRef != null) {
                Map<QName, Serializable> filingDataProperties = filingData.getProperties();
                QName changedAssocQName = assocQName;
                if (filingDataProperties.containsKey(ContentModel.PROP_NAME)) {
                    String fileName = (String) filingDataProperties.get(ContentModel.PROP_NAME);
                    String changedFileName = handleExistingFile(childParentNodeRef, fileName);
                    if (!changedFileName.equals(fileName)) {
                        filingDataProperties.put(ContentModel.PROP_NAME, changedFileName);
                        QName filingDataAssocQName = filingData.getAssocQName();
                        changedAssocQName = QName.createQName(filingDataAssocQName.getNamespaceURI(), QName.createValidLocalName(changedFileName));
                    }
                }
                ChildAssociationRef actualChildAssocRef = theTrait.createNode(childParentNodeRef, filingData.getAssocTypeQName(), changedAssocQName == null ? filingData.getAssocQName() : changedAssocQName, filingData.getNodeTypeQName(), filingDataProperties);
                Reference nodeProtocolChildRef = NodeProtocol.newReference(actualChildAssocRef.getChildRef(), parentReference);
                QName vChildAssocQName = QName.createQNameWithValidLocalName(VirtualContentModel.VIRTUAL_CONTENT_MODEL_1_0_URI, actualChildAssocRef.getQName().getLocalName());
                ChildAssociationRef childAssocRef = new ChildAssociationRef(actualChildAssocRef.getTypeQName(), parentRef, vChildAssocQName, nodeProtocolChildRef.toNodeRef());
                Set<QName> aspects = filingData.getAspects();
                for (QName aspect : aspects) {
                    theTrait.addAspect(actualChildAssocRef.getChildRef(), aspect, filingDataProperties);
                }
                return childAssocRef;
            } else {
                throw new InvalidNodeRefException("Can not create node using parent ", parentRef);
            }
        } catch (VirtualizationException e) {
            throw new InvalidNodeRefException("Could not create node in virtual context.", parentRef, e);
        }
    } else {
        QName materialAssocQName = materializeAssocQName(assocQName);
        if (isVirtualContextFolder(parentRef, environment)) {
            parentRef = smartStore.materializeIfPossible(parentRef);
        }
        return theTrait.createNode(parentRef, assocTypeQName, materialAssocQName, nodeTypeQName, properties);
    }
}
Also used : 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) FilingData(org.alfresco.repo.virtual.template.FilingData) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) VirtualizationException(org.alfresco.repo.virtual.VirtualizationException)

Example 5 with NodeServiceTrait

use of org.alfresco.repo.node.db.traitextender.NodeServiceTrait 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)

Aggregations

NodeServiceTrait (org.alfresco.repo.node.db.traitextender.NodeServiceTrait)17 NodeRef (org.alfresco.service.cmr.repository.NodeRef)16 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)14 Reference (org.alfresco.repo.virtual.ref.Reference)12 LinkedList (java.util.LinkedList)7 GetParentReferenceMethod (org.alfresco.repo.virtual.ref.GetParentReferenceMethod)3 Serializable (java.io.Serializable)2 AssociationRef (org.alfresco.service.cmr.repository.AssociationRef)2 QName (org.alfresco.service.namespace.QName)2 ArrayList (java.util.ArrayList)1 VirtualizationException (org.alfresco.repo.virtual.VirtualizationException)1 GetActualNodeRefMethod (org.alfresco.repo.virtual.ref.GetActualNodeRefMethod)1 GetAspectsMethod (org.alfresco.repo.virtual.ref.GetAspectsMethod)1 FilingData (org.alfresco.repo.virtual.template.FilingData)1 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)1