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

The following examples show how to use org.alfresco.service.cmr.repository.NodeService#getChildAssocs() . 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<ChildAssociationRef> existingChildren = nodeService.getChildAssocs(sourceNodeRef);

    for (ChildAssociationRef assoc : existingChildren)
    {
        if (assoc.getChildRef().equals(targetNodeRef))
        {
            if (logger.isWarnEnabled())
            {
                logger.warn("Attempt to add existing child association prevented. " + assoc);
            }
            return;
        }
    }
    
    // We are following the behaviour of the JSF client here in using the same
    // QName value for the 3rd and 4th parameters in the below call.
    nodeService.addChild(sourceNodeRef, targetNodeRef, assocQName, assocQName);
}
 
Example 2
Source File: ChildAssociatedNodeFinder.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 all the child nodes (filtering as necessary).
    List<ChildAssociationRef> children = nodeService.getChildAssocs(thisNode);
    boolean filterChildren = !childAssociationTypes.isEmpty();
    for (ChildAssociationRef child : children)
    {
        if (!filterChildren || !childAssociationTypes.contains(child.getTypeQName()))
        {
            results.add(child.getChildRef());
        }
    }
    return results;
}
 
Example 3
Source File: SystemNodeUtils.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns the System Container for the current tenant
 */
public static NodeRef getSystemContainer(final NodeService nodeService, final Repository repositoryHelper)
{
    // Grab the root of the repository, for the current tennant
    final NodeRef root = repositoryHelper.getRootHome();

    // Locate the system folder, in the root 
    List<ChildAssociationRef> sysRefs = nodeService.getChildAssocs(
            root, ContentModel.ASSOC_CHILDREN, SYSTEM_FOLDER_QNAME);
    if (sysRefs.size() != 1)
    {
        throw new IllegalStateException("System folder missing / duplicated! Found " + sysRefs);
    }
    final NodeRef system = sysRefs.get(0).getChildRef();
    
    return system;
}
 
Example 4
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<ChildAssociationRef> existingChildren = nodeService.getChildAssocs(sourceNodeRef);
    boolean childAssocDoesNotExist = true;
    for (ChildAssociationRef assoc : existingChildren)
    {
        if (assoc.getChildRef().equals(targetNodeRef))
        {
            childAssocDoesNotExist = false;
            break;
        }
    }
    if (childAssocDoesNotExist)
    {
        if (logger.isWarnEnabled())
        {
            StringBuilder msg = new StringBuilder();
            msg.append("Attempt to remove non-existent child association prevented. ").append(sourceNodeRef)
                        .append("|").append(targetNodeRef).append(assocQName);
            logger.warn(msg.toString());
        }
        return;
    }

    nodeService.removeChild(sourceNodeRef, targetNodeRef);
}
 
Example 5
Source File: ChildAssociatedNodeFinder.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 : childAssociationTypes)
    {
        List<ChildAssociationRef> children = nodeService.getChildAssocs(startingNode, assocType,
                RegexQNamePattern.MATCH_ALL);
        for (ChildAssociationRef child : children)
        {
            foundNodes.add(child.getChildRef());
        }
    }
    return foundNodes;
}
 
Example 6
Source File: AbstractManifestProcessorBase.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Puts information about current <code>childRef</code> and its <code>parentRef</code> into log in TRACE level. Information includes 'name', 'fromRepositoryId', 'aliened' and
 * 'invadedBy' properties. Additionally, collects the same information for children of <code>childRef</code>
 * 
 * @param parentRef - {@link NodeRef} instance of child node
 * @param childRef - {@link NodeRef} instance of parent of the <code>childRef</code>
 * @param nodeService - {@link NodeService} instance to get properties and checking other states
 * @param log - {@link Log} instance to put log for appropriate class
 */
protected void logInvasionHierarchy(NodeRef parentRef, NodeRef childRef, NodeService nodeService, Log log)
{
    Map<QName, Serializable> properties = nodeService.getProperties(childRef);
    Map<QName, Serializable> parentProperties = nodeService.getProperties(parentRef);
    StringBuilder message = new StringBuilder("Information about '").append(properties.get(ContentModel.PROP_NAME)).append("' node:\n    fromRepositoryId: ").append(
            properties.get(TransferModel.PROP_FROM_REPOSITORY_ID)).append("\n").append("    invadedBy: ").append(properties.get(TransferModel.PROP_INVADED_BY)).append("\n")
            .append("    alien: ").append(nodeService.hasAspect(childRef, TransferModel.ASPECT_ALIEN)).append("\n").append("    repositoryId: ").append(
                    properties.get(TransferModel.PROP_REPOSITORY_ID)).append("\n").append("    parent: ").append(parentProperties.get(ContentModel.PROP_NAME)).append("(")
            .append(parentProperties.get(TransferModel.PROP_FROM_REPOSITORY_ID)).append(")").append(parentProperties.get(TransferModel.PROP_INVADED_BY)).append(": ").append(
                    nodeService.hasAspect(parentRef, TransferModel.ASPECT_ALIEN)).append("\n").append("    children:\n");

    List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(childRef);

    if ((null != childAssocs) && !childAssocs.isEmpty())
    {
        for (ChildAssociationRef child : childAssocs)
        {
            properties = nodeService.getProperties(child.getChildRef());
            message.append("        ").append(properties.get(ContentModel.PROP_NAME)).append("(").append(properties.get(TransferModel.PROP_FROM_REPOSITORY_ID)).append(")")
                    .append(properties.get(TransferModel.PROP_INVADED_BY)).append(": ").append(nodeService.hasAspect(child.getChildRef(), TransferModel.ASPECT_ALIEN)).append(
                            "\n");
        }
    }

    log.trace(message.toString());
}
 
Example 7
Source File: AlfrescoEnviroment.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public List<ChildAssociationRef> getChildAssocs(NodeRef nodeRef, QNamePattern typeQNamePattern,
            QNamePattern qnamePattern, int maxResults, boolean preload) throws InvalidNodeRefException
{
    NodeService nodeService = apiFacet.getNodeService();
    return nodeService.getChildAssocs(nodeRef,
                                      typeQNamePattern,
                                      qnamePattern,
                                      maxResults,
                                      preload);
}
 
Example 8
Source File: ScheduledPersistedActionServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private List<ScheduledPersistedAction> listSchedules(NodeService nodeService)
{
    List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(
                SCHEDULED_ACTION_ROOT_NODE_REF, ACTION_TYPES);

    List<ScheduledPersistedAction> scheduledActions = new ArrayList<ScheduledPersistedAction>(
                childAssocs.size());
    for (ChildAssociationRef actionAssoc : childAssocs)
    {
        ScheduledPersistedActionImpl scheduleImpl = loadPersistentSchedule(actionAssoc.getChildRef());
        scheduledActions.add(scheduleImpl);
    }

    return scheduledActions;
}
 
Example 9
Source File: RepositoryFolderConfigBean.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Helper method to find or create the folder path referenced by this bean.
 * The {@link #getFolderPath() path} to the start of the folder path
 * must exist.  The folder path will be created, if required.
 * <p>
 * Authentication and transactions are the client's responsibility.
 * 
 * @return                      Returns an existing or new folder reference
 */
public NodeRef getOrCreateFolderPath(
        NamespaceService namespaceService,
        NodeService nodeService,
        SearchService searchService,
        FileFolderService fileFolderService)
{
    NodeRef pathStartNodeRef = super.resolveNodePath(namespaceService, nodeService, searchService);
    if (pathStartNodeRef == null)
    {
        throw new AlfrescoRuntimeException(
                "Folder path resolution requires an existing base path. \n" +
                "   Base path: " + getRootPath());
    }
    // Just choose the root path if the folder path is empty
    if (folderPath.length() == 0)
    {
        return pathStartNodeRef;
    }
    else
    {
        StringTokenizer folders = new StringTokenizer(folderPath, "/");
        NodeRef nodeRef = pathStartNodeRef;
        while (folders.hasMoreTokens())
        {
            QName folderQName = QName.createQName(folders.nextToken(), namespaceService);
            List<ChildAssociationRef> children = nodeService.getChildAssocs(nodeRef, RegexQNamePattern.MATCH_ALL, folderQName); 
            if (children.isEmpty())
            {
                nodeRef = fileFolderService.create(nodeRef, folderQName.getLocalName(), ContentModel.TYPE_FOLDER, folderQName).getNodeRef();
            }
            else
            {
                nodeRef = children.get(0).getChildRef();
            }
        }
        return nodeRef;
    }
    // Done
}
 
Example 10
Source File: FFCLoadsOfFiles.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void doExample(ServiceRegistry serviceRegistry) throws Exception
    {
        //
        // locate the company home node
        //
        SearchService searchService = serviceRegistry.getSearchService();
        NodeService nodeService = serviceRegistry.getNodeService();
        NamespaceService namespaceService = serviceRegistry.getNamespaceService();
        StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
        NodeRef rootNodeRef = nodeService.getRootNode(storeRef);
        List<NodeRef> results = searchService.selectNodes(rootNodeRef, "/app:company_home", null, namespaceService, false);
        if (results.size() == 0)
        {
            throw new AlfrescoRuntimeException("Can't find /app:company_home");
        }
        NodeRef companyHomeNodeRef = results.get(0);
        results = searchService.selectNodes(companyHomeNodeRef, "./cm:LoadTest", null, namespaceService, false);
        final NodeRef loadTestHome;
        if (results.size() == 0)
        {
            loadTestHome = nodeService.createNode(
                    companyHomeNodeRef,
                    ContentModel.ASSOC_CHILDREN,
                    QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "LoadTest"),
                    ContentModel.TYPE_FOLDER).getChildRef();
        }
        else
        {
            loadTestHome = results.get(0);
        }

        if ((currentDoc + docsPerTx) > totalNumDocs)
        {
        	docsPerTx = totalNumDocs - currentDoc;
        }
        // Create new Space
        String spaceName = "Bulk Load Space (" + System.currentTimeMillis() + ") from " + currentDoc + " to " + (currentDoc + docsPerTx - 1) + " of " + totalNumDocs;
        Map<QName, Serializable> spaceProps = new HashMap<QName, Serializable>();
    	spaceProps.put(ContentModel.PROP_NAME, spaceName);
        NodeRef  newSpace = nodeService.createNode(loadTestHome, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, spaceName),ContentModel.TYPE_FOLDER,spaceProps).getChildRef();
        

        // create new content node within new Space home
        for (int k = 1;k<=docsPerTx;k++)
        {
    		currentDoc++;
    		System.out.println("About to start document " + currentDoc);
        	// assign name
        	String name = "BulkLoad (" + System.currentTimeMillis() + ") " + currentDoc ;
        	Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
        	contentProps.put(ContentModel.PROP_NAME, name);
        	
        	// create content node
        	// NodeService nodeService = serviceRegistry.getNodeService();
        	ChildAssociationRef association = nodeService.createNode(newSpace, 
        			ContentModel.ASSOC_CONTAINS, 
        			QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, name),
        			ContentModel.TYPE_CONTENT,
        			contentProps);
        	NodeRef content = association.getChildRef();
        
        	// add titled aspect (for Web Client display)
        	Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>();
        	titledProps.put(ContentModel.PROP_TITLE, name);
        	titledProps.put(ContentModel.PROP_DESCRIPTION, name);
        	nodeService.addAspect(content, ContentModel.ASPECT_TITLED, titledProps);
        	
        	//
        	// write some content to new node
        	//

        	ContentService contentService = serviceRegistry.getContentService();
        	ContentWriter writer = contentService.getWriter(content, ContentModel.PROP_CONTENT, true);
        	writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
        	writer.setEncoding("UTF-8");
        	String text = "This is some text in a doc";
        	writer.putContent(text);
    		System.out.println("About to get child assocs ");        	
        	//Circa
//        	nodeService.getChildAssocs(newSpace);
    	       for (int count=0;count<=10000;count++)
    	        {
    	        	nodeService.getChildAssocs(newSpace);
    	        }
       	
        }
    	//doSearch(searchService);
 		System.out.println("About to end transaction " );

    }
 
Example 11
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();
  }
 
Example 12
Source File: ReplicationServiceIntegrationTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE)
    {
        fail("Dangling transaction detected, left by a previous test.");
    }
    ctx = (ConfigurableApplicationContext) ApplicationContextHelper.getApplicationContext();
    replicationActionExecutor = (ReplicationActionExecutor) ctx.getBean("replicationActionExecutor");
    replicationService = (ReplicationService) ctx.getBean("replicationService");
    replicationParams = (ReplicationParams) ctx.getBean("replicationParams");
    transactionService = (TransactionService) ctx.getBean("transactionService");
    transferService = (TransferService2) ctx.getBean("transferService2");
    contentService = (ContentService) ctx.getBean("contentService");
    jobLockService = (JobLockService) ctx.getBean("jobLockService");
    actionService = (ActionService) ctx.getBean("actionService");
    scriptService = (ScriptService)ctx.getBean("scriptService");
    nodeService = (NodeService) ctx.getBean("NodeService");
    lockService = (LockService) ctx.getBean("lockService");
    repositoryHelper = (Repository) ctx.getBean("repositoryHelper");
    actionTrackingService = (ActionTrackingService) ctx.getBean("actionTrackingService");
    scheduledPersistedActionService = (ScheduledPersistedActionService) ctx.getBean("scheduledPersistedActionService");
    
    // Set the current security context as admin
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    
    replicationParams.setEnabled(true);
    
    UserTransaction txn = transactionService.getUserTransaction();
    txn.begin();
    
    // Zap any existing replication entries
    replicationRoot = ReplicationDefinitionPersisterImpl.REPLICATION_ACTION_ROOT_NODE_REF;
    for(ChildAssociationRef child : nodeService.getChildAssocs(replicationRoot)) {
       QName type = nodeService.getType( child.getChildRef() );
       if(ReplicationDefinitionPersisterImpl.ACTION_TYPES.contains(type)) {
          nodeService.deleteNode(child.getChildRef());
       }
    }
    
    // Create the test folder structure
    destinationFolder = makeNode(repositoryHelper.getCompanyHome(), ContentModel.TYPE_FOLDER, "ReplicationTransferDestination");
    folder1 = makeNode(repositoryHelper.getCompanyHome(), ContentModel.TYPE_FOLDER);
    folder2 = makeNode(repositoryHelper.getCompanyHome(), ContentModel.TYPE_FOLDER);
    folder2a = makeNode(folder2, ContentModel.TYPE_FOLDER);
    folder2b = makeNode(folder2, ContentModel.TYPE_FOLDER);
    
    content1_1 = makeNode(folder1, ContentModel.TYPE_CONTENT);
    content1_2 = makeNode(folder1, ContentModel.TYPE_CONTENT);
    thumbnail1_3 = makeNode(folder1, ContentModel.TYPE_THUMBNAIL);
    authority1_4 = makeNode(folder1, ContentModel.TYPE_AUTHORITY);
    content2a_1 = makeNode(folder2a, ContentModel.TYPE_CONTENT);
    thumbnail2a_2 = makeNode(folder2a, ContentModel.TYPE_THUMBNAIL);
    zone2a_3 = makeNode(folder2a, ContentModel.TYPE_ZONE);
    
    deletedFolder = makeNode(repositoryHelper.getCompanyHome(), ContentModel.TYPE_FOLDER);
    nodeService.deleteNode(deletedFolder);
    
    // Tell the transfer service not to use HTTP
    makeTransferServiceLocal();
    
    // Finish setup
    txn.commit();
}