I checked out the documentation, about developing a macro that fetched some content from Wikipedia and inserts into the Confluence page:
So, my question is whenever the Confluence app is restarted, does the Wikipedia macro stays on the page with all the data, or to reformulate the question: Where the macro data is stored in order to be saved whenever some restart is done?
Hello @Ivana1 ,
The macro is stored the same way as the whole page BODY in the DataBase of your Confluence. So restart will not affect it.
In the case of https://developer.atlassian.com/server/confluence/creating-a-wikipedia-macro/ - the macro is stored in the Data Base as a code of page storage format and the very data is retrieve from Wikipedia in real-time.
Thank you @quadr988
So I guess the macro content is saved in the body content of the page and therefore automatically it is saved in the Confluence database, and whether restart or plugin clean cashed is done, there will be no loses of data from the macro plugin.
I am in doubt because I wan to develop a macro plugin for Confluence server, and I am not sure, should I connect the plugin with the Confluence database and create my tables there in order to save the macro plugin data, or this is saved automatically without connecting it to db, and therefore me as a plugin developer can be sure that the plugin data will be never lost?
Sorry for the confusion, just to clarify:
The data you get from REST API will not be saved to the page body it will just be displayed in the UI. To save the data in DB statically - you need to call corresponding API methods to change the BODY accordingly (creating new version or directly).
I meant that if you add some HTML in the macro .VM file, so if the macro is added to page, this data will be stored accordingly, but just as the body of this macro
So you need to change page BODY and save changes using corresponding Managers/Services (e.g. PageManager PageManager (Atlassian Confluence 8.4.0 API)) and it will be saved. No need to create any other DB tabls as Confluence Java API has these managers to do it for you.
Hope it helps
Thank you @quadr988
This really helped.
When using pageManagers the macro data is saved as a body Content on the page.
what I used in my code is this:
and my problem is that after executing the code above, the initial page body content is deleted and all the page content is literally the macro body content, which is expected because of the method :
How can I resolve this, in order to have the macro content body append it on the initial page content.
Hello @Ivana1 !
You can first save the body as a variable and then append the new data to it as
Page page = pageManager.getPage(pageId);
String pageBody = page.getBodyAsString();
String newBody = pageBody.append(res); // or StringBuilder or concatenate ...
pageManager.saveCOntentEntity(page, prevVersion, null);