Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Retrieving Plug-in settings using PluginSettingsFactory

Prameesha Samarakoon February 10, 2014

Hi,

I have created a servlet designed to store some configurations for my plug-in follwing this tutorial.I have used PluginSettingsFactory for this. But I need to retrieve the configuration values to and use it in a different class.

How can I retrieve the configurations I set from a java class?

Any views on this would be much appreciated.

Thanks

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Prameesha Samarakoon February 12, 2014

The trick was to make the the PluginSettingsFactory object static in the servlet. Then it was only a matter of accessing the plugin settings using get options by passing the key. PluginSettingsFactory object is accessed through a getter, and initialised in the servlets constructor. Ideally something like this.

Servlet 
		private static PluginSettingsFactory pluginSettingsFactory = null;
Java class
		PluginSettings pluginSettings = pluginSettingsFactory.createGlobalSettings();
		projects =  pluginSettings.get(PLUGIN_STORAGE_KEY + ".projects").toString();
		interval =  pluginSettings.get(PLUGIN_STORAGE_KEY + ".interval").toString();
Travis DePuy September 22, 2016

I'm trying to do the same thing, but I'm not sure how to set the variable pluginSettingsFactory in my other class. At this point I'm thinking I might just retrieve them via HTTP call!!

Travis DePuy September 22, 2016

Ahhhh, I figured it out. I found a lot of references to just including component-import in the atlassian-plugin.xml, however this would fail to build with it's own errors. So, I found this article that talks about using Spring Scanner. Soooo, in my "other" class. I added @Scanned just before the class declaration, then added @ComponentImport just before the PluginSettingsFactory. 

Like so:

@Scanned
public class MyClass {
@ComponentImport
private final PluginSettingsFactory pluginSettingsFactory;

public MyClass( PluginSettingsFactory factory ) {
this.pluginSettingsFactory = factory;
}

public String myMethod() {
PluginSettings settings = pluginSettingsFactory.createGlobalSettings();
String url      = (String) settings.get( MY_PLUGIN_NAME + ".url" );
}

 

 

Casey Stewart May 8, 2017

What is MY_PLUGIN_NAME is that actually the value from the plugin properties file for my.plugin-name?  I've tried everthing and just can seem to get this to work.

Thanks

 

Travis DePuy May 8, 2017

Actually I found a helper method:

String url = (String) settings.get( Config.class.getName() + ".url" );
Perron Jones March 5, 2019

How does another class create an instead MyClass without providing a PluginSettingsFactory since it is being imported, but it's in the method signature?

Such as,

public class OtherClass {
private MyClass myClazz;
public OtherClass() {
myClazz = new MyClass();
}
}

Wouldn't compile because the MyClass constructor accepts a PluginSettingsFactory object which I don't want to have to keep importing.

TAGS
AUG Leaders

Atlassian Community Events