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

The following examples show how to use org.alfresco.service.cmr.repository.NodeService#getType() . 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: ContentClassFilter.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public boolean accept(NodeRef thisNode)
{
    if (!initialised)
    {
        init();
    }
    NodeService nodeService = serviceRegistry.getNodeService();

    Set<QName> nodesAspects = nodeService.getAspects(thisNode);
    QName type = nodeService.getType(thisNode);

    boolean typeIsInSet = types.contains(type);
    boolean aspectIsInSet = false;
    for (QName aspect : nodesAspects)
    {
        if (aspects.contains(aspect))
        {
            aspectIsInSet = true;
            break;
        }
    }
    return (!exclude && (typeIsInSet || aspectIsInSet)) || (exclude && (!typeIsInSet && !aspectIsInSet));
}
 
Example 2
Source File: Workflow.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @return the resources from the package attached to this workflow task
 */
public List<TemplateContent> getPackageResources()
{
    List<TemplateContent> resources = new ArrayList<TemplateContent>();
    List<NodeRef> contents = this.services.getWorkflowService().getPackageContents(this.task.id);
    
    NodeService nodeService = this.services.getNodeService();
    DictionaryService ddService = this.services.getDictionaryService();
    
    for(NodeRef nodeRef : contents)
    {
        QName type = nodeService.getType(nodeRef);

        // make sure the type is defined in the data dictionary
        if (ddService.getType(type) != null)
        {
            // look for content nodes or links to content
            // NOTE: folders within workflow packages are ignored for now
            if (ddService.isSubClass(type, ContentModel.TYPE_CONTENT) || 
                    ApplicationModel.TYPE_FILELINK.equals(type))
            {
                resources.add(new TemplateNode(nodeRef, this.services, this.resolver));
            }
        }
    }
    return resources;
}
 
Example 3
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 4
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();
}
 
Example 5
Source File: ArchivedNodeState.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static ArchivedNodeState create(NodeRef archivedNode, ServiceRegistry serviceRegistry)
{
    ArchivedNodeState result = new ArchivedNodeState();
    
    NodeService nodeService = serviceRegistry.getNodeService();
    Map<QName, Serializable> properties = nodeService.getProperties(archivedNode);

    result.archivedNodeRef = archivedNode;
    result.archivedBy = (String) properties.get(ContentModel.PROP_ARCHIVED_BY);
    result.archivedDate = (Date) properties.get(ContentModel.PROP_ARCHIVED_DATE);
    result.name = (String) properties.get(ContentModel.PROP_NAME);
    result.title = (String) properties.get(ContentModel.PROP_TITLE);
    result.description = (String) properties.get(ContentModel.PROP_DESCRIPTION);
    QName type = nodeService.getType(archivedNode);
    result.isContentType = (type.equals(ContentModel.TYPE_CONTENT) || serviceRegistry.getDictionaryService().isSubClass(type, ContentModel.TYPE_CONTENT));
    result.nodeType = type.toPrefixString(serviceRegistry.getNamespaceService());

    PersonService personService = serviceRegistry.getPersonService();
    if (result.archivedBy != null && personService.personExists(result.archivedBy))
    {
        NodeRef personNodeRef = personService.getPerson(result.archivedBy, false);
        Map<QName, Serializable> personProps = nodeService.getProperties(personNodeRef);
        
        result.firstName = (String) personProps.get(ContentModel.PROP_FIRSTNAME);
        result.lastName = (String) personProps.get(ContentModel.PROP_LASTNAME);
    }
    
    ChildAssociationRef originalParentAssoc = (ChildAssociationRef) properties.get(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC);
    
    if (serviceRegistry.getPermissionService().hasPermission(originalParentAssoc.getParentRef(), PermissionService.READ).equals(AccessStatus.ALLOWED)
            && nodeService.exists(originalParentAssoc.getParentRef()))
    {
       result.displayPath = PathUtil.getDisplayPath(nodeService.getPath(originalParentAssoc.getParentRef()), true);
    }
    else
    {
       result.displayPath = "";
    }
    
    return result;
}