Search in sources :

Example 21 with Person

use of org.alfresco.rest.api.tests.client.data.Person in project alfresco-remote-api by Alfresco.

the class TestPeople method testGetPerson_withCustomProps.

@Test
public void testGetPerson_withCustomProps() throws PublicApiException {
    // Create the person directly using the Java services - we don't want to test
    // the REST API's "create person" function here, so we're isolating this test from it.
    MutableAuthenticationService authService = applicationContext.getBean("AuthenticationService", MutableAuthenticationService.class);
    PreferenceService prefService = applicationContext.getBean("PreferenceService", PreferenceService.class);
    Map<QName, Serializable> nodeProps = new HashMap<>();
    // The papi:lunchable aspect should be auto-added for the papi:lunch property
    nodeProps.put(PROP_LUNCH, "Falafel wrap");
    nodeProps.put(PROP_LUNCH_COMMENTS, "");
    // These properties should not be present when a person is retrieved
    // since they are present as top-level fields.
    String userName = "docbrown@" + account1.getId();
    nodeProps.put(ContentModel.PROP_USERNAME, userName);
    nodeProps.put(ContentModel.PROP_FIRSTNAME, "Doc");
    nodeProps.put(ContentModel.PROP_LASTNAME, "Brown");
    nodeProps.put(ContentModel.PROP_JOBTITLE, "Inventor");
    nodeProps.put(ContentModel.PROP_LOCATION, "Location");
    nodeProps.put(ContentModel.PROP_TELEPHONE, "123345");
    nodeProps.put(ContentModel.PROP_MOBILE, "456456");
    nodeProps.put(ContentModel.PROP_EMAIL, "doc.brown@example.com");
    nodeProps.put(ContentModel.PROP_ORGANIZATION, "Acme");
    nodeProps.put(ContentModel.PROP_COMPANYADDRESS1, "123 Acme Crescent");
    nodeProps.put(ContentModel.PROP_COMPANYADDRESS2, "Cholsey");
    nodeProps.put(ContentModel.PROP_COMPANYADDRESS3, "Oxfordshire");
    nodeProps.put(ContentModel.PROP_COMPANYPOSTCODE, "OX10 1AB");
    nodeProps.put(ContentModel.PROP_COMPANYTELEPHONE, "098876234");
    nodeProps.put(ContentModel.PROP_COMPANYFAX, "098234876");
    nodeProps.put(ContentModel.PROP_COMPANYEMAIL, "info@example.com");
    nodeProps.put(ContentModel.PROP_SKYPE, "doc.brown");
    nodeProps.put(ContentModel.PROP_INSTANTMSG, "doc.brown.instmsg");
    nodeProps.put(ContentModel.PROP_USER_STATUS, "status");
    nodeProps.put(ContentModel.PROP_USER_STATUS_TIME, new Date());
    nodeProps.put(ContentModel.PROP_GOOGLEUSERNAME, "doc.brown.google");
    nodeProps.put(ContentModel.PROP_SIZE_QUOTA, 12345000);
    nodeProps.put(ContentModel.PROP_SIZE_CURRENT, 1230);
    nodeProps.put(ContentModel.PROP_EMAIL_FEED_DISABLED, false);
    // TODO: PROP_PERSON_DESCRIPTION?
    // Namespaces that should be filtered
    nodeProps.put(ContentModel.PROP_ENABLED, true);
    nodeProps.put(ContentModel.PROP_SYS_NAME, "name-value");
    // Create a password and enable the user so that we can check the usr:* props aren't present later.
    AuthenticationUtil.setFullyAuthenticatedUser("admin@" + account1.getId());
    authService.createAuthentication(userName, "password".toCharArray());
    authService.setAuthenticationEnabled(userName, true);
    personService.createPerson(nodeProps);
    // Set a preference, so that we can test that we're filtering this property correctly.
    prefService.setPreferences(userName, Collections.singletonMap("olives", "green"));
    // Get the person using the REST API
    publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin"));
    Person person = people.getPerson(userName);
    // Did we get the correct aspects/properties?
    assertEquals(userName, person.getId());
    assertEquals("Doc", person.getFirstName());
    assertEquals("Falafel wrap", person.getProperties().get("papi:lunch"));
    assertTrue(person.getAspectNames().contains("papi:lunchable"));
    // Empty (zero length) string values are considered to be
    // null values, and will be represented the same as null
    // values (i.e. by non-existence of the property).
    assertNull(person.getProperties().get("papi:lunchcomments"));
    // Check that no properties are present that should have been filtered by namespace.
    for (String key : person.getProperties().keySet()) {
        if (key.startsWith("cm:") || key.startsWith("sys:") || key.startsWith("usr:")) {
            Object value = person.getProperties().get(key);
            String keyValueStr = String.format("(key=%s, value=%s)", key, value);
            fail("Property " + keyValueStr + " found with namespace that should have been excluded.");
        }
    }
}
Also used : Serializable(java.io.Serializable) PreferenceService(org.alfresco.service.cmr.preference.PreferenceService) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) JSONObject(org.json.simple.JSONObject) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) MutableAuthenticationService(org.alfresco.service.cmr.security.MutableAuthenticationService) Person(org.alfresco.rest.api.tests.client.data.Person) Date(java.util.Date) Test(org.junit.Test)

Example 22 with Person

use of org.alfresco.rest.api.tests.client.data.Person in project alfresco-remote-api by Alfresco.

the class TestPeople method testGetPerson.

@Test
public void testGetPerson() throws Exception {
    final String person1 = account1PersonIt.next();
    final String person2 = account1PersonIt.next();
    final String person3 = account2PersonIt.next();
    // Test Case cloud-2192
    // should be able to see oneself
    {
        publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1));
        Person resp = people.getPerson(person1);
        Person person1Entity = repoService.getPerson(person1);
        check(person1Entity, resp);
    }
    // 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 = people.getPerson(person1);
        Person person1Entity = repoService.getPerson(person1);
        Map<String, Boolean> respCapabilities = resp.getCapabilities();
        assertNotNull("Check if capabilities are present", respCapabilities);
        check(person1Entity, resp);
    }
    // "-me-" user
    {
        publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1));
        Person resp = people.getPerson(org.alfresco.rest.api.People.DEFAULT_USER);
        Person person1Entity = repoService.getPerson(person1);
        Map<String, Boolean> respCapabilities = resp.getCapabilities();
        assertNotNull("Check if capabilities are present", respCapabilities);
        assertTrue("Check if -me- user is mutable", respCapabilities.get("isMutable"));
        check(person1Entity, resp);
    }
    // shouldn't be able to see another user in another domain
    publicApiClient.setRequestContext(new RequestContext(account1.getId(), person3));
    try {
        people.getPerson(person1);
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
    }
    RepoService.TestPerson testP = account1.createUser();
    String personId = testP.getId();
    String desc = "<B>Nice person</B>";
    account1.addUserDescription(personId, desc);
    publicApiClient.setRequestContext(new RequestContext(account1.getId(), personId));
    Person resp = publicApiClient.people().getPerson(personId);
    assertEquals(resp.getId(), personId);
    assertEquals(resp.getDescription(), desc);
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Person(org.alfresco.rest.api.tests.client.data.Person) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 23 with Person

use of org.alfresco.rest.api.tests.client.data.Person in project alfresco-remote-api by Alfresco.

the class TestPeople method testListPeopleWithAspectNamesAndProperties.

@Test
public void testListPeopleWithAspectNamesAndProperties() throws PublicApiException {
    publicApiClient.setRequestContext(new RequestContext(account3.getId(), account3Admin, "admin"));
    personBob = new Person();
    personBob.setId("bob@" + account3.getId());
    personBob.setUserName(personBob.getId());
    personBob.setFirstName("Bob");
    personBob.setLastName("Cratchit");
    personBob.setEmail("bob.cratchit@example.com");
    personBob.setPassword("password");
    personBob.setEnabled(true);
    personBob.setProperties(Collections.singletonMap("papi:lunch", "Magical sandwich"));
    people.create(personBob);
    // 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 bob = resp.getList().stream().filter(p -> p.getUserName().equals(personBob.getId())).findFirst().get();
        assertNotNull(bob.getAspectNames());
        assertTrue(bob.getAspectNames().contains("papi:lunchable"));
        assertNotNull(bob.getProperties());
        assertEquals("Magical sandwich", bob.getProperties().get("papi:lunch"));
    }
}
Also used : Pair(org.alfresco.rest.api.tests.client.Pair) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) MutableAuthenticationService(org.alfresco.service.cmr.security.MutableAuthenticationService) Date(java.util.Date) Renditions(org.alfresco.rest.api.Renditions) Client(org.alfresco.rest.api.model.Client) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) PersonService(org.alfresco.service.cmr.security.PersonService) ContentModel(org.alfresco.model.ContentModel) After(org.junit.After) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) NodeService(org.alfresco.service.cmr.repository.NodeService) HttpStatus(org.apache.commons.httpclient.HttpStatus) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) Company(org.alfresco.rest.api.tests.client.data.Company) Set(java.util.Set) UUID(java.util.UUID) ContentLimitProvider(org.alfresco.repo.content.ContentLimitProvider) Collectors(java.util.stream.Collectors) ContentService(org.alfresco.service.cmr.repository.ContentService) Serializable(java.io.Serializable) List(java.util.List) JSONAble(org.alfresco.rest.api.tests.client.data.JSONAble) JSONObject(org.json.simple.JSONObject) AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) Assert.assertFalse(org.junit.Assert.assertFalse) NamespaceService(org.alfresco.service.namespace.NamespaceService) Person(org.alfresco.rest.api.tests.client.data.Person) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) PreferenceService(org.alfresco.service.cmr.preference.PreferenceService) RestApiUtil(org.alfresco.rest.api.tests.util.RestApiUtil) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ClassPathResource(org.springframework.core.io.ClassPathResource) HashMap(java.util.HashMap) LoginTicketResponse(org.alfresco.rest.api.model.LoginTicketResponse) Rendition(org.alfresco.rest.api.model.Rendition) ArrayList(java.util.ArrayList) People(org.alfresco.rest.api.tests.client.PublicApiClient.People) GUID(org.alfresco.util.GUID) ResetPasswordServiceImplTest.getWorkflowIdAndKeyFromUrl(org.alfresco.repo.security.authentication.ResetPasswordServiceImplTest.getWorkflowIdAndKeyFromUrl) QName(org.alfresco.service.namespace.QName) ThumbnailService(org.alfresco.service.cmr.thumbnail.ThumbnailService) LinkedList(java.util.LinkedList) EmailUtil(org.alfresco.util.email.EmailUtil) Before(org.junit.Before) PasswordReset(org.alfresco.rest.api.model.PasswordReset) EmptyStackException(java.util.EmptyStackException) Iterator(java.util.Iterator) Assert.assertNotNull(org.junit.Assert.assertNotNull) HttpServletResponse(javax.servlet.http.HttpServletResponse) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) MimeMessage(javax.mail.internet.MimeMessage) PublicApiClient(org.alfresco.rest.api.tests.client.PublicApiClient) File(java.io.File) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) Assert.assertNull(org.junit.Assert.assertNull) LoginTicket(org.alfresco.rest.api.model.LoginTicket) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) ResetPasswordServiceImpl(org.alfresco.repo.security.authentication.ResetPasswordServiceImpl) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Person(org.alfresco.rest.api.tests.client.data.Person) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 24 with Person

use of org.alfresco.rest.api.tests.client.data.Person in project alfresco-remote-api by Alfresco.

the class TestPeople method testCreatePerson_withCustomProps.

@Test
public void testCreatePerson_withCustomProps() throws Exception {
    publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin"));
    Person person = new Person();
    person.setUserName("jbloggs@" + account1.getId());
    person.setFirstName("Joe");
    person.setEmail("jbloggs@" + account1.getId());
    person.setEnabled(true);
    person.setPassword("password123");
    Map<String, Object> props = new HashMap<>();
    props.put("papi:telehash", "724332b5796a8");
    person.setProperties(props);
    // Explicitly add an aspect
    List<String> aspectNames = new ArrayList<>();
    aspectNames.add("papi:lunchable");
    person.setAspectNames(aspectNames);
    // REST API call to create person
    Person retPerson = people.create(person);
    // Check that the response contains the expected aspects and properties
    assertEquals(2, retPerson.getAspectNames().size());
    assertTrue(retPerson.getAspectNames().contains("papi:comms"));
    assertEquals(1, retPerson.getProperties().size());
    assertEquals("724332b5796a8", retPerson.getProperties().get("papi:telehash"));
    // Get the NodeRef
    AuthenticationUtil.setFullyAuthenticatedUser("admin@" + account1.getId());
    NodeRef nodeRef = personService.getPerson("jbloggs@" + account1.getId(), false);
    // Check the node has the properties and aspects we expect
    assertTrue(nodeService.hasAspect(nodeRef, ASPECT_COMMS));
    assertTrue(nodeService.hasAspect(nodeRef, ASPECT_LUNCHABLE));
    Map<QName, Serializable> retProps = nodeService.getProperties(nodeRef);
    assertEquals("724332b5796a8", retProps.get(PROP_TELEHASH));
    assertEquals(null, retProps.get(PROP_LUNCH));
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) JSONObject(org.json.simple.JSONObject) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Person(org.alfresco.rest.api.tests.client.data.Person) Test(org.junit.Test)

Example 25 with Person

use of org.alfresco.rest.api.tests.client.data.Person in project alfresco-remote-api by Alfresco.

the class TestPeople method setUp.

@Before
public void setUp() throws Exception {
    people = publicApiClient.people();
    accountsIt = getTestFixture().getNetworksIt();
    account1 = accountsIt.next();
    account2 = accountsIt.next();
    // Networks are very expensive to create, so do this once only and store statically.
    if (account3 == null) {
        account3 = createNetwork("account3");
    }
    if (account4 == null) {
        // Use account 4 only for the sorting and paging tests, so that the data doesn't change between tests.
        account4 = createNetwork("account4");
        account4Admin = "admin@" + account4.getId();
        publicApiClient.setRequestContext(new RequestContext(account4.getId(), account4Admin, "admin"));
        personAlice = new Person();
        personAlice.setUserName("alice@" + account4.getId());
        personAlice.setId("alice@" + account4.getId());
        personAlice.setFirstName("Alice");
        personAlice.setLastName("Smith");
        personAlice.setEmail("alison.smith@example.com");
        personAlice.setPassword("password");
        personAlice.setEnabled(true);
        personAlice.setProperties(Collections.singletonMap("papi:lunch", "Magical sandwich"));
        people.create(personAlice);
        personAliceD = new Person();
        personAliceD.setUserName("aliced@" + account4.getId());
        personAliceD.setId("aliced@" + account4.getId());
        personAliceD.setFirstName("Alice");
        personAliceD.setLastName("Davis");
        personAliceD.setEmail("alison.davis@example.com");
        personAliceD.setPassword("password");
        personAliceD.setEnabled(true);
        people.create(personAliceD);
        personBen = new Person();
        personBen.setUserName("ben@" + account4.getId());
        personBen.setId("ben@" + account4.getId());
        personBen.setFirstName("Ben");
        personBen.setLastName("Carson");
        personBen.setEmail("ben.smythe@example.com");
        personBen.setPassword("password");
        personBen.setEnabled(true);
        people.create(personBen);
    }
    account1Admin = "admin@" + account1.getId();
    account2Admin = "admin@" + account2.getId();
    account3Admin = "admin@" + account3.getId();
    account1PersonIt = account1.getPersonIds().iterator();
    account2PersonIt = account2.getPersonIds().iterator();
    nodeService = applicationContext.getBean("NodeService", NodeService.class);
    personService = applicationContext.getBean("PersonService", PersonService.class);
    // Capture authentication pre-test, so we can restore it again afterwards.
    AuthenticationUtil.pushAuthentication();
}
Also used : NodeService(org.alfresco.service.cmr.repository.NodeService) PersonService(org.alfresco.service.cmr.security.PersonService) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Person(org.alfresco.rest.api.tests.client.data.Person) Before(org.junit.Before)

Aggregations

Person (org.alfresco.rest.api.tests.client.data.Person)30 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)25 Test (org.junit.Test)24 PublicApiClient (org.alfresco.rest.api.tests.client.PublicApiClient)10 HashMap (java.util.HashMap)9 LinkedList (java.util.LinkedList)8 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)8 NodeRef (org.alfresco.service.cmr.repository.NodeRef)7 ArrayList (java.util.ArrayList)6 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)6 JSONObject (org.json.simple.JSONObject)6 Map (java.util.Map)5 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)5 Serializable (java.io.Serializable)4 List (java.util.List)4 Company (org.alfresco.rest.api.tests.client.data.Company)4 QName (org.alfresco.service.namespace.QName)4 Date (java.util.Date)3 Iterator (java.util.Iterator)3 MimeMessage (javax.mail.internet.MimeMessage)3