09-17-2018 01:23 PM
I used google rest api client. I wonder why this error. It appears that aspects are not allowed for comment nodes.
Http Request
PUT
alfresco/api/-default-/public/alfresco/versions/1/nodes/19a82881-3d00-4b8a-8276-dc3d8237cda8/comments/c6c9e3af-6e0b-46ad-8e11-648e1a27e7e6
JSON Body
{
"aspectNames": [
"sloperationInfo"
],
"content":"Test threez",
"lo_operation_user":"Goose"
}
Response
{
"error": {
"errorKey": "Could not read content from HTTP request body: Unrecognized field \"aspectNames\" (Class org.alfresco.rest.api.model.Comment), not marked as ignorable\n at [Source: java.io.BufferedReader@37b1c0b7; line: 2, column: 19] (through reference chain: org.alfresco.rest.api.model.Comment[\"aspectNames\"])",
"statusCode": 400,
"briefSummary": "08170028 Could not read content from HTTP request body: Unrecognized field \"aspectNames\" (Class org.alfresco.rest.api.model.Comment), not marked as ignorable\n at [Source: java.io.BufferedReader@37b1c0b7; line: 2, column: 19] (through reference chain: org.alfresco.rest.api.model.Comment[\"aspectNames\"])",
"stackTrace": "For security reasons the stack trace is no longer displayed, but the property is kept for previous versions",
"descriptionURL": ""
}
}
When I read the node details of the comment object
I get the following
GET
alfresco/api/-default-/public/alfresco/versions/1/nodes/c6c9e3af-6e0b-46ad-8e11-648e1a27e7e6
Response
{
"entry": {
"aspectNames": ["cm:titled",
"cm:auditable"],
"createdAt": "2018-09-17T18:01:05.056+0000",
"isFolder": false,
"isFile": true,
"createdByUser": {
"id": "admin",
"displayName": "Administrator"
},
"modifiedAt": "2018-09-17T19:48:48.777+0000",
"modifiedByUser": {
"id": "admin",
"displayName": "Administrator"
},
"name": "c6c9e3af-6e0b-46ad-8e11-648e1a27e7e6",
"id": "c6c9e3af-6e0b-46ad-8e11-648e1a27e7e6",
"nodeType": "fmost",
"content": {
"mimeType": "text/html",
"mimeTypeName": "HTML",
"sizeInBytes": 11,
"encoding": "UTF-8"
},
"parentId": "d1c6b26d-0956-46cb-a6a2-c254b60a2c77"
}
}
09-17-2018 08:34 PM
Have you tried doing a PUT against a URL that refers to the comment node directly (without the /comments/) part? The GET you used to fetch the info for your comment looks much more like what I'd expect a PUT to work against. In a well-designed RESTful API you can often just change the HTTP method and the API behaves as you expect. The Alfresco 5.2 API is no different.
You can do a GET using the comment's node reference to fetch info about the comment node:
And then you can do a PUT against the same URL to update it with a new aspect. In my case I added "cmwnable" to a comment node and it worked fine.
{
"aspectNames": [
"cm:titled",
"cm:auditable",
"cm:ownable"
]
}
09-17-2018 08:34 PM
Have you tried doing a PUT against a URL that refers to the comment node directly (without the /comments/) part? The GET you used to fetch the info for your comment looks much more like what I'd expect a PUT to work against. In a well-designed RESTful API you can often just change the HTTP method and the API behaves as you expect. The Alfresco 5.2 API is no different.
You can do a GET using the comment's node reference to fetch info about the comment node:
And then you can do a PUT against the same URL to update it with a new aspect. In my case I added "cmwnable" to a comment node and it worked fine.
{
"aspectNames": [
"cm:titled",
"cm:auditable",
"cm:ownable"
]
}
09-27-2018 11:47 AM
This method works. The value c6c9e3af-6e0b-46ad-8e11-648e1a27e7e6 is the comment node id. The comment must have been created already using a prior Rest API call.
HTTP PUT (for attaching aspect with its value to a comment node)
<AlfrescoServerPort>/alfresco/api/-default-/public/alfresco/versions/1/nodes/c6c9e3af-6e0b-46ad-8e11-648e1a27e7e6
HTTP Body
{
"aspectNames":[
"sloperationInfo"
],
"properties": {
"sloperation_user":"Goose",
"sloperation_info":"A comment is added"
}
}
In my code, I do like shown below. The variable restApiUrl contains the PUT url as given above, and the variable jsonString contains the above HttpBody Json content.
CloseableHttpResponse response = null;
URL restApiUrl = null;
CredentialsProvider provider = new BasicCredentialsProvider();
UsernamePasswordCredentials creds = new UsernamePasswordCredentials(this.configUser, this.configUserPassword);
provider.setCredentials(AuthScope.ANY, creds);
CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
HttpPut putFunction = new HttpPut(restApiUrl.toString());
try {
StringEntity entity = new StringEntity(jsonString);
putFunction.setEntity(entity);
putFunction.setHeader("Accept", "application/json");
putFunction.setHeader("Content-type", "application/json");
response = httpClient.execute(putFunction);
}
catch (Exception e) {}
finally {
if (response != null) { try { response.close(); } catch (Exception ignore) {} }
}
I see that this is a two call approach. First there is a Rest API call to create the comment (node). Then we have this Rest API call to attach/create the custom aspect.
For now, since this is purely user (navigation) action driven, there is only a remote possibility that it would pose scaling problem.
In future version of our application, I would certainly consider a Web Script approach, where I can achieve all this in a single call.
Explore our Alfresco products with the links below. Use labels to filter content by product module.