Java Code Examples for org.alfresco.service.cmr.repository.NodeRef#isNodeRef()

The following examples show how to use org.alfresco.service.cmr.repository.NodeRef#isNodeRef() . 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: UUIDSupport.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void setUuids(String[] uuids)
{
    this.uuids = new String[uuids.length];

    for(int i = 0; i < uuids.length; i++)
    {
        if(NodeRef.isNodeRef(uuids[i]))
        {
            NodeRef ref = new NodeRef(uuids[i]);
            this.uuids[i] = ref.getId();
        }
        else
        {
            this.uuids[i] = uuids[i];
        }
    }
}
 
Example 2
Source File: TransformerPropertySetter.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void checkNodeRefList(boolean hasValue, String line, int i)
{
    String value = checkValue(hasValue, line, i);

    if (value != null)
    {
        for (String nodeRefString: line.split(", *"))
        {
            nodeRefString = nodeRefString.trim();
            if (nodeRefString.length() != 0 && !NodeRef.isNodeRef(nodeRefString))
            {
                throw unexpectedProperty("Expected NodeRef value "+nodeRefString, line);
            }
        }
    }
}
 
Example 3
Source File: ObjectIdLuceneBuilder.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
private <Q, S, E extends Throwable> String getValueAsString(LuceneQueryParserAdaptor<Q, S, E> lqpa, Serializable value)
{
	String nodeRefStr = null;
    if(!NodeRef.isNodeRef((String)value))
    {
        // assume the object id is the node guid
        StoreRef storeRef = getStore(lqpa);
    	nodeRefStr = storeRef.toString() + "/" + (String)value;
    }
    else
    {
    	nodeRefStr = (String)value;
    }

    Object converted = DefaultTypeConverter.INSTANCE.convert(dictionaryService.getDataType(DataTypeDefinition.NODE_REF), nodeRefStr);
    String asString = DefaultTypeConverter.INSTANCE.convert(String.class, converted);
    return asString;
}
 
Example 4
Source File: DBQuery.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static String getUUID(String source)
{
 // Ignore version label  for now
    String ref;
    String versionLabel = null;
    String[] split = source.split(";");
    if(split.length == 1)
    {
        ref = source;
    }
    else
    {
        if(split[1].equalsIgnoreCase("PWC"))
        {
            throw new UnsupportedOperationException("Query for PWC is not supported");
        }
        
        ref = split[0];
        versionLabel = split[1];
    }
    
    
    if (NodeRef.isNodeRef(ref))
    {
        NodeRef nodeRef = new NodeRef(ref);
        return nodeRef.getId();
    }

    else
    {
       return ref;
    }
}
 
Example 5
Source File: UUIDSupport.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @param uuid the uud to set
 */
public void setUuid(String uuid)
{
    if(NodeRef.isNodeRef(uuid))
    {
        NodeRef ref = new NodeRef(uuid);
        this.uuid = ref.getId();
    }
    else
    {
        this.uuid = uuid;
    }
}
 
Example 6
Source File: NodeUtils.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Function<String, NodeRef> toNodeRefQueitly()
{
    return new Function<String, NodeRef>()
    {
        public NodeRef apply(String value)
        {
            if(value!=null && NodeRef.isNodeRef(value))
            {
                return new NodeRef(value);
            }
            return null;
        }
    };
}
 
Example 7
Source File: ParentLuceneBuilder.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
private <Q, S, E extends Throwable> String getValueAsString(LuceneQueryParserAdaptor<Q, S, E> lqpa, Serializable value)
{
	String nodeRefStr = (String)value;
    if(!NodeRef.isNodeRef((String)value))
    {
        // assume the value (object id) is the node guid
        StoreRef storeRef = getStore(lqpa);
    	nodeRefStr = storeRef.toString() + "/" + (String)value;
    }

    Object converted = DefaultTypeConverter.INSTANCE.convert(dictionaryService.getDataType(DataTypeDefinition.NODE_REF), nodeRefStr);
    String asString = DefaultTypeConverter.INSTANCE.convert(String.class, converted);
    return asString;
}
 
Example 8
Source File: NodesImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 
 * @param node
 */
private boolean isFavorite(NodeRef node)
{
    PreferenceService preferenceService = (PreferenceService) sr.getService(ServiceRegistry.PREFERENCE_SERVICE);
    String currentUserName = AuthenticationUtil.getFullyAuthenticatedUser();
    Map<String, Serializable> preferences = preferenceService.getPreferences(currentUserName);

    for (Serializable nodesFavorites : preferences.values())
    {
        if (nodesFavorites instanceof String)
        {
            StringTokenizer st = new StringTokenizer((String) nodesFavorites, ",");
            while (st.hasMoreTokens())
            {
                String nodeRefStr = st.nextToken();
                nodeRefStr = nodeRefStr.trim();

                if (!NodeRef.isNodeRef((String) nodeRefStr))
                {
                    continue;
                }

                NodeRef nodeRef = new NodeRef((String) nodeRefStr);

                if (nodeRef.equals(node))
                {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 9
Source File: BaseActivitySummaryProcessor.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void process(Map<String, Object> entries)
{
	String value = (String)entries.remove(key);
	try
	{
		value = URLDecoder.decode(value, "UTF-8");
		Matcher matcher = pattern.matcher(value);
		if(matcher.matches())
		{
			String nodeRefStr = matcher.group(1);
			boolean isNodeRef = NodeRef.isNodeRef(nodeRefStr);
			if(isNodeRef)
			{
				NodeRef nodeRef = new NodeRef(nodeRefStr);
				entries.put("objectId", nodeRef.getId());
			}
			else
			{
				logger.warn("Activity page url contains an invalid NodeRef " + value);
			}
		}
		else
		{
			logger.warn("Failed to match activity page url for objectId extraction " + value);
		}
	}
	catch (UnsupportedEncodingException e)
	{
		logger.warn("Unable to decode activity page url " + value);
	}
}
 
Example 10
Source File: Activity.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Map<String, Object> getActivitySummary(JSONObject activitySummary, String activityType)
{
	Map<String, Object> summary = new HashMap<String, Object>();

	if(activityType.equals("org.alfresco.documentlibrary.file-added"))
	{
		String nodeRefStr = (String)activitySummary.remove("nodeRef");
		if(NodeRef.isNodeRef(nodeRefStr))
		{
			summary.put("objectId", new NodeRef(nodeRefStr).getId());
		}
		else
		{
			throw new RuntimeException("nodeRef " + nodeRefStr + " in activity feed is not a valid NodeRef");
		}
		String parentNodeRefStr = (String)activitySummary.remove("parentNodeRef");
		if(NodeRef.isNodeRef(parentNodeRefStr))
		{
			summary.put("parentObjectId", new NodeRef(parentNodeRefStr).getId());
		}
		else
		{
			throw new RuntimeException("parentNodeRef " + parentNodeRefStr + " in activity feed is not a valid NodeRef");
		}
		summary.put("lastName", activitySummary.get("lastName"));
		summary.put("firstName", activitySummary.get("firstName"));
		summary.put("title", activitySummary.get("title"));
	} else if(activityType.equals("org.alfresco.site.user-joined"))
	{
		summary.put("lastName", activitySummary.get("lastName"));
		summary.put("firstName", activitySummary.get("firstName"));
		summary.put("memberLastName", activitySummary.get("memberLastName"));
		summary.put("memberFirstName", activitySummary.get("memberFirstName"));
		summary.put("memberPersonId", activitySummary.get("memberUserName"));
		summary.put("role", activitySummary.get("role"));
		summary.put("title", activitySummary.get("title"));
	}

	return summary;
}
 
Example 11
Source File: Jackson2NodeRefDeserializer.java    From alfresco-mvc with Apache License 2.0 5 votes vote down vote up
@Override
public NodeRef deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {

	String id = jp.getText();
	if (NodeRef.isNodeRef(id)) {
		return new NodeRef(id);
	}
	return new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, id);
}
 
Example 12
Source File: Jackson2NodeRefDeserializer.java    From alfresco-mvc with Apache License 2.0 5 votes vote down vote up
@Override
public NodeRef convert(String id) {
	if (!StringUtils.hasText(id)) {
		return null;
	}
	if (NodeRef.isNodeRef(id)) {
		return new NodeRef(id);
	}
	return new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, id);
}
 
Example 13
Source File: FavouritesServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private Map<PersonFavouriteKey, PersonFavourite> extractFavouriteNodes(String userName, Type type, String nodes)
 {
 	PrefKeys prefKeys = getPrefKeys(type);
 	Map<PersonFavouriteKey, PersonFavourite> favouriteNodes = new HashMap<PersonFavouriteKey, PersonFavourite>();

     StringTokenizer st = new StringTokenizer(nodes, ",");
     while(st.hasMoreTokens())
     {
     	String nodeRefStr = st.nextToken();
     	nodeRefStr = nodeRefStr.trim();
     	if(!NodeRef.isNodeRef((String)nodeRefStr))
     	{
     		continue;
     	}

     	NodeRef nodeRef = new NodeRef((String)nodeRefStr);

     	if(!nodeService.exists(nodeRef))
     	{
     		continue;
     	}

if(permissionService.hasPermission(nodeRef, PermissionService.READ_PROPERTIES) == AccessStatus.DENIED)
{
	continue;
}

     	// get createdAt for this favourited node
     	// use ISO8601
StringBuilder builder = new StringBuilder(prefKeys.getAlfrescoPrefKey());
builder.append(nodeRef.toString());
builder.append(".createdAt");
String prefKey = builder.toString();
String createdAtStr = (String)preferenceService.getPreference(userName, prefKey);
Date createdAt = (createdAtStr != null ? ISO8601DateFormat.parse(createdAtStr): null);

     	String name = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);

     	PersonFavourite personFavourite = new PersonFavourite(userName, nodeRef, type, name, createdAt);
     	PersonFavouriteKey key = personFavourite.getKey();
     	favouriteNodes.put(key, personFavourite);
     }

     return favouriteNodes;
 }
 
Example 14
Source File: EmailHelper.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Gets the email template path or the given fallback template path.
 *
 * @param clientName           optional client app name (used only for logging)
 * @param emailTemplatePath    the email template xpath or class path
 * @param fallbackTemplatePath the fallback template
 * @return <ul>
 * <li>If {@code emailTemplatePath} is empty the fallback template is returned.</li>
 * <li>if the given {@code emailTemplatePath} is an xpath (i.e. starts with app:company_home),
 * then an xpath search will be performed to find the {@code NodeRef}. If no nodeRef
 * is found, the fallback template is returned. </li>
 * <li>If {@code emailTemplatePath} is a nodeRef and the node does not exist, the fallback
 * template is returned, otherwise a string representation of the NodeRef is returned.</li>
 * <li>if {@code emailTemplatePath} is a class path which results in a template being found,
 * then the {@code emailTemplatePath} is returned; otherwise, the fallback template is returned.</li>
 * </ul>
 */
public String getEmailTemplate(String clientName, String emailTemplatePath, String fallbackTemplatePath)
{
    if (StringUtils.isEmpty(emailTemplatePath))
    {
        if (LOGGER.isDebugEnabled())
        {
            LOGGER.debug("No email template path is set for client [" + clientName + "]. The fallback template will be used: "
                        + fallbackTemplatePath);
        }
        return fallbackTemplatePath;
    }

    // Make sure that the path doesn't start with '/'
    if (emailTemplatePath.startsWith("/"))
    {
        emailTemplatePath = emailTemplatePath.substring(1);
    }

    if (emailTemplatePath.startsWith(companyHomeChildName))
    {
        NodeRef nodeRef = getLocalizedEmailTemplateNodeRef(emailTemplatePath);
        if (nodeRef == null)
        {
            LOGGER.warn("Couldn't find email template with the XPath [" + emailTemplatePath + "] for client [" + clientName
                        + "]. The fallback template will be used: " + fallbackTemplatePath);

            return fallbackTemplatePath;
        }
        return nodeRef.toString();
    }
    else if (NodeRef.isNodeRef(emailTemplatePath))
    {
        // Just check whether the nodeRef exists or not
        NodeRef ref = new NodeRef(emailTemplatePath);
        if (!nodeService.exists(ref))
        {
            LOGGER.warn("Couldn't find email template with the NodeRef [" + ref + "] for client [" + clientName
                        + "]. The fallback template will be used: " + fallbackTemplatePath);

            return fallbackTemplatePath;
        }

        // No need to return the nodeRef, as this will be handled later by the 'ClassPathRepoTemplateLoader' class
        return emailTemplatePath;
    }
    else
    {
        try
        {
            // We just use the template loader to check whether the given
            // template path is valid and the file is found
            Object template = templateLoader.findTemplateSource(emailTemplatePath);
            if (template != null)
            {
                if (LOGGER.isDebugEnabled())
                {
                    LOGGER.debug("Using email template with class path [" + emailTemplatePath + "] for client: " + clientName);
                }
                return emailTemplatePath;
            }
            else
            {
                LOGGER.warn("Couldn't find email template with class path [" + emailTemplatePath + "] for client [" + clientName
                            + "]. The fallback template will be used: " + fallbackTemplatePath);
            }
        }
        catch (IOException ex)
        {
            LOGGER.error("Error occurred while finding the email template with the class path [" + emailTemplatePath + "] for client ["
                        + clientName + "]. The fallback template will be used: " + fallbackTemplatePath, ex);

        }
        return fallbackTemplatePath;
    }
}