Hello,
I’m trying to both set and get page properties.
In the developer documentation under “Persistence in Confluence” it does discuss using PageManager/ContentPropertyManager (which must of course be injected with P2 plugins via the constructor).
Seems straight forward. However, when I look up ContentPropertyManager in the java API reference, it says it is almost deprecated, use ContentProperties instead. The API reference for ContentProperties indicates ContentPropertyService must be injected and invoked with a JsonContentProperty object. This has been available since 5.6. I’d like to develop my solution on the most up-to-date API. Does anyone have any good examples on how to use this to set/get page properties?
I tried the following:
Per “Powerful new search and property storage APIs in Confluence 5.7” I added:
public class setProperty implements Macro {
@ComponentImport
private ContentPropertyService contentPropertyService;
@ComponentImport
private ContentService contentService;
@Autowired
public setProperty(ContentPropertyService contentPropertyService, ContentService contentService) {
this.contentPropertyService = contentPropertyService;
this.contentService = contentService;
}
public String execute(Map<String, String> parameters, String body, ConversionContext conversionContext) throws MacroExecutionException {
Content content = contentService.find().withId(ContentId.valueOf("background")).fetchOneOrNull();
if (content != null ) {
JsonContentProperty property = JsonContentProperty.builder()
.content(content)
.key("background")
.value(new JsonString("{\"background\":\"This is my test background property\"}")).build();
contentPropertyService.create(property);
}
I’m trying to create a new page property called “background”. This is just throwing the following exception:
[INFO] [talledLocalContainer] com.atlassian.confluence.api.service.exceptions.BadRequestException: Can’t parse as a ContentId: background
Any help on how to use this API would be much appreciated!
Thanks!