mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged DEV/SWIFT-MIKE to HEAD
28328: Merged DEV/SWIFT-UI to DEV/SWIFT-MIKE 28245: Work in Progress: DocLib data webscript and action config refactor. 28676: Work in Progress: Document Library list view renders with new data structures. Action evaluators mostly populated. Tweaks to appUtils.toJSON. Client-side "ScriptNode-lite". Evaluators now use json-simple lib. 28898: Work in progress. New doclib webscripts into new "v2" namespace. Action refactoring. Initial status indicator config. Site preset & container type returned & evaluator templates to support wcmqs and dod5015. 28952: Work in Progress: End of Sprint 3. Refactored web-tier data webscripts. Full parent node details returned with nodes (or in metadata for common parent scenario). Action fixes. 28971: Merged HEAD@28970 to DEV/SWIFT-MIKE 29018: Work in progress: Document details page. Evaluator tweaks. New value evaluator. Consolidated getActionUrls. 29037: Merged HEAD@29035 to DEV/SWIFT-MIKE (Bringing in publishing action to migrate to new framework) 29156: Work in progress: Folder details page refactor. "working mode" flag removed to allow removal of some repository browser-specific overrides. Client-side folder and document renderers coalesced. Category, link and working copy handling improved. 29168: Merged HEAD@29166 to DEV/SWIFT-MIKE (Share extensibility features merged across. Folder details page conflicts resolved by migrating to new extensibility model.) 29195: Minor fixes for action event handler and changes to Surf API 29197: Merged HEAD@29196 to DEV/SWIFT-MIKE to prepare for merge back to trunk Note: Awaiting imminent Spring Surf fix before Document Libraries are fully functional. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29201 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -220,4 +220,63 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="usernamePropertyDecorator" class="org.alfresco.repo.jscript.app.UsernamePropertyDecorator">
|
||||
<property name="serviceRegistry">
|
||||
<ref bean="ServiceRegistry"/>
|
||||
</property>
|
||||
</bean>
|
||||
<bean id="tagPropertyDecorator" class="org.alfresco.repo.jscript.app.TagPropertyDecorator">
|
||||
<property name="serviceRegistry">
|
||||
<ref bean="ServiceRegistry"/>
|
||||
</property>
|
||||
</bean>
|
||||
<bean id="categoryPropertyDecorator" class="org.alfresco.repo.jscript.app.CategoryPropertyDecorator">
|
||||
<property name="serviceRegistry">
|
||||
<ref bean="ServiceRegistry"/>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="applicationScriptUtils" parent="baseJavaScriptExtension" class="org.alfresco.repo.jscript.ApplicationScriptUtils">
|
||||
<property name="extensionName">
|
||||
<value>appUtils</value>
|
||||
</property>
|
||||
<property name="serviceRegistry">
|
||||
<ref bean="ServiceRegistry"/>
|
||||
</property>
|
||||
<property name="decoratedProperties">
|
||||
<map>
|
||||
<entry key="cm:creator">
|
||||
<ref bean="usernamePropertyDecorator"/>
|
||||
</entry>
|
||||
<entry key="cm:modifier">
|
||||
<ref bean="usernamePropertyDecorator"/>
|
||||
</entry>
|
||||
<entry key="cm:workingCopyOwner">
|
||||
<ref bean="usernamePropertyDecorator"/>
|
||||
</entry>
|
||||
<entry key="cm:lockOwner">
|
||||
<ref bean="usernamePropertyDecorator"/>
|
||||
</entry>
|
||||
<entry key="cm:owner">
|
||||
<ref bean="usernamePropertyDecorator"/>
|
||||
</entry>
|
||||
<entry key="cm:taggable">
|
||||
<ref bean="tagPropertyDecorator"/>
|
||||
</entry>
|
||||
<entry key="cm:categories">
|
||||
<ref bean="categoryPropertyDecorator"/>
|
||||
</entry>
|
||||
</map>
|
||||
</property>
|
||||
<property name="userPermissions">
|
||||
<list>
|
||||
<value>CancelCheckOut</value>
|
||||
<value>ChangePermissions</value>
|
||||
<value>CreateChildren</value>
|
||||
<value>Delete</value>
|
||||
<value>Write</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
@@ -0,0 +1,291 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.jscript;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.jscript.app.JSONPropertyDecorator;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.security.AccessStatus;
|
||||
import org.alfresco.service.namespace.NamespaceException;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.ISO8601DateFormat;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.extensions.surf.util.URLEncoder;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Utility functions specifically for external application use.
|
||||
*
|
||||
* @author Mike Hatfield
|
||||
*/
|
||||
|
||||
public final class ApplicationScriptUtils extends BaseScopableProcessorExtension
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(ApplicationScriptUtils.class);
|
||||
|
||||
/** Repository Service Registry */
|
||||
private ServiceRegistry services;
|
||||
private NodeService nodeService = null;
|
||||
private Map<String, Object> decoratedProperties;
|
||||
private String[] userPermissions;
|
||||
|
||||
private final static String CONTENT_DOWNLOAD_API_URL = "/api/node/content/{0}/{1}/{2}/{3}";
|
||||
|
||||
/**
|
||||
* Set the service registry
|
||||
*
|
||||
* @param serviceRegistry the service registry
|
||||
*/
|
||||
public void setServiceRegistry(ServiceRegistry serviceRegistry)
|
||||
{
|
||||
this.services = serviceRegistry;
|
||||
this.nodeService = services.getNodeService();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the properties that require decorator beans
|
||||
*
|
||||
* @param decoratedProperties
|
||||
*/
|
||||
public void setDecoratedProperties(Map<String, Object> decoratedProperties)
|
||||
{
|
||||
this.decoratedProperties = decoratedProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the list of user permissions to return in the JSON body
|
||||
*
|
||||
* @param userPermissions
|
||||
*/
|
||||
public void setUserPermissions(String[] userPermissions)
|
||||
{
|
||||
this.userPermissions = userPermissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the JSON representation of a node. Long-form QNames are used in the
|
||||
* result.
|
||||
*
|
||||
* @param node the node to convert to JSON representation.
|
||||
* @return The JSON representation of this node
|
||||
*/
|
||||
public String toJSON(ScriptNode node)
|
||||
{
|
||||
return this.toJSON(node, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the JSON representation of this node.
|
||||
*
|
||||
* @param node the node to convert to JSON representation.
|
||||
* @param useShortQNames if true short-form qnames will be returned, else long-form.
|
||||
* @return The JSON representation of this node
|
||||
*/
|
||||
public String toJSON(ScriptNode node, boolean useShortQNames)
|
||||
{
|
||||
return this.toJSONObj(node, useShortQNames).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a JSON object representing the node.
|
||||
*
|
||||
* @param node the node to convert to JSON representation.
|
||||
* @param useShortQNames if true short-form qnames will be returned, else long-form.
|
||||
* @return The JSON representation of this node
|
||||
*/
|
||||
protected Object toJSONObj(ScriptNode node, boolean useShortQNames)
|
||||
{
|
||||
NodeRef nodeRef = node.getNodeRef();
|
||||
JSONObject json = new JSONObject();
|
||||
|
||||
if (this.nodeService.exists(nodeRef))
|
||||
{
|
||||
if (this.services.getPublicServiceAccessService().hasAccess(ServiceRegistry.NODE_SERVICE.getLocalName(), "getProperties", nodeRef) == AccessStatus.ALLOWED)
|
||||
{
|
||||
try
|
||||
{
|
||||
String typeString = useShortQNames ? this.getShortQName(node.getQNameType()) : node.getType();
|
||||
boolean isLink = node.getIsLinkToContainer() || node.getIsLinkToDocument();
|
||||
|
||||
json.put("nodeRef", nodeRef.toString());
|
||||
json.put("type", typeString);
|
||||
json.put("isContainer", node.getIsContainer() || node.getIsLinkToContainer());
|
||||
json.put("isLink", isLink);
|
||||
json.put("isLocked", node.getIsLocked());
|
||||
|
||||
if (node.getIsDocument())
|
||||
{
|
||||
json.put("contentURL", this.getDownloadAPIUrl(node));
|
||||
json.put("mimetype", node.getMimetype());
|
||||
json.put("size", node.getSize());
|
||||
}
|
||||
|
||||
// permissions
|
||||
Map<String, Serializable> permissionsJSON = new LinkedHashMap<String, Serializable>(3);
|
||||
if (node.hasPermission("ReadPermissions"))
|
||||
{
|
||||
permissionsJSON.put("roles", node.retrieveAllSetPermissions(false, true));
|
||||
}
|
||||
permissionsJSON.put("inherited", node.inheritsPermissions());
|
||||
Map<String, Serializable> userPermissionJSON = new LinkedHashMap<String, Serializable>(this.userPermissions.length);
|
||||
for (String userPermission : this.userPermissions)
|
||||
{
|
||||
userPermissionJSON.put(userPermission, node.hasPermission(userPermission));
|
||||
}
|
||||
permissionsJSON.put("user", (Serializable) userPermissionJSON);
|
||||
json.put("permissions", permissionsJSON);
|
||||
|
||||
// add properties
|
||||
Map<QName, Serializable> nodeProperties = this.nodeService.getProperties(nodeRef);
|
||||
json.put("properties", this.parseToJSON(nodeRef, nodeProperties, useShortQNames));
|
||||
|
||||
// add aspects as an array
|
||||
Set<QName> nodeAspects = this.nodeService.getAspects(nodeRef);
|
||||
if (useShortQNames)
|
||||
{
|
||||
Set<String> nodeAspectsShortQNames = new LinkedHashSet<String>(nodeAspects.size());
|
||||
for (QName nextLongQName : nodeAspects)
|
||||
{
|
||||
String nextShortQName = this.getShortQName(nextLongQName);
|
||||
nodeAspectsShortQNames.add(nextShortQName);
|
||||
}
|
||||
json.put("aspects", nodeAspectsShortQNames);
|
||||
}
|
||||
else
|
||||
{
|
||||
json.put("aspects", nodeAspects);
|
||||
}
|
||||
|
||||
// link to document or folder?
|
||||
if (isLink)
|
||||
{
|
||||
NodeRef targetNodeRef = (NodeRef) nodeProperties.get(ContentModel.PROP_LINK_DESTINATION);
|
||||
if (targetNodeRef != null)
|
||||
{
|
||||
json.put("linkedNode", this.toJSONObj(new ScriptNode(targetNodeRef, this.services, node.scope), useShortQNames));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (JSONException error)
|
||||
{
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a long-form QName, this method uses the namespace service to create a
|
||||
* short-form QName string.
|
||||
*
|
||||
* @param longQName
|
||||
* @return the short form of the QName string, e.g. "cm:content"
|
||||
*/
|
||||
protected String getShortQName(QName longQName)
|
||||
{
|
||||
return longQName.toPrefixString(this.services.getNamespaceService());
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a map of node properties to a format suitable for JSON output
|
||||
*
|
||||
* @param nodeRef
|
||||
* @param properties
|
||||
* @param useShortQNames
|
||||
* @return a decorated map of properties suitable for JSON output
|
||||
*/
|
||||
protected Map<String, Serializable> parseToJSON(NodeRef nodeRef, Map<QName, Serializable> properties, boolean useShortQNames)
|
||||
{
|
||||
Map<String, Serializable> json = new LinkedHashMap<String, Serializable>(properties.size());
|
||||
|
||||
for (QName nextLongQName : properties.keySet())
|
||||
{
|
||||
try
|
||||
{
|
||||
String shortQName = this.getShortQName(nextLongQName);
|
||||
String key = useShortQNames ? shortQName : nextLongQName.toString();
|
||||
Serializable value = properties.get(nextLongQName);
|
||||
|
||||
// Has a decorator has been registered for this property?
|
||||
if (this.decoratedProperties.containsKey(shortQName))
|
||||
{
|
||||
json.put(key, ((JSONPropertyDecorator) this.decoratedProperties.get(shortQName)).decorate(nodeRef, shortQName, value));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Built-in data type processing
|
||||
if (value instanceof Date)
|
||||
{
|
||||
Map<String, Serializable> dateObj = new LinkedHashMap<String, Serializable>(1);
|
||||
dateObj.put("value", value);
|
||||
dateObj.put("iso8601", ISO8601DateFormat.format((Date)value));
|
||||
json.put(key, (Serializable)dateObj);
|
||||
}
|
||||
else
|
||||
{
|
||||
json.put(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (NamespaceException ne)
|
||||
{
|
||||
// ignore properties that do not have a registered namespace
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Ignoring property '" + nextLongQName + "' as its namespace is not registered");
|
||||
}
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param node the node to construct the download URL for
|
||||
* @return For a content document, this method returns the URL to the /api/node/content
|
||||
* API for the default content property
|
||||
* <p>
|
||||
* For a container node, this method returns an empty string
|
||||
* </p>
|
||||
*/
|
||||
public String getDownloadAPIUrl(ScriptNode node)
|
||||
{
|
||||
if (node.getIsDocument())
|
||||
{
|
||||
return MessageFormat.format(CONTENT_DOWNLOAD_API_URL, new Object[]{
|
||||
node.nodeRef.getStoreRef().getProtocol(),
|
||||
node.nodeRef.getStoreRef().getIdentifier(),
|
||||
node.nodeRef.getId(),
|
||||
URLEncoder.encode(node.getName())});
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1411,7 +1411,7 @@ public class ScriptNode implements Serializable, Scopeable, NamespacePrefixResol
|
||||
*
|
||||
* @return Object[] of packed permission strings.
|
||||
*/
|
||||
private Object[] retrieveAllSetPermissions(boolean direct, boolean full)
|
||||
protected Object[] retrieveAllSetPermissions(boolean direct, boolean full)
|
||||
{
|
||||
Set<AccessPermission> acls = this.services.getPermissionService().getAllSetPermissions(getNodeRef());
|
||||
List<Object> permissions = new ArrayList<Object>(acls.size());
|
||||
@@ -3076,7 +3076,7 @@ public class ScriptNode implements Serializable, Scopeable, NamespacePrefixResol
|
||||
* @param longQName
|
||||
* @return the short form of the QName string, e.g. "cm:content"
|
||||
*/
|
||||
private String getShortQName(QName longQName)
|
||||
protected String getShortQName(QName longQName)
|
||||
{
|
||||
return longQName.toPrefixString(services.getNamespaceService());
|
||||
}
|
||||
@@ -3088,7 +3088,7 @@ public class ScriptNode implements Serializable, Scopeable, NamespacePrefixResol
|
||||
*
|
||||
* @return QName
|
||||
*/
|
||||
private QName createQName(String s)
|
||||
protected QName createQName(String s)
|
||||
{
|
||||
QName qname;
|
||||
if (s.indexOf(NAMESPACE_BEGIN) != -1)
|
||||
|
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.jscript.app;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Category property decorator class.
|
||||
*
|
||||
* @author Mike Hatfield
|
||||
*/
|
||||
public class CategoryPropertyDecorator implements JSONPropertyDecorator
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(CategoryPropertyDecorator.class);
|
||||
|
||||
private ServiceRegistry services;
|
||||
private NodeService nodeService = null;
|
||||
private PermissionService permissionService = null;
|
||||
|
||||
public void setServiceRegistry(ServiceRegistry serviceRegistry)
|
||||
{
|
||||
this.services = serviceRegistry;
|
||||
this.nodeService = serviceRegistry.getNodeService();
|
||||
this.permissionService = serviceRegistry.getPermissionService();
|
||||
}
|
||||
|
||||
public Serializable decorate(NodeRef nodeRef, String propertyName, Serializable value)
|
||||
{
|
||||
Collection<NodeRef> collection = (Collection<NodeRef>)value;
|
||||
Object[] array = new Object[collection.size()];
|
||||
int index = 0;
|
||||
|
||||
for (NodeRef obj : collection)
|
||||
{
|
||||
try
|
||||
{
|
||||
Map<String, Serializable> jsonObj = new LinkedHashMap<String, Serializable>(4);
|
||||
jsonObj.put("name", this.nodeService.getProperty(obj, ContentModel.PROP_NAME));
|
||||
jsonObj.put("path", this.getPath(obj));
|
||||
jsonObj.put("nodeRef", obj.toString());
|
||||
array[index++] = jsonObj;
|
||||
}
|
||||
catch (InvalidNodeRefException e)
|
||||
{
|
||||
logger.warn("Category with nodeRef " + obj.toString() + " does not exist.");
|
||||
}
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Category path used for node membership queries
|
||||
*
|
||||
* @return Display path to this node
|
||||
*/
|
||||
public String getPath(NodeRef nodeRef)
|
||||
{
|
||||
String displayPath = this.nodeService.getPath(nodeRef).toDisplayPath(this.nodeService, this.permissionService);
|
||||
return displayPath.replaceFirst("/categories/General", "");
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.jscript.app;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Interface for property decorators used by ApplicationScriptUtils.toJSON()
|
||||
*
|
||||
* @author Mike Hatfield
|
||||
*/
|
||||
public interface JSONPropertyDecorator
|
||||
{
|
||||
Serializable decorate(NodeRef nodeRef, String propertyName, Serializable value);
|
||||
}
|
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.jscript.app;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Tag property decorator class.
|
||||
*
|
||||
* @author Mike Hatfield
|
||||
*/
|
||||
public class TagPropertyDecorator implements JSONPropertyDecorator
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(TagPropertyDecorator.class);
|
||||
|
||||
private ServiceRegistry services;
|
||||
private NodeService nodeService = null;
|
||||
|
||||
public void setServiceRegistry(ServiceRegistry serviceRegistry)
|
||||
{
|
||||
this.services = serviceRegistry;
|
||||
this.nodeService = serviceRegistry.getNodeService();
|
||||
}
|
||||
|
||||
public Serializable decorate(NodeRef nodeRef, String propertyName, Serializable value)
|
||||
{
|
||||
Collection<NodeRef> collection = (Collection<NodeRef>)value;
|
||||
Object[] array = new Object[collection.size()];
|
||||
int index = 0;
|
||||
|
||||
for (NodeRef obj : collection)
|
||||
{
|
||||
try
|
||||
{
|
||||
Map<String, Serializable> jsonObj = new LinkedHashMap<String, Serializable>(2);
|
||||
jsonObj.put("name", this.nodeService.getProperty(obj, ContentModel.PROP_NAME));
|
||||
jsonObj.put("nodeRef", obj.toString());
|
||||
array[index++] = jsonObj;
|
||||
}
|
||||
catch (InvalidNodeRefException e)
|
||||
{
|
||||
logger.warn("Tag with nodeRef " + obj.toString() + " does not exist.");
|
||||
}
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
}
|
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.jscript.app;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Username property decorator class.
|
||||
*
|
||||
* @author Mike Hatfield
|
||||
*/
|
||||
public class UsernamePropertyDecorator implements JSONPropertyDecorator
|
||||
{
|
||||
private ServiceRegistry services;
|
||||
private NodeService nodeService = null;
|
||||
private PersonService personService = null;
|
||||
|
||||
public void setServiceRegistry(ServiceRegistry serviceRegistry)
|
||||
{
|
||||
this.services = serviceRegistry;
|
||||
this.nodeService = serviceRegistry.getNodeService();
|
||||
this.personService = serviceRegistry.getPersonService();
|
||||
}
|
||||
|
||||
public Serializable decorate(NodeRef nodeRef, String propertyName, Serializable value)
|
||||
{
|
||||
String username = value.toString();
|
||||
String firstName = null;
|
||||
String lastName = null;
|
||||
Map<String, Serializable> map = new LinkedHashMap<String, Serializable>(1);
|
||||
map.put("userName", username);
|
||||
|
||||
if (this.personService.personExists(username))
|
||||
{
|
||||
NodeRef personRef = this.personService.getPerson(username);
|
||||
Map<QName, Serializable> properties = this.nodeService.getProperties(personRef);
|
||||
firstName = properties.get(ContentModel.PROP_FIRSTNAME).toString();
|
||||
lastName = properties.get(ContentModel.PROP_LASTNAME).toString();
|
||||
}
|
||||
else if (username.equals("System") || username.startsWith("System@"))
|
||||
{
|
||||
firstName = "System";
|
||||
lastName = "User";
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
map.put("firstName", firstName);
|
||||
map.put("lastName", lastName);
|
||||
map.put("displayName", (firstName + " " + lastName).replaceAll("^\\s+|\\s+$", ""));
|
||||
return (Serializable)map;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user