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:
Jan Vonka
2016-11-30 13:33:55 +00:00
parent c6a643ae99
commit 78a7208ad7
7 changed files with 384 additions and 128 deletions

View File

@@ -486,8 +486,15 @@ public class PeopleImpl implements People
@Override @Override
public Void doWork() throws Exception public Void doWork() throws Exception
{ {
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_PERSONDESC, true); if (description != null)
writer.putContent(description); {
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_PERSONDESC, true);
writer.putContent(description);
}
else
{
nodeService.setProperty(nodeRef, ContentModel.PROP_PERSONDESC, null);
}
return null; return null;
} }
}); });
@@ -566,7 +573,7 @@ public class PeopleImpl implements People
} }
NodeRef personNodeRef = personService.getPerson(personIdToUpdate, false); NodeRef personNodeRef = personService.getPerson(personIdToUpdate, false);
if (person.getDescription() != null) if (person.wasSet(Person.PROP_PERSON_DESCRIPTION))
{ {
// Remove person description from saved properties // Remove person description from saved properties
properties.remove(ContentModel.PROP_PERSONDESC); properties.remove(ContentModel.PROP_PERSONDESC);

View File

@@ -25,6 +25,12 @@
*/ */
package org.alfresco.rest.api.model; 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 * Represents a company
* *
@@ -42,6 +48,8 @@ public class Company
private String fax; private String fax;
private String email; private String email;
private Map<QName, Boolean> setFields = new HashMap<>(7);
/** /**
* Default constructor, required for deserialising from JSON. * Default constructor, required for deserialising from JSON.
*/ */
@@ -53,14 +61,14 @@ public class Company
String postcode, String telephone, String fax, String email) String postcode, String telephone, String fax, String email)
{ {
super(); super();
this.organization = organization; setOrganization(organization);
this.address1 = address1; setAddress1(address1);
this.address2 = address2; setAddress2(address2);
this.address3 = address3; setAddress3(address3);
this.postcode = postcode; setPostcode(postcode);
this.telephone = telephone; setTelephone(telephone);
this.fax = fax; setFax(fax);
this.email = email; setEmail(email);
} }
public String getOrganization() public String getOrganization()
@@ -103,6 +111,60 @@ public class Company
return email; 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 @Override
public String toString() public String toString()
{ {
@@ -111,5 +173,4 @@ public class Company
+ ", telephone=" + telephone + ", fax=" + fax + ", email=" + ", telephone=" + telephone + ", fax=" + fax + ", email="
+ email + "]"; + email + "]";
} }
} }

View File

@@ -37,15 +37,13 @@ import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
* Represents a user of the system. * Represents a person (aka user) within the system.
* *
* @author steveglover * @author steveglover
* *
*/ */
public class Person public class Person
{ {
public static final QName PROP_PERSON_DESCRIPTION = QName.createQName("RestApi", "description");
protected String userName; protected String userName;
protected Boolean enabled; protected Boolean enabled;
protected NodeRef avatarId; protected NodeRef avatarId;
@@ -71,6 +69,14 @@ public class Person
protected Map<String, Object> properties; protected Map<String, Object> properties;
protected List<String> aspectNames; 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() public Person()
{ {
} }
@@ -97,26 +103,28 @@ public class Person
String description, String description,
Company company) Company company)
{ {
this.userName = userName; setUserName(userName);
this.enabled = enabled; setEnabled(enabled);
this.avatarId = avatarId; setAvatarId(avatarId);
this.firstName = firstName; setFirstName(firstName);
this.lastName = lastName; setLastName(lastName);
this.jobTitle = jobTitle; setJobTitle(jobTitle);
this.location = location; setLocation(location);
this.telephone = telephone; setTelephone(telephone);
this.mobile = mobile; setMobile(mobile);
this.email = email; setEmail(email);
this.skypeId = skypeId; setSkypeId(skypeId);
this.instantMessageId = instantMessageId; setInstantMessageId(instantMessageId);
this.userStatus = userStatus; setUserStatus(userStatus);
this.statusUpdatedAt = statusUpdatedAt; setGoogleId(googleId);
this.googleId = googleId; setEmailNotificationsEnabled(emailNotificationsEnabled);
this.quota = quota; setDescription(description);
this.quotaUsed = quotaUsed; setCompany(company);
this.emailNotificationsEnabled = emailNotificationsEnabled;
this.description = description; // system-maintained / derived
this.company = company; setStatusUpdatedAt(statusUpdatedAt);
setQuota(quota);
setQuotaUsed(quotaUsed);
} }
public Person(NodeRef nodeRef, Map<QName, Serializable> nodeProps, boolean enabled) public Person(NodeRef nodeRef, Map<QName, Serializable> nodeProps, boolean enabled)
@@ -129,15 +137,15 @@ public class Person
{ {
nodeProps.remove(ContentModel.PROP_CONTENT); nodeProps.remove(ContentModel.PROP_CONTENT);
this.userName = (String) nodeProps.get(ContentModel.PROP_USERNAME); setUserName((String) nodeProps.get(ContentModel.PROP_USERNAME));
this.firstName = (String) nodeProps.get(ContentModel.PROP_FIRSTNAME); setFirstName((String) nodeProps.get(ContentModel.PROP_FIRSTNAME));
this.lastName = (String) nodeProps.get(ContentModel.PROP_LASTNAME); setLastName((String) nodeProps.get(ContentModel.PROP_LASTNAME));
this.jobTitle = (String) nodeProps.get(ContentModel.PROP_JOBTITLE); setJobTitle((String) nodeProps.get(ContentModel.PROP_JOBTITLE));
this.location = (String) nodeProps.get(ContentModel.PROP_LOCATION); setLocation((String) nodeProps.get(ContentModel.PROP_LOCATION));
this.telephone = (String) nodeProps.get(ContentModel.PROP_TELEPHONE); setTelephone((String) nodeProps.get(ContentModel.PROP_TELEPHONE));
this.mobile = (String) nodeProps.get(ContentModel.PROP_MOBILE); setMobile((String) nodeProps.get(ContentModel.PROP_MOBILE));
this.email = (String) nodeProps.get(ContentModel.PROP_EMAIL); setEmail((String) nodeProps.get(ContentModel.PROP_EMAIL));
String organization = (String) nodeProps.get(ContentModel.PROP_ORGANIZATION); String organization = (String) nodeProps.get(ContentModel.PROP_ORGANIZATION);
String companyAddress1 = (String) nodeProps.get(ContentModel.PROP_COMPANYADDRESS1); String companyAddress1 = (String) nodeProps.get(ContentModel.PROP_COMPANYADDRESS1);
@@ -147,20 +155,22 @@ public class Person
String companyTelephone = (String) nodeProps.get(ContentModel.PROP_COMPANYTELEPHONE); String companyTelephone = (String) nodeProps.get(ContentModel.PROP_COMPANYTELEPHONE);
String companyFax = (String) nodeProps.get(ContentModel.PROP_COMPANYFAX); String companyFax = (String) nodeProps.get(ContentModel.PROP_COMPANYFAX);
String companyEmail = (String) nodeProps.get(ContentModel.PROP_COMPANYEMAIL); 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); setSkypeId((String) nodeProps.get(ContentModel.PROP_SKYPE));
this.instantMessageId = (String) nodeProps.get(ContentModel.PROP_INSTANTMSG); setInstantMessageId((String) nodeProps.get(ContentModel.PROP_INSTANTMSG));
this.userStatus = (String) nodeProps.get(ContentModel.PROP_USER_STATUS); setUserStatus((String) nodeProps.get(ContentModel.PROP_USER_STATUS));
this.statusUpdatedAt = (Date) nodeProps.get(ContentModel.PROP_USER_STATUS_TIME); setGoogleId((String) nodeProps.get(ContentModel.PROP_GOOGLEUSERNAME));
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);
Boolean bool = (Boolean)nodeProps.get(ContentModel.PROP_EMAIL_FEED_DISABLED); Boolean bool = (Boolean)nodeProps.get(ContentModel.PROP_EMAIL_FEED_DISABLED);
this.emailNotificationsEnabled = (bool == null ? Boolean.TRUE : !bool.booleanValue()); setEmailNotificationsEnabled(bool == null ? Boolean.TRUE : !bool.booleanValue());
this.description = (String)nodeProps.get(PROP_PERSON_DESCRIPTION); 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() public Company getCompany()
{ {
return company; return company;
@@ -169,6 +179,7 @@ public class Person
public void setCompany(Company company) public void setCompany(Company company)
{ {
this.company = company; this.company = company;
setFields.put(PROP_PERSON_COMPANY, true);
} }
public String getInstantMessageId() public String getInstantMessageId()
@@ -179,6 +190,7 @@ public class Person
public void setInstantMessageId(String instantMessageId) public void setInstantMessageId(String instantMessageId)
{ {
this.instantMessageId = instantMessageId; this.instantMessageId = instantMessageId;
setFields.put(ContentModel.PROP_INSTANTMSG, true);
} }
public String getGoogleId() public String getGoogleId()
@@ -189,18 +201,33 @@ public class Person
public void setGoogleId(String googleId) public void setGoogleId(String googleId)
{ {
this.googleId = googleId; this.googleId = googleId;
setFields.put(ContentModel.PROP_GOOGLEUSERNAME, true);
} }
public Long getQuota() public Long getQuota()
{ {
return quota; 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() public Long getQuotaUsed()
{ {
return quotaUsed; 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() public String getDescription()
{ {
return description; return description;
@@ -209,8 +236,9 @@ public class Person
public void setDescription(String description) public void setDescription(String description)
{ {
this.description = description; this.description = description;
setFields.put(PROP_PERSON_DESCRIPTION, true);
} }
@UniqueId @UniqueId
public String getUserName() public String getUserName()
{ {
@@ -220,6 +248,7 @@ public class Person
public void setUserName(String userName) public void setUserName(String userName)
{ {
this.userName = userName; this.userName = userName;
setFields.put(ContentModel.PROP_USERNAME, true);
} }
public Boolean isEnabled() public Boolean isEnabled()
@@ -230,21 +259,25 @@ public class Person
public void setEnabled(Boolean enabled) public void setEnabled(Boolean enabled)
{ {
this.enabled = enabled; this.enabled = enabled;
setFields.put(ContentModel.PROP_ENABLED, true);
} }
public void setAvatarId(NodeRef avatarId) public void setAvatarId(NodeRef avatarId)
{ {
this.avatarId = avatarId; this.avatarId = avatarId;
setFields.put(PROP_PERSON_AVATAR_ID, true);
} }
public void setPassword(String password) public void setPassword(String password)
{ {
this.password = password; this.password = password;
setFields.put(PROP_PERSON_PASSWORD, true);
} }
public void setOldPassword(String oldPassword) public void setOldPassword(String oldPassword)
{ {
this.oldPassword = oldPassword; this.oldPassword = oldPassword;
setFields.put(PROP_PERSON_OLDPASSWORD, true);
} }
public NodeRef getAvatarId() public NodeRef getAvatarId()
@@ -260,11 +293,13 @@ public class Person
public void setFirstName(String firstName) public void setFirstName(String firstName)
{ {
this.firstName = firstName; this.firstName = firstName;
setFields.put(ContentModel.PROP_FIRSTNAME, true);
} }
public void setLastName(String lastName) public void setLastName(String lastName)
{ {
this.lastName = lastName; this.lastName = lastName;
setFields.put(ContentModel.PROP_LASTNAME, true);
} }
public String getLastName() public String getLastName()
@@ -280,6 +315,7 @@ public class Person
public void setJobTitle(String jobTitle) public void setJobTitle(String jobTitle)
{ {
this.jobTitle = jobTitle; this.jobTitle = jobTitle;
setFields.put(ContentModel.PROP_JOBTITLE, true);
} }
public String getLocation() public String getLocation()
@@ -290,6 +326,7 @@ public class Person
public void setLocation(String location) public void setLocation(String location)
{ {
this.location = location; this.location = location;
setFields.put(ContentModel.PROP_LOCATION, true);
} }
public String getTelephone() public String getTelephone()
@@ -300,6 +337,7 @@ public class Person
public void setTelephone(String telephone) public void setTelephone(String telephone)
{ {
this.telephone = telephone; this.telephone = telephone;
setFields.put(ContentModel.PROP_TELEPHONE, true);
} }
public String getMobile() public String getMobile()
@@ -310,6 +348,7 @@ public class Person
public void setMobile(String mobile) public void setMobile(String mobile)
{ {
this.mobile = mobile; this.mobile = mobile;
setFields.put(ContentModel.PROP_MOBILE, true);
} }
public String getEmail() public String getEmail()
@@ -320,6 +359,7 @@ public class Person
public void setEmail(String email) public void setEmail(String email)
{ {
this.email = email; this.email = email;
setFields.put(ContentModel.PROP_EMAIL, true);
} }
public String getSkypeId() public String getSkypeId()
@@ -330,6 +370,7 @@ public class Person
public void setSkypeId(String skypeId) public void setSkypeId(String skypeId)
{ {
this.skypeId = skypeId; this.skypeId = skypeId;
setFields.put(ContentModel.PROP_SKYPE, true);
} }
public String getUserStatus() public String getUserStatus()
@@ -340,6 +381,7 @@ public class Person
public void setUserStatus(String userStatus) public void setUserStatus(String userStatus)
{ {
this.userStatus = userStatus; this.userStatus = userStatus;
setFields.put(ContentModel.PROP_USER_STATUS, true);
} }
public Date getStatusUpdatedAt() public Date getStatusUpdatedAt()
@@ -347,6 +389,13 @@ public class Person
return statusUpdatedAt; 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() public Boolean isEmailNotificationsEnabled()
{ {
return emailNotificationsEnabled; return emailNotificationsEnabled;
@@ -355,6 +404,7 @@ public class Person
public void setEmailNotificationsEnabled(Boolean emailNotificationsEnabled) public void setEmailNotificationsEnabled(Boolean emailNotificationsEnabled)
{ {
this.emailNotificationsEnabled = emailNotificationsEnabled; this.emailNotificationsEnabled = emailNotificationsEnabled;
setFields.put(ContentModel.PROP_EMAIL_FEED_DISABLED, true);
} }
public String getPassword() public String getPassword()
@@ -387,6 +437,12 @@ public class Person
this.aspectNames = aspectNames; this.aspectNames = aspectNames;
} }
public boolean wasSet(QName fieldName)
{
Boolean b = setFields.get(fieldName);
return (b != null ? b : false);
}
@Override @Override
public String toString() public String toString()
{ {
@@ -413,12 +469,16 @@ public class Person
private void addToMap(Map<QName, Serializable> properties, QName name, Serializable value) private void addToMap(Map<QName, Serializable> properties, QName name, Serializable value)
{ {
if(name != null && value != null) if (name != null)
{ {
properties.put(name, value); Boolean b = setFields.get(name);
if (Boolean.TRUE.equals(b))
{
properties.put(name, value);
}
} }
} }
private void populateProps(Map<QName, Serializable> properties) private void populateProps(Map<QName, Serializable> properties)
{ {
addToMap(properties, ContentModel.PROP_USERNAME, getUserName()); addToMap(properties, ContentModel.PROP_USERNAME, getUserName());
@@ -429,29 +489,63 @@ public class Person
addToMap(properties, ContentModel.PROP_TELEPHONE, getTelephone()); addToMap(properties, ContentModel.PROP_TELEPHONE, getTelephone());
addToMap(properties, ContentModel.PROP_MOBILE, getMobile()); addToMap(properties, ContentModel.PROP_MOBILE, getMobile());
addToMap(properties, ContentModel.PROP_EMAIL, getEmail()); addToMap(properties, ContentModel.PROP_EMAIL, getEmail());
if (wasSet(PROP_PERSON_COMPANY))
{
Company company = getCompany();
if (company != null)
{
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());
}
Company company = getCompany(); if (company.wasSet(ContentModel.PROP_COMPANYPOSTCODE))
if(company != null) {
{ properties.put(ContentModel.PROP_COMPANYPOSTCODE, company.getPostcode());
addToMap(properties, ContentModel.PROP_ORGANIZATION, company.getOrganization()); }
addToMap(properties, ContentModel.PROP_COMPANYADDRESS1, company.getAddress1());
addToMap(properties, ContentModel.PROP_COMPANYADDRESS2, company.getAddress2()); if (company.wasSet(ContentModel.PROP_COMPANYTELEPHONE))
addToMap(properties, ContentModel.PROP_COMPANYADDRESS3, company.getAddress3()); {
addToMap(properties, ContentModel.PROP_COMPANYPOSTCODE, company.getPostcode()); properties.put(ContentModel.PROP_COMPANYTELEPHONE, company.getTelephone());
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_COMPANYFAX))
} {
else properties.put(ContentModel.PROP_COMPANYFAX, company.getFax());
{ }
addToMap(properties, ContentModel.PROP_ORGANIZATION, null);
addToMap(properties, ContentModel.PROP_COMPANYADDRESS1, null); if (company.wasSet(ContentModel.PROP_COMPANYEMAIL))
addToMap(properties, ContentModel.PROP_COMPANYADDRESS2, null); {
addToMap(properties, ContentModel.PROP_COMPANYADDRESS3, null); properties.put(ContentModel.PROP_COMPANYEMAIL, company.getEmail());
addToMap(properties, ContentModel.PROP_COMPANYPOSTCODE, null); }
addToMap(properties, ContentModel.PROP_COMPANYTELEPHONE, null); }
addToMap(properties, ContentModel.PROP_COMPANYFAX, null); else
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()); // addToMap(properties, ContentModel.ASSOC_AVATAR, getAvatarId());

View File

@@ -25,6 +25,7 @@
*/ */
package org.alfresco.rest.api.people; package org.alfresco.rest.api.people;
import org.alfresco.model.ContentModel;
import org.alfresco.rest.api.People; import org.alfresco.rest.api.People;
import org.alfresco.rest.api.model.Person; import org.alfresco.rest.api.model.Person;
import org.alfresco.rest.framework.WebApiDescription; import org.alfresco.rest.framework.WebApiDescription;
@@ -89,25 +90,7 @@ public class PeopleEntityResource implements EntityResourceAction.ReadById<Perso
{ {
Person p = persons.get(0); Person p = persons.get(0);
// Until REPO-110 is solved, we need to explicitly test for the presence of fields validateDerivedFieldsExistence(p);
// 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");
}
List<Person> result = new ArrayList<>(1); List<Person> result = new ArrayList<>(1);
result.add(people.create(p)); 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") @WebApiDescription(title="Update person", description="Update the given person's details")
public Person update(String personId, Person person, Parameters parameters) public Person update(String personId, Person person, Parameters parameters)
{ {
validateNonUpdatableFieldsExistence(person); if (person.wasSet(ContentModel.PROP_USERNAME))
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)
{ {
// REPO-1537 // REPO-1537
throw new InvalidArgumentException("Unsupported field: id"); 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"); throw new InvalidArgumentException("Unsupported field: statusUpdatedAt");
} }
if (person.getAvatarId() != null) if (person.wasSet(Person.PROP_PERSON_AVATAR_ID))
{ {
throw new InvalidArgumentException("Unsupported field: avatarId"); throw new InvalidArgumentException("Unsupported field: avatarId");
} }
if (person.getQuota() != null) if (person.wasSet(ContentModel.PROP_SIZE_QUOTA))
{ {
throw new InvalidArgumentException("Unsupported field: quota"); throw new InvalidArgumentException("Unsupported field: quota");
} }
if (person.getQuotaUsed() != null) if (person.wasSet(ContentModel.PROP_SIZE_CURRENT))
{ {
throw new InvalidArgumentException("Unsupported field: quotaUsed"); throw new InvalidArgumentException("Unsupported field: quotaUsed");
} }

View File

@@ -323,7 +323,18 @@ public class TestPeople extends EnterpriseTestApi
assertEquals(null, p.getInstantMessageId()); assertEquals(null, p.getInstantMessageId());
assertEquals(null, p.getJobTitle()); assertEquals(null, p.getJobTitle());
assertEquals(null, p.getLocation()); 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.getMobile());
assertEquals("1234 5678 9012", p.getTelephone()); assertEquals("1234 5678 9012", p.getTelephone());
assertEquals(null, p.getUserStatus()); assertEquals(null, p.getUserStatus());
@@ -351,7 +362,18 @@ public class TestPeople extends EnterpriseTestApi
assertEquals(null, p.getInstantMessageId()); assertEquals(null, p.getInstantMessageId());
assertEquals(null, p.getJobTitle()); assertEquals(null, p.getJobTitle());
assertEquals(null, p.getLocation()); 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.getMobile());
assertEquals(null, p.getTelephone()); assertEquals(null, p.getTelephone());
assertEquals(null, p.getUserStatus()); assertEquals(null, p.getUserStatus());
@@ -854,7 +876,7 @@ public class TestPeople extends EnterpriseTestApi
} }
@Test @Test
public void testUpdatePersonUpdate() throws Exception public void testUpdatePersonUpdateAsAdmin() throws Exception
{ {
final String personId = account3PersonIt.next(); final String personId = account3PersonIt.next();
@@ -934,6 +956,89 @@ public class TestPeople extends EnterpriseTestApi
assertEquals(userStatus, updatedPerson.getUserStatus()); assertEquals(userStatus, updatedPerson.getUserStatus());
assertEquals(emailNotificationsEnabled, updatedPerson.isEmailNotificationsEnabled()); assertEquals(emailNotificationsEnabled, updatedPerson.isEmailNotificationsEnabled());
assertEquals(enabled, updatedPerson.isEnabled()); 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 @Test

View File

@@ -31,6 +31,10 @@ import org.json.simple.JSONObject;
public class Company extends org.alfresco.rest.api.model.Company implements ExpectedComparison public class Company extends org.alfresco.rest.api.model.Company implements ExpectedComparison
{ {
public Company()
{
}
public Company(org.alfresco.rest.api.model.Company 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()); super(company.getOrganization(), company.getAddress1(), company.getAddress2(), company.getAddress3(), company.getPostcode(), company.getTelephone(), company.getFax(), company.getEmail());
@@ -40,7 +44,7 @@ public class Company extends org.alfresco.rest.api.model.Company implements Expe
{ {
super(organization, address1, address2, address3, postcode, telephone, fax, email); super(organization, address1, address2, address3, postcode, telephone, fax, email);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public JSONObject toJSON() public JSONObject toJSON()
{ {
@@ -55,14 +59,14 @@ public class Company extends org.alfresco.rest.api.model.Company implements Expe
companyJson.put("email", getEmail()); companyJson.put("email", getEmail());
return companyJson; return companyJson;
} }
@Override @Override
public void expected(Object o) public void expected(Object o)
{ {
assertTrue(o instanceof Company); assertTrue(o instanceof Company);
Company other = (Company)o; Company other = (Company)o;
AssertUtil.assertEquals("organization", getOrganization(), other.getOrganization()); AssertUtil.assertEquals("organization", getOrganization(), other.getOrganization());
AssertUtil.assertEquals("address1", getAddress1(), other.getAddress1()); AssertUtil.assertEquals("address1", getAddress1(), other.getAddress1());
AssertUtil.assertEquals("address2", getAddress2(), other.getAddress2()); AssertUtil.assertEquals("address2", getAddress2(), other.getAddress2());

View File

@@ -219,6 +219,10 @@ public class Person
{ {
company = new Company(organization, address1, address2, address3, postcode, companyTelephone, fax, companyEmail); company = new Company(organization, address1, address2, address3, postcode, companyTelephone, fax, companyEmail);
} }
else
{
company = new Company();
}
} }
String mobile = (String)jsonObject.get("mobile"); String mobile = (String)jsonObject.get("mobile");