Search in sources :

Example 36 with AssociationRef

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

the class PeerAssociatedNodeFinder method processIncludedSet.

private Set<NodeRef> processIncludedSet(NodeRef startingNode) {
    NodeService nodeService = serviceRegistry.getNodeService();
    Set<NodeRef> foundNodes = new HashSet<NodeRef>(89);
    for (QName assocType : peerAssociationTypes) {
        List<AssociationRef> targets = nodeService.getTargetAssocs(startingNode, assocType);
        for (AssociationRef target : targets) {
            foundNodes.add(target.getTargetRef());
        }
    }
    return foundNodes;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) NodeService(org.alfresco.service.cmr.repository.NodeService) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) HashSet(java.util.HashSet)

Example 37 with AssociationRef

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

the class XMLTransferManifestWriter method writeSourceAssocs.

private void writeSourceAssocs(List<AssociationRef> refs) throws SAXException {
    if (refs != null) {
        writer.startElement(TransferModel.TRANSFER_MODEL_1_0_URI, ManifestModel.LOCALNAME_ELEMENT_SOURCE_ASSOCS, PREFIX + ":" + ManifestModel.LOCALNAME_ELEMENT_SOURCE_ASSOCS, EMPTY_ATTRIBUTES);
        for (AssociationRef assoc : refs) {
            writeAssoc(assoc);
        }
        writer.endElement(TransferModel.TRANSFER_MODEL_1_0_URI, ManifestModel.LOCALNAME_ELEMENT_SOURCE_ASSOCS, PREFIX + ":" + ManifestModel.LOCALNAME_ELEMENT_SOURCE_ASSOCS);
    }
}
Also used : AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 38 with AssociationRef

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

the class XMLTransferManifestWriter method writeTargetAssocs.

private void writeTargetAssocs(List<AssociationRef> refs) throws SAXException {
    if (refs != null) {
        writer.startElement(TransferModel.TRANSFER_MODEL_1_0_URI, ManifestModel.LOCALNAME_ELEMENT_TARGET_ASSOCS, PREFIX + ":" + ManifestModel.LOCALNAME_ELEMENT_TARGET_ASSOCS, EMPTY_ATTRIBUTES);
        for (AssociationRef assoc : refs) {
            writeAssoc(assoc);
        }
        writer.endElement(TransferModel.TRANSFER_MODEL_1_0_URI, ManifestModel.LOCALNAME_ELEMENT_TARGET_ASSOCS, PREFIX + ":" + ManifestModel.LOCALNAME_ELEMENT_TARGET_ASSOCS);
    }
}
Also used : AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 39 with AssociationRef

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

the class RepoSecondaryManifestProcessorImpl method processNode.

protected void processNode(TransferManifestNormalNode node) {
    logComment("Seconday Processing incoming node: " + node.getNodeRef());
    log.debug("Seconday Processing incoming node: " + node.getNodeRef());
    NodeRef correspondingNodeRef = nodeResolver.resolveCorrespondingNode(node.getNodeRef(), TransferManifestNodeHelper.getPrimaryParentAssoc(node), node.getParentPath()).resolvedChild;
    if (correspondingNodeRef == null) {
        correspondingNodeRef = node.getNodeRef();
    }
    // Process parent assocs...
    List<ChildAssociationRef> requiredAssocs = node.getParentAssocs();
    List<ChildAssociationRef> currentAssocs = nodeService.getParentAssocs(correspondingNodeRef);
    processParentChildAssociations(requiredAssocs, currentAssocs, correspondingNodeRef, false);
    // Process child assocs...
    requiredAssocs = node.getChildAssocs();
    currentAssocs = nodeService.getChildAssocs(correspondingNodeRef);
    processParentChildAssociations(requiredAssocs, currentAssocs, correspondingNodeRef, true);
    // Process "target" peer associations (associations *from* this node)
    List<AssociationRef> requiredTargetAssocs = node.getTargetAssocs();
    List<AssociationRef> currentTargetAssocs = nodeService.getTargetAssocs(correspondingNodeRef, RegexQNamePattern.MATCH_ALL);
    processPeerAssociations(requiredTargetAssocs, currentTargetAssocs, correspondingNodeRef, true);
    // Process "source" peer associations (associations *to* this node)
    List<AssociationRef> requiredSourceAssocs = node.getSourceAssocs();
    List<AssociationRef> currentSourceAssocs = nodeService.getSourceAssocs(correspondingNodeRef, RegexQNamePattern.MATCH_ALL);
    processPeerAssociations(requiredSourceAssocs, currentSourceAssocs, correspondingNodeRef, false);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 40 with AssociationRef

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

the class CopyServiceImpl method copyPendingAssociations.

/**
 * Copy any remaining associations that could not be copied or ignored during the copy process.
 * See <a href=http://issues.alfresco.com/jira/browse/ALF-958>ALF-958: Target associations aren't copied</a>.
 */
private void copyPendingAssociations(Map<NodeRef, NodeRef> copiedNodeRefs) {
    // Prepare storage for post-copy association handling
    List<Pair<AssociationRef, AssocCopyTargetAction>> postCopyAssocs = TransactionalResourceHelper.getList(KEY_POST_COPY_ASSOCS);
    for (Pair<AssociationRef, AssocCopyTargetAction> pair : postCopyAssocs) {
        AssociationRef assocRef = pair.getFirst();
        AssocCopyTargetAction action = pair.getSecond();
        // Was the original target copied?
        NodeRef newSourceForAssoc = copiedNodeRefs.get(assocRef.getSourceRef());
        if (newSourceForAssoc == null) {
            // Developer #fail
            throw new IllegalStateException("Post-copy association has a source that was NOT copied.");
        }
        NodeRef oldTargetForAssoc = assocRef.getTargetRef();
        // May be null
        NodeRef newTargetForAssoc = copiedNodeRefs.get(oldTargetForAssoc);
        QName assocTypeQName = assocRef.getTypeQName();
        switch(action) {
            case USE_ORIGINAL_TARGET:
                internalNodeService.createAssociation(newSourceForAssoc, oldTargetForAssoc, assocTypeQName);
                break;
            case USE_COPIED_TARGET:
                // Do nothing if the target was not copied
                if (newTargetForAssoc != null) {
                    internalNodeService.createAssociation(newSourceForAssoc, newTargetForAssoc, assocTypeQName);
                }
                break;
            case USE_COPIED_OTHERWISE_ORIGINAL_TARGET:
                if (newTargetForAssoc == null) {
                    internalNodeService.createAssociation(newSourceForAssoc, oldTargetForAssoc, assocTypeQName);
                } else {
                    internalNodeService.createAssociation(newSourceForAssoc, newTargetForAssoc, assocTypeQName);
                }
                break;
            default:
                throw new IllegalStateException("Unknown association action: " + action);
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) AssocCopyTargetAction(org.alfresco.repo.copy.CopyBehaviourCallback.AssocCopyTargetAction) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) Pair(org.alfresco.util.Pair)

Aggregations

AssociationRef (org.alfresco.service.cmr.repository.AssociationRef)138 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)112 NodeRef (org.alfresco.service.cmr.repository.NodeRef)102 QName (org.alfresco.service.namespace.QName)56 ArrayList (java.util.ArrayList)44 Serializable (java.io.Serializable)30 Test (org.junit.Test)26 HashMap (java.util.HashMap)24 List (java.util.List)15 Pair (org.alfresco.util.Pair)14 HashSet (java.util.HashSet)13 Map (java.util.Map)13 StoreRef (org.alfresco.service.cmr.repository.StoreRef)12 BaseSpringTest (org.alfresco.util.BaseSpringTest)10 Extend (org.alfresco.traitextender.Extend)8 Iterator (java.util.Iterator)7 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)7 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)7 Path (org.alfresco.service.cmr.repository.Path)6 Version (org.alfresco.service.cmr.version.Version)6