mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged mward/5.2.n-optionalcustomprops (5.2.1) to 5.2.N (5.2.1)
132978 mward: REPO-1395: make aspectNames, properties optional 'includes' when listing people git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@132993 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -34,7 +34,8 @@ import org.alfresco.service.cmr.security.NoSuchPersonException;
|
|||||||
public interface People
|
public interface People
|
||||||
{
|
{
|
||||||
String DEFAULT_USER = "-me-";
|
String DEFAULT_USER = "-me-";
|
||||||
|
String PARAM_INCLUDE_ASPECTNAMES = "aspectNames";
|
||||||
|
String PARAM_INCLUDE_PROPERTIES = "properties";
|
||||||
String PARAM_FIRST_NAME = "firstName";
|
String PARAM_FIRST_NAME = "firstName";
|
||||||
String PARAM_LAST_NAME = "lastName";
|
String PARAM_LAST_NAME = "lastName";
|
||||||
String PARAM_ID = "id";
|
String PARAM_ID = "id";
|
||||||
|
@@ -297,7 +297,10 @@ public class PeopleImpl implements People
|
|||||||
public Person getPerson(String personId)
|
public Person getPerson(String personId)
|
||||||
{
|
{
|
||||||
personId = validatePerson(personId);
|
personId = validatePerson(personId);
|
||||||
Person person = getPersonWithProperties(personId);
|
List<String> include = Arrays.asList(
|
||||||
|
PARAM_INCLUDE_ASPECTNAMES,
|
||||||
|
PARAM_INCLUDE_PROPERTIES);
|
||||||
|
Person person = getPersonWithProperties(personId, include);
|
||||||
|
|
||||||
return person;
|
return person;
|
||||||
}
|
}
|
||||||
@@ -322,7 +325,7 @@ public class PeopleImpl implements People
|
|||||||
public Person get(int index)
|
public Person get(int index)
|
||||||
{
|
{
|
||||||
PersonService.PersonInfo personInfo = page.get(index);
|
PersonService.PersonInfo personInfo = page.get(index);
|
||||||
Person person = getPersonWithProperties(personInfo.getUserName());
|
Person person = getPersonWithProperties(personInfo.getUserName(), parameters.getInclude());
|
||||||
return person;
|
return person;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,7 +363,7 @@ public class PeopleImpl implements People
|
|||||||
return sortProps;
|
return sortProps;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Person getPersonWithProperties(String personId)
|
private Person getPersonWithProperties(String personId, List<String> include)
|
||||||
{
|
{
|
||||||
Person person = null;
|
Person person = null;
|
||||||
NodeRef personNode = personService.getPerson(personId, false);
|
NodeRef personNode = personService.getPerson(personId, false);
|
||||||
@@ -384,12 +387,18 @@ public class PeopleImpl implements People
|
|||||||
nodeProps.remove(Person.PROP_PERSON_DESCRIPTION);
|
nodeProps.remove(Person.PROP_PERSON_DESCRIPTION);
|
||||||
|
|
||||||
// Expose properties
|
// Expose properties
|
||||||
Map<String, Object> custProps = new HashMap<>();
|
if (include.contains(PARAM_INCLUDE_PROPERTIES))
|
||||||
custProps.putAll(nodes.mapFromNodeProperties(nodeProps, new ArrayList<>(), new HashMap<>(), EXCLUDED_PROPS));
|
{
|
||||||
person.setProperties(custProps);
|
Map<String, Object> custProps = new HashMap<>();
|
||||||
// Expose aspect names
|
custProps.putAll(nodes.mapFromNodeProperties(nodeProps, new ArrayList<>(), new HashMap<>(), EXCLUDED_PROPS));
|
||||||
Set<QName> aspects = nodeService.getAspects(personNode);
|
person.setProperties(custProps);
|
||||||
person.setAspectNames(nodes.mapFromNodeAspects(aspects, EXCLUDED_ASPECTS));
|
}
|
||||||
|
if (include.contains(PARAM_INCLUDE_ASPECTNAMES))
|
||||||
|
{
|
||||||
|
// Expose aspect names
|
||||||
|
Set<QName> aspects = nodeService.getAspects(personNode);
|
||||||
|
person.setAspectNames(nodes.mapFromNodeAspects(aspects, EXCLUDED_ASPECTS));
|
||||||
|
}
|
||||||
|
|
||||||
// get avatar information
|
// get avatar information
|
||||||
if (hasAvatar(personNode))
|
if (hasAvatar(personNode))
|
||||||
|
@@ -120,12 +120,12 @@ public class TestPeople extends EnterpriseTestApi
|
|||||||
return network;
|
return network;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPeople() throws Exception
|
public void testGetPerson() throws Exception
|
||||||
{
|
{
|
||||||
final String person1 = account1PersonIt.next();
|
final String person1 = account1PersonIt.next();
|
||||||
final String person2 = account1PersonIt.next();
|
final String person2 = account1PersonIt.next();
|
||||||
final String person3 = account2PersonIt.next();
|
final String person3 = account2PersonIt.next();
|
||||||
|
|
||||||
// Test Case cloud-2192
|
// Test Case cloud-2192
|
||||||
// should be able to see oneself
|
// should be able to see oneself
|
||||||
@@ -1022,8 +1022,13 @@ public class TestPeople extends EnterpriseTestApi
|
|||||||
{
|
{
|
||||||
params.put("orderBy", sortColumn + " " + (asc ? "ASC" : "DESC"));
|
params.put("orderBy", sortColumn + " " + (asc ? "ASC" : "DESC"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return listPeople(createParams(paging, params), statusCode);
|
||||||
|
}
|
||||||
|
|
||||||
HttpResponse response = people.getAll("people", null, null, null, createParams(paging, params), "Failed to get people", statusCode);
|
private PublicApiClient.ListResponse<Person> listPeople(Map<String, String> parameters, int expectedStatusCode) throws PublicApiException
|
||||||
|
{
|
||||||
|
HttpResponse response = people.getAll("people", null, null, null, parameters, "Failed to get people", expectedStatusCode);
|
||||||
JSONObject jsonList = (JSONObject) response.getJsonResponse().get("list");
|
JSONObject jsonList = (JSONObject) response.getJsonResponse().get("list");
|
||||||
if (jsonList == null)
|
if (jsonList == null)
|
||||||
{
|
{
|
||||||
@@ -1033,6 +1038,32 @@ public class TestPeople extends EnterpriseTestApi
|
|||||||
return Person.parsePeople(response.getJsonResponse());
|
return Person.parsePeople(response.getJsonResponse());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testListPeopleWithAspectNamesAndProperties() throws PublicApiException
|
||||||
|
{
|
||||||
|
initializeContextForGetPeople();
|
||||||
|
|
||||||
|
// Are aspectNames and properties left absent when not required?
|
||||||
|
{
|
||||||
|
PublicApiClient.ListResponse<Person> resp = listPeople(Collections.emptyMap(), 200);
|
||||||
|
assertNull(resp.getList().get(0).getAspectNames());
|
||||||
|
assertNull(resp.getList().get(0).getProperties());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Are aspectNames and properties populated when requested?
|
||||||
|
{
|
||||||
|
Map<String, String> parameters = Collections.singletonMap("include", "aspectNames,properties");
|
||||||
|
PublicApiClient.ListResponse<Person> resp = listPeople(parameters, 200);
|
||||||
|
Person alice = resp.getList().stream().
|
||||||
|
filter(p -> p.getUserName().equals("alice@"+account4.getId()))
|
||||||
|
.findFirst().get();
|
||||||
|
assertNotNull(alice.getAspectNames());
|
||||||
|
assertTrue(alice.getAspectNames().contains("cm:titled"));
|
||||||
|
assertNotNull(alice.getProperties());
|
||||||
|
assertEquals("Alice through the REST API", alice.getProperties().get("cm:title"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the capability to sort and paginate the list of people orderBy =
|
* Tests the capability to sort and paginate the list of people orderBy =
|
||||||
* firstName ASC skip = 1, count = 3
|
* firstName ASC skip = 1, count = 3
|
||||||
@@ -1232,6 +1263,7 @@ public class TestPeople extends EnterpriseTestApi
|
|||||||
personAlice.setEmail("alison.smith@example.com");
|
personAlice.setEmail("alison.smith@example.com");
|
||||||
personAlice.setPassword("password");
|
personAlice.setPassword("password");
|
||||||
personAlice.setEnabled(true);
|
personAlice.setEnabled(true);
|
||||||
|
personAlice.setProperties(Collections.singletonMap("cm:title", "Alice through the REST API"));
|
||||||
people.create(personAlice);
|
people.create(personAlice);
|
||||||
|
|
||||||
publicApiClient.setRequestContext(new RequestContext(account4.getId(), account4Admin, "admin"));
|
publicApiClient.setRequestContext(new RequestContext(account4.getId(), account4Admin, "admin"));
|
||||||
|
Reference in New Issue
Block a user