mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
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:
@@ -26,6 +26,7 @@
|
||||
package org.alfresco.rest.api;
|
||||
|
||||
import org.alfresco.rest.api.model.Person;
|
||||
import org.alfresco.rest.api.model.PersonUpdate;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.security.NoSuchPersonException;
|
||||
|
||||
@@ -42,5 +43,14 @@ public interface People
|
||||
* @throws NoSuchPersonException if personId does not exist
|
||||
*/
|
||||
Person getPerson(final String personId);
|
||||
|
||||
/**
|
||||
* Create a person.
|
||||
*
|
||||
* @param person
|
||||
* @return
|
||||
*/
|
||||
Person create(PersonUpdate person);
|
||||
|
||||
//Person updatePerson(String personId, Person person);
|
||||
}
|
||||
|
@@ -38,6 +38,7 @@ import org.alfresco.rest.api.People;
|
||||
import org.alfresco.rest.api.Sites;
|
||||
import org.alfresco.rest.api.model.Company;
|
||||
import org.alfresco.rest.api.model.Person;
|
||||
import org.alfresco.rest.api.model.PersonUpdate;
|
||||
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
@@ -280,61 +281,29 @@ public class PeopleImpl implements People
|
||||
|
||||
return person;
|
||||
}
|
||||
/**
|
||||
private void addToMap(Map<QName, Serializable> properties, QName name, Serializable value)
|
||||
|
||||
@Override
|
||||
public Person create(PersonUpdate person)
|
||||
{
|
||||
// if(name != null && value != null)
|
||||
// {
|
||||
properties.put(name, value);
|
||||
// }
|
||||
Map<QName, Serializable> props = person.toProperties();
|
||||
NodeRef nodeRef = personService.createPerson(props);
|
||||
|
||||
// Return a fresh retrieval
|
||||
props = nodeService.getProperties(nodeRef);
|
||||
final boolean enabled = personService.isEnabled(person.getUserName());
|
||||
return new Person(nodeRef, props, enabled);
|
||||
|
||||
// ...or
|
||||
// return getPerson(person.getUserName());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
public Person updatePerson(String personId, final Person person)
|
||||
{
|
||||
personId = validatePerson(personId);
|
||||
|
||||
final Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
|
||||
// addToMap(properties, ContentModel.PROP_USERNAME, person.getUserName());
|
||||
addToMap(properties, ContentModel.PROP_FIRSTNAME, person.getFirstName());
|
||||
addToMap(properties, ContentModel.PROP_LASTNAME, person.getLastName());
|
||||
addToMap(properties, ContentModel.PROP_JOBTITLE, person.getJobTitle());
|
||||
addToMap(properties, ContentModel.PROP_LOCATION, person.getLocation());
|
||||
addToMap(properties, ContentModel.PROP_TELEPHONE, person.getTelephone());
|
||||
addToMap(properties, ContentModel.PROP_MOBILE, person.getMobile());
|
||||
addToMap(properties, ContentModel.PROP_EMAIL, person.getEmail());
|
||||
|
||||
Company company = person.getCompany();
|
||||
if(company != null)
|
||||
{
|
||||
addToMap(properties, ContentModel.PROP_ORGANIZATION, company.getOrganization());
|
||||
addToMap(properties, ContentModel.PROP_COMPANYADDRESS1, company.getAddress1());
|
||||
addToMap(properties, ContentModel.PROP_COMPANYADDRESS2, company.getAddress2());
|
||||
addToMap(properties, ContentModel.PROP_COMPANYADDRESS3, company.getAddress3());
|
||||
addToMap(properties, ContentModel.PROP_COMPANYPOSTCODE, company.getPostcode());
|
||||
addToMap(properties, ContentModel.PROP_COMPANYTELEPHONE, company.getTelephone());
|
||||
addToMap(properties, ContentModel.PROP_COMPANYFAX, company.getFax());
|
||||
addToMap(properties, ContentModel.PROP_COMPANYEMAIL, company.getEmail());
|
||||
}
|
||||
else
|
||||
{
|
||||
addToMap(properties, ContentModel.PROP_ORGANIZATION, null);
|
||||
addToMap(properties, ContentModel.PROP_COMPANYADDRESS1, null);
|
||||
addToMap(properties, ContentModel.PROP_COMPANYADDRESS2, null);
|
||||
addToMap(properties, ContentModel.PROP_COMPANYADDRESS3, null);
|
||||
addToMap(properties, ContentModel.PROP_COMPANYPOSTCODE, null);
|
||||
addToMap(properties, ContentModel.PROP_COMPANYTELEPHONE, null);
|
||||
addToMap(properties, ContentModel.PROP_COMPANYFAX, null);
|
||||
addToMap(properties, ContentModel.PROP_COMPANYEMAIL, null);
|
||||
}
|
||||
|
||||
addToMap(properties, ContentModel.PROP_SKYPE, person.getSkypeId());
|
||||
addToMap(properties, ContentModel.PROP_INSTANTMSG, person.getInstantMessageId());
|
||||
addToMap(properties, ContentModel.PROP_USER_STATUS, person.getUserStatus());
|
||||
addToMap(properties, ContentModel.PROP_USER_STATUS_TIME, person.getStatusUpdatedAt());
|
||||
addToMap(properties, ContentModel.PROP_GOOGLEUSERNAME, person.getGoogleId());
|
||||
addToMap(properties, ContentModel.PROP_SIZE_QUOTA, person.getQuota());
|
||||
addToMap(properties, ContentModel.PROP_SIZE_CURRENT, person.getQuotaUsed());
|
||||
addToMap(properties, ContentModel.PROP_DESCRIPTION, person.getDescription());
|
||||
final Map<QName, Serializable> properties = toProperties(person);
|
||||
|
||||
final String pId = personId;
|
||||
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
|
||||
|
@@ -42,6 +42,13 @@ public class Company
|
||||
private String fax;
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* Default constructor, required for deserialising from JSON.
|
||||
*/
|
||||
public Company()
|
||||
{
|
||||
}
|
||||
|
||||
public Company(String organization, String address1, String address2, String address3,
|
||||
String postcode, String telephone, String fax, String email)
|
||||
{
|
||||
|
@@ -27,6 +27,7 @@ package org.alfresco.rest.api.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
@@ -69,6 +70,50 @@ public class Person
|
||||
{
|
||||
}
|
||||
|
||||
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,
|
||||
Company company)
|
||||
{
|
||||
this.userName = userName;
|
||||
this.enabled = enabled;
|
||||
this.avatarId = avatarId;
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
this.jobTitle = jobTitle;
|
||||
this.location = location;
|
||||
this.telephone = telephone;
|
||||
this.mobile = mobile;
|
||||
this.email = email;
|
||||
this.skypeId = skypeId;
|
||||
this.instantMessageId = instantMessageId;
|
||||
this.userStatus = userStatus;
|
||||
this.statusUpdatedAt = statusUpdatedAt;
|
||||
this.googleId = googleId;
|
||||
this.quota = quota;
|
||||
this.quotaUsed = quotaUsed;
|
||||
this.emailNotificationsEnabled = emailNotificationsEnabled;
|
||||
this.description = description;
|
||||
this.company = company;
|
||||
}
|
||||
|
||||
public Person(NodeRef nodeRef, Map<QName, Serializable> nodeProps, boolean enabled)
|
||||
{
|
||||
mapProperties(nodeProps);
|
||||
@@ -244,4 +289,68 @@ public class Person
|
||||
+ ", company=" + company + "]";
|
||||
}
|
||||
|
||||
public Map<QName, Serializable> toProperties()
|
||||
{
|
||||
Map<QName, Serializable> props = new HashMap<>();
|
||||
populateProps(props);
|
||||
return props;
|
||||
}
|
||||
|
||||
private void addToMap(Map<QName, Serializable> properties, QName name, Serializable value)
|
||||
{
|
||||
if(name != null && value != null)
|
||||
{
|
||||
properties.put(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
private void populateProps(Map<QName, Serializable> properties)
|
||||
{
|
||||
addToMap(properties, ContentModel.PROP_USERNAME, getUserName());
|
||||
addToMap(properties, ContentModel.PROP_FIRSTNAME, getFirstName());
|
||||
addToMap(properties, ContentModel.PROP_LASTNAME, getLastName());
|
||||
addToMap(properties, ContentModel.PROP_JOBTITLE, getJobTitle());
|
||||
addToMap(properties, ContentModel.PROP_LOCATION, getLocation());
|
||||
addToMap(properties, ContentModel.PROP_TELEPHONE, getTelephone());
|
||||
addToMap(properties, ContentModel.PROP_MOBILE, getMobile());
|
||||
addToMap(properties, ContentModel.PROP_EMAIL, getEmail());
|
||||
|
||||
Company company = getCompany();
|
||||
if(company != null)
|
||||
{
|
||||
addToMap(properties, ContentModel.PROP_ORGANIZATION, company.getOrganization());
|
||||
addToMap(properties, ContentModel.PROP_COMPANYADDRESS1, company.getAddress1());
|
||||
addToMap(properties, ContentModel.PROP_COMPANYADDRESS2, company.getAddress2());
|
||||
addToMap(properties, ContentModel.PROP_COMPANYADDRESS3, company.getAddress3());
|
||||
addToMap(properties, ContentModel.PROP_COMPANYPOSTCODE, company.getPostcode());
|
||||
addToMap(properties, ContentModel.PROP_COMPANYTELEPHONE, company.getTelephone());
|
||||
addToMap(properties, ContentModel.PROP_COMPANYFAX, company.getFax());
|
||||
addToMap(properties, ContentModel.PROP_COMPANYEMAIL, company.getEmail());
|
||||
}
|
||||
else
|
||||
{
|
||||
addToMap(properties, ContentModel.PROP_ORGANIZATION, null);
|
||||
addToMap(properties, ContentModel.PROP_COMPANYADDRESS1, null);
|
||||
addToMap(properties, ContentModel.PROP_COMPANYADDRESS2, null);
|
||||
addToMap(properties, ContentModel.PROP_COMPANYADDRESS3, null);
|
||||
addToMap(properties, ContentModel.PROP_COMPANYPOSTCODE, null);
|
||||
addToMap(properties, ContentModel.PROP_COMPANYTELEPHONE, null);
|
||||
addToMap(properties, ContentModel.PROP_COMPANYFAX, null);
|
||||
addToMap(properties, ContentModel.PROP_COMPANYEMAIL, null);
|
||||
}
|
||||
|
||||
// addToMap(properties, ContentModel.ASSOC_AVATAR, getAvatarId());
|
||||
addToMap(properties, ContentModel.PROP_SKYPE, getSkypeId());
|
||||
addToMap(properties, ContentModel.PROP_INSTANTMSG, getInstantMessageId());
|
||||
addToMap(properties, ContentModel.PROP_USER_STATUS, getUserStatus());
|
||||
addToMap(properties, ContentModel.PROP_USER_STATUS_TIME, getStatusUpdatedAt());
|
||||
addToMap(properties, ContentModel.PROP_GOOGLEUSERNAME, getGoogleId());
|
||||
addToMap(properties, ContentModel.PROP_SIZE_QUOTA, getQuota());
|
||||
addToMap(properties, ContentModel.PROP_SIZE_CURRENT, getQuotaUsed());
|
||||
|
||||
// What's the correct behaviour here? Store it as "content" somehow?
|
||||
// so that it can be 'inlined' by the code in PeopleImpl.processPersonProperties ?
|
||||
addToMap(properties, ContentModel.PROP_PERSONDESC, getDescription());
|
||||
}
|
||||
|
||||
}
|
||||
|
399
source/java/org/alfresco/rest/api/model/PersonUpdate.java
Normal file
399
source/java/org/alfresco/rest/api/model/PersonUpdate.java
Normal file
@@ -0,0 +1,399 @@
|
||||
/*
|
||||
* #%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.model;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.rest.framework.resource.UniqueId;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Create or update a person.
|
||||
*
|
||||
* @since 5.2
|
||||
* @author Matt Ward
|
||||
*/
|
||||
public class PersonUpdate
|
||||
{
|
||||
protected final String userName;
|
||||
protected final String firstName;
|
||||
protected final String lastName;
|
||||
protected final String description;
|
||||
protected final String email;
|
||||
protected final String skypeId;
|
||||
protected final String googleId;
|
||||
protected final String instantMessageId;
|
||||
protected final String jobTitle;
|
||||
protected final String location;
|
||||
protected final Company company;
|
||||
protected final String mobile;
|
||||
protected final String telephone;
|
||||
protected final String userStatus;
|
||||
protected final Boolean enabled;
|
||||
protected final Boolean emailNotificationsEnabled;
|
||||
|
||||
|
||||
private PersonUpdate(
|
||||
String userName,
|
||||
String firstName,
|
||||
String lastName,
|
||||
String description,
|
||||
String email,
|
||||
String skypeId,
|
||||
String googleId,
|
||||
String instantMessageId,
|
||||
String jobTitle,
|
||||
String location,
|
||||
Company company,
|
||||
String mobile,
|
||||
String telephone,
|
||||
String userStatus,
|
||||
Boolean enabled,
|
||||
Boolean emailNotificationsEnabled)
|
||||
{
|
||||
this.userName = userName;
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
this.description = description;
|
||||
this.email = email;
|
||||
this.skypeId = skypeId;
|
||||
this.googleId = googleId;
|
||||
this.instantMessageId = instantMessageId;
|
||||
this.jobTitle = jobTitle;
|
||||
this.location = location;
|
||||
this.company = company;
|
||||
this.mobile = mobile;
|
||||
this.telephone = telephone;
|
||||
this.userStatus = userStatus;
|
||||
this.enabled = enabled;
|
||||
this.emailNotificationsEnabled = emailNotificationsEnabled;
|
||||
}
|
||||
|
||||
public Company getCompany()
|
||||
{
|
||||
return company;
|
||||
}
|
||||
|
||||
public String getInstantMessageId()
|
||||
{
|
||||
return instantMessageId;
|
||||
}
|
||||
|
||||
public String getGoogleId()
|
||||
{
|
||||
return googleId;
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
@UniqueId
|
||||
public String getUserName()
|
||||
{
|
||||
return userName;
|
||||
}
|
||||
|
||||
public Boolean isEnabled()
|
||||
{
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public String getFirstName()
|
||||
{
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public String getLastName()
|
||||
{
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public String getJobTitle()
|
||||
{
|
||||
return jobTitle;
|
||||
}
|
||||
|
||||
public String getLocation()
|
||||
{
|
||||
return location;
|
||||
}
|
||||
|
||||
public String getTelephone()
|
||||
{
|
||||
return telephone;
|
||||
}
|
||||
|
||||
public String getMobile()
|
||||
{
|
||||
return mobile;
|
||||
}
|
||||
|
||||
public String getEmail()
|
||||
{
|
||||
return email;
|
||||
}
|
||||
|
||||
public String getSkypeId()
|
||||
{
|
||||
return skypeId;
|
||||
}
|
||||
|
||||
public String getUserStatus()
|
||||
{
|
||||
return userStatus;
|
||||
}
|
||||
|
||||
public Boolean isEmailNotificationsEnabled()
|
||||
{
|
||||
return emailNotificationsEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Person [userName=" + userName
|
||||
+ ", enabled=" + enabled
|
||||
+ ", firstName=" + firstName
|
||||
+ ", lastName=" + lastName
|
||||
+ ", jobTitle=" + jobTitle
|
||||
+ ", location=" + location
|
||||
+ ", telephone=" + telephone
|
||||
+ ", mobile=" + mobile
|
||||
+ ", email=" + email
|
||||
+ ", skypeId=" + skypeId
|
||||
+ ", instantMessageId=" + instantMessageId
|
||||
+ ", userStatus=" + userStatus
|
||||
+ ", googleId=" + googleId
|
||||
+ ", emailNotificationsEnabled=" + emailNotificationsEnabled
|
||||
+ ", description=" + description
|
||||
+ ", company=" + company + "]";
|
||||
}
|
||||
|
||||
public Map<QName, Serializable> toProperties()
|
||||
{
|
||||
Map<QName, Serializable> props = new HashMap<>();
|
||||
populateProps(props);
|
||||
return props;
|
||||
}
|
||||
|
||||
private void addToMap(Map<QName, Serializable> properties, QName name, Serializable value)
|
||||
{
|
||||
if(name != null && value != null)
|
||||
{
|
||||
properties.put(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
private void populateProps(Map<QName, Serializable> properties)
|
||||
{
|
||||
addToMap(properties, ContentModel.PROP_USERNAME, getUserName());
|
||||
addToMap(properties, ContentModel.PROP_FIRSTNAME, getFirstName());
|
||||
addToMap(properties, ContentModel.PROP_LASTNAME, getLastName());
|
||||
// What's the correct behaviour here? Store it as "content" somehow?
|
||||
// so that it can be 'inlined' by the code in PeopleImpl.processPersonProperties ?
|
||||
addToMap(properties, ContentModel.PROP_PERSONDESC, getDescription());
|
||||
addToMap(properties, ContentModel.PROP_EMAIL, getEmail());
|
||||
addToMap(properties, ContentModel.PROP_SKYPE, getSkypeId());
|
||||
addToMap(properties, ContentModel.PROP_GOOGLEUSERNAME, getGoogleId());
|
||||
addToMap(properties, ContentModel.PROP_INSTANTMSG, getInstantMessageId());
|
||||
addToMap(properties, ContentModel.PROP_JOBTITLE, getJobTitle());
|
||||
addToMap(properties, ContentModel.PROP_LOCATION, getLocation());
|
||||
|
||||
Company company = getCompany();
|
||||
if(company != null)
|
||||
{
|
||||
addToMap(properties, ContentModel.PROP_ORGANIZATION, company.getOrganization());
|
||||
addToMap(properties, ContentModel.PROP_COMPANYADDRESS1, company.getAddress1());
|
||||
addToMap(properties, ContentModel.PROP_COMPANYADDRESS2, company.getAddress2());
|
||||
addToMap(properties, ContentModel.PROP_COMPANYADDRESS3, company.getAddress3());
|
||||
addToMap(properties, ContentModel.PROP_COMPANYPOSTCODE, company.getPostcode());
|
||||
addToMap(properties, ContentModel.PROP_COMPANYTELEPHONE, company.getTelephone());
|
||||
addToMap(properties, ContentModel.PROP_COMPANYFAX, company.getFax());
|
||||
addToMap(properties, ContentModel.PROP_COMPANYEMAIL, company.getEmail());
|
||||
}
|
||||
else
|
||||
{
|
||||
addToMap(properties, ContentModel.PROP_ORGANIZATION, null);
|
||||
addToMap(properties, ContentModel.PROP_COMPANYADDRESS1, null);
|
||||
addToMap(properties, ContentModel.PROP_COMPANYADDRESS2, null);
|
||||
addToMap(properties, ContentModel.PROP_COMPANYADDRESS3, null);
|
||||
addToMap(properties, ContentModel.PROP_COMPANYPOSTCODE, null);
|
||||
addToMap(properties, ContentModel.PROP_COMPANYTELEPHONE, null);
|
||||
addToMap(properties, ContentModel.PROP_COMPANYFAX, null);
|
||||
addToMap(properties, ContentModel.PROP_COMPANYEMAIL, null);
|
||||
}
|
||||
|
||||
addToMap(properties, ContentModel.PROP_MOBILE, getMobile());
|
||||
addToMap(properties, ContentModel.PROP_TELEPHONE, getTelephone());
|
||||
addToMap(properties, ContentModel.PROP_USER_STATUS, getUserStatus());
|
||||
addToMap(properties, ContentModel.PROP_EMAIL_FEED_DISABLED,
|
||||
isEmailNotificationsEnabled() != null ? !isEmailNotificationsEnabled() : null);
|
||||
|
||||
}
|
||||
|
||||
public static class Builder
|
||||
{
|
||||
private String userName; // is "id" in request JSON
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private String description;
|
||||
private String email;
|
||||
private String skypeId;
|
||||
private String googleId;
|
||||
private String instantMessageId;
|
||||
private String jobTitle;
|
||||
private String location;
|
||||
private Company company;
|
||||
private String mobile;
|
||||
private String telephone;
|
||||
private String userStatus;
|
||||
private Boolean enabled;
|
||||
private Boolean emailNotificationsEnabled;
|
||||
|
||||
public Builder id(String userId)
|
||||
{
|
||||
this.userName = userId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder firstName(String fn)
|
||||
{
|
||||
this.firstName = fn;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder lastName(String ln)
|
||||
{
|
||||
this.lastName = ln;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder description(String description)
|
||||
{
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder email(String email)
|
||||
{
|
||||
this.email = email;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder skypeId(String skypeId)
|
||||
{
|
||||
this.skypeId = skypeId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder googleId(String googleId)
|
||||
{
|
||||
this.googleId = googleId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder instantMessageId(String instantMessageId)
|
||||
{
|
||||
this.instantMessageId = instantMessageId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder jobTitle(String jobTitle)
|
||||
{
|
||||
this.jobTitle = jobTitle;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder location(String location)
|
||||
{
|
||||
this.location = location;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder company(Company company)
|
||||
{
|
||||
this.company = company;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder mobile(String mobile)
|
||||
{
|
||||
this.mobile = mobile;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder telephone(String telephone)
|
||||
{
|
||||
this.telephone = telephone;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder userStatus(String userStatus)
|
||||
{
|
||||
this.userStatus = userStatus;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder enabled(Boolean enabled)
|
||||
{
|
||||
this.enabled = enabled;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder emailNotificationsEnabled(Boolean emailNotificationsEnabled)
|
||||
{
|
||||
this.emailNotificationsEnabled = emailNotificationsEnabled;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PersonUpdate build()
|
||||
{
|
||||
return new PersonUpdate(
|
||||
userName,
|
||||
firstName,
|
||||
lastName,
|
||||
description,
|
||||
email,
|
||||
skypeId,
|
||||
googleId,
|
||||
instantMessageId,
|
||||
jobTitle,
|
||||
location,
|
||||
company,
|
||||
mobile,
|
||||
telephone,
|
||||
userStatus,
|
||||
enabled,
|
||||
emailNotificationsEnabled
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@@ -27,8 +27,10 @@ package org.alfresco.rest.api.people;
|
||||
|
||||
import org.alfresco.rest.api.People;
|
||||
import org.alfresco.rest.api.model.Person;
|
||||
import org.alfresco.rest.api.model.PersonUpdate;
|
||||
import org.alfresco.rest.framework.WebApiDescription;
|
||||
import org.alfresco.rest.framework.WebApiParam;
|
||||
import org.alfresco.rest.framework.core.ResourceParameter;
|
||||
import org.alfresco.rest.framework.resource.EntityResource;
|
||||
import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
@@ -37,6 +39,9 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An implementation of an Entity Resource for a Person
|
||||
*
|
||||
@@ -44,7 +49,7 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
* @author Gethin James
|
||||
*/
|
||||
@EntityResource(name="people", title = "People")
|
||||
public class PeopleEntityResource implements EntityResourceAction.ReadById<Person>, InitializingBean
|
||||
public class PeopleEntityResource implements EntityResourceAction.ReadById<Person>, EntityResourceAction.Create<Person>, InitializingBean
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(PeopleEntityResource.class);
|
||||
|
||||
@@ -75,4 +80,43 @@ public class PeopleEntityResource implements EntityResourceAction.ReadById<Perso
|
||||
return person;
|
||||
}
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title="Create person", description="Create a person")
|
||||
@WebApiParam(name="entity", title="A single person", description="A single person, multiple people are not supported.",
|
||||
kind= ResourceParameter.KIND.HTTP_BODY_OBJECT, allowMultiple=false)
|
||||
public List<Person> create(List<Person> persons, Parameters parameters)
|
||||
{
|
||||
// Until REPO-110 is solved, we need to explicitly test for the presence of fields
|
||||
// that are present on Person but not PersonUpdate
|
||||
// see also, SiteEntityResource.update(String, Site, Parameters)
|
||||
|
||||
// TODO: these are the extras:
|
||||
// avatarId
|
||||
// statusUpdatedAt
|
||||
// quota
|
||||
// quotaUsed
|
||||
|
||||
List<Person> result = new ArrayList<>(1);
|
||||
Person p = persons.get(0);
|
||||
PersonUpdate person = new PersonUpdate.Builder()
|
||||
.id(p.getUserName())
|
||||
.firstName(p.getFirstName())
|
||||
.lastName(p.getLastName())
|
||||
.description(p.getDescription())
|
||||
.email(p.getEmail())
|
||||
.skypeId(p.getSkypeId())
|
||||
.googleId(p.getGoogleId())
|
||||
.instantMessageId(p.getInstantMessageId())
|
||||
.jobTitle(p.getJobTitle())
|
||||
.location(p.getLocation())
|
||||
.company(p.getCompany())
|
||||
.mobile(p.getMobile())
|
||||
.telephone(p.getTelephone())
|
||||
.userStatus(p.getUserStatus())
|
||||
.enabled(p.isEnabled())
|
||||
.emailNotificationsEnabled(p.isEmailNotificationsEnabled()).build();
|
||||
|
||||
result.add(people.create(person));
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
|
@@ -25,30 +25,34 @@
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -29,78 +29,16 @@ 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());
|
||||
}
|
||||
}
|
||||
|
@@ -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");
|
||||
@@ -271,15 +203,39 @@ public class Person implements Serializable, Comparable<Person>, ExpectedCompari
|
||||
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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user