Following the Alfresco Java Client SDK introduction in my last post it's now time to dive in and start using the SDK. We will follow Gavin Cornwell https://community.alfresco.com/community/ecm/blog/2016/10/17/v1-rest-api-part-2-navigation examples and see how we can achieve the same experience.
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.
To retrieve the children for a folder we need it's id, to help get started the Alfresco REST API have provided three aliases, -root-, -my- and -shared-. Those constant are available as constants with NodesAPI.FOLDER_ROOT, NodesAPI.FOLDER_MY and NodesAPI.FOLDER_SHARED
In this section we will retrieve a collection of node object. As mentionned in previous blog collection of objects are retrieved with the SDK as ResultPaging of NodeRepresentation.
//List Root Children
Response<ResultPaging<NodeRepresentation>> rootChildrenResponse = nodesAPI.listNodeChildrenCall(NodesAPI.FOLDER_ROOT).execute();
//Check Response status
if (rootChildrenResponse.isSuccessful())
{
//Iterate over the listing
for (NodeRepresentation node : rootChildrenResponse.body().getList())
{
Assert.assertNotNull(node.getId());
}
}
// List Root Children with Include Parameters
ResultPaging<NodeRepresentation> rootChildren = nodesAPI
.listNodeChildrenCall(NodesAPI.FOLDER_ROOT, null, null, null, null,
new IncludeParam(Arrays.asList("properties", "aspectNames")), null, null, null)
.execute().body();
// Retrieve child nodes 3 through 5
Assert.assertEquals(nodesAPI.listNodeChildrenCall(NodesAPI.FOLDER_ROOT, 2, 3, null).execute().body()
.getPagination().getCount(), 3);
// Retrieve files only
Assert.assertEquals(nodesAPI
.listNodeChildrenCall(NodesAPI.FOLDER_ROOT, null, null, null, "(isFile=true)", null, null, null, null)
.execute().body().getPagination().getCount(), 0);
// Retrieve Sites folder only
Assert.assertEquals(nodesAPI.listNodeChildrenCall(NodesAPI.FOLDER_ROOT, null, null, null, "(nodeType=st:sites)",
null, null, null, null).execute().body().getList().get(0).getName(), "Sites");
// Retrieve children ordered by name
Assert.assertEquals(nodesAPI
.listNodeChildrenCall(NodesAPI.FOLDER_ROOT, null, null, new OrderByParam(Arrays.asList("name ASC")))
.execute().body().getList().size(), 7);
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.