I want to create a comment with custom properties via the Confluence Java API (in a Rest endpoint I am exposing by a Confluence plugin).
My code is as following:
Content commentedPage = contentService.find(new Expansion("id"))
.withId(ContentId.of(comment.getCoordinates().getPageObjects().get(comment.getCoordinates().getPageObjects().size()-1).getPageId()))
.fetch().get();
comment.getProperties().put("highlight", comment.getHighlight());
comment.getProperties().put("coordinates", comment.getCoordinates());
String amdocsProps = "{\"key\": \"amdocsProps\", \"value\":" + new Gson().toJson(comment.getProperties()) + "}";
logger.error("amdocsProps is: " + amdocsProps);
Content.ContentBuilder contentBuilder = Content.builder()
.type(ContentType.COMMENT)
.container(commentedPage)
.body(comment.getContent(), ContentRepresentation.STORAGE)
.metadata(new HashMap<String,Object>(){{put("properties",new HashMap<String,String>(){{put("amdocsProps", amdocsProps);}});}});
I printed to the log the value of amdocsProps and it is as following:
{“key”: “amdocsProps”, “value”:{“visibility”:“medium”,“priority”:“medium”,“reply”:,“highlight”:{“text”:“performed during customer billing and f”,“occurrences”:1,“occurrence”:1},“coordinates”:{“pageObjects”:[{“pageId”:28216445,“pageVersion”:1}],“section”:“overviewsec”}}}
When I take this json string and use it as the body of Confluence API - /rest/api/content/{commentId}/property - The custom properties are added as required.
But, when doing it via server side - the properties do not get added.
I’ve tried also to create the comment without the properties, and only after the creation, to fetch it and add to it the properties. I did it like this:
Content newComment = contentService.create(contentBuilder.build());
@Nullable ContentEntityObject createdComment = contentEntityManager.getById(newComment.getId().asLong());
ContentProperties commentProperties = createdComment.getProperties();
propertyManager.setStringProperty(createdComment, "amdocsProps", new Gson().toJson(comment.getProperties()));
But again - the properties do not get added.
What am I doing wrong?
Any advice?
Thanks
Tova