mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
REPO-1646: V1 REST API - cannot unset optional fields (eg. when updating person / site details ...)
- part 2 (Update Person) - REPO-1268, REPO-893 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@133293 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -485,9 +485,16 @@ public class PeopleImpl implements People
|
||||
{
|
||||
@Override
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
if (description != null)
|
||||
{
|
||||
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_PERSONDESC, true);
|
||||
writer.putContent(description);
|
||||
}
|
||||
else
|
||||
{
|
||||
nodeService.setProperty(nodeRef, ContentModel.PROP_PERSONDESC, null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
@@ -566,7 +573,7 @@ public class PeopleImpl implements People
|
||||
}
|
||||
|
||||
NodeRef personNodeRef = personService.getPerson(personIdToUpdate, false);
|
||||
if (person.getDescription() != null)
|
||||
if (person.wasSet(Person.PROP_PERSON_DESCRIPTION))
|
||||
{
|
||||
// Remove person description from saved properties
|
||||
properties.remove(ContentModel.PROP_PERSONDESC);
|
||||
|
@@ -25,6 +25,12 @@
|
||||
*/
|
||||
package org.alfresco.rest.api.model;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Represents a company
|
||||
*
|
||||
@@ -42,6 +48,8 @@ public class Company
|
||||
private String fax;
|
||||
private String email;
|
||||
|
||||
private Map<QName, Boolean> setFields = new HashMap<>(7);
|
||||
|
||||
/**
|
||||
* Default constructor, required for deserialising from JSON.
|
||||
*/
|
||||
@@ -53,14 +61,14 @@ public class Company
|
||||
String postcode, String telephone, String fax, String email)
|
||||
{
|
||||
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;
|
||||
setOrganization(organization);
|
||||
setAddress1(address1);
|
||||
setAddress2(address2);
|
||||
setAddress3(address3);
|
||||
setPostcode(postcode);
|
||||
setTelephone(telephone);
|
||||
setFax(fax);
|
||||
setEmail(email);
|
||||
}
|
||||
|
||||
public String getOrganization()
|
||||
@@ -103,6 +111,60 @@ public class Company
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setOrganization(String organization)
|
||||
{
|
||||
this.organization = organization;
|
||||
setFields.put(ContentModel.PROP_ORGANIZATION, true);
|
||||
}
|
||||
|
||||
public void setAddress1(String address1)
|
||||
{
|
||||
this.address1 = address1;
|
||||
setFields.put(ContentModel.PROP_COMPANYADDRESS1, true);
|
||||
}
|
||||
|
||||
public void setAddress2(String address2)
|
||||
{
|
||||
this.address2 = address2;
|
||||
setFields.put(ContentModel.PROP_COMPANYADDRESS2, true);
|
||||
}
|
||||
|
||||
public void setAddress3(String address3)
|
||||
{
|
||||
this.address3 = address3;
|
||||
setFields.put(ContentModel.PROP_COMPANYADDRESS3, true);
|
||||
}
|
||||
|
||||
public void setPostcode(String postcode)
|
||||
{
|
||||
this.postcode = postcode;
|
||||
setFields.put(ContentModel.PROP_COMPANYPOSTCODE, true);
|
||||
}
|
||||
|
||||
public void setTelephone(String telephone)
|
||||
{
|
||||
this.telephone = telephone;
|
||||
setFields.put(ContentModel.PROP_COMPANYTELEPHONE, true);
|
||||
}
|
||||
|
||||
public void setFax(String fax)
|
||||
{
|
||||
this.fax = fax;
|
||||
setFields.put(ContentModel.PROP_COMPANYFAX, true);
|
||||
}
|
||||
|
||||
public void setEmail(String email)
|
||||
{
|
||||
this.email = email;
|
||||
setFields.put(ContentModel.PROP_COMPANYEMAIL, true);
|
||||
}
|
||||
|
||||
public boolean wasSet(QName fieldName)
|
||||
{
|
||||
Boolean b = setFields.get(fieldName);
|
||||
return (b != null ? b : false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
@@ -111,5 +173,4 @@ public class Company
|
||||
+ ", telephone=" + telephone + ", fax=" + fax + ", email="
|
||||
+ email + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -37,15 +37,13 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Represents a user of the system.
|
||||
* Represents a person (aka user) within the system.
|
||||
*
|
||||
* @author steveglover
|
||||
*
|
||||
*/
|
||||
public class Person
|
||||
{
|
||||
public static final QName PROP_PERSON_DESCRIPTION = QName.createQName("RestApi", "description");
|
||||
|
||||
protected String userName;
|
||||
protected Boolean enabled;
|
||||
protected NodeRef avatarId;
|
||||
@@ -71,6 +69,14 @@ public class Person
|
||||
protected Map<String, Object> properties;
|
||||
protected List<String> aspectNames;
|
||||
|
||||
private Map<QName, Boolean> setFields = new HashMap<>(7);
|
||||
|
||||
public static final QName PROP_PERSON_DESCRIPTION = QName.createQName("RestApi", "description");
|
||||
public static final QName PROP_PERSON_COMPANY = QName.createQName("RestApi", "company");
|
||||
public static final QName PROP_PERSON_AVATAR_ID = QName.createQName("RestApi", "avatarId");
|
||||
public static final QName PROP_PERSON_OLDPASSWORD = QName.createQName("RestApi", "oldPassword");
|
||||
public static final QName PROP_PERSON_PASSWORD = QName.createQName("RestApi", "password");
|
||||
|
||||
public Person()
|
||||
{
|
||||
}
|
||||
@@ -97,26 +103,28 @@ public class Person
|
||||
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;
|
||||
setUserName(userName);
|
||||
setEnabled(enabled);
|
||||
setAvatarId(avatarId);
|
||||
setFirstName(firstName);
|
||||
setLastName(lastName);
|
||||
setJobTitle(jobTitle);
|
||||
setLocation(location);
|
||||
setTelephone(telephone);
|
||||
setMobile(mobile);
|
||||
setEmail(email);
|
||||
setSkypeId(skypeId);
|
||||
setInstantMessageId(instantMessageId);
|
||||
setUserStatus(userStatus);
|
||||
setGoogleId(googleId);
|
||||
setEmailNotificationsEnabled(emailNotificationsEnabled);
|
||||
setDescription(description);
|
||||
setCompany(company);
|
||||
|
||||
// system-maintained / derived
|
||||
setStatusUpdatedAt(statusUpdatedAt);
|
||||
setQuota(quota);
|
||||
setQuotaUsed(quotaUsed);
|
||||
}
|
||||
|
||||
public Person(NodeRef nodeRef, Map<QName, Serializable> nodeProps, boolean enabled)
|
||||
@@ -129,15 +137,15 @@ public class Person
|
||||
{
|
||||
nodeProps.remove(ContentModel.PROP_CONTENT);
|
||||
|
||||
this.userName = (String) nodeProps.get(ContentModel.PROP_USERNAME);
|
||||
this.firstName = (String) nodeProps.get(ContentModel.PROP_FIRSTNAME);
|
||||
this.lastName = (String) nodeProps.get(ContentModel.PROP_LASTNAME);
|
||||
this.jobTitle = (String) nodeProps.get(ContentModel.PROP_JOBTITLE);
|
||||
setUserName((String) nodeProps.get(ContentModel.PROP_USERNAME));
|
||||
setFirstName((String) nodeProps.get(ContentModel.PROP_FIRSTNAME));
|
||||
setLastName((String) nodeProps.get(ContentModel.PROP_LASTNAME));
|
||||
setJobTitle((String) nodeProps.get(ContentModel.PROP_JOBTITLE));
|
||||
|
||||
this.location = (String) nodeProps.get(ContentModel.PROP_LOCATION);
|
||||
this.telephone = (String) nodeProps.get(ContentModel.PROP_TELEPHONE);
|
||||
this.mobile = (String) nodeProps.get(ContentModel.PROP_MOBILE);
|
||||
this.email = (String) nodeProps.get(ContentModel.PROP_EMAIL);
|
||||
setLocation((String) nodeProps.get(ContentModel.PROP_LOCATION));
|
||||
setTelephone((String) nodeProps.get(ContentModel.PROP_TELEPHONE));
|
||||
setMobile((String) nodeProps.get(ContentModel.PROP_MOBILE));
|
||||
setEmail((String) nodeProps.get(ContentModel.PROP_EMAIL));
|
||||
|
||||
String organization = (String) nodeProps.get(ContentModel.PROP_ORGANIZATION);
|
||||
String companyAddress1 = (String) nodeProps.get(ContentModel.PROP_COMPANYADDRESS1);
|
||||
@@ -147,18 +155,20 @@ public class Person
|
||||
String companyTelephone = (String) nodeProps.get(ContentModel.PROP_COMPANYTELEPHONE);
|
||||
String companyFax = (String) nodeProps.get(ContentModel.PROP_COMPANYFAX);
|
||||
String companyEmail = (String) nodeProps.get(ContentModel.PROP_COMPANYEMAIL);
|
||||
this.company = new Company(organization, companyAddress1, companyAddress2, companyAddress3, companyPostcode, companyTelephone, companyFax, companyEmail);
|
||||
setCompany(new Company(organization, companyAddress1, companyAddress2, companyAddress3, companyPostcode, companyTelephone, companyFax, companyEmail));
|
||||
|
||||
this.skypeId = (String) nodeProps.get(ContentModel.PROP_SKYPE);
|
||||
this.instantMessageId = (String) nodeProps.get(ContentModel.PROP_INSTANTMSG);
|
||||
this.userStatus = (String) nodeProps.get(ContentModel.PROP_USER_STATUS);
|
||||
this.statusUpdatedAt = (Date) nodeProps.get(ContentModel.PROP_USER_STATUS_TIME);
|
||||
this.googleId = (String) nodeProps.get(ContentModel.PROP_GOOGLEUSERNAME);
|
||||
this.quota = (Long) nodeProps.get(ContentModel.PROP_SIZE_QUOTA);
|
||||
this.quotaUsed = (Long) nodeProps.get(ContentModel.PROP_SIZE_CURRENT);
|
||||
setSkypeId((String) nodeProps.get(ContentModel.PROP_SKYPE));
|
||||
setInstantMessageId((String) nodeProps.get(ContentModel.PROP_INSTANTMSG));
|
||||
setUserStatus((String) nodeProps.get(ContentModel.PROP_USER_STATUS));
|
||||
setGoogleId((String) nodeProps.get(ContentModel.PROP_GOOGLEUSERNAME));
|
||||
Boolean bool = (Boolean)nodeProps.get(ContentModel.PROP_EMAIL_FEED_DISABLED);
|
||||
this.emailNotificationsEnabled = (bool == null ? Boolean.TRUE : !bool.booleanValue());
|
||||
this.description = (String)nodeProps.get(PROP_PERSON_DESCRIPTION);
|
||||
setEmailNotificationsEnabled(bool == null ? Boolean.TRUE : !bool.booleanValue());
|
||||
setDescription((String)nodeProps.get(PROP_PERSON_DESCRIPTION));
|
||||
|
||||
// system-maintained / derived
|
||||
setStatusUpdatedAt((Date) nodeProps.get(ContentModel.PROP_USER_STATUS_TIME));
|
||||
setQuota((Long) nodeProps.get(ContentModel.PROP_SIZE_QUOTA));
|
||||
setQuotaUsed((Long) nodeProps.get(ContentModel.PROP_SIZE_CURRENT));
|
||||
}
|
||||
|
||||
public Company getCompany()
|
||||
@@ -169,6 +179,7 @@ public class Person
|
||||
public void setCompany(Company company)
|
||||
{
|
||||
this.company = company;
|
||||
setFields.put(PROP_PERSON_COMPANY, true);
|
||||
}
|
||||
|
||||
public String getInstantMessageId()
|
||||
@@ -179,6 +190,7 @@ public class Person
|
||||
public void setInstantMessageId(String instantMessageId)
|
||||
{
|
||||
this.instantMessageId = instantMessageId;
|
||||
setFields.put(ContentModel.PROP_INSTANTMSG, true);
|
||||
}
|
||||
|
||||
public String getGoogleId()
|
||||
@@ -189,6 +201,7 @@ public class Person
|
||||
public void setGoogleId(String googleId)
|
||||
{
|
||||
this.googleId = googleId;
|
||||
setFields.put(ContentModel.PROP_GOOGLEUSERNAME, true);
|
||||
}
|
||||
|
||||
public Long getQuota()
|
||||
@@ -196,11 +209,25 @@ public class Person
|
||||
return quota;
|
||||
}
|
||||
|
||||
// TEMP: for tracking (pending REPO-110)
|
||||
protected void setQuota(Long quota)
|
||||
{
|
||||
this.quota = quota;
|
||||
setFields.put(ContentModel.PROP_SIZE_QUOTA, true);
|
||||
}
|
||||
|
||||
public Long getQuotaUsed()
|
||||
{
|
||||
return quotaUsed;
|
||||
}
|
||||
|
||||
// TEMP: for tracking (pending REPO-110)
|
||||
protected void setQuotaUsed(Long quotaUsed)
|
||||
{
|
||||
this.quotaUsed = quotaUsed;
|
||||
setFields.put(ContentModel.PROP_SIZE_CURRENT, true);
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
@@ -209,6 +236,7 @@ public class Person
|
||||
public void setDescription(String description)
|
||||
{
|
||||
this.description = description;
|
||||
setFields.put(PROP_PERSON_DESCRIPTION, true);
|
||||
}
|
||||
|
||||
@UniqueId
|
||||
@@ -220,6 +248,7 @@ public class Person
|
||||
public void setUserName(String userName)
|
||||
{
|
||||
this.userName = userName;
|
||||
setFields.put(ContentModel.PROP_USERNAME, true);
|
||||
}
|
||||
|
||||
public Boolean isEnabled()
|
||||
@@ -230,21 +259,25 @@ public class Person
|
||||
public void setEnabled(Boolean enabled)
|
||||
{
|
||||
this.enabled = enabled;
|
||||
setFields.put(ContentModel.PROP_ENABLED, true);
|
||||
}
|
||||
|
||||
public void setAvatarId(NodeRef avatarId)
|
||||
{
|
||||
this.avatarId = avatarId;
|
||||
setFields.put(PROP_PERSON_AVATAR_ID, true);
|
||||
}
|
||||
|
||||
public void setPassword(String password)
|
||||
{
|
||||
this.password = password;
|
||||
setFields.put(PROP_PERSON_PASSWORD, true);
|
||||
}
|
||||
|
||||
public void setOldPassword(String oldPassword)
|
||||
{
|
||||
this.oldPassword = oldPassword;
|
||||
setFields.put(PROP_PERSON_OLDPASSWORD, true);
|
||||
}
|
||||
|
||||
public NodeRef getAvatarId()
|
||||
@@ -260,11 +293,13 @@ public class Person
|
||||
public void setFirstName(String firstName)
|
||||
{
|
||||
this.firstName = firstName;
|
||||
setFields.put(ContentModel.PROP_FIRSTNAME, true);
|
||||
}
|
||||
|
||||
public void setLastName(String lastName)
|
||||
{
|
||||
this.lastName = lastName;
|
||||
setFields.put(ContentModel.PROP_LASTNAME, true);
|
||||
}
|
||||
|
||||
public String getLastName()
|
||||
@@ -280,6 +315,7 @@ public class Person
|
||||
public void setJobTitle(String jobTitle)
|
||||
{
|
||||
this.jobTitle = jobTitle;
|
||||
setFields.put(ContentModel.PROP_JOBTITLE, true);
|
||||
}
|
||||
|
||||
public String getLocation()
|
||||
@@ -290,6 +326,7 @@ public class Person
|
||||
public void setLocation(String location)
|
||||
{
|
||||
this.location = location;
|
||||
setFields.put(ContentModel.PROP_LOCATION, true);
|
||||
}
|
||||
|
||||
public String getTelephone()
|
||||
@@ -300,6 +337,7 @@ public class Person
|
||||
public void setTelephone(String telephone)
|
||||
{
|
||||
this.telephone = telephone;
|
||||
setFields.put(ContentModel.PROP_TELEPHONE, true);
|
||||
}
|
||||
|
||||
public String getMobile()
|
||||
@@ -310,6 +348,7 @@ public class Person
|
||||
public void setMobile(String mobile)
|
||||
{
|
||||
this.mobile = mobile;
|
||||
setFields.put(ContentModel.PROP_MOBILE, true);
|
||||
}
|
||||
|
||||
public String getEmail()
|
||||
@@ -320,6 +359,7 @@ public class Person
|
||||
public void setEmail(String email)
|
||||
{
|
||||
this.email = email;
|
||||
setFields.put(ContentModel.PROP_EMAIL, true);
|
||||
}
|
||||
|
||||
public String getSkypeId()
|
||||
@@ -330,6 +370,7 @@ public class Person
|
||||
public void setSkypeId(String skypeId)
|
||||
{
|
||||
this.skypeId = skypeId;
|
||||
setFields.put(ContentModel.PROP_SKYPE, true);
|
||||
}
|
||||
|
||||
public String getUserStatus()
|
||||
@@ -340,6 +381,7 @@ public class Person
|
||||
public void setUserStatus(String userStatus)
|
||||
{
|
||||
this.userStatus = userStatus;
|
||||
setFields.put(ContentModel.PROP_USER_STATUS, true);
|
||||
}
|
||||
|
||||
public Date getStatusUpdatedAt()
|
||||
@@ -347,6 +389,13 @@ public class Person
|
||||
return statusUpdatedAt;
|
||||
}
|
||||
|
||||
// TEMP: for tracking (pending REPO-110)
|
||||
protected void setStatusUpdatedAt(Date statusUpdatedAt)
|
||||
{
|
||||
this.statusUpdatedAt = statusUpdatedAt;
|
||||
setFields.put(ContentModel.PROP_USER_STATUS_TIME, true);
|
||||
}
|
||||
|
||||
public Boolean isEmailNotificationsEnabled()
|
||||
{
|
||||
return emailNotificationsEnabled;
|
||||
@@ -355,6 +404,7 @@ public class Person
|
||||
public void setEmailNotificationsEnabled(Boolean emailNotificationsEnabled)
|
||||
{
|
||||
this.emailNotificationsEnabled = emailNotificationsEnabled;
|
||||
setFields.put(ContentModel.PROP_EMAIL_FEED_DISABLED, true);
|
||||
}
|
||||
|
||||
public String getPassword()
|
||||
@@ -387,6 +437,12 @@ public class Person
|
||||
this.aspectNames = aspectNames;
|
||||
}
|
||||
|
||||
public boolean wasSet(QName fieldName)
|
||||
{
|
||||
Boolean b = setFields.get(fieldName);
|
||||
return (b != null ? b : false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
@@ -413,11 +469,15 @@ public class Person
|
||||
|
||||
private void addToMap(Map<QName, Serializable> properties, QName name, Serializable value)
|
||||
{
|
||||
if(name != null && value != null)
|
||||
if (name != null)
|
||||
{
|
||||
Boolean b = setFields.get(name);
|
||||
if (Boolean.TRUE.equals(b))
|
||||
{
|
||||
properties.put(name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void populateProps(Map<QName, Serializable> properties)
|
||||
{
|
||||
@@ -430,28 +490,62 @@ public class Person
|
||||
addToMap(properties, ContentModel.PROP_MOBILE, getMobile());
|
||||
addToMap(properties, ContentModel.PROP_EMAIL, getEmail());
|
||||
|
||||
if (wasSet(PROP_PERSON_COMPANY))
|
||||
{
|
||||
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());
|
||||
if (company.wasSet(ContentModel.PROP_ORGANIZATION))
|
||||
{
|
||||
properties.put(ContentModel.PROP_ORGANIZATION, company.getOrganization());
|
||||
}
|
||||
|
||||
if (company.wasSet(ContentModel.PROP_COMPANYADDRESS1))
|
||||
{
|
||||
properties.put(ContentModel.PROP_COMPANYADDRESS1, company.getAddress1());
|
||||
}
|
||||
|
||||
if (company.wasSet(ContentModel.PROP_COMPANYADDRESS2))
|
||||
{
|
||||
properties.put(ContentModel.PROP_COMPANYADDRESS2, company.getAddress2());
|
||||
}
|
||||
|
||||
if (company.wasSet(ContentModel.PROP_COMPANYADDRESS3))
|
||||
{
|
||||
properties.put(ContentModel.PROP_COMPANYADDRESS3, company.getAddress3());
|
||||
}
|
||||
|
||||
if (company.wasSet(ContentModel.PROP_COMPANYPOSTCODE))
|
||||
{
|
||||
properties.put(ContentModel.PROP_COMPANYPOSTCODE, company.getPostcode());
|
||||
}
|
||||
|
||||
if (company.wasSet(ContentModel.PROP_COMPANYTELEPHONE))
|
||||
{
|
||||
properties.put(ContentModel.PROP_COMPANYTELEPHONE, company.getTelephone());
|
||||
}
|
||||
|
||||
if (company.wasSet(ContentModel.PROP_COMPANYFAX))
|
||||
{
|
||||
properties.put(ContentModel.PROP_COMPANYFAX, company.getFax());
|
||||
}
|
||||
|
||||
if (company.wasSet(ContentModel.PROP_COMPANYEMAIL))
|
||||
{
|
||||
properties.put(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);
|
||||
properties.put(ContentModel.PROP_ORGANIZATION, null);
|
||||
properties.put(ContentModel.PROP_COMPANYADDRESS1, null);
|
||||
properties.put(ContentModel.PROP_COMPANYADDRESS2, null);
|
||||
properties.put(ContentModel.PROP_COMPANYADDRESS3, null);
|
||||
properties.put(ContentModel.PROP_COMPANYPOSTCODE, null);
|
||||
properties.put(ContentModel.PROP_COMPANYTELEPHONE, null);
|
||||
properties.put(ContentModel.PROP_COMPANYFAX, null);
|
||||
properties.put(ContentModel.PROP_COMPANYEMAIL, null);
|
||||
}
|
||||
}
|
||||
|
||||
// addToMap(properties, ContentModel.ASSOC_AVATAR, getAvatarId());
|
||||
|
@@ -25,6 +25,7 @@
|
||||
*/
|
||||
package org.alfresco.rest.api.people;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.rest.api.People;
|
||||
import org.alfresco.rest.api.model.Person;
|
||||
import org.alfresco.rest.framework.WebApiDescription;
|
||||
@@ -89,25 +90,7 @@ public class PeopleEntityResource implements EntityResourceAction.ReadById<Perso
|
||||
{
|
||||
Person p = persons.get(0);
|
||||
|
||||
// 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)
|
||||
if (p.getStatusUpdatedAt() != null)
|
||||
{
|
||||
throw new InvalidArgumentException("Unsupported field: statusUpdatedAt");
|
||||
}
|
||||
if (p.getAvatarId() != null)
|
||||
{
|
||||
throw new InvalidArgumentException("Unsupported field: avatarId");
|
||||
}
|
||||
if (p.getQuota() != null)
|
||||
{
|
||||
throw new InvalidArgumentException("Unsupported field: quota");
|
||||
}
|
||||
if (p.getQuotaUsed() != null)
|
||||
{
|
||||
throw new InvalidArgumentException("Unsupported field: quotaUsed");
|
||||
}
|
||||
validateDerivedFieldsExistence(p);
|
||||
|
||||
List<Person> result = new ArrayList<>(1);
|
||||
result.add(people.create(p));
|
||||
@@ -118,42 +101,40 @@ public class PeopleEntityResource implements EntityResourceAction.ReadById<Perso
|
||||
@WebApiDescription(title="Update person", description="Update the given person's details")
|
||||
public Person update(String personId, Person person, Parameters parameters)
|
||||
{
|
||||
validateNonUpdatableFieldsExistence(person);
|
||||
|
||||
return people.update(personId, person);
|
||||
}
|
||||
|
||||
/**
|
||||
* Explicitly test for the presence of fields that are present on Person but
|
||||
* shouldn't be updatable (until REPO-110 is solved).
|
||||
*
|
||||
* @param person
|
||||
*/
|
||||
private void validateNonUpdatableFieldsExistence(Person person)
|
||||
{
|
||||
|
||||
if (person.getUserName() != null)
|
||||
if (person.wasSet(ContentModel.PROP_USERNAME))
|
||||
{
|
||||
// REPO-1537
|
||||
throw new InvalidArgumentException("Unsupported field: id");
|
||||
}
|
||||
|
||||
if (person.getStatusUpdatedAt() != null)
|
||||
validateDerivedFieldsExistence(person);
|
||||
|
||||
return people.update(personId, person);
|
||||
}
|
||||
|
||||
/**
|
||||
* Explicitly test for the presence of system-maintained (derived) fields that are settable on Person (see also REPO-110).
|
||||
*
|
||||
* @param person
|
||||
*/
|
||||
private void validateDerivedFieldsExistence(Person person)
|
||||
{
|
||||
if (person.wasSet(ContentModel.PROP_USER_STATUS_TIME))
|
||||
{
|
||||
throw new InvalidArgumentException("Unsupported field: statusUpdatedAt");
|
||||
}
|
||||
|
||||
if (person.getAvatarId() != null)
|
||||
if (person.wasSet(Person.PROP_PERSON_AVATAR_ID))
|
||||
{
|
||||
throw new InvalidArgumentException("Unsupported field: avatarId");
|
||||
}
|
||||
|
||||
if (person.getQuota() != null)
|
||||
if (person.wasSet(ContentModel.PROP_SIZE_QUOTA))
|
||||
{
|
||||
throw new InvalidArgumentException("Unsupported field: quota");
|
||||
}
|
||||
|
||||
if (person.getQuotaUsed() != null)
|
||||
if (person.wasSet(ContentModel.PROP_SIZE_CURRENT))
|
||||
{
|
||||
throw new InvalidArgumentException("Unsupported field: quotaUsed");
|
||||
}
|
||||
|
@@ -323,7 +323,18 @@ public class TestPeople extends EnterpriseTestApi
|
||||
assertEquals(null, p.getInstantMessageId());
|
||||
assertEquals(null, p.getJobTitle());
|
||||
assertEquals(null, p.getLocation());
|
||||
assertEquals(null, p.getCompany());
|
||||
|
||||
// note: empty company object is returned for backwards compatibility (with pre-existing getPerson API <= 5.1)
|
||||
assertNotNull(p.getCompany());
|
||||
assertNull(p.getCompany().getOrganization());
|
||||
assertNull(p.getCompany().getAddress1());
|
||||
assertNull(p.getCompany().getAddress2());
|
||||
assertNull(p.getCompany().getAddress3());
|
||||
assertNull(p.getCompany().getPostcode());
|
||||
assertNull(p.getCompany().getFax());
|
||||
assertNull(p.getCompany().getEmail());
|
||||
assertNull(p.getCompany().getTelephone());
|
||||
|
||||
assertEquals(null, p.getMobile());
|
||||
assertEquals("1234 5678 9012", p.getTelephone());
|
||||
assertEquals(null, p.getUserStatus());
|
||||
@@ -351,7 +362,18 @@ public class TestPeople extends EnterpriseTestApi
|
||||
assertEquals(null, p.getInstantMessageId());
|
||||
assertEquals(null, p.getJobTitle());
|
||||
assertEquals(null, p.getLocation());
|
||||
assertEquals(null, p.getCompany());
|
||||
|
||||
// note: empty company object is returned for backwards compatibility (with pre-existing getPerson API <= 5.1)
|
||||
assertNotNull(p.getCompany());
|
||||
assertNull(p.getCompany().getOrganization());
|
||||
assertNull(p.getCompany().getAddress1());
|
||||
assertNull(p.getCompany().getAddress2());
|
||||
assertNull(p.getCompany().getAddress3());
|
||||
assertNull(p.getCompany().getPostcode());
|
||||
assertNull(p.getCompany().getFax());
|
||||
assertNull(p.getCompany().getEmail());
|
||||
assertNull(p.getCompany().getTelephone());
|
||||
|
||||
assertEquals(null, p.getMobile());
|
||||
assertEquals(null, p.getTelephone());
|
||||
assertEquals(null, p.getUserStatus());
|
||||
@@ -854,7 +876,7 @@ public class TestPeople extends EnterpriseTestApi
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdatePersonUpdate() throws Exception
|
||||
public void testUpdatePersonUpdateAsAdmin() throws Exception
|
||||
{
|
||||
final String personId = account3PersonIt.next();
|
||||
|
||||
@@ -934,6 +956,89 @@ public class TestPeople extends EnterpriseTestApi
|
||||
assertEquals(userStatus, updatedPerson.getUserStatus());
|
||||
assertEquals(emailNotificationsEnabled, updatedPerson.isEmailNotificationsEnabled());
|
||||
assertEquals(enabled, updatedPerson.isEnabled());
|
||||
|
||||
// test ability to unset optional fields (could be one or more - here all) including individual company fields
|
||||
response = people.update("people", personId, null, null,
|
||||
"{\n"
|
||||
+ " \"lastName\":null,\n"
|
||||
+ " \"description\":null,\n"
|
||||
+ " \"skypeId\":null,\n"
|
||||
+ " \"googleId\":null,\n"
|
||||
+ " \"instantMessageId\":null,\n"
|
||||
+ " \"jobTitle\":null,\n"
|
||||
+ " \"location\":null,\n"
|
||||
|
||||
+ " \"company\": {\n"
|
||||
+ " \"organization\":null,\n"
|
||||
+ " \"address1\":null,\n"
|
||||
+ " \"address2\":null,\n"
|
||||
+ " \"address3\":null,\n"
|
||||
+ " \"postcode\":null,\n"
|
||||
+ " \"telephone\":null,\n"
|
||||
+ " \"fax\":null,\n"
|
||||
+ " \"email\":null\n"
|
||||
+ " },\n"
|
||||
|
||||
+ " \"mobile\":null,\n"
|
||||
+ " \"telephone\":null,\n"
|
||||
+ " \"userStatus\":null\n"
|
||||
+ "}", params,
|
||||
"Expected 200 response when updating " + personId, 200);
|
||||
|
||||
updatedPerson = Person.parsePerson((JSONObject) response.getJsonResponse().get("entry"));
|
||||
|
||||
assertNotNull(updatedPerson.getId());
|
||||
assertNull(updatedPerson.getLastName());
|
||||
assertNull(updatedPerson.getDescription());
|
||||
assertNull(updatedPerson.getSkypeId());
|
||||
assertNull(updatedPerson.getGoogleId());
|
||||
assertNull(updatedPerson.getInstantMessageId());
|
||||
assertNull(updatedPerson.getJobTitle());
|
||||
assertNull(updatedPerson.getLocation());
|
||||
|
||||
assertNotNull(updatedPerson.getCompany());
|
||||
assertNull(updatedPerson.getCompany().getOrganization());
|
||||
assertNull(updatedPerson.getCompany().getAddress1());
|
||||
assertNull(updatedPerson.getCompany().getAddress2());
|
||||
assertNull(updatedPerson.getCompany().getAddress3());
|
||||
assertNull(updatedPerson.getCompany().getPostcode());
|
||||
assertNull(updatedPerson.getCompany().getFax());
|
||||
assertNull(updatedPerson.getCompany().getEmail());
|
||||
assertNull(updatedPerson.getCompany().getTelephone());
|
||||
|
||||
assertNull(updatedPerson.getMobile());
|
||||
assertNull(updatedPerson.getTelephone());
|
||||
assertNull(updatedPerson.getUserStatus());
|
||||
|
||||
// set at least one company field
|
||||
String updatedOrgName = "another org";
|
||||
|
||||
response = people.update("people", personId, null, null,
|
||||
"{\n"
|
||||
+ " \"company\": {\n"
|
||||
+ " \"organization\":\""+updatedOrgName+"\"\n"
|
||||
+ " }\n"
|
||||
+ "}", params,
|
||||
"Expected 200 response when updating " + personId, 200);
|
||||
|
||||
updatedPerson = Person.parsePerson((JSONObject) response.getJsonResponse().get("entry"));
|
||||
|
||||
assertNotNull(updatedPerson.getCompany());
|
||||
assertEquals(updatedOrgName, updatedPerson.getCompany().getOrganization());
|
||||
|
||||
// test ability to unset company fields as a whole
|
||||
response = people.update("people", personId, null, null,
|
||||
"{\n"
|
||||
+ " \"company\": null\n"
|
||||
+ "}", params,
|
||||
"Expected 200 response when updating " + personId, 200);
|
||||
|
||||
updatedPerson = Person.parsePerson((JSONObject) response.getJsonResponse().get("entry"));
|
||||
|
||||
// note: empty company object is returned for backwards compatibility (with pre-existing getPerson API <= 5.1)
|
||||
assertNotNull(updatedPerson.getCompany());
|
||||
|
||||
assertNull(updatedPerson.getCompany().getOrganization());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -31,6 +31,10 @@ import org.json.simple.JSONObject;
|
||||
|
||||
public class Company extends org.alfresco.rest.api.model.Company implements ExpectedComparison
|
||||
{
|
||||
public Company()
|
||||
{
|
||||
}
|
||||
|
||||
public Company(org.alfresco.rest.api.model.Company company)
|
||||
{
|
||||
super(company.getOrganization(), company.getAddress1(), company.getAddress2(), company.getAddress3(), company.getPostcode(), company.getTelephone(), company.getFax(), company.getEmail());
|
||||
|
@@ -219,6 +219,10 @@ public class Person
|
||||
{
|
||||
company = new Company(organization, address1, address2, address3, postcode, companyTelephone, fax, companyEmail);
|
||||
}
|
||||
else
|
||||
{
|
||||
company = new Company();
|
||||
}
|
||||
}
|
||||
|
||||
String mobile = (String)jsonObject.get("mobile");
|
||||
|
Reference in New Issue
Block a user