Merged 5.2.N (5.2.1) to HEAD (5.2)

131858 mward: Merged 131464:131680 from DEV/mward/5.2.n_createperson to 5.2.n
     Creating branch for REPO-892 (Create person REST API)
     REPO-892: create person - initial commit, bare-bones implementation and test.
     REPO-892: refactored test versions of Person and Company to reduce duplication.
     REPO-892: further refactoring to reduce prod/test duplication.
     REPO-892: add missing fields to the 'create person' operation.
     REPO-892: introduced PersonUpdate class for create (and I'm assuming update) operations.
     REPO-892: missing license header
     REPO-892: very minor refactoring - extract field in tests.
     REPO-892: make sure not all fields need to be supplied during create.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@132307 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2016-11-03 13:59:35 +00:00
parent 4158363319
commit 373d976faa
11 changed files with 1041 additions and 547 deletions

View File

@@ -450,7 +450,7 @@ public class RepoService
personInfo.getCompany(), network, personInfo.getSkype(), personInfo.getLocation(), personInfo.getTel(),
personInfo.getMob(), personInfo.getInstantmsg(), personInfo.getGoogle());
final Map<QName, Serializable> props = testPerson.getProperties();
final Map<QName, Serializable> props = testPerson.toProperties();
// short-circuit for default/tenant "admin"
if (! isDefaultAdmin(username, network))
@@ -1880,7 +1880,7 @@ public class RepoService
return defaultAccount == null ? null : defaultAccount.getId();
}
public boolean isEnabled()
public Boolean isEnabled()
{
return enabled;
}

View File

@@ -1,54 +1,58 @@
/*
* #%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;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import java.util.Iterator;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.tenant.TenantUtil;
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.rest.api.tests.RepoService.SiteInformation;
import org.alfresco.rest.api.model.PersonUpdate;
import org.alfresco.rest.api.tests.RepoService.TestNetwork;
import org.alfresco.rest.api.tests.RepoService.TestSite;
import org.alfresco.rest.api.tests.client.PublicApiClient.People;
import org.alfresco.rest.api.tests.client.PublicApiException;
import org.alfresco.rest.api.tests.client.RequestContext;
import org.alfresco.rest.api.tests.client.data.Company;
import org.alfresco.rest.api.tests.client.data.JSONAble;
import org.alfresco.rest.api.tests.client.data.Person;
import org.alfresco.rest.api.tests.client.data.SiteRole;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.apache.commons.httpclient.HttpStatus;
import org.json.simple.JSONObject;
import org.junit.Before;
import org.junit.Test;
import java.util.Iterator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
public class TestPeople extends EnterpriseTestApi
{
private People people;
@Before
public void setUp() throws Exception
{
people = publicApiClient.people();
}
@Test
public void testPeople() throws Exception
{
@@ -62,13 +66,11 @@ public class TestPeople extends EnterpriseTestApi
Iterator<String> personIt2 = account2.getPersonIds().iterator();
final String person3 = personIt2.next();
People peopleProxy = publicApiClient.people();
// Test Case cloud-2192
// should be able to see oneself
{
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1));
Person resp = peopleProxy.getPerson(person1);
Person resp = people.getPerson(person1);
Person person1Entity = repoService.getPerson(person1);
check(person1Entity, resp);
}
@@ -76,7 +78,7 @@ public class TestPeople extends EnterpriseTestApi
// should be able to see another user in the same domain, and be able to see full profile
{
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person2));
Person resp = peopleProxy.getPerson(person1);
Person resp = people.getPerson(person1);
Person person1Entity = repoService.getPerson(person1);
check(person1Entity, resp);
}
@@ -84,7 +86,7 @@ public class TestPeople extends EnterpriseTestApi
// "-me-" user
{
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1));
Person resp = peopleProxy.getPerson(org.alfresco.rest.api.People.DEFAULT_USER);
Person resp = people.getPerson(org.alfresco.rest.api.People.DEFAULT_USER);
Person person1Entity = repoService.getPerson(person1);
check(person1Entity, resp);
}
@@ -93,7 +95,7 @@ public class TestPeople extends EnterpriseTestApi
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person3));
try
{
peopleProxy.getPerson(person1);
people.getPerson(person1);
fail("");
}
catch(PublicApiException e)
@@ -111,4 +113,156 @@ public class TestPeople extends EnterpriseTestApi
assertEquals(resp.getDescription(), desc);
}
@Test
public void testCreatePerson() throws Exception
{
Iterator<TestNetwork> accountsIt = getTestFixture().getNetworksIt();
final TestNetwork account1 = accountsIt.next();
final String networkAdmin = "admin@"+account1.getId();
publicApiClient.setRequestContext(new RequestContext(account1.getId(), networkAdmin, "admin"));
PersonUpdate person = new PersonUpdate.Builder().
id("myUserName@"+account1.getId()).
firstName("Firstname").
lastName("Lastname").
description("my description").
email("email@example.com").
skypeId("my.skype.id").
googleId("google").
instantMessageId("jabber@im.example.com").
jobTitle("International Man of Mystery").
location("location").
company(new Company("Org", "addr1", "addr2", "addr3", "AB1 1BA", "111 12312123", "222 345345345", "company.email@example.com")).
mobile("5657 567567 34543").
telephone("1234 5678 9012").
userStatus("userStatus").
enabled(true).
emailNotificationsEnabled(true).
build();
// true -> use extra fields such as company
Person p = people.create(person, true);
assertEquals("myUserName@"+account1.getId(), p.getId());
assertEquals("Firstname", p.getFirstName());
assertEquals("Lastname", p.getLastName());
// TODO: we currently have confusion over cm:description, cm:persondescription and RestApi:description
// PeopleImpl currently removes cm:persondescription and replaces it with {RestApi}description
// We'll keep description as null until we know better.
// assertEquals("my description", p.getDescription());
assertEquals(null, p.getDescription());
assertEquals("email@example.com", p.getEmail());
assertEquals("my.skype.id", p.getSkypeId());
assertEquals("google", p.getGoogleId());
assertEquals("jabber@im.example.com", p.getInstantMessageId());
assertEquals("International Man of Mystery", p.getJobTitle());
assertEquals("location", p.getLocation());
// Check embedded "company" document
org.alfresco.rest.api.model.Company co = p.getCompany();
assertEquals("Org", co.getOrganization());
assertEquals("addr1", co.getAddress1());
assertEquals("addr2", co.getAddress2());
assertEquals("addr3", co.getAddress3());
assertEquals("AB1 1BA", co.getPostcode());
assertEquals("111 12312123", co.getTelephone());
assertEquals("222 345345345", co.getFax());
assertEquals("company.email@example.com", co.getEmail());
assertEquals("5657 567567 34543", p.getMobile());
assertEquals("1234 5678 9012", p.getTelephone());
assertEquals("userStatus", p.getUserStatus());
assertEquals(true, p.isEnabled());
assertEquals(true, p.isEmailNotificationsEnabled());
}
@Test
public void testCreatePerson_notAllFieldsRequired() throws Exception
{
Iterator<TestNetwork> accountsIt = getTestFixture().getNetworksIt();
final TestNetwork account1 = accountsIt.next();
final String networkAdmin = "admin@"+account1.getId();
publicApiClient.setRequestContext(new RequestContext(account1.getId(), networkAdmin, "admin"));
PersonUpdate person = new PersonUpdate.Builder().
id("joe.bloggs@"+account1.getId()).
firstName("Joe").
lastName("Bloggs").
email("joe.bloggs@example.com").
skypeId("jb.skype.id").
telephone("1234 5678 9012").
enabled(false).
emailNotificationsEnabled(false).
build();
// true -> use extra fields such as company
Person p = people.create(person, true);
assertEquals("joe.bloggs@"+account1.getId(), p.getId());
assertEquals("Joe", p.getFirstName());
assertEquals("Bloggs", p.getLastName());
assertEquals(null, p.getDescription());
assertEquals("joe.bloggs@example.com", p.getEmail());
assertEquals("jb.skype.id", p.getSkypeId());
assertEquals(null, p.getGoogleId());
assertEquals(null, p.getInstantMessageId());
assertEquals(null, p.getJobTitle());
assertEquals(null, p.getLocation());
assertEquals(null, p.getCompany());
assertEquals(null, p.getMobile());
assertEquals("1234 5678 9012", p.getTelephone());
assertEquals(null, p.getUserStatus());
assertEquals(true, p.isEnabled());
assertEquals(false, p.isEmailNotificationsEnabled());
}
public static class PersonUpdateJSONSerializer implements JSONAble
{
private final PersonUpdate personUpdate;
public PersonUpdateJSONSerializer(PersonUpdate personUpdate)
{
this.personUpdate = personUpdate;
}
@Override
public JSONObject toJSON()
{
return toJSON(true);
}
public JSONObject toJSON(boolean fullVisibility)
{
JSONObject personJson = new JSONObject();
personJson.put("id", personUpdate.getUserName());
personJson.put("firstName", personUpdate.getFirstName());
personJson.put("lastName", personUpdate.getLastName());
if (fullVisibility)
{
personJson.put("description", personUpdate.getDescription());
personJson.put("email", personUpdate.getEmail());
personJson.put("skypeId", personUpdate.getSkypeId());
personJson.put("googleId", personUpdate.getGoogleId());
personJson.put("instantMessageId", personUpdate.getInstantMessageId());
personJson.put("jobTitle", personUpdate.getJobTitle());
personJson.put("location", personUpdate.getLocation());
org.alfresco.rest.api.model.Company co = personUpdate.getCompany();
if (co == null)
{
co = new org.alfresco.rest.api.model.Company();
}
personJson.put("company", new Company(co).toJSON());
personJson.put("mobile", personUpdate.getMobile());
personJson.put("telephone", personUpdate.getTelephone());
personJson.put("userStatus", personUpdate.getUserStatus());
personJson.put("enabled", personUpdate.isEnabled());
personJson.put("emailNotificationsEnabled", personUpdate.isEmailNotificationsEnabled());
}
return personJson;
}
}
}

View File

@@ -44,7 +44,9 @@ import javax.servlet.http.HttpServletResponse;
import org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl;
import org.alfresco.opencmis.CMISDispatcherRegistry.Binding;
import org.alfresco.rest.api.model.PersonUpdate;
import org.alfresco.rest.api.model.SiteUpdate;
import org.alfresco.rest.api.tests.TestPeople;
import org.alfresco.rest.api.tests.TestSites;
import org.alfresco.rest.api.tests.client.PublicApiHttpClient.BinaryPayload;
import org.alfresco.rest.api.tests.client.PublicApiHttpClient.RequestBuilder;
@@ -1070,9 +1072,10 @@ public class PublicApiClient
return retSite;
}
public Person create(Person person, boolean fullVisibility) throws PublicApiException
public Person create(PersonUpdate person, boolean fullVisibility) throws PublicApiException
{
HttpResponse response = create("people", null, null, null, person.toJSON(fullVisibility).toString(), "Failed to create person");
TestPeople.PersonUpdateJSONSerializer jsonizer = new TestPeople.PersonUpdateJSONSerializer(person) ;
HttpResponse response = create("people", null, null, null, jsonizer.toJSON(fullVisibility).toString(), "Failed to create person");
Person retSite = Person.parsePerson((JSONObject)response.getJsonResponse().get("entry"));
return retSite;
}

View File

@@ -1,106 +1,44 @@
/*
* #%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.assertTrue;
import org.json.simple.JSONObject;
public class Company implements ExpectedComparison
public class Company extends org.alfresco.rest.api.model.Company implements ExpectedComparison
{
private String organization;
private String address1;
private String address2;
private String address3;
private String postcode;
private String telephone;
private String fax;
private String email;
public Company(String organization, String address1, String address2, String address3,
String postcode, String telephone, String fax, String email)
public Company(org.alfresco.rest.api.model.Company company)
{
super();
this.organization = organization;
this.address1 = address1;
this.address2 = address2;
this.address3 = address3;
this.postcode = postcode;
this.telephone = telephone;
this.fax = fax;
this.email = email;
super(company.getOrganization(), company.getAddress1(), company.getAddress2(), company.getAddress3(), company.getPostcode(), company.getTelephone(), company.getFax(), company.getEmail());
}
public String getOrganization()
public Company(String organization, String address1, String address2, String address3, String postcode, String telephone, String fax, String email)
{
return organization;
}
public String getAddress1()
{
return address1;
}
public String getAddress2()
{
return address2;
}
public String getAddress3()
{
return address3;
}
public String getPostcode()
{
return postcode;
}
public String getTelephone()
{
return telephone;
}
public String getFax()
{
return fax;
}
public String getEmail()
{
return email;
}
@Override
public String toString()
{
return "Company [address1=" + address1 + ", address2=" + address2
+ ", address3=" + address3 + ", postcode=" + postcode
+ ", telephone=" + telephone + ", fax=" + fax + ", email="
+ email + "]";
super(organization, address1, address2, address3, postcode, telephone, fax, email);
}
@SuppressWarnings("unchecked")
@@ -112,7 +50,7 @@ public class Company implements ExpectedComparison
companyJson.put("address2", getAddress2());
companyJson.put("address3", getAddress3());
companyJson.put("postcode", getPostcode());
companyJson.put("telephone", getPostcode());
companyJson.put("telephone", getTelephone());
companyJson.put("fax", getFax());
companyJson.put("email", getEmail());
return companyJson;
@@ -125,13 +63,13 @@ public class Company implements ExpectedComparison
Company other = (Company)o;
AssertUtil.assertEquals("organization", organization, other.getOrganization());
AssertUtil.assertEquals("address1", address1, other.getAddress1());
AssertUtil.assertEquals("address2", address2, other.getAddress2());
AssertUtil.assertEquals("address3", address3, other.getAddress3());
AssertUtil.assertEquals("postcode", postcode, other.getPostcode());
AssertUtil.assertEquals("telephone", telephone, other.getTelephone());
AssertUtil.assertEquals("fax", fax, other.getFax());
AssertUtil.assertEquals("email", email, other.getEmail());
AssertUtil.assertEquals("organization", getOrganization(), other.getOrganization());
AssertUtil.assertEquals("address1", getAddress1(), other.getAddress1());
AssertUtil.assertEquals("address2", getAddress2(), other.getAddress2());
AssertUtil.assertEquals("address3", getAddress3(), other.getAddress3());
AssertUtil.assertEquals("postcode", getPostcode(), other.getPostcode());
AssertUtil.assertEquals("telephone", getTelephone(), other.getTelephone());
AssertUtil.assertEquals("fax", getFax(), other.getFax());
AssertUtil.assertEquals("email", getEmail(), other.getEmail());
}
}

View File

@@ -30,36 +30,26 @@ 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 java.util.*;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.rest.api.tests.QueriesPeopleApiTest;
import org.alfresco.rest.api.tests.client.PublicApiClient.ExpectedPaging;
import org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.codehaus.jackson.map.ObjectMapper;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
public class Person implements Serializable, Comparable<Person>, ExpectedComparison
public class Person
extends org.alfresco.rest.api.model.Person
implements Serializable, Comparable<Person>, ExpectedComparison
{
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 static Collator collator = Collator.getInstance();
@@ -67,20 +57,52 @@ public class Person implements Serializable, Comparable<Person>, ExpectedCompari
Company company, String skype, String location, String tel,
String mob, String instantmsg, String google, String description)
{
super();
super(username, enabled, null, firstName, lastName, null, location, tel, mob, null, skype, instantmsg, null, null, google, null, null, null, description, company);
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 userName,
Boolean enabled,
NodeRef avatarId,
String firstName,
String lastName,
String jobTitle,
String location,
String telephone,
String mobile,
String email,
String skypeId,
String instantMessageId,
String userStatus,
Date statusUpdatedAt,
String googleId,
Long quota,
Long quotaUsed,
Boolean emailNotificationsEnabled,
String description,
org.alfresco.rest.api.model.Company company)
{
super(userName,
enabled,
avatarId,
firstName,
lastName,
jobTitle,
location,
telephone,
mobile,
email,
skypeId,
instantMessageId,
userStatus,
statusUpdatedAt,
googleId,
quota,
quotaUsed,
emailNotificationsEnabled,
description,
company);
this.id = userName;
}
public String getId()
@@ -93,120 +115,25 @@ public class Person implements Serializable, Comparable<Person>, ExpectedCompari
this.id = id;
}
public Boolean getEnabled() {
return enabled;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getSkype() {
return skype;
}
public void setSkype(String skype) {
this.skype = skype;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getMob() {
return mob;
}
public void setMob(String mob) {
this.mob = mob;
}
public String getInstantmsg() {
return instantmsg;
}
public void setInstantmsg(String instantmsg) {
this.instantmsg = instantmsg;
}
public String getGoogle() {
return google;
}
public void setGoogle(String google) {
this.google = google;
}
public String getFirstName()
{
return firstName;
}
public Company getCompany()
{
return company;
}
public void setCompany(Company company)
{
this.company = company;
}
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
public String getLastName()
{
return lastName;
}
public void setLastName(String lastName)
{
this.lastName = lastName;
}
public String getDescription()
{
return description;
}
/**
* Note: used for string comparisons in tests.
*
* @see QueriesPeopleApiTest#checkApiCall(java.lang.String, java.lang.String, java.lang.String, org.alfresco.rest.api.tests.client.PublicApiClient.Paging, int, java.lang.String[])
*/
@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 + ", " : "")
+ (skypeId != null ? "skype=" + skypeId + ", " : "")
+ (location != null ? "location=" + location + ", " : "")
+ (tel != null ? "tel=" + tel + ", " : "")
+ (mob != null ? "mob=" + mob + ", " : "")
+ (instantmsg != null ? "instantmsg=" + instantmsg + ", " : "")
+ (google != null ? "google=" + google + ", " : "")
+ (telephone != null ? "tel=" + telephone + ", " : "")
+ (mobile != null ? "mob=" + mobile + ", " : "")
+ (instantMessageId != null ? "instantmsg=" + instantMessageId + ", " : "")
+ (googleId != null ? "google=" + googleId + ", " : "")
+ (description != null ? "description=" + description + ", " : "")
+ "]";
}
@@ -215,41 +142,46 @@ public class Person implements Serializable, Comparable<Person>, ExpectedCompari
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("description", getDescription());
personJson.put("email", getEmail());
personJson.put("skypeId", getSkypeId());
personJson.put("googleId", getGoogleId());
personJson.put("instantMessageId", getInstantMessageId());
personJson.put("jobTitle", getJobTitle());
personJson.put("location", getLocation());
personJson.put("company", new Company(company).toJSON());
personJson.put("mobile", getMobile());
personJson.put("telephone", getTelephone());
personJson.put("userStatus", getUserStatus());
personJson.put("enabled", isEnabled());
personJson.put("emailNotificationsEnabled", isEmailNotificationsEnabled());
}
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");
String description = (String)jsonObject.get("description");
String email = (String) jsonObject.get("email");
String skypeId = (String)jsonObject.get("skypeId");
String googleId = (String)jsonObject.get("googleId");
String instantMessageId = (String)jsonObject.get("instantMessageId");
String jobTitle = (String) jsonObject.get("jobTitle");
String location = (String)jsonObject.get("location");
Company company = null;
JSONObject companyJSON = (JSONObject)jsonObject.get("company");
if(companyJSON != null)
{
String organization = (String)companyJSON.get("organization");
@@ -261,25 +193,49 @@ public class Person implements Serializable, Comparable<Person>, ExpectedCompari
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)
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);
String mobile = (String)jsonObject.get("mobile");
String telephone = (String)jsonObject.get("telephone");
String userStatus = (String) jsonObject.get("userStatus");
Boolean enabled = (Boolean)jsonObject.get("enabled");
Boolean emailNotificationsEnabled = (Boolean) jsonObject.get("emailNotificationsEnabled");
// TODO: create a PersonCreate request class.
Person person = new Person(
userId,
enabled,
null, // avatarId is not accepted by "create person"
firstName,
lastName,
jobTitle,
location,
telephone,
mobile,
email,
skypeId,
instantMessageId,
userStatus,
null, // userStatusUpdateAt is read only - not used in create person
googleId,
null, // quota - not used in create person
null, // quotaUsers - not used
emailNotificationsEnabled,
description,
company
);
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
{
@@ -356,121 +312,26 @@ public class Person implements Serializable, Comparable<Person>, ExpectedCompari
Person other = (Person)o;
AssertUtil.assertEquals("userId", id, other.getId());
AssertUtil.assertEquals("userId", getId(), other.getId());
AssertUtil.assertEquals("firstName", firstName, other.getFirstName());
AssertUtil.assertEquals("lastName", lastName, other.getLastName());
AssertUtil.assertEquals("enabled", enabled, other.getEnabled());
AssertUtil.assertEquals("enabled", enabled, other.isEnabled());
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());
AssertUtil.assertEquals("skype", getSkypeId(), other.getSkypeId());
AssertUtil.assertEquals("location", getLocation(), other.getLocation());
AssertUtil.assertEquals("tel", getTelephone(), other.getTelephone());
AssertUtil.assertEquals("mobile", getMobile(), other.getMobile());
AssertUtil.assertEquals("instanceMessageId", getInstantMessageId(), other.getInstantMessageId());
AssertUtil.assertEquals("googleId", getGoogleId(), other.getGoogleId());
if(company != null)
{
company.expected(getCompany());
new Company(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(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)
{