We will now follow Gavin Cornwell https://community.alfresco.com/community/ecm/blog/2017/04/18/v1-rest-api-part-10-people examples and see how we can achieve the same experience using the SDK
To make the exercise more concise we will execute each request in a synchronous way.
Alfresco Java Client is currently in Early Access mode. It evolves as you use them, as you give feedback, and as the developers update and add file. We like to think app & lib development as services that grow and evolve with the involvement of the community.
In order to follow along you'll need an environment to do so, firstly download and install the 5.2.c Early Access Community Release. In our case we will consider Alfresco is available at http://localhost:8080/alfresco and the "admin" user is available and has "admin" as password.
//Create Person
PeopleAPI peopleAPI = client.getPeopleAPI();
PersonBodyCreate bodyCreate = new PersonBodyCreate("jdoe").firstName("John").lastName("Doe")
.email("[email protected]").password("jdoe").skypeId("johndoe_skype").jobTitle("Software Engineer");
PersonRepresentation personRepresentation = peopleAPI.createPersonCall(bodyCreate).execute().body();
Assert.assertEquals(personRepresentation.getId(), "jdoe");
Assert.assertEquals(personRepresentation.getFirstName(), "John");
Assert.assertEquals(personRepresentation.getLastName(), "Doe");
Assert.assertEquals(personRepresentation.getEmail(), "[email protected]");
Assert.assertEquals(personRepresentation.getSkypeId(), "johndoe_skype");
Assert.assertEquals(personRepresentation.getJobTitle(), "Software Engineer");ResultPaging<PersonRepresentation> personList = peopleAPI.listPeopleCall().execute().body();
Assert.assertEquals(personList.getCount(), 7);ResultPaging<PersonRepresentation> searchPersonList = client.getQueriesAPI().findPeopleCall("jdoe").execute().body();
Assert.assertEquals(searchPersonList.getCount(), 1);
Assert.assertEquals(searchPersonList.getList().get(0).getId(), "jdoe");PersonRepresentation jdoeDetails = peopleAPI.getPersonCall("jdoe").execute().body();
Assert.assertEquals(jdoeDetails.getId(), "jdoe");
Assert.assertEquals(jdoeDetails.getFirstName(), "John");
Assert.assertEquals(jdoeDetails.getLastName(), "Doe");
Assert.assertEquals(jdoeDetails.getEmail(), "[email protected]");
Assert.assertEquals(jdoeDetails.getSkypeId(), "johndoe_skype");
Assert.assertEquals(jdoeDetails.getJobTitle(), "Software Engineer");PersonBodyUpdate bodyUpdate = new PersonBodyUpdate().firstName("Johnathon").mobile("07000 123456");
PersonRepresentation updatedPerson = peopleAPI.updatePersonCall("jdoe", bodyUpdate, null).execute().body();
Assert.assertEquals(updatedPerson.getMobile(), "07000 123456");
Assert.assertEquals(updatedPerson.getFirstName(), "Johnathon");PersonBodyUpdate changePassword = new PersonBodyUpdate().oldPassword("jdoe").password("my-new-password");
PersonRepresentation updatedPPerson = peopleAPI.updatePersonCall("jdoe", changePassword, null).execute().body();
PersonBodyUpdate disablePersonBody = new PersonBodyUpdate().enabled(false);
PersonRepresentation disablePerson = peopleAPI.updatePersonCall("jdoe", disablePersonBody, null).execute().body();
Assert.assertEquals(disablePerson.isEnabled(), Boolean.FALSE);You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.