I looked for a way to store project-specific configurations for my plugin. In the first step i only want to store a simple String like "Hello".
So, what i found is SAL and the PluginSettings. https://developer.atlassian.com/docs/atlassian-platform-common-components/shared-access-layer/sal-services
This seems pretty easy to use but I don´t have any idea how to implement it into my code. I used a WebWork taking place in the project administration section:
@Override
public String doDefault() throws Exception {
Project project = getProjectManager().getProjectObjByKey(_projectKey);
HttpServletRequest request = ExecutingHttpRequest.get();
request.setAttribute((new StringBuilder()).append("com.atlassian.jira.projectconfig.util.ServletRequestProjectConfigRequestCache").append(":project").toString(), project);
return INPUT;
}
@Override
protected String doExecute() throws Exception {
Project project = getProjectManager().getProjectObjByKey(_projectKey);
HttpServletRequest request = ExecutingHttpRequest.get();
request.setAttribute((new StringBuilder()).append("com.atlassian.jira.projectconfig.util.ServletRequestProjectConfigRequestCache").append(":project").toString(), project);
String param = request.getParameter("param");
return SUCCESS;
}
public void setProjectKey(String projectKey) {
_projectKey = projectKey;
}
public String getProjectKey() {
return _projectKey;
}
public String getBaseUrl() {
return ComponentAccessor.getApplicationProperties().getString(APKeys.JIRA_BASEURL);
}
As SAL said i implemented a Settings-Class:
public CustomProjectSettings(
final PluginSettingsFactory pluginSettingsFactory,
final String projectKey) {
this.pluginSettingsFactory = pluginSettingsFactory;
this.projectKey = projectKey;
}
public void setValue(final String key, final String value) {
final PluginSettings settings = pluginSettingsFactory
.createSettingsForKey(projectKey);
settings.put(key, value);
}
public Object getValue(final String key) {
final PluginSettings settings = pluginSettingsFactory
.createSettingsForKey(projectKey);
return settings.get(key);
}
And I added the component in the xml:
<component-import key="pluginSettingsFactory" interface="com.atlassian.sal.api.pluginsettings.PluginSettingsFactory" />
So how do i connect and implement this into my webwork to say
protected String doExecute() throws Exception{
[...]
pluginSettings.setValue("Key", param);
[...]
}
It was easier than i thought. I simply had to inject the Settings as a dependency for my WebWork:
public WebWorkAction(CustomProjectSettings settings){
this.settings = settings
}
The Settings-Class gets autowired by
<component-import key="pluginSettingsFactory"
interface="com.atlassian.sal.api.pluginsettings.PluginSettingsFactory" />
and by adding
<component key="settingsComponent"
class="com.xxx.CustomProjectSettings">
</component>