Fix for ALF-11570 - NPE in UsernamePropertyDecorator on null lastname

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@32098 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2011-11-18 13:46:41 +00:00
parent 7dd72bc691
commit 51b41465ba

View File

@@ -18,6 +18,10 @@
*/
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;
@@ -25,10 +29,6 @@ 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.
*
@@ -52,15 +52,15 @@ public class UsernamePropertyDecorator implements PropertyDecorator
String username = value.toString();
String firstName = null;
String lastName = null;
Map<String, Serializable> map = new LinkedHashMap<String, Serializable>(1);
Map<String, Serializable> map = new LinkedHashMap<String, Serializable>(4);
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();
firstName = (String)properties.get(ContentModel.PROP_FIRSTNAME);
lastName = (String)properties.get(ContentModel.PROP_LASTNAME);
}
else if (username.equals("System") || username.startsWith("System@"))
{
@@ -75,7 +75,7 @@ public class UsernamePropertyDecorator implements PropertyDecorator
map.put("firstName", firstName);
map.put("lastName", lastName);
map.put("displayName", (firstName + " " + lastName).replaceAll("^\\s+|\\s+$", ""));
map.put("displayName", (firstName != null ? firstName + " " : "" + lastName != null ? lastName : "").replaceAll("^\\s+|\\s+$", ""));
return (Serializable)map;
}
}