Java Code Examples for org.alfresco.service.cmr.repository.NodeService#getTargetAssocs()

The following examples show how to use org.alfresco.service.cmr.repository.NodeService#getTargetAssocs() . 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: ContentModelFormProcessor.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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);
}
 
Example 2
Source File: PeerAssociatedNodeFinder.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @param thisNode NodeRef
 * @return Set<NodeRef>
 */
private Set<NodeRef> processExcludedSet(NodeRef thisNode)
{
    Set<NodeRef> results = new HashSet<NodeRef>(89);
    NodeService nodeService = serviceRegistry.getNodeService();

    // Find any peer nodes (filtering as necessary)
    List<AssociationRef> targets = nodeService.getTargetAssocs(thisNode, RegexQNamePattern.MATCH_ALL);
    boolean filterPeers = !peerAssociationTypes.isEmpty();
    for (AssociationRef target : targets)
    {
        if (!filterPeers || !peerAssociationTypes.contains(target.getTypeQName()))
        {
            results.add(target.getTargetRef());
        }
    }
    return results;
}
 
Example 3
Source File: ContentModelFormProcessor.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void updateAssociations(NodeService nodeService)
{
    List<AssociationRef> existingAssocs = nodeService.getTargetAssocs(sourceNodeRef, assocQName);
    boolean assocDoesNotExist = true;
    for (AssociationRef assoc : existingAssocs)
    {
        if (assoc.getTargetRef().equals(targetNodeRef))
        {
            assocDoesNotExist = false;
            break;
        }
    }
    if (assocDoesNotExist)
    {
        if (logger.isWarnEnabled())
        {
            StringBuilder msg = new StringBuilder();
            msg.append("Attempt to remove non-existent association prevented. ").append(sourceNodeRef).append("|")
                        .append(targetNodeRef).append(assocQName);
            logger.warn(msg.toString());
        }
        return;
    }

    nodeService.removeAssociation(sourceNodeRef, targetNodeRef, assocQName);
}
 
Example 4
Source File: PeerAssociatedNodeFinder.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 5
Source File: NodeStoreInspector.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
   * Output the node 
   * 
   * @param iIndent int
   * @param nodeService NodeService
   * @param nodeRef NodeRef
   * @return String
   */
  private static String outputNode(int iIndent, NodeService nodeService, NodeRef nodeRef)
  {
      StringBuilder builder = new StringBuilder();
      
try
{
       QName nodeType = nodeService.getType(nodeRef);
       builder.
           append(getIndent(iIndent)).
           append("node: ").
           append(nodeRef.getId()).
           append(" (").
           append(nodeType.getLocalName());
	
	Collection<QName> aspects = nodeService.getAspects(nodeRef);
	for (QName aspect : aspects) 
	{
		builder.
			append(", ").
			append(aspect.getLocalName());
	}
	
       builder.append(")\n");        

       Map<QName, Serializable> props = nodeService.getProperties(nodeRef);
       for (QName name : props.keySet())
       {
		String valueAsString = "null";
		Serializable value = props.get(name);
		if (value != null)
		{
			valueAsString = value.toString();
		}
		
           builder.
               append(getIndent(iIndent+1)).
               append("@").
               append(name.getLocalName()).
               append(" = ").
               append(valueAsString).
               append("\n");
           
       }

          Collection<ChildAssociationRef> childAssocRefs = nodeService.getChildAssocs(nodeRef);
          for (ChildAssociationRef childAssocRef : childAssocRefs)
          {
              builder.
                  append(getIndent(iIndent+1)).
                  append("-> ").
                  append(childAssocRef.getQName().toString()).
                  append(" (").
                  append(childAssocRef.getQName().toString()).
                  append(")\n");
              
              builder.append(outputNode(iIndent+2, nodeService, childAssocRef.getChildRef()));
          }

          Collection<AssociationRef> assocRefs = nodeService.getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL);
          for (AssociationRef assocRef : assocRefs)
          {
              builder.
                  append(getIndent(iIndent+1)).
                  append("-> associated to ").
                  append(assocRef.getTargetRef().getId()).
                  append("\n");
          }
}
catch (InvalidNodeRefException invalidNode)
{
	invalidNode.printStackTrace();
}
      
      return builder.toString();
  }