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

The following examples show how to use org.alfresco.service.cmr.repository.NodeService#addAspect() . 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: AbstractEmailMessageHandler.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Adds new node into Alfresco repository and mark its as an attachment.
 * 
 * @param nodeService Alfresco Node Service.
 * @param folder Space/Folder to add.
 * @param mainContentNode Main content node. Any mail is added into Alfresco as one main content node and several its attachments. Each attachment related with its main node.
 * @param fileName File name for the attachment.
 * @return Reference to created node.
 */
protected NodeRef addAttachment(NodeService nodeService, NodeRef folder, NodeRef mainContentNode, String fileName)
{
    
    if (log.isDebugEnabled())
    {
        log.debug("Adding attachment node (name=" + fileName + ").");
    }
    
    NodeRef attachmentNode = addContentNode(nodeService, folder, fileName, false);
    
    // Add attached aspect
    nodeService.addAspect(mainContentNode, ContentModel.ASPECT_ATTACHABLE, null);
    // Add the association
    nodeService.createAssociation(mainContentNode, attachmentNode, ContentModel.ASSOC_ATTACHMENTS);
    
    if (log.isDebugEnabled())
    {
        log.debug("Attachment has been added.");
    }
    return attachmentNode;
}
 
Example 2
Source File: DocumentEmailMessageHandler.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
     * Adds forum node
     * 
     * @param nodeRef Paren node
     * @return Reference to created node
     */
    private NodeRef addForumNode(NodeRef nodeRef)
    {
        NodeService nodeService = getNodeService();
        
//        //Add discussable aspect to content node
//        if (!nodeService.hasAspect(nodeRef, ForumModel.ASPECT_DISCUSSABLE))
//        {
//            nodeService.addAspect(nodeRef, ForumModel.ASPECT_DISCUSSABLE, null);
//        }

        //Create forum node and associate it with content node
        Map<QName, Serializable> properties = new HashMap<QName, Serializable>(1);
        properties.put(ContentModel.PROP_NAME, forumNodeName);
        ChildAssociationRef childAssoc = nodeService.createNode(nodeRef, ForumModel.ASSOC_DISCUSSION, ForumModel.ASSOC_DISCUSSION, ForumModel.TYPE_FORUM, properties);
        NodeRef forumNode = childAssoc.getChildRef();        

        //Add necessary aspects to forum node
        properties.clear();
        properties.put(ApplicationModel.PROP_ICON, "forum");
        nodeService.addAspect(forumNode, ApplicationModel.ASPECT_UIFACETS, properties);
        
        return forumNode;
    }
 
Example 3
Source File: IncomingImapMessage.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void buildMessageInternal() throws MessagingException
{
    setMessageHeaders();
    // Add Imap Content Aspect with properties
    NodeService nodeService = serviceRegistry.getNodeService();
    nodeService.addAspect(this.messageFileInfo.getNodeRef(), ImapModel.ASPECT_IMAP_CONTENT, null);
    imapService.setFlags(messageFileInfo, flags, true);
    // Write content
    writeContent();
}
 
Example 4
Source File: InvitationWebScriptTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static String makeAvatar(final NodeService nodeService, final NodeRef person)
{
    nodeService.addAspect(person, ContentModel.ASPECT_PREFERENCES, null);
    ChildAssociationRef assoc = nodeService.createNode(person, ContentModel.ASSOC_PREFERENCE_IMAGE, avatarQName,
                ContentModel.TYPE_CONTENT);
    NodeRef avatar = assoc.getChildRef();
    nodeService.createAssociation(person, avatar, ContentModel.ASSOC_AVATAR);
    return "api/node/" + avatar + "/content/thumbnails/avatar";
}
 
Example 5
Source File: AbstractForumEmailMessageHandler.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Posts content
 * 
 * @param nodeRef   Reference to node
 * @param message    Mail parser
 * @return          Returns the new post node
 */
protected NodeRef addPostNode(NodeRef nodeRef, EmailMessage message)
{
    NodeService nodeService = getNodeService();
    Date now = new Date();
    String nodeName = "posted-" + new SimpleDateFormat("dd-MM-yyyy-hh-mm-ss").format(now) + ".html";

    PropertyMap properties = new PropertyMap(3);
    properties.put(ContentModel.PROP_NAME, nodeName);

    NodeRef postNodeRef = nodeService.getChildByName(nodeRef, ContentModel.ASSOC_CONTAINS, nodeName);
    if (postNodeRef == null)
    {
        ChildAssociationRef childAssoc = nodeService.createNode(
                nodeRef,
                ContentModel.ASSOC_CONTAINS,
                QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, nodeName),
                ForumModel.TYPE_POST,
                properties);
        postNodeRef = childAssoc.getChildRef();
    }

    // Add necessary aspects
    properties.clear();
    properties.put(ContentModel.PROP_TITLE, nodeName);
    nodeService.addAspect(postNodeRef, ContentModel.ASPECT_TITLED, properties);
    properties.clear();
    properties.put(ApplicationModel.PROP_EDITINLINE, true);
    nodeService.addAspect(postNodeRef, ApplicationModel.ASPECT_INLINEEDITABLE, properties);

    // Write content
    if (message.getBody() != null)
    {
        writeContent(
                postNodeRef,
                message.getBody().getContent(),
                message.getBody().getContentType(),
                message.getBody().getEncoding());
    }
    else
    {
        writeContent(postNodeRef, "<The message was empty>", MimetypeMap.MIMETYPE_TEXT_PLAIN);
    }
    addEmailedAspect(postNodeRef, message);
    
    // Done
    return postNodeRef;
}
 
Example 6
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 7
Source File: AbstractSignatureActionExecuter.java    From CounterSign with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Creates a "signature" object and associates it with the signed doc
 * @param node
 * @param location
 * @param reason
 */
protected NodeRef addSignatureNodeAssociation(NodeRef node, String location, String reason, 
		String signatureField, java.util.Date sigDate, String geolocation, int page, String position)
{
	NodeService nodeService = serviceRegistry.getNodeService();
	
	String userId = AuthenticationUtil.getRunAsUser();
	NodeRef person = serviceRegistry.getPersonService().getPerson(userId);
	
	// if page is -1, then this was a signature field, set position to "none"
	if(page == -1) position = "none";
	
	HashMap<QName, Serializable> props = new HashMap<QName, Serializable>();
	props.put(CounterSignSignatureModel.PROP_REASON, reason);
	props.put(CounterSignSignatureModel.PROP_LOCATION, location);
	props.put(CounterSignSignatureModel.PROP_SIGNATUREDATE, sigDate);
	props.put(CounterSignSignatureModel.PROP_SIGNATUREFIELD, signatureField);
	props.put(CounterSignSignatureModel.PROP_SIGNATUREPAGE, page);
	props.put(CounterSignSignatureModel.PROP_SIGNATUREPOSITION, position);
	props.put(CounterSignSignatureModel.PROP_EXTERNALSIGNER, userId);
	
	// check the geolocation data, if it is valid, split it out and add
	if(geolocation.indexOf(",") != -1)
	{
		String[] latLong = geolocation.split(",");
		props.put(ContentModel.PROP_LATITUDE, latLong[0]);
		props.put(ContentModel.PROP_LONGITUDE, latLong[1]);
	}
	else
	{
		props.put(ContentModel.PROP_LATITUDE, -1);
		props.put(ContentModel.PROP_LONGITUDE, -1);
	}
	
	QName assocQName = QName.createQName(
			CounterSignSignatureModel.COUNTERSIGN_SIGNATURE_MODEL_1_0_URI,
			QName.createValidLocalName(userId + "-" + sigDate.getTime()));
		
	ChildAssociationRef sigChildRef = nodeService.createNode(
			node, 
			CounterSignSignatureModel.ASSOC_SIGNATURES, 
			assocQName, 
			CounterSignSignatureModel.TYPE_SIGNATURE, 
			props);
	
	NodeRef signature = sigChildRef.getChildRef();
	
	// add hidden aspect to signature nodes, these should not be 
	// shown in any document lists or other Share views
	HashMap<QName, Serializable> aspectProps = new HashMap<QName, Serializable>();
	aspectProps.put(ContentModel.PROP_VISIBILITY_MASK, HiddenAspect.Visibility.NotVisible.getMask());
	nodeService.addAspect(signature, ContentModel.ASPECT_HIDDEN, aspectProps);

	nodeService.createAssociation(signature, person, CounterSignSignatureModel.ASSOC_SIGNEDBY);
	
	return signature;
}