Move a CS Content in the right folder using the PS

Showing results for 
Search instead for 
Did you mean: 

Move a CS Content in the right folder using the PS

Alfresco Employee
4 0 1,791

This blog post is part of another blog post that I wrote around the text sentiment analysis topic. This blog will focus on the process side and how to Move a file automatically in a folder using the metadata info. If you want more details about the sentiment analysis you can read this article.

For which of you is familiar with the BPM world the diagram below is almost self-explanatory but let's see in details what does the Process that we are going to implement:

  • The process starts getting a nodeId as an input.

  • In the second block, all the metadata related to this node is fetched from the content service through the API

  • If the sentiment is <0.5, the content will be moved to the "Bad Folder"
  • If the sentiment is >=0.5,  the content will be moved to the "Good Folder"

How import the app

To simplify the execution of this example I have already created the app that implements the flow above.You can download the sentiment app from the following link.

Once you have downloaded the sentiment app from the main page of the process service:

1. App Designer ->  

2. Select the App tab and click on import App -> 

3. Import the sentiment-app downloaded.

Process service Endpoint configuration

Let's see how to configure the content service endpoint in the process service tenant configuration. From the main page of the process service:

1. Open the process service as admin

2. Identity management -> 

3. Select the Tenants tab and form the Tenant dropdown select the tennant that will run the app

4. Press the plus button in Basic Auth configuration and add your credentials for the Content service and press save:

5.Click on the endpoints table plus button and add your content service endpoint information as the screenshot below:

Now that our app is configured in the process service we need to configure the content service.

Content service Metadata configuration

As you can see from the BPM graph, our Process has a gateway:

This gateway decides if the next step to execute is move the content file in a bad folder or a good folder.

How does the process know if is a good/bad file?

In order to archive this level of consciousness, I have added a new metadata inside the content service. The process gateway will analyze the value of this metadata and from its value will execute the corresponding action.

Let's see how to add a new metadata in the content service:

1. Login inside your content service

2. Click on the admin tab

3. From the left Tools menu select Model Manager

4.  and import the Model downloaded from the Github repository

Now as last step of configuration we need to create our bad folder and good folder in the content repository. 

Curl call bad folder:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Basic YWRtaW46YWRtaW4=' -d '{
  "name":"bad folder",
' ''‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Curl call good folder:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Basic YWRtaW46YWRtaW4=' -d '{
  "name":"good folder",
' ''‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Get the two nodeId returned by those calls above and use it to configure the steps Move Bad Folder and Move Good Folder of the process service.

Click on the Move good folder step and Bad Folder step to replace your folder Id in the request calls as in the gif below:

At this point, all our process is configured what you need to do is only valorize the value of the metadata for the choice and pass in input to this process the nodeId to check.

For executing those step in a nice visual way I suggest you give a look to this other blog post otherwise you can still populate the metadata using the rest API of the Content service and start the process using the rest API of the process service.