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.
Part 2 - Navigation
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.
Response<ResultPaging<NodeRepresentation>> rootChildrenResponse = nodesAPI.listNodeChildrenCall(NodesAPI.FOLDER_ROOT).execute();
for (NodeRepresentation node : rootChildrenResponse.body().getList())
Retrieve children with properties and aspects
ResultPaging<NodeRepresentation> rootChildren = nodesAPI
.listNodeChildrenCall(NodesAPI.FOLDER_ROOT, null, null, null, null,
new IncludeParam(Arrays.asList("properties", "aspectNames")), null, null, null)
Retrieve child nodes 3 through 5
Assert.assertEquals(nodesAPI.listNodeChildrenCall(NodesAPI.FOLDER_ROOT, 2, 3, null).execute().body()
Retrieve files only
.listNodeChildrenCall(NodesAPI.FOLDER_ROOT, null, null, null, "(isFile=true)", null, null, null, null)
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
.listNodeChildrenCall(NodesAPI.FOLDER_ROOT, null, null, new OrderByParam(Arrays.asList("name ASC")))
Alfresco Java Client SDK Series