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

@@ -1,32 +1,33 @@
/*
* #%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.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);
@@ -243,5 +288,69 @@ public class Person
+ 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());
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());
}
}