Accessing the JIRA configuration properties

We have seen how to use PropertySet to store details of plugins in the previous recipes. In this recipe, we will see how we can access the JIRA configuration properties using PropertySet.

How to do it...

There are lots of global configuration settings in JIRA that are configured using administration menus. More on the various options can be read at http://confluence.atlassian.com/display/JIRA/Configuring+Global+Settings. Where does JIRA store this information and how do we access it?

All these configuration properties, such as settings under General Configuration, Base URL, Attachments Path, License Info, and more, are stored in the PropertySet tables we saw earlier. They are stored against a virtual entity, jira.properties. This is the same virtual entity that is used when PropertySet is retrieved using PropertiesManager, as we saw while persisting plugin information.

Here, all the property key entries are stored in the propertyentry table, with jira. properties as the entity name and entity id as 1. The propertytype value for each property varies, depending on what is stored against it. For example, jira.option. allowattachments is a flag and hence is stored in the propertynumber table, with a value of either 0 or 1. In this case, propertytype is 1, denoting the number value. jira. path.index, on the other hand, stores a String that holds the index path and will have 5 as propertytype. Here the value is stored in the propertystring table.

All the properties can be accessed using the following SQL command:

SELECT * FROM propertyentry WHERE ENTITY_NAME='jira.properties'; 

If you want to see only String properties and their values, you can get it using the following command:

SELECT PROPERTY_KEY, propertyvalue
      FROM propertyentry pe, propertystring ps
      WHERE pe.id=ps.id AND pe.ENTITY_NAME='jira.properties' AND propertytype='5'; 

If you want to search for a specific property, you can do that using the following command:

SELECT PROPERTY_KEY, propertyvalue 
     FROM propertyentry pe, propertynumber pn
     WHERE pe.id=pn.id AND pe.ENTITY_NAME='jira.properties' AND pe.PROPERTY_KEY='jira.option.allowattachments';

Tip

Note that the appropriate property table should be used, propertynumber in this case!

The same things can be achieved in a plugin, as follows:

  1. Retrieve the PropertySet object using PropertiesManager:
          PropetySet propertySet = 
          ComponentAccessor.getComponent
          (PropertiesManager.class).getPropertySet();
  2. All property keys can be retrieved as follows:
          Collection<String> keys = propertySet.getKeys();
  3. Similarly, all the properties of a specific type can be accessed as:
          Collection<String> stringKeys = propertySet.getKeys(5);
  4. The value of a particular key can be accessed as follows:
          String attachmentHome = 
          propertySet.getString("jira.path.attachments");
          boolean attachmentsAllowed = 
          propertySet.getBoolean("jira.option. allowattachments");
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.212.170