Java Code Examples for org.alfresco.service.cmr.repository.AssociationRef#getSourceRef()

The following examples show how to use org.alfresco.service.cmr.repository.AssociationRef#getSourceRef() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SingleAssocRefPolicyRuleTrigger.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void policyBehaviour(AssociationRef assocRef)
{
    final QName assocTypeQName = assocRef.getTypeQName();
    if ( !excludedAssocTypes.contains(assocTypeQName))
    {
        NodeRef nodeRef = assocRef.getSourceRef();
        
        if (nodeService.exists(nodeRef))
        {
            List<ChildAssociationRef> parentsAssocRefs = this.nodeService.getParentAssocs(nodeRef);
            for (ChildAssociationRef parentAssocRef : parentsAssocRefs)
            {
                triggerRules(parentAssocRef.getParentRef(), nodeRef);
                if (logger.isDebugEnabled() == true)
                {
                    logger.debug(
                            "OnUpdateAssoc rule triggered (parent); " +
                                    "nodeRef=" + parentAssocRef.getParentRef());
                }
            }
        }
    }
}
 
Example 2
Source File: WorkingCopyAspect.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * onDeleteAssociation policy behaviour If the node has the aspect ASPECT_CMIS_CREATED_CHECKEDOUT and ASSOC_WORKING_COPY_LINK association is deleted, delete the node. Fix for MNT-14850.
 * 
 * @param nodeAssocRef ASSOC_WORKING_COPY_LINK association where the source is the checkedOut node and the target is the workingCopy
 */
public void onDeleteCmisCreatedCheckoutWorkingCopyAssociation(AssociationRef nodeAssocRef)
{
    NodeRef checkedOutNodeRef = nodeAssocRef.getSourceRef();
    policyBehaviourFilter.disableBehaviour(checkedOutNodeRef, ContentModel.ASPECT_AUDITABLE);
    try
    {

        nodeService.deleteNode(checkedOutNodeRef);
    }
    finally
    {
        policyBehaviourFilter.enableBehaviour(checkedOutNodeRef, ContentModel.ASPECT_AUDITABLE);
    }

}
 
Example 3
Source File: BaseNodeServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testGetSourceAssocs() throws Exception
{
    AssociationRef assocRef = createAssociation();
    NodeRef sourceRef = assocRef.getSourceRef();
    NodeRef targetRef = assocRef.getTargetRef();
    QName qname = assocRef.getTypeQName();
    // get the source assocs
    List<AssociationRef> sourceAssocs = nodeService.getSourceAssocs(targetRef, qname);
    assertEquals("Incorrect number of source assocs", 1, sourceAssocs.size());
    assertTrue("Source not found", sourceAssocs.contains(assocRef));
    
    // Check that IDs are present
    for (AssociationRef sourceAssoc : sourceAssocs)
    {
        assertNotNull("Association does not have ID", sourceAssoc.getId());
    }
}
 
Example 4
Source File: CopyServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Callback behaviour for the 'original' assoc ('copiedfrom' aspect).
 */
public void beforeDeleteOriginalAssociation(AssociationRef nodeAssocRef)
{
    // Remove the cm:copiedfrom aspect
    NodeRef sourceNodeRef = nodeAssocRef.getSourceRef();
    // We are about to modify a copied node.  For this specific action, we do not
    // want to leave any trace of the action as it's a task invisible to the end-user.
    try
    {
        behaviourFilter.disableBehaviour(sourceNodeRef, ContentModel.ASPECT_LOCKABLE);
        behaviourFilter.disableBehaviour(sourceNodeRef, ContentModel.ASPECT_AUDITABLE);
        internalNodeService.removeAspect(sourceNodeRef, ContentModel.ASPECT_COPIEDFROM);
    }
    finally
    {
        behaviourFilter.enableBehaviour(sourceNodeRef, ContentModel.ASPECT_LOCKABLE);
        behaviourFilter.enableBehaviour(sourceNodeRef, ContentModel.ASPECT_AUDITABLE);
    }
}
 
Example 5
Source File: AbstractNodeServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @see NodeServicePolicies.OnCreateAssociationPolicy#onCreateAssociation(AssociationRef)
 */
protected void invokeOnCreateAssociation(AssociationRef nodeAssocRef)
{
    NodeRef sourceNodeRef = nodeAssocRef.getSourceRef();
    
    if (ignorePolicy(sourceNodeRef))
    {
        return;
    }
    
    QName assocTypeQName = nodeAssocRef.getTypeQName();
    // get qnames to invoke against
    Set<QName> qnames = getTypeAndAspectQNames(sourceNodeRef);
    // execute policy for node type and aspects
    NodeServicePolicies.OnCreateAssociationPolicy policy = onCreateAssociationDelegate.get(sourceNodeRef, qnames, assocTypeQName);
    policy.onCreateAssociation(nodeAssocRef);
}
 
Example 6
Source File: AbstractNodeServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @see NodeServicePolicies.BeforeDeleteAssociationPolicy#beforeDeleteAssociation(AssociationRef)
 */
protected void invokeBeforeDeleteAssociation(AssociationRef nodeAssocRef)
{
    NodeRef sourceNodeRef = nodeAssocRef.getSourceRef();
    
    if (ignorePolicy(sourceNodeRef))
    {
        return;
    }
    
    QName assocTypeQName = nodeAssocRef.getTypeQName();
    // get qnames to invoke against
    Set<QName> qnames = getTypeAndAspectQNames(sourceNodeRef);
    // execute policy for node type and aspects
    NodeServicePolicies.BeforeDeleteAssociationPolicy policy = beforeDeleteAssociationDelegate.get(sourceNodeRef, qnames, assocTypeQName);
    policy.beforeDeleteAssociation(nodeAssocRef);
}
 
Example 7
Source File: AbstractNodeServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @see NodeServicePolicies.OnDeleteAssociationPolicy#onDeleteAssociation(AssociationRef)
 */
protected void invokeOnDeleteAssociation(AssociationRef nodeAssocRef)
{
    NodeRef sourceNodeRef = nodeAssocRef.getSourceRef();
    
    if (ignorePolicy(sourceNodeRef))
    {
        return;
    }
    
    QName assocTypeQName = nodeAssocRef.getTypeQName();
    // get qnames to invoke against
    Set<QName> qnames = getTypeAndAspectQNames(sourceNodeRef);
    // execute policy for node type and aspects
    NodeServicePolicies.OnDeleteAssociationPolicy policy = onDeleteAssociationDelegate.get(sourceNodeRef, qnames, assocTypeQName);
    policy.onDeleteAssociation(nodeAssocRef);
}
 
Example 8
Source File: BaseNodeServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testGetTargetAssocs() throws Exception
{
    AssociationRef assocRef = createAssociation();
    NodeRef sourceRef = assocRef.getSourceRef();
    NodeRef targetRef = assocRef.getTargetRef();
    QName qname = assocRef.getTypeQName();
    // get the target assocs
    List<AssociationRef> targetAssocs = nodeService.getTargetAssocs(sourceRef, qname);
    assertEquals("Incorrect number of targets", 1, targetAssocs.size());
    assertTrue("Target not found", targetAssocs.contains(assocRef));
    
    // Check that IDs are present
    for (AssociationRef targetAssoc : targetAssocs)
    {
        assertNotNull("Association does not have ID", targetAssoc.getId());
    }
}
 
Example 9
Source File: IntegrityChecker.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @see AssocSourceMultiplicityIntegrityEvent
 * @see AssocTargetMultiplicityIntegrityEvent
 */
public void onDeleteAssociation(AssociationRef nodeAssocRef)
{
    if (! storesToIgnore.contains(tenantService.getBaseName(nodeAssocRef.getSourceRef().getStoreRef()).toString()))
    {
        IntegrityEvent event = null;
        // check source multiplicity
        event = new AssocSourceMultiplicityIntegrityEvent(
                nodeService,
                dictionaryService,
                nodeAssocRef.getTargetRef(),
                nodeAssocRef.getTypeQName(),
                true);
        save(event);
        // check target multiplicity
        event = new AssocTargetMultiplicityIntegrityEvent(
                nodeService,
                dictionaryService,
                nodeAssocRef.getSourceRef(),
                nodeAssocRef.getTypeQName(),
                true);
        save(event);
    }
}
 
Example 10
Source File: BaseNodeServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testDuplicateAssociationDetection() throws Exception
{
    AssociationRef assocRef = createAssociation();
    NodeRef sourceRef = assocRef.getSourceRef();
    NodeRef targetRef = assocRef.getTargetRef();
    QName qname = assocRef.getTypeQName();
    try
    {
        // attempt repeat
        nodeService.createAssociation(sourceRef, targetRef, qname);
        fail("Duplicate assocation not detected");
    }
    catch (AssociationExistsException e)
    {
        // expected
    }
}
 
Example 11
Source File: AbstractNodeRelation.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected CollectionWithPagingInfo<Node> listNodePeerAssocs(List<AssociationRef> assocRefs, Parameters parameters, boolean returnTarget)
{
    Map<QName, String> qnameMap = new HashMap<>(3);

    Map<String, UserInfo> mapUserInfo = new HashMap<>(10);

    List<String> includeParam = parameters.getInclude();

    List<Node> collection = new ArrayList<Node>(assocRefs.size());
    for (AssociationRef assocRef : assocRefs)
    {
        // minimal info by default (unless "include"d otherwise)
        NodeRef nodeRef = (returnTarget ? assocRef.getTargetRef() : assocRef.getSourceRef());

        Node node = nodes.getFolderOrDocument(nodeRef, null, null, includeParam, mapUserInfo);

        QName assocTypeQName = assocRef.getTypeQName();

        if (! EXCLUDED_NS.contains(assocTypeQName.getNamespaceURI()))
        {
            String assocType = qnameMap.get(assocTypeQName);
            if (assocType == null)
            {
                assocType = assocTypeQName.toPrefixString(namespaceService);
                qnameMap.put(assocTypeQName, assocType);
            }

            node.setAssociation(new Assoc(assocType));

            collection.add(node);
        }
    }
    
    return listPage(collection, parameters.getPaging());
}
 
Example 12
Source File: RepoSecondaryManifestProcessorImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 
 * @param ref AssociationRef
 */
public AssociationRefKey(AssociationRef ref)
{
    this.sourceRef = ref.getSourceRef();
    this.targetRef = ref.getTargetRef();
    this.assocTypeQName = ref.getTypeQName();
}
 
Example 13
Source File: BaseNodeServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testCreateAndRemoveAssociation() throws Exception
{
    AssociationRef assocRef = createAssociation();
    NodeRef sourceRef = assocRef.getSourceRef();
    
    // create another
    Map<QName, Serializable> properties = new HashMap<QName, Serializable>(5);
    fillProperties(ASPECT_QNAME_TEST_TITLED, properties);
    ChildAssociationRef childAssocRef = nodeService.createNode(
            rootNodeRef,
            ASSOC_TYPE_QNAME_TEST_CHILDREN,
            QName.createQName(null, "N3"),
            TYPE_QNAME_TEST_CONTENT,
            properties);
    NodeRef anotherTargetRef = childAssocRef.getChildRef();
    AssociationRef anotherAssocRef = nodeService.createAssociation(
            sourceRef,
            anotherTargetRef,
            ASSOC_TYPE_QNAME_TEST_NEXT);
    Long anotherAssocId = anotherAssocRef.getId();
    assertNotNull("Created association does not have an ID", anotherAssocId);
    AssociationRef anotherAssocRefCheck = nodeService.getAssoc(anotherAssocId);
    assertEquals("Assoc fetched by ID is incorrect.", anotherAssocRef, anotherAssocRefCheck);
    
    // remove assocs
    List<AssociationRef> assocs = nodeService.getTargetAssocs(sourceRef, ASSOC_TYPE_QNAME_TEST_NEXT);
    for (AssociationRef assoc : assocs)
    {
        nodeService.removeAssociation(
                assoc.getSourceRef(),
                assoc.getTargetRef(),
                assoc.getTypeQName());
    }
}
 
Example 14
Source File: ActionsAspect.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onDeleteAssociation(AssociationRef nodeAssocRef)
{
    // The act:actionSchedule type must have the association, so remove the source when the
    // association is deleted.
    NodeRef actionScheduleNodeRef = nodeAssocRef.getSourceRef();
    if (nodeService.exists(actionScheduleNodeRef) && !nodeService.hasAspect(actionScheduleNodeRef, ContentModel.ASPECT_PENDING_DELETE))
    {
        // Delete the source
        nodeService.deleteNode(actionScheduleNodeRef);
    }
}
 
Example 15
Source File: IntegrityChecker.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @see AssocSourceTypeIntegrityEvent
 * @see AssocTargetTypeIntegrityEvent
 * @see AssocSourceMultiplicityIntegrityEvent
 * @see AssocTargetMultiplicityIntegrityEvent
 */
public void onCreateAssociation(AssociationRef nodeAssocRef)
{
    if (! storesToIgnore.contains(tenantService.getBaseName(nodeAssocRef.getSourceRef().getStoreRef()).toString()))
    {
        IntegrityEvent event = null;
        // check source type
        event = new AssocSourceTypeIntegrityEvent(
                nodeService,
                dictionaryService,
                nodeAssocRef.getSourceRef(),
                nodeAssocRef.getTypeQName());
        save(event);
        // check target type
        event = new AssocTargetTypeIntegrityEvent(
                nodeService,
                dictionaryService,
                nodeAssocRef.getTargetRef(),
                nodeAssocRef.getTypeQName());
        save(event);
        // check source multiplicity
        event = new AssocSourceMultiplicityIntegrityEvent(
                nodeService,
                dictionaryService,
                nodeAssocRef.getTargetRef(),
                nodeAssocRef.getTypeQName(),
                false);
        save(event);
        // check target multiplicity
        event = new AssocTargetMultiplicityIntegrityEvent(
                nodeService,
                dictionaryService,
                nodeAssocRef.getSourceRef(),
                nodeAssocRef.getTypeQName(),
                false);
        save(event);
    }
}
 
Example 16
Source File: NodeUtils.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static NodeRef getSingleAssocNode(Collection<AssociationRef> assocs, boolean getTarget)
{
    if(assocs != null && assocs.size()==1 )
    {
        AssociationRef association = assocs.iterator().next();
        return getTarget ? association.getTargetRef() : association.getSourceRef();
    }
    return null;
}
 
Example 17
Source File: WorkingCopyAspect.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * onRestoreNode policy behaviour
 * 
 * @param nodeRef
 *            the node reference that was restored
 */
@SuppressWarnings("unchecked")
@Override
public void onRestoreNode(ChildAssociationRef childAssocRef)
{
    NodeRef workingCopyNodeRef = childAssocRef.getChildRef();

    //check that node is working copy 
    if (nodeService.hasAspect(workingCopyNodeRef, ContentModel.ASPECT_WORKING_COPY))
    {
        try
        {

            NodeRef checkedOutNodeRef = null;
            policyBehaviourFilter.disableBehaviour(workingCopyNodeRef, ContentModel.ASPECT_AUDITABLE);

            Map<QName, Serializable> workingCopyProperties = nodeService.getProperties(workingCopyNodeRef);

            //get archived lock properties in order to be restored on the original node
            String lockOwner = (String) workingCopyProperties.get(ContentModel.PROP_ARCHIVED_LOCK_OWNER);
            workingCopyProperties.remove(ContentModel.PROP_ARCHIVED_LOCK_OWNER);
            Date expiryDate = (Date) workingCopyProperties.get(ContentModel.PROP_ARCHIVED_EXPIRY_DATE);
            workingCopyProperties.remove(ContentModel.PROP_ARCHIVED_EXPIRY_DATE);
            String lockTypeStr = (String) workingCopyProperties.get(ContentModel.PROP_ARCHIVED_LOCK_TYPE);
            workingCopyProperties.remove(ContentModel.PROP_ARCHIVED_LOCK_TYPE);
            LockType lockType = lockTypeStr != null ? LockType.valueOf(lockTypeStr) : null;
            String lifetimeStr = (String) workingCopyProperties.get(ContentModel.PROP_ARCHIVED_LOCK_LIFETIME);
            workingCopyProperties.remove(ContentModel.PROP_ARCHIVED_LOCK_LIFETIME);
            Lifetime lifetime = lifetimeStr != null ? Lifetime.valueOf(lifetimeStr) : null;
            String additionalInfo = (String) workingCopyProperties.get(ContentModel.PROP_ARCHIVED_LOCK_ADDITIONAL_INFO);
            workingCopyProperties.remove(ContentModel.PROP_ARCHIVED_LOCK_ADDITIONAL_INFO);

            List<AssociationRef> targetAssocList = (ArrayList<AssociationRef>) workingCopyProperties
                    .get(ContentModel.PROP_ARCHIVED_TARGET_ASSOCS);
            if (targetAssocList != null && targetAssocList.get(0) != null)
            {
                AssociationRef targetAssoc = (AssociationRef) targetAssocList.get(0);
                checkedOutNodeRef = targetAssoc.getSourceRef();
                nodeService.createAssociation( targetAssoc.getSourceRef(),targetAssoc.getTargetRef(), ContentModel.ASSOC_ORIGINAL);

            }
            workingCopyProperties.remove( ContentModel.PROP_ARCHIVED_TARGET_ASSOCS);

            ArrayList<AssociationRef> sourceAssocList = (ArrayList<AssociationRef>) workingCopyProperties
                    .get(ContentModel.PROP_ARCHIVED_SOURCE_ASSOCS);
            if (sourceAssocList != null && sourceAssocList.get(0) != null)
            {
                AssociationRef sourceAssoc = (AssociationRef) sourceAssocList.get(0);
                checkedOutNodeRef = sourceAssoc.getSourceRef();
                nodeService.createAssociation(sourceAssoc.getSourceRef(), sourceAssoc.getTargetRef(),
                        ContentModel.ASSOC_WORKING_COPY_LINK);
            }
            workingCopyProperties.remove(ContentModel.PROP_ARCHIVED_SOURCE_ASSOCS);

            //clean up the archived aspect and properties for working copy node
            nodeService.removeAspect(workingCopyNodeRef, ContentModel.ASPECT_ARCHIVE_LOCKABLE);
            nodeService.setProperties(workingCopyNodeRef, workingCopyProperties);

            //restore properties on original node
            nodeService.addAspect(checkedOutNodeRef, ContentModel.ASPECT_LOCKABLE, null);
            Map<QName, Serializable> checkedOutNodeProperties = nodeService.getProperties(checkedOutNodeRef);

            checkedOutNodeProperties.put(ContentModel.PROP_LOCK_OWNER, lockOwner);
            checkedOutNodeProperties.put(ContentModel.PROP_LOCK_TYPE, lockType);
            checkedOutNodeProperties.put(ContentModel.PROP_LOCK_LIFETIME, lifetime);
            checkedOutNodeProperties.put(ContentModel.PROP_EXPIRY_DATE, expiryDate);
            checkedOutNodeProperties.put(ContentModel.PROP_LOCK_ADDITIONAL_INFO, additionalInfo);

            nodeService.setProperties(checkedOutNodeRef, checkedOutNodeProperties);
        }
        finally
        {
            policyBehaviourFilter.enableBehaviour(workingCopyNodeRef, ContentModel.ASPECT_AUDITABLE);
        }

    }
}
 
Example 18
Source File: VirtualNodeServiceExtension.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@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);
            }
        }

        // Download sources are deliberately not virtualized due to
        // performance and complexity issues.
        // However they could be detected using
        // if (qnamePattern.isMatch(DownloadModel.ASSOC_REQUESTED_NODES))

        return materialAssocs;
    }
    else
    {
        return theTrait.getSourceAssocs(targetRef,
                                        qnamePattern);
    }
}