Alfresco Java Client SDK - Usage Part 2 - Navigation

cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco Java Client SDK - Usage Part 2 - Navigation

Active Member
1 1 1,332

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.

Important Notice

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.

Prerequisites

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.

Retrieve children

//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());
   }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Retrieve children with properties and aspects

// 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

// Retrieve child nodes 3 through 5
Assert.assertEquals(nodesAPI.listNodeChildrenCall(NodesAPI.FOLDER_ROOT, 2, 3, null).execute().body()
.getPagination().getCount(), 3);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Retrieve files only

// 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

// 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 

// 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);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Alfresco Java Client SDK Series

1 Comment
Alfresco Employee

Is there any way to get primary path? 

I'm trying to identify nodes like /app:company_home/app:user_homes in any language.