cancel
Showing results for 
Search instead for 
Did you mean: 

Adding tags to document in Alfresco 6.0.2V

Aswani_Juvva
Confirmed Champ
Confirmed Champ

Hi 

Greetings of the day!

Currently, I have facing one issue regarding tagging.

while tagging the documnet with string as [0001213, 8574,01,ID0123] getting tags in alfresco as 1213  8574 1 ID0123

tags with leading 0's are discarded. 

Here is part my code to add tags :

HttpPost httpPost = new HttpPost(url);

StringEntity stringEntity = new StringEntity("[0001213, 8574,01, ID0123]", ContentType.APPLICATION_JSON);
httpPost.setEntity(stringEntity);
HttpResponse httpResponse = closeableHttpClient.execute(httpPost);

Except leading 0's it's working fine, So someone please help on this issue, or Explain to me how tag store in alfresco.

Thanks in advance

5 REPLIES 5

kaynezhang
World-Class Innovator
World-Class Innovator

Which api are you using ,I'm using https://api-explorer.alfresco.com/api-explorer/#!/tags/createTagForNode

It works fine for me. And by the way my alfresco version is 6.2.0

Hi kaynezhang,

The api address which I'm using is working fine with 6.0.2V, but when I'm giving tags with leading 0's, in alfresco site those leading 0's are discarded for the tags(Eg: 009TG as 9TG) and functionality is working fine with tags which are not starting with 0's.

Here is my sample Json for tags in request :: {"tags" :["ID001","ID-Proof","00112"]}

Here is my sample code 

ArrayList<String> tagsList= objModel.getTagsList();

HttpPost httpPost = new HttpPost(url);
StringEntity stringEntity = new StringEntity(tagsList.toString(), ContentType.APPLICATION_JSON);
httpPost.setEntity(stringEntity);
HttpResponse httpResponse = closeableHttpClient.execute(httpPost);

sample url is : http://localhost:8090/alfresco/service/api/node/{nodeRef}/tags

If possible, can you please suggest other alternative for tagging a document in alfresco.

Thanks in Advance!   

It is strage. The API you are using is this one: 

https://github.com/Alfresco/alfresco-remote-api/blob/master/src/main/resources/alfresco/templates/we...

https://github.com/Alfresco/alfresco-remote-api/blob/master/src/main/resources/alfresco/templates/we...

It is working as expected when i pass string representation of tags. See the sample code below:

import java.io.IOException;
import java.nio.charset.StandardCharsets;

import org.apache.commons.io.IOUtils;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;


public class CreateTags {
	
	public static void main(String[] args) throws ClientProtocolException, IOException {
                final String tagURL = "http://127.0.0.1:8080/alfresco/service/api/node/workspace/SpacesStore/da36bb7e-5202-4dd4-a19b-3caf96d6fdb7/tags?alf_ticket=TICKET_ddd66235f30c68fcf1ec10ee2dbfd82ce18e0ef2";
try (final CloseableHttpResponse httpResp = httpPost(tagURL, "[\"ID001\",\"ID-Proof\",\"00112\",\"0ID001\",\"00ID-Proof\",\"0001120\"]")) { final StatusLine status = httpResp.getStatusLine(); final int statusCode = status.getStatusCode(); if (statusCode == 200) { final String resonseStr = IOUtils.toString(httpResp.getEntity().getContent(), StandardCharsets.UTF_8); System.out.println(resonseStr); } } } public static CloseableHttpResponse httpPost(final String url, final String jsonReqData) throws ClientProtocolException, IOException { final CloseableHttpClient httpclient = HttpClientBuilder.create().build(); final HttpPost httpPost = new HttpPost(url); final StringEntity httpEntity = new StringEntity(jsonReqData); httpEntity.setContentType("application/json"); httpPost.setEntity(httpEntity); return httpclient.execute(httpPost); } }

Response from API:

[
  "id001",
  "id-proof",
  "00112",
  "0id001",
  "00id-proof",
  "0001120"
]

image

V1 Api works fine as well: https://docs.alfresco.com/6.2/concepts/dev-api-by-language-alf-rest-add-remove-tags-on-node.html

POSThttp://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/2245c97b-1da4-41c9-8275-f1d87140585f/tags

[
    {
     "tag": "ID001"
    },
    {
     "tag": "ID-Proof"
    },
    {
     "tag": "00112"
    },
    {
     "tag": "00ID-Proof"
    }
]

Response:

{
    "list": {
        "pagination": {
            "count": 4,
            "hasMoreItems": false,
            "totalItems": 4,
            "skipCount": 0,
            "maxItems": 100
        },
        "entries": [
            {
                "entry": {
                    "tag": "ID001",
                    "id": "4682305c-71c2-4db8-bc04-0e6baffdbc75"
                }
            },
            {
                "entry": {
                    "tag": "ID-Proof",
                    "id": "fb2ff153-3420-4ff3-a206-425142958314"
                }
            },
            {
                "entry": {
                    "tag": "00112",
                    "id": "18e43c99-bdd6-4551-8448-8f6b1d1460f0"
                }
            },
            {
                "entry": {
                    "tag": "00ID-Proof",
                    "id": "d2c09f86-6c5a-46db-8946-959d47a21a32"
                }
            }
        ]
    }
}
~Abhinav
(ACSCE, AWS SAA, Azure Admin)

abhinavmishra14
World-Class Innovator
World-Class Innovator

The json array you are passing seems like integer array. Since the values are recognized as integer, the preceding 0s are getting stripped. Try passing the string representation of the json array with tag values and see if it works for you.

~Abhinav
(ACSCE, AWS SAA, Azure Admin)

Thanks for your quick responce Abhinav!