Java源码示例:org.alfresco.service.cmr.repository.AssociationRef

示例1
@Extend(traitAPI=NodeServiceTrait.class,extensionAPI=NodeServiceExtension.class)
public void removeAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName)
        throws InvalidNodeRefException
{
    // The node(s) involved may not be pending deletion
    checkPendingDelete(sourceRef);
    checkPendingDelete(targetRef);
    
    Pair<Long, NodeRef> sourceNodePair = getNodePairNotNull(sourceRef);
    Long sourceNodeId = sourceNodePair.getFirst();
    Pair<Long, NodeRef> targetNodePair = getNodePairNotNull(targetRef);
    Long targetNodeId = targetNodePair.getFirst();

    AssociationRef assocRef = new AssociationRef(sourceRef, assocTypeQName, targetRef);
    // Invoke policy behaviours
    invokeBeforeDeleteAssociation(assocRef);

    // delete it
    int assocsDeleted = nodeDAO.removeNodeAssoc(sourceNodeId, targetNodeId, assocTypeQName);
    
    if (assocsDeleted > 0)
    {
        // Invoke policy behaviours
        invokeOnDeleteAssociation(assocRef);
    }
}
 
示例2
@Override
protected void updateAssociations(NodeService nodeService)
{
    List<AssociationRef> existingAssocs = nodeService.getTargetAssocs(sourceNodeRef, assocQName);
    for (AssociationRef assoc : existingAssocs)
    {
        if (assoc.getTargetRef().equals(targetNodeRef))
        {
            if (logger.isWarnEnabled())
            {
                logger.warn("Attempt to add existing association prevented. " + assoc);
            }
            return;
        }
    }
    nodeService.createAssociation(sourceNodeRef, targetNodeRef, assocQName);
}
 
示例3
/**
 * Freeze associations
 *
 * @param versionNodeRef   the version node reference
 * @param associations     the list of associations
 * 
 * @since 3.3 (Ent)
 */
private void freezeAssociations(NodeRef versionNodeRef, List<AssociationRef> associations)
{
    for (AssociationRef targetAssocRef : associations)
    {
        HashMap<QName, Serializable> properties = new HashMap<QName, Serializable>();
        
        QName sourceTypeRef = nodeService.getType(targetAssocRef.getSourceRef());
        
        NodeRef targetRef = targetAssocRef.getTargetRef();
        
        // Set the reference property to point to the target node
        properties.put(ContentModel.PROP_REFERENCE, targetRef);
        properties.put(Version2Model.PROP_QNAME_ASSOC_DBID, targetAssocRef.getId());
        
        // Create peer version reference
        dbNodeService.createNode(
                versionNodeRef,
                Version2Model.CHILD_QNAME_VERSIONED_ASSOCS,
                targetAssocRef.getTypeQName(),
                sourceTypeRef,
                properties);
    }
}
 
示例4
@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
    }
}
 
示例5
/**
 * Gets the current source associations
 * 
 * @return associations
 */
public List<PeerAssociation> getSourceAssocs(NodeRef nodeRef)
{
    List<AssociationRef> refs = null;
    try
    {
        refs = getNodeService().getSourceAssocs(nodeRef, RegexQNamePattern.MATCH_ALL);
    }
    catch (UnsupportedOperationException err)
    {
       // some stores do not support associations
       // but we doesn't want NPE in code below
       refs = new ArrayList<AssociationRef>(); 
    }
    List<PeerAssociation> assocs = new ArrayList<PeerAssociation>(refs.size());
    for (AssociationRef ref : refs)
    {
        assocs.add(new PeerAssociation(ref.getTypeQName(), ref.getSourceRef(), ref.getTargetRef()));
    }
    return assocs;
}
 
示例6
/**
 * Tests get target associations by property value.</p>
 * See <b>MNT-14504</b> for more details.
 */
@Test
public void testGetTargetAssocsByPropertyValue()
{
    // Create a new versionable node
    NodeRef versionableNode = createNewVersionableNode();

    QName propertyQName = PROP_1;
    Serializable propertyValue = VALUE_1;
    // Store the current details of the target associations
    List<AssociationRef> origAssocs = this.dbNodeService.getTargetAssocsByPropertyValue(versionableNode, RegexQNamePattern.MATCH_ALL,
            propertyQName, propertyValue);

    // Create a new version
    Version version = createVersion(versionableNode, this.versionProperties);

    List<AssociationRef> assocs = this.versionStoreNodeService.getTargetAssocsByPropertyValue(version.getFrozenStateNodeRef(),
            RegexQNamePattern.MATCH_ALL, propertyQName, propertyValue);
    assertNotNull(assocs);
    assertEquals(origAssocs.size(), assocs.size());
}
 
示例7
@Test
public void testGetNull()
{
    assertNull(tenantService.getName((NodeRef)null));
    assertNull(tenantService.getName((String)null));
    assertNull(tenantService.getName((StoreRef) null));
    assertNull(tenantService.getName("", (StoreRef) null));
    assertNull(tenantService.getName((ChildAssociationRef) null));
    assertNull(tenantService.getName((AssociationRef) null));
    assertNull(tenantService.getName((NodeRef)null,(NodeRef)null));
    assertNull(tenantService.getBaseName((StoreRef) null));
    assertNull(tenantService.getBaseName((AssociationRef) null));
    assertNull(tenantService.getBaseName((ChildAssociationRef) null, false));
    assertNull(tenantService.getBaseName((String)null, false));
    tenantService.checkDomain((String)null);
}
 
示例8
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);
    }
}
 
示例9
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);
    }
}
 
示例10
/**
 * Test getAssociationTargets
 */
@Test
public void testGetAssociationTargets()
{
    // Create a new versionable node
    NodeRef versionableNode = createNewVersionableNode();
    
    // Store the current details of the target associations
    List<AssociationRef> origAssocs = this.dbNodeService.getTargetAssocs(
            versionableNode,
            RegexQNamePattern.MATCH_ALL);
    
    // Create a new version
    Version version = createVersion(versionableNode, this.versionProperties);
    
    List<AssociationRef> assocs = this.versionStoreNodeService.getTargetAssocs(
            version.getFrozenStateNodeRef(), 
            RegexQNamePattern.MATCH_ALL);
    assertNotNull(assocs);
    assertEquals(origAssocs.size(), assocs.size());
}
 
示例11
/**
 * Add an association
 * 
 * @param classRef QName
 * @param nodeAssocRef AssociationRef
 */
public void addAssociation(QName classRef, AssociationRef nodeAssocRef)
{
	if (classRef.equals(this.classRef) == true)
	{
		addAssociation(nodeAssocRef);
	}
	else
	{
		AspectDetails aspectDetails = this.aspectCopyDetails.get(classRef);
		if (aspectDetails == null)
		{
			// Add the aspect
			aspectDetails = addAspect(classRef);
		}
		aspectDetails.addAssociation(nodeAssocRef);
	}
}
 
示例12
/**
 * Get associations
 * 
 * @param classRef QName
 */
public List<AssociationRef> getAssociations(QName classRef) 
{
	List<AssociationRef> result = null;
	if (classRef.equals(this.classRef) == true)
	{
		result = getAssociations();
	}
	else
	{
		AspectDetails aspectDetails = this.aspectCopyDetails.get(classRef);
		if (aspectDetails != null)
		{
			result = aspectDetails.getAssociations();
		}
	}
	
	return result;
}
 
示例13
@Override
public AssociationRef createAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName)
{
	Reference targetReference = Reference.fromNodeRef(targetRef);
    if (targetReference != null
                && getTrait().getType(materializeIfPossible(sourceRef)).equals(DownloadModel.TYPE_DOWNLOAD))
    {
        // NOTE : this is enables downloads of virtual structures
        createDownloadAssociation(sourceRef,
                                  targetRef);

        AssociationRef assocRef = new AssociationRef(sourceRef,
                                                     assocTypeQName,
                                                     targetRef);
        return assocRef;
    }
    else
    {
        return getTrait().createAssociation(materializeIfPossible(sourceRef),
                                            materializeIfPossible(targetRef),
                                            assocTypeQName);
    }
}
 
示例14
@Override
@Extend(traitAPI=CheckOutCheckInServiceTrait.class,extensionAPI=CheckOutCheckInServiceExtension.class)
public NodeRef getWorkingCopy(NodeRef nodeRef)
{
    NodeRef workingCopy = null;
    if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_CHECKED_OUT))
    {
        List<AssociationRef> assocs = nodeService.getTargetAssocs(nodeRef, ContentModel.ASSOC_WORKING_COPY_LINK);
        // It is a 1:1 relationship
        if (assocs.size() == 0)
        {
            logger.warn("Found node with cm:checkedOut aspect but no association.  Current node state: " + nodeService.getNodeStatus(nodeRef));
        }
        else if (assocs.size() > 1)
        {
            logger.warn("Found multiple " + ContentModel.ASSOC_WORKING_COPY_LINK + " association from node: " + nodeRef);
        }
        else
        {
            workingCopy = assocs.get(0).getTargetRef();
        }
    }
    
    return workingCopy;
}
 
示例15
@Override
@Extend(traitAPI=CheckOutCheckInServiceTrait.class,extensionAPI=CheckOutCheckInServiceExtension.class)
public NodeRef getCheckedOut(NodeRef nodeRef)
{
    NodeRef original = null;
    if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY))
    {
        List<AssociationRef> assocs = nodeService.getSourceAssocs(nodeRef, ContentModel.ASSOC_WORKING_COPY_LINK);
        // It is a 1:1 relationship
        if (assocs.size() == 0)
        {
            logger.warn("Found node with cm:workingcopy aspect but no association.  Current node state: " + nodeService.getNodeStatus(nodeRef));
        }
        else if (assocs.size() > 1)
        {
            logger.warn("Found multiple " + ContentModel.ASSOC_WORKING_COPY_LINK + " association to node: " + nodeRef);
        }
        else
        {
            original = assocs.get(0).getSourceRef();
        }
    }
    
    return original;
}
 
示例16
/**
 * 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);
    }

}
 
示例17
/**
 * 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);
    }
}
 
示例18
/**
 * @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);
}
 
示例19
/**
 * @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);
}
 
示例20
@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());
    }
}
 
示例21
/**
 * Add peer association created event on create of a peer association.
 *
 * @param associationRef AssociationRef
 */
@Override
public void onCreateAssociation(AssociationRef associationRef)
{
    eventTypes.add(EventType.PEER_ASSOC_CREATED);
    resource = buildPeerAssociationResource(associationRef);
}
 
示例22
/**
 * Add peer association deleted event on delete of a peer association.
 *
 * @param associationRef AssociationRef
 */
@Override
public void beforeDeleteAssociation(AssociationRef associationRef)
{
    eventTypes.add(EventType.PEER_ASSOC_DELETED);
    resource = buildPeerAssociationResource(associationRef);
}
 
示例23
@Override
@WebApiDescription(title = "Remove node assoc(s)")
public void delete(String sourceNodeId, String targetNodeId, Parameters parameters)
{
    NodeRef srcNodeRef = nodes.validateNode(sourceNodeId);
    NodeRef tgtNodeRef = nodes.validateNode(targetNodeId);

    String assocTypeStr = parameters.getParameter(Nodes.PARAM_ASSOC_TYPE);
    QNamePattern assocTypeQName = nodes.getAssocType(assocTypeStr, false);

    if (assocTypeQName == null)
    {
        assocTypeQName = RegexQNamePattern.MATCH_ALL;
    }

    boolean found = false;

    List<AssociationRef> assocRefs = nodeService.getTargetAssocs(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, sourceNodeId), assocTypeQName);
    for (AssociationRef assocRef : assocRefs)
    {
        if (assocRef.getTargetRef().equals(tgtNodeRef))
        {
            nodeService.removeAssociation(srcNodeRef, tgtNodeRef, assocRef.getTypeQName());
            found = true;
        }
    }

    if (! found)
    {
        throw new EntityNotFoundException(sourceNodeId+","+assocTypeStr+","+targetNodeId);
    }
}
 
示例24
/**
 * List sources
 *
 * @param targetNodeId String id of target node
 */
@Override
@WebApiDescription(title = "Return a paged list of sources nodes based on (peer) assocs")
public CollectionWithPagingInfo<Node> readAll(String targetNodeId, Parameters parameters)
{
    NodeRef targetNodeRef = nodes.validateOrLookupNode(targetNodeId, null);

    QNamePattern assocTypeQNameParam = getAssocTypeFromWhereElseAll(parameters);

    List<AssociationRef> assocRefs = nodeService.getSourceAssocs(targetNodeRef, assocTypeQNameParam);

    return listNodePeerAssocs(assocRefs, parameters, false);
}
 
示例25
private Map<String, Object> getPersonModel(Serializable nameSer)
{
    if (!(nameSer instanceof String))
        return null;

    String name = (String) nameSer;

    // TODO Person URL?
    Map<String, Object> model = new HashMap<String, Object>();
    model.put(PERSON_USER_NAME, name);
    
    if (personService.personExists(name))
    {
        NodeRef person = personService.getPerson(name);
        Map<QName, Serializable> properties = nodeService.getProperties(person);
        model.put(PERSON_FIRST_NAME, properties.get(ContentModel.PROP_FIRSTNAME));
        model.put(PERSON_LAST_NAME, properties.get(ContentModel.PROP_LASTNAME));
        
        // add the avatar, id present
        List<AssociationRef> avatar = nodeService.getTargetAssocs(person, ContentModel.ASSOC_AVATAR);
        if (avatar != null && !avatar.isEmpty())
        {
            model.put(PERSON_AVATAR, getAvatarUrl(avatar.get(0).getTargetRef()));
        }
    }
    
    return model;
}
 
示例26
/**
 * Helper method to fetch the association reference
 */
public AssociationRef getAssociationRef(QNameDAO qnameDAO)
{
    QName assocTypeQName = qnameDAO.getQName(typeQNameId).getSecond();
    AssociationRef assocRef = new AssociationRef(
            id,
            sourceNode.getNodeRef(),
            assocTypeQName,
            targetNode.getNodeRef());
    return assocRef;
}
 
示例27
/**
 * Assocs translation for version store
 * 
 * @since 3.3 (Ent)
 */
@Override
public List<AssociationRef> getTargetAssocs(NodeRef sourceRef, QNamePattern qnamePattern)
{
    // Get the assoc references from the version store
    List<ChildAssociationRef> childAssocRefs = this.dbNodeService.getChildAssocs(
            VersionUtil.convertNodeRef(sourceRef),
            Version2Model.CHILD_QNAME_VERSIONED_ASSOCS, qnamePattern);
    
    List<AssociationRef> result = new ArrayList<AssociationRef>(childAssocRefs.size());
    
    for (ChildAssociationRef childAssocRef : childAssocRefs)
    {
        // Get the assoc reference
        NodeRef childRef = childAssocRef.getChildRef();
        NodeRef referencedNode = (NodeRef)this.dbNodeService.getProperty(childRef, ContentModel.PROP_REFERENCE);
        
        if (this.dbNodeService.exists(referencedNode))
        {
            Long assocDbId = (Long)this.dbNodeService.getProperty(childRef, Version2Model.PROP_QNAME_ASSOC_DBID);
            
            // Build an assoc ref to add to the returned list
            AssociationRef newAssocRef = new AssociationRef(
                    assocDbId,
                    sourceRef,
                    childAssocRef.getQName(),
                    referencedNode);
            
            result.add(newAssocRef);
            }
    }
    
    return result;
}
 
示例28
/**
 * @throws UnsupportedOperationException always
 */
public AssociationRef createAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName)
        throws InvalidNodeRefException, AssociationExistsException
{
    // This operation is not supported for a version store
    throw new UnsupportedOperationException(MSG_UNSUPPORTED);
}
 
示例29
/**
 * @throws UnsupportedOperationException always
 */
public List<AssociationRef> getTargetAssocs(NodeRef sourceRef, QNamePattern qnamePattern)
{
    // Get the child assocs from the version store
    List<ChildAssociationRef> childAssocRefs = this.dbNodeService.getChildAssocs(
            VersionUtil.convertNodeRef(sourceRef),
            RegexQNamePattern.MATCH_ALL, CHILD_QNAME_VERSIONED_ASSOCS);
    List<AssociationRef> result = new ArrayList<AssociationRef>(childAssocRefs.size());
    for (ChildAssociationRef childAssocRef : childAssocRefs)
    {
        // Get the assoc reference
        NodeRef childRef = childAssocRef.getChildRef();
        NodeRef referencedNode = (NodeRef)this.dbNodeService.getProperty(childRef, ContentModel.PROP_REFERENCE);

        if (this.dbNodeService.exists(referencedNode) == true)
        {
            // get the qualified type name of the frozen child association and filter out unwanted names
            QName qName = (QName)this.dbNodeService.getProperty(childRef, PROP_QNAME_ASSOC_TYPE_QNAME);

            if (qnamePattern.isMatch(qName) == true)
            {
                AssociationRef newAssocRef = new AssociationRef(null, sourceRef, qName, referencedNode);
                result.add(newAssocRef);
            }
        }
    }

    return result;
}
 
示例30
/**
 * @throws UnsupportedOperationException always
 */
@Override
public List<AssociationRef> getTargetAssocsByPropertyValue(NodeRef sourceRef, QNamePattern qnamePattern, QName propertyQName, Serializable propertyValue)
{
    // This operation is not supported for versioning V1
    throw new UnsupportedOperationException(MSG_UNSUPPORTED_V1);
}