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

The following examples show how to use org.alfresco.service.cmr.repository.NodeService#getProperty() . 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: ScriptUser.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Constructs a scriptable object representing a user.
 * 
 * @param userName The username
 * @param personNodeRef The NodeRef
 * @param serviceRegistry A ServiceRegistry instance
 * @param scope Script scope
 * @since 4.0
 */
public ScriptUser(String userName, NodeRef personNodeRef, ServiceRegistry serviceRegistry, Scriptable scope)
{
   this.serviceRegistry = serviceRegistry;
   this.authorityService = serviceRegistry.getAuthorityService();
   this.personService = serviceRegistry.getPersonService();
   this.scope = scope;
   this.personNodeRef = personNodeRef == null ? personService.getPerson(userName) : personNodeRef;
   this.userName = userName;
   
   this.shortName = authorityService.getShortName(userName);
   NodeService nodeService = serviceRegistry.getNodeService();
   String firstName = (String)nodeService.getProperty(this.personNodeRef, ContentModel.PROP_FIRSTNAME);
   String lastName = (String)nodeService.getProperty(this.personNodeRef, ContentModel.PROP_LASTNAME);
   this.displayName = this.fullName = (firstName != null ? firstName : "") + (lastName != null ? (' ' + lastName) : "");
}
 
Example 2
Source File: AbstractMimeMessage.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void setPersistedHeaders() throws MessagingException
{
    NodeService nodeService = serviceRegistry.getNodeService();
    if (nodeService.hasAspect(messageFileInfo.getNodeRef(), ImapModel.ASPECT_IMAP_MESSAGE_HEADERS))
    {
        @SuppressWarnings("unchecked")
        List<String> messageHeaders = (List<String>)nodeService.getProperty(messageFileInfo.getNodeRef(), ImapModel.PROP_MESSAGE_HEADERS);
        
        if (messageHeaders == null)
        {
            return;
        }
        
        for (String header : messageHeaders)
        {
            String headerValue = header.substring(header.indexOf(ImapModel.MESSAGE_HEADER_TO_PERSIST_SPLITTER) + 1);
            String headerName  = header.substring(0, header.indexOf(ImapModel.MESSAGE_HEADER_TO_PERSIST_SPLITTER));
            
            setHeader(headerName, headerValue);
        }
    }
}
 
Example 3
Source File: NodeUtils.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Comparator<NodeRef> getNodeCreationDateComparator(final NodeService nodeService)
{
    return new Comparator<NodeRef>()
    {
        private Map<NodeRef, Long> dates = new HashMap<NodeRef, Long>();
        
        public int compare(NodeRef o1, NodeRef o2)
        {
            long date1 = getDate(o1);
            long date2 = getDate(o1);
            return (int)(date1 - date2);
        }

        private long getDate(NodeRef node)
        {
            Long date = dates.get(node);
            if(date == null)
            {
                Date dateObj = (Date) nodeService.getProperty(node, ContentModel.PROP_CREATED);
                date = dateObj == null ? -1 : dateObj.getTime();
                dates.put(node, date);
            }
            return date;
        }
    }; 
}
 
Example 4
Source File: UserNameDisplayHandler.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public FacetLabel getDisplayLabel(String value)
{
    String name = null;

    final NodeRef personRef = serviceRegistry.getPersonService().getPersonOrNull(value);
    if (personRef != null)
    {
        NodeService nodeService = serviceRegistry.getNodeService();
        final String firstName = (String) nodeService.getProperty(personRef, ContentModel.PROP_FIRSTNAME);
        final String lastName = (String) nodeService.getProperty(personRef, ContentModel.PROP_LASTNAME);
        name = (firstName != null ? firstName + " " : "") + (lastName != null ? lastName : "");
    }
    return new FacetLabel(value, name == null ? value : name.trim(), -1);
}
 
Example 5
Source File: StandardRenditionLocationResolverImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * This method creates a {@link RenditionLocation} object from the specified destination node.
 * This is formed from the specified destination NodeRef, its cm:name and its primary parent.
 * 
 * @param destination NodeRef
 * @return RenditionLocationImpl
 * @throws RenditionServiceException if the destination node does not exist.
 */
private RenditionLocationImpl createNodeLocation(NodeRef destination)
{
    NodeService nodeService = serviceRegistry.getNodeService();
    if(nodeService.exists(destination)==false)
        throw new RenditionServiceException("The rendition destination node does not exist! NodeRef: "+destination);
    
    NodeRef parentRef = nodeService.getPrimaryParent(destination).getParentRef();
    String destinationCmName = (String) nodeService.getProperty(destination, ContentModel.PROP_NAME);
    RenditionLocationImpl location  = new RenditionLocationImpl(parentRef, destination, destinationCmName);
    return location;
}
 
Example 6
Source File: People.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Faster helper when the script just wants to build the Full name for a person.
 * Avoids complete getProperties() retrieval for a cm:person.
 * 
 * @param username  the username of the person to get Full name for
 * @return full name for a person or null if the user does not exist in the system.
 */
public String getPersonFullName(final String username)
{
    String name = null;
    ParameterCheck.mandatoryString("Username", username);
    final NodeRef personRef = personService.getPersonOrNull(username);
    if (personRef != null)
    {
        final NodeService nodeService = services.getNodeService();
        final String firstName = (String)nodeService.getProperty(personRef, ContentModel.PROP_FIRSTNAME);
        final String lastName = (String)nodeService.getProperty(personRef, ContentModel.PROP_LASTNAME);
        name = (firstName != null ? firstName + " " : "") + (lastName != null ? lastName : "");
    }
    return name;
}
 
Example 7
Source File: SiteState.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static SiteState create(SiteInfo siteInfo, Map<String, String> members, String currentUser,
            NodeService nodeService, PersonService personService)
{
    SiteState result = new SiteState();
    result.members = new ArrayList<MemberState>(members.size());

    result.siteInfo = siteInfo;

    boolean found = false;
    Set<String> siteMembers = members.keySet();
    for (String userName : siteMembers)
    {
        NodeRef person = personService.getPersonOrNull(userName);
        if (person != null)
        {
            String firstName = (String) nodeService.getProperty(person, ContentModel.PROP_FIRSTNAME);
            String lastName = (String) nodeService.getProperty(person, ContentModel.PROP_LASTNAME);
            result.members.add(new MemberState(userName, firstName, lastName));
        }
        
        if (!found && userName.equals(currentUser))
        {
            found = true;
            result.currentUserSiteManager = true;
        }
    }

    return result;
}
 
Example 8
Source File: ScriptActionExecuter.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef)
 */
protected void executeImpl(Action action, NodeRef actionedUponNodeRef)
{
    NodeService nodeService = this.serviceRegistry.getNodeService();
    if (nodeService.exists(actionedUponNodeRef))
    {
        NodeRef scriptRef = (NodeRef)action.getParameterValue(PARAM_SCRIPTREF);
        NodeRef spaceRef = this.serviceRegistry.getRuleService().getOwningNodeRef(action);
        if (spaceRef == null)
        {
            // the actionedUponNodeRef may actually be a space
            if (this.serviceRegistry.getDictionaryService().isSubClass(
                    nodeService.getType(actionedUponNodeRef), ContentModel.TYPE_FOLDER))
            {
                spaceRef = actionedUponNodeRef;
            }
            else
            {
                spaceRef = nodeService.getPrimaryParent(actionedUponNodeRef).getParentRef();
            }
        }
        
        if (this.scriptLocation != null || (scriptRef != null && nodeService.exists(scriptRef) == true))
        {
            // get the references we need to build the default scripting data-model
            String userName = this.serviceRegistry.getAuthenticationService().getCurrentUserName();
            NodeRef personRef = this.personService.getPerson(userName);
            NodeRef homeSpaceRef = (NodeRef)nodeService.getProperty(personRef, ContentModel.PROP_HOMEFOLDER);
            
            // the default scripting model provides access to well known objects and searching
            // facilities - it also provides basic create/update/delete/copy/move services
            Map<String, Object> model = this.serviceRegistry.getScriptService().buildDefaultModel(
                    personRef,
                    getCompanyHome(),
                    homeSpaceRef,
                    scriptRef,
                    actionedUponNodeRef,
                    spaceRef);
            
            // Add the action to the default model
            ScriptAction scriptAction = new ScriptAction(this.serviceRegistry, action, this.actionDefinition);
            model.put("action", scriptAction);

            model.put("webApplicationContextUrl", UrlUtil.getAlfrescoUrl(sysAdminParams)); 

            Object result = null;
            if (this.scriptLocation == null)
            {
                // execute the script against the default model
                result = this.serviceRegistry.getScriptService().executeScript(
                    scriptRef,
                    ContentModel.PROP_CONTENT,
                    model);
            }
            else
            {
                // execute the script at the specified script location
                result = this.serviceRegistry.getScriptService().executeScript(this.scriptLocation, model);
            }
            
            // Set the result
            if (result != null)
            {
                action.setParameterValue(PARAM_RESULT, (Serializable)result);
            }
        }
    }
}
 
Example 9
Source File: XmlMetadataExtracterTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Tests metadata extraction using an action with an EAGER MetadataExtracter for XML.
 */
public void testLifecycleOfXmlMetadataExtraction() throws Exception
{
    NodeService nodeService = serviceRegistry.getNodeService();
    ContentService contentService = serviceRegistry.getContentService();
    ActionExecuter executer = (ActionExecuter) ctx.getBean("extract-metadata");
    Action action = new ActionImpl(null, GUID.generate(), SetPropertyValueActionExecuter.NAME, null);
    
    StoreRef storeRef = new StoreRef("test", getName());
    NodeRef rootNodeRef = null;
    if (nodeService.exists(storeRef))
    {
        rootNodeRef = nodeService.getRootNode(storeRef);
    }
    else
    {
        nodeService.createStore("test", getName());
        rootNodeRef = nodeService.getRootNode(storeRef);
    }
    
    // Set up some properties
    PropertyMap properties = new PropertyMap();
    properties.put(ContentModel.PROP_TITLE, "My title");
    properties.put(ContentModel.PROP_DESCRIPTION, "My description");
    
    NodeRef contentNodeRef = nodeService.createNode(
            rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, getName()),
            ContentModel.TYPE_CONTENT,
            properties).getChildRef();
    // Add some content
    ContentReader alfrescoModelReader = getReader(FILE_ALFRESCO_MODEL);
    assertTrue(alfrescoModelReader.exists());
    ContentWriter writer = contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true);
    writer.setEncoding("UTF-8");
    writer.setMimetype(MimetypeMap.MIMETYPE_XML);
    writer.putContent(alfrescoModelReader);
    
    // Execute the action
    executer.execute(action, contentNodeRef);
    
    // Check the node's properties.  The EAGER overwrite policy should have replaced the required
    // properties.
    String checkTitle = (String) nodeService.getProperty(contentNodeRef, ContentModel.PROP_TITLE);
    String checkDescription = (String) nodeService.getProperty(contentNodeRef, ContentModel.PROP_DESCRIPTION);
    assertEquals("fm:forummodel", checkTitle);
    assertEquals("Forum Model", checkDescription);
}