Merged RETURN-OF-THE-API (5.2.0) to 5.2.N (5.2.1)

129011 adavis: REPO-243 People Live Search
      - Fix build failures
      - replace tabs in Person.java


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@129189 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Martin Muller
2016-08-05 13:49:23 +00:00
parent f83b4b7654
commit 4350d8026b
5 changed files with 493 additions and 468 deletions

View File

@@ -46,6 +46,7 @@ import org.junit.runners.Suite;
NodeAssociationsApiTest.class,
NodeVersionsApiTest.class,
QueriesNodesApiTest.class,
QueriesPeopleApiTest.class,
RenditionsTest.class,
SharedLinkApiTest.class,
ActivitiesPostingTest.class,

View File

@@ -348,10 +348,10 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
assertEquals(content1_Id, node.getId());
UserInfo createdByUser = node.getCreatedByUser();
assertEquals(user1, createdByUser.getId());
assertEquals(user1 + " " + user1, createdByUser.getDisplayName());
assertEquals(UserInfo.getTestDisplayName(user1), createdByUser.getDisplayName());
UserInfo modifiedByUser = node.getModifiedByUser();
assertEquals(user1, modifiedByUser.getId());
assertEquals(user1 + " " + user1, modifiedByUser.getDisplayName());
assertEquals(UserInfo.getTestDisplayName(user1), modifiedByUser.getDisplayName());
assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, node.getContent().getMimeType());
assertNotNull(node.getContent().getMimeTypeName());
assertNotNull(node.getContent().getEncoding());
@@ -665,7 +665,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
String content_Id = documentResp.getId();
// Expected result ...
UserInfo expectedUser = new UserInfo(user1, user1+" "+user1);
UserInfo expectedUser = new UserInfo(user1);
Document d1 = new Document();
d1.setId(content_Id);
@@ -1912,7 +1912,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
String myNodeId = getMyNodeId();
UserInfo expectedUser = new UserInfo(user1, user1+" "+user1);
UserInfo expectedUser = new UserInfo(user1);
String postUrl = getNodeChildrenUrl(myNodeId);
@@ -2392,7 +2392,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
setRequestContext(user1);
String myNodeId = getMyNodeId();
UserInfo expectedUser = new UserInfo(user1, user1+" "+user1);
UserInfo expectedUser = new UserInfo(user1);
String myChildrenUrl = getNodeChildrenUrl(myNodeId);
// create folder f1
@@ -2576,7 +2576,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
String folder0Name = "f0-testCreateEmptyFile-"+RUNID;
String f0Id = createFolder(Nodes.PATH_MY, folder0Name).getId();
UserInfo expectedUser = new UserInfo(user1, user1+" "+user1);
UserInfo expectedUser = new UserInfo(user1);
String postUrl = getNodeChildrenUrl(f0Id);
@@ -2718,7 +2718,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
String folder0Name = "f0-testUpdateNodeInfo-"+RUNID;
String f0Id = createFolder(Nodes.PATH_MY, folder0Name).getId();
UserInfo expectedUser = new UserInfo(user1, user1+" "+user1);
UserInfo expectedUser = new UserInfo(user1);
String postUrl = getNodeChildrenUrl(f0Id);

View File

@@ -38,6 +38,7 @@ import org.alfresco.rest.api.tests.client.data.Document;
import org.alfresco.rest.api.tests.client.data.Node;
import org.alfresco.rest.api.tests.client.data.QuickShareLinkEmailRequest;
import org.alfresco.rest.api.tests.client.data.Rendition;
import org.alfresco.rest.api.tests.client.data.UserInfo;
import org.alfresco.rest.api.tests.util.MultiPartBuilder;
import org.alfresco.rest.api.tests.util.RestApiUtil;
import org.junit.Test;
@@ -153,10 +154,10 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
assertEquals(docModifiedAt.getTime(), resp.getModifiedAt().getTime()); // not changed
assertEquals(docModifiedBy, resp.getModifiedByUser().getId()); // not changed (ie. not user2)
assertEquals(docModifiedBy+" "+docModifiedBy, resp.getModifiedByUser().getDisplayName());
assertEquals(UserInfo.getTestDisplayName(docModifiedBy), resp.getModifiedByUser().getDisplayName());
assertEquals(user2, resp.getSharedByUser().getId());
assertEquals(user2+" "+user2, resp.getSharedByUser().getDisplayName());
assertEquals(UserInfo.getTestDisplayName(user2), resp.getSharedByUser().getDisplayName());
// -ve test - try to create again (same user) - already exists
post(URL_SHARED_LINKS, toJsonAsStringNonNull(body), 409);
@@ -187,9 +188,9 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
assertNull(resp.getAllowableOperations()); // include is ignored
assertNull(resp.getModifiedByUser().getId()); // userId not returned
assertEquals(user1+" "+user1, resp.getModifiedByUser().getDisplayName());
assertEquals(UserInfo.getTestDisplayName(user1), resp.getModifiedByUser().getDisplayName());
assertNull(resp.getSharedByUser().getId()); // userId not returned
assertEquals(user2+" "+user2, resp.getSharedByUser().getDisplayName());
assertEquals(UserInfo.getTestDisplayName(user2), resp.getSharedByUser().getDisplayName());
// access to get shared link info - pass user2 (but ignore in non-MT)
params = Collections.singletonMap("include", "allowableOperations");
@@ -202,9 +203,9 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
assertNull(resp.getAllowableOperations()); // include is ignored
assertNull(resp.getModifiedByUser().getId()); // userId not returned
assertEquals(user1+" "+user1, resp.getModifiedByUser().getDisplayName());
assertEquals(UserInfo.getTestDisplayName(user1), resp.getModifiedByUser().getDisplayName());
assertNull(resp.getSharedByUser().getId()); // userId not returned
assertEquals(user2+" "+user2, resp.getSharedByUser().getDisplayName());
assertEquals(UserInfo.getTestDisplayName(user2), resp.getSharedByUser().getDisplayName());
// allowable operations not included - no params
@@ -225,9 +226,9 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
assertNull(resp.getAllowableOperations()); // include is ignored
assertNull(resp.getModifiedByUser().getId()); // userId not returned
assertEquals(user1+" "+user1, resp.getModifiedByUser().getDisplayName());
assertEquals(UserInfo.getTestDisplayName(user1), resp.getModifiedByUser().getDisplayName());
assertNull(resp.getSharedByUser().getId()); // userId not returned
assertEquals(user2+" "+user2, resp.getSharedByUser().getDisplayName());
assertEquals(UserInfo.getTestDisplayName(user2), resp.getSharedByUser().getDisplayName());
// unauth access to file 1 content (via shared link)
response = getSingle(QuickShareLinkEntityResource.class, shared1Id + "/content", null, 200);

View File

@@ -1,511 +1,511 @@
/*
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* 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/>.
* #L%
*/
/*
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* 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/>.
* #L%
*/
package org.alfresco.rest.api.tests.client.data;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.Serializable;
import java.text.Collator;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.rest.api.tests.client.PublicApiClient.ExpectedPaging;
import org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse;
import org.alfresco.service.namespace.QName;
import org.json.simple.JSONArray;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.Serializable;
import java.text.Collator;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.rest.api.tests.client.PublicApiClient.ExpectedPaging;
import org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse;
import org.alfresco.service.namespace.QName;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
public class Person implements Serializable, Comparable<Person>, ExpectedComparison
{
private static final long serialVersionUID = 3185698391792389751L;
private static final long serialVersionUID = 3185698391792389751L;
private String id;
private Boolean enabled;
private String username;
private String firstName;
private String lastName;
private Company company;
private String skype;
private String location;
private String tel;
private String mob;
private String instantmsg;
private String google;
private String description;
private String id;
private Boolean enabled;
private String username;
private String firstName;
private String lastName;
private Company company;
private String skype;
private String location;
private String tel;
private String mob;
private String instantmsg;
private String google;
private String description;
private static Collator collator = Collator.getInstance();
private static Collator collator = Collator.getInstance();
public Person(String id, String username, Boolean enabled, String firstName, String lastName,
Company company, String skype, String location, String tel,
String mob, String instantmsg, String google, String description)
{
super();
if(id == null)
{
throw new IllegalArgumentException();
}
this.id = id;
this.username = username;
this.enabled = enabled;
this.firstName = firstName;
this.lastName = lastName;
this.company = company;
this.skype = skype;
this.location = location;
this.tel = tel;
this.mob = mob;
this.instantmsg = instantmsg;
this.google = google;
this.description = description;
}
public Person(String id, String username, Boolean enabled, String firstName, String lastName,
Company company, String skype, String location, String tel,
String mob, String instantmsg, String google, String description)
{
super();
if(id == null)
{
throw new IllegalArgumentException();
}
this.id = id;
this.username = username;
this.enabled = enabled;
this.firstName = firstName;
this.lastName = lastName;
this.company = company;
this.skype = skype;
this.location = location;
this.tel = tel;
this.mob = mob;
this.instantmsg = instantmsg;
this.google = google;
this.description = description;
}
public String getId()
{
return id;
}
public String getId()
{
return id;
}
public void setId(String id)
{
this.id = id;
}
public void setId(String id)
{
this.id = id;
}
public Boolean getEnabled() {
return enabled;
}
public Boolean getEnabled() {
return enabled;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
public String getUsername() {
return username;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public void setUsername(String username) {
this.username = username;
}
public String getSkype() {
return skype;
}
public String getSkype() {
return skype;
}
public void setSkype(String skype) {
this.skype = skype;
}
public void setSkype(String skype) {
this.skype = skype;
}
public String getLocation() {
return location;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public void setLocation(String location) {
this.location = location;
}
public String getTel() {
return tel;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getMob() {
return mob;
}
public String getMob() {
return mob;
}
public void setMob(String mob) {
this.mob = mob;
}
public void setMob(String mob) {
this.mob = mob;
}
public String getInstantmsg() {
return instantmsg;
}
public String getInstantmsg() {
return instantmsg;
}
public void setInstantmsg(String instantmsg) {
this.instantmsg = instantmsg;
}
public void setInstantmsg(String instantmsg) {
this.instantmsg = instantmsg;
}
public String getGoogle() {
return google;
}
public String getGoogle() {
return google;
}
public void setGoogle(String google) {
this.google = google;
}
public void setGoogle(String google) {
this.google = google;
}
public String getFirstName()
{
return firstName;
}
public String getFirstName()
{
return firstName;
}
public Company getCompany()
{
return company;
}
public Company getCompany()
{
return company;
}
public void setCompany(Company company)
{
this.company = company;
}
public void setCompany(Company company)
{
this.company = company;
}
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
public String getLastName()
{
return lastName;
}
public String getLastName()
{
return lastName;
}
public void setLastName(String lastName)
{
this.lastName = lastName;
}
public void setLastName(String lastName)
{
this.lastName = lastName;
}
public String getDescription()
{
return description;
}
public String getDescription()
{
return description;
}
@Override
public String toString()
{
return "Person [" + (id != null ? "id=" + id + ", " : "")
+ (enabled != null ? "enabled=" + enabled + ", " : "")
+ (username != null ? "username=" + username + ", " : "")
+ (firstName != null ? "firstName=" + firstName + ", " : "")
+ (lastName != null ? "lastName=" + lastName + ", " : "")
+ (company != null ? "company=" + company + ", " : "")
+ (skype != null ? "skype=" + skype + ", " : "")
+ (location != null ? "location=" + location + ", " : "")
+ (tel != null ? "tel=" + tel + ", " : "")
+ (mob != null ? "mob=" + mob + ", " : "")
+ (instantmsg != null ? "instantmsg=" + instantmsg + ", " : "")
+ (google != null ? "google=" + google + ", " : "")
+ (description != null ? "description=" + description + ", " : "")
+ "]";
}
@Override
public String toString()
{
return "Person [" + (id != null ? "id=" + id + ", " : "")
+ (enabled != null ? "enabled=" + enabled + ", " : "")
+ (username != null ? "username=" + username + ", " : "")
+ (firstName != null ? "firstName=" + firstName + ", " : "")
+ (lastName != null ? "lastName=" + lastName + ", " : "")
+ (company != null ? "company=" + company + ", " : "")
+ (skype != null ? "skype=" + skype + ", " : "")
+ (location != null ? "location=" + location + ", " : "")
+ (tel != null ? "tel=" + tel + ", " : "")
+ (mob != null ? "mob=" + mob + ", " : "")
+ (instantmsg != null ? "instantmsg=" + instantmsg + ", " : "")
+ (google != null ? "google=" + google + ", " : "")
+ (description != null ? "description=" + description + ", " : "")
+ "]";
}
@SuppressWarnings("unchecked")
public JSONObject toJSON(boolean fullVisibility)
{
JSONObject personJson = new JSONObject();
personJson.put("id", getId());
personJson.put("firstName", getFirstName());
personJson.put("lastName", getLastName());
if(fullVisibility)
{
personJson.put("skypeId", "skype");
personJson.put("location", "location");
personJson.put("telephone", "tel");
personJson.put("mobile", "mob");
personJson.put("instantMessageId", "instantmsg");
personJson.put("googleId", "google");
@SuppressWarnings("unchecked")
public JSONObject toJSON(boolean fullVisibility)
{
JSONObject personJson = new JSONObject();
personJson.put("id", getId());
personJson.put("firstName", getFirstName());
personJson.put("lastName", getLastName());
if(fullVisibility)
{
personJson.put("skypeId", "skype");
personJson.put("location", "location");
personJson.put("telephone", "tel");
personJson.put("mobile", "mob");
personJson.put("instantMessageId", "instantmsg");
personJson.put("googleId", "google");
personJson.put("company", company.toJSON());
personJson.put("company", company.toJSON());
}
return personJson;
}
public static Person parsePerson(JSONObject jsonObject)
{
Boolean enabled = (Boolean)jsonObject.get("enabled");
String location = (String)jsonObject.get("location");
String instantMessageId = (String)jsonObject.get("instantMessageId");
String googleId = (String)jsonObject.get("googleId");
String skypeId = (String)jsonObject.get("skypeId");
String username = (String)jsonObject.get("username");
String telephone = (String)jsonObject.get("telephone");
String mobile = (String)jsonObject.get("mobile");
String userId = (String)jsonObject.get("id");
String firstName = (String)jsonObject.get("firstName");
String lastName = (String)jsonObject.get("lastName");
String description = (String)jsonObject.get("description");
}
return personJson;
}
public static Person parsePerson(JSONObject jsonObject)
{
Boolean enabled = (Boolean)jsonObject.get("enabled");
String location = (String)jsonObject.get("location");
String instantMessageId = (String)jsonObject.get("instantMessageId");
String googleId = (String)jsonObject.get("googleId");
String skypeId = (String)jsonObject.get("skypeId");
String username = (String)jsonObject.get("username");
String telephone = (String)jsonObject.get("telephone");
String mobile = (String)jsonObject.get("mobile");
String userId = (String)jsonObject.get("id");
String firstName = (String)jsonObject.get("firstName");
String lastName = (String)jsonObject.get("lastName");
String description = (String)jsonObject.get("description");
JSONObject companyJSON = (JSONObject)jsonObject.get("company");
Company company = null;
if(companyJSON != null)
{
String organization = (String)companyJSON.get("organization");
String address1 = (String)companyJSON.get("address1");
String address2 = (String)companyJSON.get("address2");
String address3 = (String)companyJSON.get("address3");
String postcode = (String)companyJSON.get("postcode");
String companyTelephone = (String)companyJSON.get("telephone");
String fax = (String)companyJSON.get("fax");
String companyEmail = (String)companyJSON.get("email");
if (organization != null ||
address2 != null ||
address3 != null ||
postcode != null ||
companyTelephone != null ||
fax != null ||
companyEmail != null)
{
company = new Company(organization, address1, address2, address3, postcode, companyTelephone, fax, companyEmail);
}
}
Person person = new Person(userId, username, enabled, firstName, lastName, company, skypeId, location, telephone, mobile, instantMessageId, googleId, description);
return person;
}
public Person restriced()
{
Person p = new Person(getId(), getUsername(), getEnabled(), getFirstName(), getLastName(), null, null, null, null, null, null, null, null);
return p;
}
JSONObject companyJSON = (JSONObject)jsonObject.get("company");
Company company = null;
if(companyJSON != null)
{
String organization = (String)companyJSON.get("organization");
String address1 = (String)companyJSON.get("address1");
String address2 = (String)companyJSON.get("address2");
String address3 = (String)companyJSON.get("address3");
String postcode = (String)companyJSON.get("postcode");
String companyTelephone = (String)companyJSON.get("telephone");
String fax = (String)companyJSON.get("fax");
String companyEmail = (String)companyJSON.get("email");
if (organization != null ||
address2 != null ||
address3 != null ||
postcode != null ||
companyTelephone != null ||
fax != null ||
companyEmail != null)
{
company = new Company(organization, address1, address2, address3, postcode, companyTelephone, fax, companyEmail);
}
}
Person person = new Person(userId, username, enabled, firstName, lastName, company, skypeId, location, telephone, mobile, instantMessageId, googleId, description);
return person;
}
public Person restriced()
{
Person p = new Person(getId(), getUsername(), getEnabled(), getFirstName(), getLastName(), null, null, null, null, null, null, null, null);
return p;
}
private static class UserContext
{
private String networkId;
private String personId;
private static class UserContext
{
private String networkId;
private String personId;
UserContext(String networkId, String personId)
{
super();
this.networkId = networkId;
this.personId = personId;
}
UserContext(String networkId, String personId)
{
super();
this.networkId = networkId;
this.personId = personId;
}
String getNetworkId()
{
return networkId;
}
String getNetworkId()
{
return networkId;
}
String getPersonId()
{
return personId;
}
}
String getPersonId()
{
return personId;
}
}
private static ThreadLocal<UserContext> userContext = new ThreadLocal<UserContext>();
public static void setUserContext(String personId)
{
String networkId = Person.getNetworkId(personId);
userContext.set(new UserContext(networkId, personId));
}
public static void clearUserContext()
{
userContext.set(null);
}
public static UserContext gettUserContext()
{
return userContext.get();
}
public static String getNetworkId(String personId)
{
int idx = personId.indexOf("@");
return(idx == -1 ? TenantService.DEFAULT_DOMAIN : personId.substring(idx + 1));
}
private static ThreadLocal<UserContext> userContext = new ThreadLocal<UserContext>();
public static void setUserContext(String personId)
{
String networkId = Person.getNetworkId(personId);
userContext.set(new UserContext(networkId, personId));
}
public static void clearUserContext()
{
userContext.set(null);
}
public static UserContext gettUserContext()
{
return userContext.get();
}
public static String getNetworkId(String personId)
{
int idx = personId.indexOf("@");
return(idx == -1 ? TenantService.DEFAULT_DOMAIN : personId.substring(idx + 1));
}
private String getNetworkId()
{
return Person.getNetworkId(id);
}
public boolean isVisible()
{
boolean ret = true;
private String getNetworkId()
{
return Person.getNetworkId(id);
}
public boolean isVisible()
{
boolean ret = true;
UserContext uc = gettUserContext();
String networkId = getNetworkId();
if(uc != null)
{
if(!networkId.equals(uc.getNetworkId()))
{
ret = false;
}
}
UserContext uc = gettUserContext();
String networkId = getNetworkId();
if(uc != null)
{
if(!networkId.equals(uc.getNetworkId()))
{
ret = false;
}
}
return ret;
}
@Override
public void expected(Object o)
{
assertTrue("o is an instance of " + o.getClass(), o instanceof Person);
return ret;
}
@Override
public void expected(Object o)
{
assertTrue("o is an instance of " + o.getClass(), o instanceof Person);
Person other = (Person)o;
AssertUtil.assertEquals("userId", id, other.getId());
AssertUtil.assertEquals("firstName", firstName, other.getFirstName());
AssertUtil.assertEquals("lastName", lastName, other.getLastName());
AssertUtil.assertEquals("enabled", enabled, other.getEnabled());
Person other = (Person)o;
AssertUtil.assertEquals("userId", id, other.getId());
AssertUtil.assertEquals("firstName", firstName, other.getFirstName());
AssertUtil.assertEquals("lastName", lastName, other.getLastName());
AssertUtil.assertEquals("enabled", enabled, other.getEnabled());
if(isVisible())
{
AssertUtil.assertEquals("skype", skype, other.getSkype());
AssertUtil.assertEquals("location", location, other.getLocation());
AssertUtil.assertEquals("tel", tel, other.getTel());
AssertUtil.assertEquals("mobile", mob, other.getMob());
AssertUtil.assertEquals("instanceMessageId", instantmsg, other.getInstantmsg());
AssertUtil.assertEquals("googleId", google, other.getGoogle());
if(company != null)
{
company.expected(getCompany());
}
}
}
public Map<QName, Serializable> getProperties()
{
final Map<QName, Serializable> props = new HashMap<QName, Serializable>();
if(firstName != null)
{
props.put(ContentModel.PROP_FIRSTNAME, firstName);
}
if(lastName != null)
{
props.put(ContentModel.PROP_LASTNAME, lastName);
}
if(skype != null)
{
props.put(ContentModel.PROP_SKYPE, skype);
}
if(location != null)
{
props.put(ContentModel.PROP_LOCATION, location);
}
if(tel != null)
{
props.put(ContentModel.PROP_TELEPHONE, tel);
}
if(isVisible())
{
AssertUtil.assertEquals("skype", skype, other.getSkype());
AssertUtil.assertEquals("location", location, other.getLocation());
AssertUtil.assertEquals("tel", tel, other.getTel());
AssertUtil.assertEquals("mobile", mob, other.getMob());
AssertUtil.assertEquals("instanceMessageId", instantmsg, other.getInstantmsg());
AssertUtil.assertEquals("googleId", google, other.getGoogle());
if(company != null)
{
company.expected(getCompany());
}
}
}
public Map<QName, Serializable> getProperties()
{
final Map<QName, Serializable> props = new HashMap<QName, Serializable>();
if(firstName != null)
{
props.put(ContentModel.PROP_FIRSTNAME, firstName);
}
if(lastName != null)
{
props.put(ContentModel.PROP_LASTNAME, lastName);
}
if(skype != null)
{
props.put(ContentModel.PROP_SKYPE, skype);
}
if(location != null)
{
props.put(ContentModel.PROP_LOCATION, location);
}
if(tel != null)
{
props.put(ContentModel.PROP_TELEPHONE, tel);
}
if(username != null)
{
props.put(ContentModel.PROP_USERNAME, username);
}
if(mob != null)
{
props.put(ContentModel.PROP_MOBILE, mob);
}
if(instantmsg != null)
{
props.put(ContentModel.PROP_INSTANTMSG, instantmsg);
}
if(google != null)
{
props.put(ContentModel.PROP_GOOGLEUSERNAME, google);
}
if(username != null)
{
props.put(ContentModel.PROP_USERNAME, username);
}
if(mob != null)
{
props.put(ContentModel.PROP_MOBILE, mob);
}
if(instantmsg != null)
{
props.put(ContentModel.PROP_INSTANTMSG, instantmsg);
}
if(google != null)
{
props.put(ContentModel.PROP_GOOGLEUSERNAME, google);
}
if(company != null)
{
if(company.getOrganization() != null)
{
props.put(ContentModel.PROP_ORGANIZATION, company.getOrganization());
}
if(company.getAddress1() != null)
{
props.put(ContentModel.PROP_COMPANYADDRESS1, company.getAddress1());
}
if(company.getAddress2() != null)
{
props.put(ContentModel.PROP_COMPANYADDRESS2, company.getAddress2());
}
if(company.getAddress3() != null)
{
props.put(ContentModel.PROP_COMPANYADDRESS3, company.getAddress3());
}
if(company.getPostcode() != null)
{
props.put(ContentModel.PROP_COMPANYPOSTCODE, company.getPostcode());
}
if(company.getTelephone() != null)
{
props.put(ContentModel.PROP_COMPANYTELEPHONE, company.getTelephone());
}
if(company.getFax() != null)
{
props.put(ContentModel.PROP_COMPANYFAX, company.getFax());
}
if(company.getEmail() != null)
{
props.put(ContentModel.PROP_COMPANYEMAIL, company.getEmail());
}
}
if(company != null)
{
if(company.getOrganization() != null)
{
props.put(ContentModel.PROP_ORGANIZATION, company.getOrganization());
}
if(company.getAddress1() != null)
{
props.put(ContentModel.PROP_COMPANYADDRESS1, company.getAddress1());
}
if(company.getAddress2() != null)
{
props.put(ContentModel.PROP_COMPANYADDRESS2, company.getAddress2());
}
if(company.getAddress3() != null)
{
props.put(ContentModel.PROP_COMPANYADDRESS3, company.getAddress3());
}
if(company.getPostcode() != null)
{
props.put(ContentModel.PROP_COMPANYPOSTCODE, company.getPostcode());
}
if(company.getTelephone() != null)
{
props.put(ContentModel.PROP_COMPANYTELEPHONE, company.getTelephone());
}
if(company.getFax() != null)
{
props.put(ContentModel.PROP_COMPANYFAX, company.getFax());
}
if(company.getEmail() != null)
{
props.put(ContentModel.PROP_COMPANYEMAIL, company.getEmail());
}
}
return props;
}
@Override
public int compareTo(Person o)
{
int ret = Person.collator.compare(lastName, o.getLastName());
if(ret == 0)
{
ret = Person.collator.compare(firstName, o.getFirstName());
}
return ret;
}
return props;
}
@Override
public int compareTo(Person o)
{
int ret = Person.collator.compare(lastName, o.getLastName());
if(ret == 0)
{
ret = Person.collator.compare(firstName, o.getFirstName());
}
return ret;
}
public static ListResponse<Person> parsePeople(JSONObject jsonObject)
{
List<Person> people = new ArrayList<Person>();
public static ListResponse<Person> parsePeople(JSONObject jsonObject)
{
List<Person> people = new ArrayList<Person>();
JSONObject jsonList = (JSONObject)jsonObject.get("list");
assertNotNull(jsonList);
JSONObject jsonList = (JSONObject)jsonObject.get("list");
assertNotNull(jsonList);
JSONArray jsonEntries = (JSONArray)jsonList.get("entries");
assertNotNull(jsonEntries);
JSONArray jsonEntries = (JSONArray)jsonList.get("entries");
assertNotNull(jsonEntries);
for(int i = 0; i < jsonEntries.size(); i++)
{
JSONObject jsonEntry = (JSONObject)jsonEntries.get(i);
JSONObject entry = (JSONObject)jsonEntry.get("entry");
people.add(parsePerson(entry));
}
for(int i = 0; i < jsonEntries.size(); i++)
{
JSONObject jsonEntry = (JSONObject)jsonEntries.get(i);
JSONObject entry = (JSONObject)jsonEntry.get("entry");
people.add(parsePerson(entry));
}
ExpectedPaging paging = ExpectedPaging.parsePagination(jsonList);
ListResponse<Person> resp = new ListResponse<Person>(paging, people);
return resp;
}
ExpectedPaging paging = ExpectedPaging.parsePagination(jsonList);
ListResponse<Person> resp = new ListResponse<Person>(paging, people);
return resp;
}
}

View File

@@ -42,12 +42,35 @@ public class UserInfo
{
}
public UserInfo(String id)
{
this(id, getTestDisplayName(id));
}
public UserInfo(String id, String displayName)
{
this.id = id;
this.displayName = displayName;
}
/*
* Builds a test display name from a test user id. The display name is normally
* make up of the first and last name and in the case of test users the user id
* is also used for both first and last name. With the addition of a network to
* the user id, the display name looks rather strange. This method simply strips
* the network (if it exists) from the user id and uses that for both first and
* last names.
*/
public static String getTestDisplayName(String id)
{
int i = id.lastIndexOf('@');
if (i != -1)
{
id = id.substring(0, i);
}
return id+' '+id;
}
public String getDisplayName()
{
return displayName;