How can I modify Scaffold data from another plugin?
Sometimes you need to either create a new page with Scaffold data pre-entered, or manually update some data from your own plugin. How can it be done?
3
people have this question
I have this question, too!
Tell me when someone answers.
The more people who ask this question, the more it gets noticed.
The more people who ask this question, the more it gets noticed.
The best answer from the company
-
Here's the basic procedure.
1. Create the page with the scaffolding macro markup on it and save it.
2. Import the 'org.randombits.confluence.metadata' package. JavaDocs for it are here. To access it, add this dependency to your project:
<dependency>
<groupid>org.randombits.confluence</groupid>
<artifactid>confluence-metadata</artifactid>
<!-- Check for the latest version number in the repository -->
<version>4.1.1</version>
</dependency>
3. Call the 'MetadataManager.getInstance().loadData( yourNewPage )' method to retrieve a MetadataStorage object to put values into.
4. Add your default values.
5. Save the data via the 'MetadataManager.getInstance().saveData( myData, true )' method.
6. Once you've saved the metadata, you will need to reindex the page so that the new metadata is added to the search index.
The code for the above looks like this:
Page newPage = new Page();
// 1. Set various page values, including your scaffold markup...
// 2. Save the new page.
// 3. Get the MetadataStorage value for the new page.
MetadataStorage data = MetadataManager.getInstance().loadData( newPage );
// 4. Set default values for the page.
data.setString( "My Text Field", "My default text value" );
data.setObject( "My List Data Field", new ContentReference( someOtherPage ) );
// etc...
// 5. Save the metadata against the current page
MetadataManager.getInstance().saveData( data, true );
// 6. Reindex the page (via the com.atlassian.confluence.search.ConfluenceIndexer
// instance retrieved via autowiring)
indexer.reIndex( newPage );
That should do the trick.
The company says
this answers the question
-
This reply was removed on 06/03/09.
see the change log -
Inappropriate?Hi David,
I tried out the solution you described and I ran into one problem:
After I modified the Scaffold data of an already existing Confluence page it happens that I only see the new data after editing the page.
When I open the changed page in edit mode and do a save on it the changed values appear.
Do you have any idea why this is happening?
Regards
Boris
-
Inappropriate?There was a typo in the actual code example, although I did mention it earlier. It is very important to have "saveData( myData, true )", rather than "saveData( myData )", or the data will only appear on the next version of the page. I think that should solve your problem.
-
Inappropriate?I also tried "saveData( myData, true )", but this is also not working. What I figured out is, that if I manualy flush the cache "cache.name.org.randombits.confluence.metadata.MetadataManager" in the administration console, the changed value appears on the page. Is there a way to do this via api?
Regards
Boris -
Inappropriate?Hmm. Sounds like a bug. Could you please create a bug report here and I'll schedule it for the next version.
In the meantime, you could try adding 'metadataManager.clearCache()'. This will clear all cached values for all pages. Theoretically... -
Inappropriate?I think I figured out the problem. I used the wrong version in the pom.xml. Using the following dependency in the pom it works:
<dependency>
<groupid>org.randombits.confluence</groupid>
<artifactid>confluence-metadata</artifactid>
<version>4.1.1</version>
</dependency> -
Thanks for the update Boris. I've reposted the example with the corrections. -
Inappropriate?Here's the basic procedure.
1. Create the page with the scaffolding macro markup on it and save it.
2. Import the 'org.randombits.confluence.metadata' package. JavaDocs for it are here. To access it, add this dependency to your project:
<dependency>
<groupid>org.randombits.confluence</groupid>
<artifactid>confluence-metadata</artifactid>
<!-- Check for the latest version number in the repository -->
<version>4.1.1</version>
</dependency>
3. Call the 'MetadataManager.getInstance().loadData( yourNewPage )' method to retrieve a MetadataStorage object to put values into.
4. Add your default values.
5. Save the data via the 'MetadataManager.getInstance().saveData( myData, true )' method.
6. Once you've saved the metadata, you will need to reindex the page so that the new metadata is added to the search index.
The code for the above looks like this:
Page newPage = new Page();
// 1. Set various page values, including your scaffold markup...
// 2. Save the new page.
// 3. Get the MetadataStorage value for the new page.
MetadataStorage data = MetadataManager.getInstance().loadData( newPage );
// 4. Set default values for the page.
data.setString( "My Text Field", "My default text value" );
data.setObject( "My List Data Field", new ContentReference( someOtherPage ) );
// etc...
// 5. Save the metadata against the current page
MetadataManager.getInstance().saveData( data, true );
// 6. Reindex the page (via the com.atlassian.confluence.search.ConfluenceIndexer
// instance retrieved via autowiring)
indexer.reIndex( newPage );
That should do the trick.
The company says
this answers the question
Loading Profile...


EMPLOYEE
