Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
58 lines (44 sloc) 2.47 KB
layout title date comments permalink tags
post
HOW-TO: propertyset-storage-toolkit - Jira configuration data storage made easy
2010-12-12
false
2010/12/how-to-propertyset-storage-toolkit-jira.html
atlassian
jira
pdk
java

Q: What is your favorite type of job? Atlassian Plugin SDK? A: Sure! Q: How exactly you like to code? A: As little as possibe!

Here it comes - propertyset-storage-toolkit with as bare minimal API set as it could be.

Let's see what the standard project for me as Jira plugin developer is? The answer probably would be - to make this thing A, that thing B and yeah, almost forgot - to make this configurable, there definitely should be a switch et cetera and this should be administration UI dialog.

And yeah, there are a lots of data persistence options available, but they all too complic-API-cated. So after scratching my head several times I remembered one piece of code I've written before while being employed   by some company and decided to re-implement the idea from the scratch on my own and to use in my current project assignment.

So, to illustrate how EASY is to do plugin configuration from now on, see the code snippet below


private final StorageService storageService; // IoC by framework via Constructor Dependency Injection
 ...

 // data fields
 private boolean adminOnly;
 private String helloText;
 private String welcomeText;

 private StorageFacade getStorage()
 {
     return storageService.actionStorage(this);
 }


 private void loadConfig(StorageFacade storage)
 {
     setAdminOnly(storage.getBoolean(ADMIN_ONLY));
     setHelloText(StringUtils.defaultString(storage.getString(HELLO_TEXT), 
         "Hello, "));
     setWelcomeText(StringUtils
         .defaultString(storage.getString(WELCOME_TEXT), "World"));
 }

 private void saveConfig(StorageFacade storage)
 {
     storage.setBoolean(ADMIN_ONLY, isAdminOnly());
     storage.setString(HELLO_TEXT, getHelloText());
     storage.setString(WELCOME_TEXT, getWelcomeText());
 }

And voila, it's as easy as this, no strings attached.

Please take a look into README file for more details.

And, please, do not shy to contact me in case of any problems, issues, thoughts or comments. Your feedback is always appreciated.

See ya ;)