Merged V4.0-BUG-FIX to HEAD

33836: Fix for ALF-10651 Fix patches that trigger reindexing and ALF-10656 SOLR: Patches execute search during bootstrap causing deadlock
   33842: Fixes ALF-12797: i18n strings in activiti-admin login-screen escaped properly
   33844: Fix for ALF-10651 Fix patches that trigger reindexing and ALF-10656 SOLR: Patches execute search during bootstrap causing deadlock
   - batch touch to limit the in clause size generated
   33845: Manually added extra core Share extensions needed for the V4.0 Records Management module from the development branch.
   - Refactored JSON property decorators for the Document Library data webscripts
   - Document List banners (e.g. working copy) moved into metadata template config
   - Ability to override default document/folder title within Document Library (<title> element in metadata template - unused in core code)
   - Additional extension point in surf-doclist to override remote data URL
   - Better handling for missing content property
   33852: ALF-12725: Merged V3.4-BUG-FIX (3.4.9) to V4.0-BUG-FIX (4.0.1)
      33849: Merged V3 (3.4.8) to V3.4-BUG-FIX (3.4.9)
         33848: ALF-10976 (relates to ALF-10412)
            Fixed bug to do with preview being stuck as always being 'Content cannot be previewed.
            Do you wish to download?' or a 'blank preview after a transformer is not found' for all
            content with the same mimetype. Cache in ThumbnailRegistory.getThumbnailDefinitions()
            now understands that transformers may have an upper content size limit. The choice between
            the two options was based on the size of the first file previewed of each mimetype.
            Needed to add getMaxSourceSizeBytes() to support this (see below).
            - refactored (previous refactor was incomplete) ContentTransformer so that
              the two halfs of isTransformable is now split into sub methods
              isTransformableMimetypes and isTransformableSize.
              This is why there are so many files changed.
            - Moved getMaxSourceSizeBytes() from AbstractContentTransformerLimits to ContentTransformer as
              there were becomming too many places in the code that needed needed to check if the ContentTransformer
              was an instanceof AbstractContentTransformerLimits before calling this method.
            - TransformerDebug now uses KB MB GB values in output to make it simpler to read.
            - TransformerDebug now uses thousand separaters in millisecond values to make it simpler to read.
            - TransformerDebug now reports the 'parent' transformer name rather than the sub-transformer name 
              when an unavailable transformer is found. Makes it simpler to tie up with the 'available transformer'
              list with the new pushIsTransformableSize() calls.
            - TransformerDebug now uses trace logging for calls from ThumbnailRegistory.isThumbnailDefinitionAvailable()
              as it is normally followed by a ContentService.transform() which is logged at debug level anyway.
            - TransformerDebug now turns logging level to trace if the file size is 0 bytes. Request from Jan.
              Not sure how one uploads such a file!
            - Modified ComplexContentTransformer.isTransformable() so that it checks the mimetypes before the sizes
              so that TransformerDebug does not report 'unavailable transformers' that don't support the
              mimetype conversion.
            - Modified ComplexContentTransformer.getLimits and ComplexContentTransformer.isPageLimitSupported()
              to include the limits from the first sub transformer.
              Was not an issue until ContentTransformer.getMaxSourceSizeBytes() was introduced.
            - Added logger to RhinoScriptProcessor to debug requests run javascript on the server.
            - Dropped the sourceUrl parameter from ThumbnailRegistry.getThumbnailDefinitions() which was
              introduced with limits as it is logicall not needed.
   33853: DiskInterface.renameFile() can now throw PermissionDeniedException to return a different status to the client. Part of ALF-12717.
   33856: Merged V3.4-BUG-FIX to V4.0-BUG-FIX
      33835: ALF-12546: Remove references to retired RegPaths.exe from installed apply_amps.bat script
      33843: Fix for ALF-12775
      33855: Merged V3.4 to V3.4-BUG-FIX
         33851: ALF-12588: Documents Intermittently Do Not Appear in Share
            - Fix by Alex Busel for regression I accidentally caused in 3.4.6
            - Simple typo in mergeDeletions() caused path deletions to sometimes not get applied or get processed twice
            - Yikes!


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@33857 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Dave Ward
2012-02-13 12:24:24 +00:00
parent ac387f5f7b
commit c3a622e3c4
50 changed files with 1916 additions and 801 deletions

View File

@@ -0,0 +1,75 @@
/**
*
*/
package org.alfresco.repo.jscript.app;
import java.util.HashSet;
import java.util.Set;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
/**
* @author Roy Wetherall
*/
public abstract class BasePropertyDecorator implements PropertyDecorator
{
protected Set<QName> propertyNames;
protected NodeService nodeService;
protected NamespaceService namespaceService;
protected PermissionService permissionService;
protected JSONConversionComponent jsonConversionComponent;
public void setNamespaceService(NamespaceService namespaceService)
{
this.namespaceService = namespaceService;
}
public void setJsonConversionComponent(JSONConversionComponent jsonConversionComponent)
{
this.jsonConversionComponent = jsonConversionComponent;
}
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setPermissionService(PermissionService permissionService)
{
this.permissionService = permissionService;
}
public void init()
{
jsonConversionComponent.registerPropertyDecorator(this);
}
@Override
public Set<QName> getPropertyNames()
{
return propertyNames;
}
public void setPropertyName(String propertyName)
{
propertyNames = new HashSet<QName>(1);
propertyNames.add(QName.createQName(propertyName, namespaceService));
}
public void setPropertyNames(Set<String> propertyNames)
{
this.propertyNames = new HashSet<QName>(propertyNames.size());
for (String propertyName : propertyNames)
{
this.propertyNames.add(QName.createQName(propertyName, namespaceService));
}
}
}

View File

@@ -18,55 +18,46 @@
*/
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;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.simple.JSONArray;
import org.json.simple.JSONAware;
import org.json.simple.JSONObject;
/**
* Category property decorator class.
*
* @author Mike Hatfield
*/
public class CategoryPropertyDecorator implements PropertyDecorator
public class CategoryPropertyDecorator extends BasePropertyDecorator
{
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)
/**
* @see org.alfresco.repo.jscript.app.PropertyDecorator#decorate(org.alfresco.service.namespace.QName, org.alfresco.service.cmr.repository.NodeRef, java.io.Serializable)
*/
@SuppressWarnings("unchecked")
public JSONAware decorate(QName propertyName, NodeRef nodeRef, Serializable value)
{
Collection<NodeRef> collection = (Collection<NodeRef>)value;
Object[] array = new Object[collection.size()];
int index = 0;
JSONArray array = new JSONArray();
for (NodeRef obj : collection)
{
try
{
Map<String, Serializable> jsonObj = new LinkedHashMap<String, Serializable>(4);
JSONObject jsonObj = new JSONObject();
jsonObj.put("name", this.nodeService.getProperty(obj, ContentModel.PROP_NAME));
jsonObj.put("path", this.getPath(obj));
jsonObj.put("nodeRef", obj.toString());
array[index++] = jsonObj;
array.add(jsonObj);
}
catch (InvalidNodeRefException e)
{

View File

@@ -0,0 +1,42 @@
/*
* 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 java.io.Serializable;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.json.simple.JSONAware;
/**
* Ignores a given property and doesn't output anything in the decoration. This means the property will not appear in the
* resulting JSON.
*
* @author Roy Wetherall
*/
public class IgnorePropertyDecorator extends BasePropertyDecorator
{
/**
* @see org.alfresco.repo.jscript.app.PropertyDecorator#decorate(org.alfresco.service.cmr.repository.NodeRef, java.io.Serializable)
*/
public JSONAware decorate(QName propertyName, NodeRef nodeRef, Serializable value)
{
return null;
}
}

View File

@@ -0,0 +1,413 @@
/**
*
*/
package org.alfresco.repo.jscript.app;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.alfresco.model.ContentModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.lock.LockService;
import org.alfresco.service.cmr.lock.LockStatus;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.AccessPermission;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.PublicServiceAccessService;
import org.alfresco.service.namespace.NamespaceException;
import org.alfresco.service.namespace.NamespaceService;
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.simple.JSONArray;
import org.json.simple.JSONAware;
import org.json.simple.JSONObject;
import org.springframework.extensions.surf.util.URLEncoder;
/**
* JSON Conversion Component
*
* @author Roy Wetherall
*/
public class JSONConversionComponent
{
/** Content download API URL template */
private final static String CONTENT_DOWNLOAD_API_URL = "/api/node/content/{0}/{1}/{2}/{3}";
/** Logger */
private static Log logger = LogFactory.getLog(JSONConversionComponent.class);
/** Registered decorators */
protected Map<QName, PropertyDecorator> propertyDecorators = new HashMap<QName, PropertyDecorator>(3);
/** User permissions */
protected String[] userPermissions;
/** Services */
protected NodeService nodeService;
protected PublicServiceAccessService publicServiceAccessService;
protected NamespaceService namespaceService;
protected FileFolderService fileFolderService;
protected LockService lockService;
protected ContentService contentService;
protected PermissionService permissionService;
/**
* @param nodeService node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @param publicServiceAccessService public service access service
*/
public void setPublicServiceAccessService(PublicServiceAccessService publicServiceAccessService)
{
this.publicServiceAccessService = publicServiceAccessService;
}
/**
* @param namespaceService namespace service
*/
public void setNamespaceService(NamespaceService namespaceService)
{
this.namespaceService = namespaceService;
}
/**
* @param fileFolderService file folder service
*/
public void setFileFolderService(FileFolderService fileFolderService)
{
this.fileFolderService = fileFolderService;
}
/**
* @param lockService lock service
*/
public void setLockService(LockService lockService)
{
this.lockService = lockService;
}
/**
* @param permissionService permission service
*/
public void setPermissionService(PermissionService permissionService)
{
this.permissionService = permissionService;
}
/**
* @param userPermissions user permissions
*/
public void setUserPermissions(String[] userPermissions)
{
this.userPermissions = userPermissions;
}
/**
* @param contentService content service
*/
public void setContentService(ContentService contentService)
{
this.contentService = contentService;
}
/**
* Register a property decorator;
*
* @param propertyDecorator
*/
public void registerPropertyDecorator(PropertyDecorator propertyDecorator)
{
for (QName propertyName : propertyDecorator.getPropertyNames())
{
propertyDecorators.put(propertyName, propertyDecorator);
}
}
/**
* Convert a node reference to a JSON string. Selects the correct converter based on selection
* implementation.
*/
@SuppressWarnings("unchecked")
public String toJSON(NodeRef nodeRef, boolean useShortQNames)
{
JSONObject json = new JSONObject();
if (this.nodeService.exists(nodeRef) == true)
{
if (publicServiceAccessService.hasAccess(ServiceRegistry.NODE_SERVICE.getLocalName(), "getProperties", nodeRef) == AccessStatus.ALLOWED)
{
// Get node info
FileInfo nodeInfo = fileFolderService.getFileInfo(nodeRef);
// Set root values
setRootValues(nodeInfo, json, useShortQNames);
// add permissions
json.put("permissions", permissionsToJSON(nodeRef));
// add properties
json.put("properties", propertiesToJSON(nodeRef, useShortQNames));
// add aspects
json.put("aspects", apsectsToJSON(nodeRef, useShortQNames));
}
}
return json.toJSONString();
}
/**
*
* @param nodeInfo
* @param rootJSONObject
* @param useShortQNames
* @throws JSONException
*/
@SuppressWarnings("unchecked")
protected void setRootValues(FileInfo nodeInfo, JSONObject rootJSONObject, boolean useShortQNames)
{
NodeRef nodeRef = nodeInfo.getNodeRef();
rootJSONObject.put("nodeRef", nodeInfo.getNodeRef().toString());
rootJSONObject.put("type", nameToString(nodeInfo.getType(), useShortQNames));
rootJSONObject.put("isContainer", nodeInfo.isFolder()); //node.getIsContainer() || node.getIsLinkToContainer());
rootJSONObject.put("isLocked", isLocked(nodeInfo.getNodeRef()));
rootJSONObject.put("isLink", nodeInfo.isLink());
if (nodeInfo.isLink() == true)
{
NodeRef targetNodeRef = nodeInfo.getLinkNodeRef();
if (targetNodeRef != null)
{
rootJSONObject.put("linkedNode", toJSON(targetNodeRef, useShortQNames));
}
}
// TODO should this be moved to the property output since we may have more than one content property
// or a non-standard content property
if (nodeInfo.isFolder() == false)
{
ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
if (reader != null)
{
String contentURL = MessageFormat.format(
CONTENT_DOWNLOAD_API_URL, new Object[]{
nodeRef.getStoreRef().getProtocol(),
nodeRef.getStoreRef().getIdentifier(),
nodeRef.getId(),
URLEncoder.encode(nodeInfo.getName())});
rootJSONObject.put("contentURL", contentURL);
rootJSONObject.put("mimetype", reader.getMimetype());
rootJSONObject.put("encoding", reader.getEncoding());
rootJSONObject.put("size", reader.getSize());
}
}
}
/**
*
* @param nodeRef
* @return
* @throws JSONException
*/
@SuppressWarnings("unchecked")
protected JSONObject permissionsToJSON(NodeRef nodeRef)
{
JSONObject permissionsJSON = new JSONObject();
if (AccessStatus.ALLOWED.equals(permissionService.hasPermission(nodeRef, PermissionService.READ_PERMISSIONS)) == true)
{
permissionsJSON.put("inherited", permissionService.getInheritParentPermissions(nodeRef));
permissionsJSON.put("roles", allSetPermissionsToJSON(nodeRef));
permissionsJSON.put("user", userPermissionsToJSON(nodeRef));
}
return permissionsJSON;
}
/**
*
* @param nodeRef
* @return
*/
@SuppressWarnings("unchecked")
protected JSONObject userPermissionsToJSON(NodeRef nodeRef)
{
JSONObject userPermissionJSON = new JSONObject();
for (String userPermission : this.userPermissions)
{
boolean hasPermission = AccessStatus.ALLOWED.equals(permissionService.hasPermission(nodeRef, userPermission));
userPermissionJSON.put(userPermission, hasPermission);
}
return userPermissionJSON;
}
/**
*
* @param nodeRef
* @param useShortQNames
* @return
* @throws JSONException
*/
@SuppressWarnings("unchecked")
protected JSONObject propertiesToJSON(NodeRef nodeRef, boolean useShortQNames)
{
JSONObject propertiesJSON = new JSONObject();
Map<QName, Serializable> properties = nodeService.getProperties(nodeRef);
for (QName propertyName : properties.keySet())
{
try
{
String key = nameToString(propertyName, useShortQNames);
Serializable value = properties.get(propertyName);
if (value != null)
{
// Has a decorator has been registered for this property?
if (propertyDecorators.containsKey(propertyName) == true)
{
JSONAware jsonAware = propertyDecorators.get(propertyName).decorate(propertyName, nodeRef, value);
if (jsonAware != null)
{
propertiesJSON.put(key, jsonAware);
}
}
else
{
// Built-in data type processing
if (value instanceof Date)
{
JSONObject dateObj = new JSONObject();
dateObj.put("value", JSONObject.escape(value.toString()));
dateObj.put("iso8601", JSONObject.escape(ISO8601DateFormat.format((Date)value)));
propertiesJSON.put(key, dateObj);
}
else
{
propertiesJSON.put(key, value.toString());
}
}
}
else
{
propertiesJSON.put(key, null);
}
}
catch (NamespaceException ne)
{
// ignore properties that do not have a registered namespace
if (logger.isDebugEnabled() == true)
{
logger.debug("Ignoring property '" + propertyName + "' as its namespace is not registered");
}
}
}
return propertiesJSON;
}
/**
*
* @param nodeRef
* @param useShortQNames
* @return
* @throws JSONException
*/
@SuppressWarnings("unchecked")
protected JSONArray apsectsToJSON(NodeRef nodeRef, boolean useShortQNames)
{
JSONArray aspectsJSON = new JSONArray();
Set<QName> aspects = this.nodeService.getAspects(nodeRef);
for (QName aspect : aspects)
{
aspectsJSON.add(nameToString(aspect, useShortQNames));
}
return aspectsJSON;
}
/**
*
* @param nodeRef
* @return
*/
@SuppressWarnings("unchecked")
protected JSONArray allSetPermissionsToJSON(NodeRef nodeRef)
{
Set<AccessPermission> acls = permissionService.getAllSetPermissions(nodeRef);
JSONArray permissions = new JSONArray();
for (AccessPermission permission : acls)
{
StringBuilder buf = new StringBuilder(64);
buf.append(permission.getAccessStatus())
.append(';')
.append(permission.getAuthority())
.append(';')
.append(permission.getPermission())
.append(';').append(permission.isSetDirectly() ? "DIRECT" : "INHERITED");
permissions.add(buf.toString());
}
return permissions;
}
/**
*
* @param qname
* @param isShortName
* @return
*/
private String nameToString(QName qname, boolean isShortName)
{
String result = null;
if (isShortName == true)
{
result = qname.toPrefixString(namespaceService);
}
else
{
result = qname.toString();
}
return result;
}
/**
*
* @param nodeRef
* @return
*/
private boolean isLocked(NodeRef nodeRef)
{
boolean locked = false;
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_LOCKABLE) == true)
{
LockStatus lockStatus = lockService.getLockStatus(nodeRef);
if (lockStatus == LockStatus.LOCKED || lockStatus == LockStatus.LOCK_OWNER)
{
locked = true;
}
}
return locked;
}
}

View File

@@ -18,8 +18,12 @@
*/
package org.alfresco.repo.jscript.app;
import org.alfresco.service.cmr.repository.NodeRef;
import java.io.Serializable;
import java.util.Set;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.json.simple.JSONAware;
/**
* Interface for property decorators used by ApplicationScriptUtils.toJSON()
@@ -28,5 +32,7 @@ import java.io.Serializable;
*/
public interface PropertyDecorator
{
Serializable decorate(NodeRef nodeRef, String propertyName, Serializable value);
Set<QName> getPropertyNames();
JSONAware decorate(QName propertyName, NodeRef nodeRef, Serializable value);
}

View File

@@ -18,51 +18,45 @@
*/
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;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.simple.JSONArray;
import org.json.simple.JSONAware;
import org.json.simple.JSONObject;
/**
* Tag property decorator class.
*
* @author Mike Hatfield
*/
public class TagPropertyDecorator implements PropertyDecorator
public class TagPropertyDecorator extends BasePropertyDecorator
{
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)
/**
* @see org.alfresco.repo.jscript.app.PropertyDecorator#decorate(org.alfresco.service.namespace.QName, org.alfresco.service.cmr.repository.NodeRef, java.io.Serializable)
*/
@SuppressWarnings("unchecked")
public JSONAware decorate(QName propertyName, NodeRef nodeRef, Serializable value)
{
Collection<NodeRef> collection = (Collection<NodeRef>)value;
Object[] array = new Object[collection.size()];
int index = 0;
JSONArray array = new JSONArray();
for (NodeRef obj : collection)
{
try
{
Map<String, Serializable> jsonObj = new LinkedHashMap<String, Serializable>(2);
JSONObject jsonObj = new JSONObject();
jsonObj.put("name", this.nodeService.getProperty(obj, ContentModel.PROP_NAME));
jsonObj.put("nodeRef", obj.toString());
array[index++] = jsonObj;
array.add(jsonObj);
}
catch (InvalidNodeRefException e)
{

View File

@@ -19,40 +19,43 @@
package org.alfresco.repo.jscript.app;
import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Map;
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 org.json.simple.JSONAware;
import org.json.simple.JSONObject;
/**
* Username property decorator class.
*
* @author Mike Hatfield
*/
public class UsernamePropertyDecorator implements PropertyDecorator
public class UsernamePropertyDecorator extends BasePropertyDecorator
{
private ServiceRegistry services;
private NodeService nodeService = null;
/** Person service */
private PersonService personService = null;
public void setServiceRegistry(ServiceRegistry serviceRegistry)
/**
* @param personService person service
*/
public void setPersonService(PersonService personService)
{
this.services = serviceRegistry;
this.nodeService = serviceRegistry.getNodeService();
this.personService = serviceRegistry.getPersonService();
this.personService = personService;
}
public Serializable decorate(NodeRef nodeRef, String propertyName, Serializable value)
/**
* @see org.alfresco.repo.jscript.app.PropertyDecorator#decorate(org.alfresco.service.cmr.repository.NodeRef, java.io.Serializable)
*/
@SuppressWarnings("unchecked")
public JSONAware decorate(QName propertyName, NodeRef nodeRef, Serializable value)
{
String username = value.toString();
String firstName = null;
String lastName = null;
Map<String, Serializable> map = new LinkedHashMap<String, Serializable>(4);
JSONObject map = new JSONObject();
map.put("userName", username);
if (this.personService.personExists(username))
@@ -70,12 +73,12 @@ public class UsernamePropertyDecorator implements PropertyDecorator
else
{
map.put("isDeleted", true);
return (Serializable)map;
return map;
}
map.put("firstName", firstName);
map.put("lastName", lastName);
map.put("displayName", (firstName != null ? firstName + " " : "" + lastName != null ? lastName : "").replaceAll("^\\s+|\\s+$", ""));
return (Serializable)map;
return map;
}
}