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
Community moderators have prevented the ability to post new answers.
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();
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!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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" );
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Actually I found a helper method:
String url = (String) settings.get( Config.class.getName() + ".url" );
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.