Database Values JIRA Plugin

Name Database Values JIRA Plugin
Version 0.2.5
Product Versions 3.12.x
JDK Version 1.4.x - 1.6.x
Author(s) Wim Deblauwe
Homepage http://confluence.atlassian.com/display/JIRAEXT/Database+Values+JIRA+Plugin
Price FREE
License BSD
IssueTracking http://developer.atlassian.com/jira/browse/JDVP
Source http://svn.atlassian.com/fisheye/browse/public/contrib/jira/database-values-plugin/trunk
Download JAR database-values-plugin-0.2.5.jar
Download Source database-values-plugin-0.2.5-sources.jar

Description/Features

This plugin for JIRA is a custom field that allows you to connect to an external database and fetch some values from there. After adding this custom field to an issue edit screen, you can select one of those values so it will be associated with the current issue.
You can choose how the values are rendered for viewing, editing and searching independently. For the editing, you can use a combobox or an AJAX-style input field.
Internally, the plugin will store only the primary key of the item you have selected, so you can safely edit things in your database, as long as you keep the primary key constant.

Usage

The custom field must be configured using a properties file. E.g.:

jira-database-values-plugin-10000.properties
# The database connection parameters
database.driver=org.hsqldb.jdbcDriver
database.user=sa
database.password=
database.connection.url=jdbc:hsqldb:mem:plugintestdb

# Cache Timeout (= 15 minutes by default). The actual db is queried only once and then the results are kept in the cache for the given timeout. Uncomment the line below to change it.
#cache.timeout=900000 

# The SQL Query that will be executed on the database
sql.query=select id, firstname, lastname, city, country from customer
# The column number (starting from 0) that contains the primary key of the returned data.
primarykey.column.number=0
# The pattern that should be used to render the data in view mode. Use {column_number} as placeholders.
rendering.viewpattern={1} {2} from <a href="http://maps.google.com/maps?f=q&hl=nl&geocode=&q={3}, {4}">{3}, {4}</a>
# The pattern that should be used to render the data in edit mode. Use {column_number} as placeholders.
rendering.editpattern={2}, {1}
# The pattern that should be used to render the data in searcher. Use {column_number} as placeholders.
rendering.searchpattern={1} {2} ({0})
# This is used when sorting in the issue navigator. When not defined, the 'rendering.viewpattern' is used.
rendering.sortpattern={1} {2}
# Use 0 to have a combobox for editing, 1 to have AJAX-style input field, 2 for cascading select
edit.type=0

The name of the properties file must be jira-database-values-plugin-10000.properties where 10000 should be replaced with the id of the custom field. This allows you to define multiple custom fields with different queries or even pointing to completely different databases.

As you can see, you can even include some html into the viewing. In the above example, clicking the link will open a window of google maps with the address.

Database parameters

The first 4 parameters (database.driver, database.user, database.password, database.connection.url) are needed to be able to connect to the database. They define what database should be used, where it is and what user should be used to read from it.

The sql.query parameter contains the SQL statement that will be used to query the database. Note that I do not do any checking on the query to see if you are not doing anything wrong with it. You are advised to only use SELECT statements

Rendering parameters

The sql.query will return a number of database rows with a number of columns. The order of the column is important for the rendering parameters (rendering.viewpattern, rendering.editpattern, rendering.searchpattern and rendering.sortpattern) and the primarykey.column.number parameter.
This last one defines what value the plugin will store in the JIRA database to know what value was selected by the user. You are strongly adviced to use the column that contains your primary key there.

In the rendering patterns, you must use MessageFormat-alike formatting to define where the values should come. If we look at the following example:

rendering.editpattern={2}, {1}

Here we define that the pattern for editing should contain the 3rd column, then a comma and a space and then the 2nd column (Note that we work zero-based!)

Sorting

You can control how the custom field is sorted in the issue navigator via rendering.sortpattern.

The pattern is optional. When not defined, the rendering.viewpattern is used. This pattern can be useful if the rendering.viewpattern uses some HTML elements and you don't want those to interfere with proper sorting. The sorting pattern is only used internaly to ensure proper sorting. The actual value you see in the issue navigator is defined by the rendering.viewpattern. The sorting is not case sensitive.

By using this separate property, we can display the names as:

Wim Deblauwe from Heule, Belgium

but sort on last name for example by setting the rendering.sortpattern={2}.


Screenshot of sorting in the issue navigator

If you want to sort in the drop-down menu that is used when selecting a value, then you need to use ORDER BY in you SQL query.
Depending on the project

You can make the results of the custom field depend on the actual project that is being used if you use the following SQL query syntax:

sql.query=select id, firstname, lastname, city, country from customer where jira_key like '${jira.project.key}'

The above example assumes that you have a 'jira_key' column in your table containing the JIRA project key.

You need to use like in your where clause otherwise, things will not work properly.

You also need to specify the primarykey.column.name property with the exact name of your primary key column. This is needed because the cache is bypassed for the issue navigator when depending on the project.

To avoid the cache growing too big, you need to configure cache.maximum.projects when using this functionality. This parameter defines how many different projects are being kept in the cache at the same time. By default this is 1. If you have only a small number of rows but many projects, you can increase this without problem to the number of projects you have. If you have a large number of rows per project, you need to keep this low.

Also know that depending on the project has an impact on performance in the issue navigator. Since issues from multiple projects can be shown in the issue navigator, I bypass the cache there (since otherwise, I still need to put everything in the cache).

Configuring AJAX-style input field

By default, a combobox is used to allow the user to input a value. However, you can configure the plugin to use an AJAX-style input field. For that, you need to set edit.type in the properties file to 1.
It is also possible to add additional information with the AJAX-style input field that will be displayed when the user is making his choice, but will not appear in the input box once he has made his selection.
In editing-ajax-example.png, the rendering.editpattern is defined as follows:

rendering.editpattern={2}, {1}<span class="informal" style="color: grey;"><br/>{3}, {4}</span>

You will notice that the additional information about each choice (a customer name in the example) needs to be included in a span html element with the class attribute set to 'informal'. If you want to style using inline CSS, then do it after the class attribute. It is important the if you use the 'informal' part, you start with <span class="informal", otherwise, you will not get the results you would expect.


Screenshot of AJAX-style edit

Configurating cascading select comboboxes

You can use a cascading select (like the build-in custom field) also with this plugin. If you have a lot of entries, it might be easier for the user to first select some kind of category and then make this final selection. For this you need the following configuration:

edit.type=2
rendering.editpattern.group.column.number=4

An edit.type of 2 means you want a cascading select. The rendering.editpattern.group.column.number identifies the column you want to group by. In our customer example, we group by the country. So a user can first select the country and then the 2nd combobox will only contain the customers from that country.


Screenshot of cascading select edit

Examples

Suppose you already have a database with customer information. Your JIRA is not open to customers, but you would like to track which customer has put in which request. With this custom field, you point to that database, put in an SQL script that extracts the customers and you can start choosing the correct customer in your issues.

See also Screenshots

Installation

  1. Copy the database-values-plugin-xxx.jar to WEB-INF/lib
  2. Create a properties file jira-database-values-plugin-customfieldid.properties
  3. Copy the properties file to WEB-INF/classes
  4. If you use a different database then the one JIRA uses, then make sure you also add the database driver jar to JIRA.
  5. Add a new custom field of type 'Database Values Selection Field' (You might want to do this before creating the properties file so you can know the custom field id)

FAQ

Where can I find the custom field id?
  1. Go to the administration section of JIRA
  2. Locate the "Issue Fields" section and select "Custom Fields"
  3. Click on the "Configure" link for the custom field
  4. Look at the url, it will end in customFieldId=10000, this is the custom field id

Version History

0.1 - Initial Version
0.1.1 - Bugfixing + i18n support
0.2 - Added cascading select edit type
0.2.1 - Add proper sorting in issue navigator.
0.2.2 - Add support for ${jira.project.key}. Support for making custom field required.
0.2.3 - fixes for cascading select
0.2.4 - fixed for caching when using project key dependency
0.2.5 - NPE fixed

Screenshots

Labels

codegeist_2008_jira codegeist_2008_jira Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Mar 25

    Paul Csapo says:

    This sounds very useful. Could it also be used internally? So that we could make...

    This sounds very useful.
    Could it also be used internally? So that we could make a selection and populate a normal custom field within jira, based on a selection of field values from a particular custom field used in other issues?

    regards,
    Paul

    1. Mar 25

      Wim Deblauwe says:

      Hi Paul, If I understand you correctly, you already have a custom field now and...

      Hi Paul,

      If I understand you correctly, you already have a custom field now and you want to add another custom field based on this plugin and fill out that new custom field with values from the database, based on the value of the first custom field?

      This is not possible. You could write a (Jelly) script or use the SOAP interface to iterate over all your issues and update the new custom field.

      regards,

      Wim

  2. Mar 26

    Paul Csapo says:

    Thanks for replying back Wim, Just to check something, using your 2nd screenshot...

    Thanks for replying back Wim,
    Just to check something, using your 2nd screenshot called "Editing the database value"...

    If the "db test 2" is a custom drop down field, where are the values "None, Wim Deblauwe and John Atlassian" coming from? If they are coming from a database, could we not configure the plugin to point to the jira database itself?

    In this way, the values would end up coming from an existing list, which would be as though we are pulling the data internally from jira. (unless i have misunderstood something)

    regards,
    Paul

    1. Mar 26

      Wim Deblauwe says:

      Hi Paul, you can point to any database you like, so yes, the jira database is a...

      Hi Paul,

      you can point to any database you like, so yes, the jira database is also an option. Just configure the properties file to point to the jira db and put in the correct SQL statement.

      regards,

      Wim

  3. Mar 27

    Mike Holdsworth says:

    Hi Wim, Cheers for this, I was about to set to and write something like this mys...

    Hi Wim,

    Cheers for this, I was about to set to and write something like this myself!  How often does code arrive JIT?

    We're evaluating the effort of replacing our ageing issue management system with Jira and it's looking very good.  I do have A question, similar to Paul's I think.  We have a corporate Project recording and Time management system that we need to integrate with.  The idea is to have Jira present a list of Projects and Tasks from this corporate system so that as the Jira issue is raised, the developer will know exactly how to record their time in the Corporate Time management system.

     My question is thus:

    Assuming a Project has many Tasks and we have 2 of these controls defined as custom fields using this plugin, can I use the use the selected Project as an argument to the available tasks?  As I type this I realise the complexity of such a request ( having to dynamcially re-retrieve the Task list whenever the user changes the Project) and assume the answer to be no.

    As an alternative approach, I would look to pass a search value from a text box as an argument to a query which would search for all Projects containing that Task and present a list such as

       Project A
             A TASKB
             A TASKB
       Project B
             B TaskA
             B TaskB

     The indenting would be important, so I assume some kind of HTML tab can be past during rendering?

    The fugly approach would be to present all 300 projects +  4000 tasks as one big list

     Any suggestions on the applicability of this or some other plugin?

    cheers

    1. Mar 28

      Wim Deblauwe says:

      Hi Mike, I'm currently working on replacing the simple dropdown combobox with A...

      Hi Mike,

      I'm currently working on replacing the simple drop-down combobox with AJAX-style suggestion field. This would make it a lot easier to find something if you have that many choices. I will have a first version after the weekend normally. Watch this page for updates. After that, we can discuss further if something more can be implemented to better fit your needs.

      regards,

      Wim

      1. Apr 01

        Mike Holdsworth says:

        Cheers Wim, this is just what I need that plus a vote for Peters enhancement bel...

        Cheers Wim, this is just what I need - that plus a vote for Peters enhancement below

      2. Apr 13

        Mike Holdsworth says:

        Good luck with the codegiest Wim, if there were a way to vote, I'd give you mine...

        Good luck with the codegiest Wim, if there were a way to vote, I'd give you mine.  This is a very useful plugin for integrating data from legacy systems.  My users are delighted.

  4. Apr 01

    Peter Brandström says:

    Hi Wim\! I think you have a winner :D Is it possible to make the query condition...

    Hi Wim!

    I think you have a winner

    Is it possible to make the query conditional (add a WHERE clause), where the condition is for instance the project id? Or the value of another custom field in the same form?

    Things which are missing in Jira:

    • "Customers" e.g. you want to select a person from an address book, who is the contact person reporting the problem (e.g. he reports over the phone).
    • "Assets" e.g. you have a bunch of systems out there and they have various hardware configurations, and now there's a hardware fault and you want to pinpoint the exact box where the fault occurs. You want to limit the selection to the boxes known to be on this site, e.g. by having a relation between the project id and the site with the hardware.

    There are variations such as you first pick the customer, then you select which of the two customer sites exhibit the problem and then you select the box at the site.

    Cheers,
    Peter

    1. Apr 01

      Wim Deblauwe says:

      Hi Peter, thank you for your kind comments! Interesting ideas! I will think so...

      Hi Peter,

      thank you for your kind comments!

      Interesting ideas! I will think some more about it and let you know if I can do something.

      regards,

      Wim

  5. Apr 03

    Peter Brandström says:

    Looking better and better! 1) The cascading select, is it limited to only two l...

    Looking better and better!

    1) The cascading select, is it limited to only two levels?

    2) Any chance of supplying the project id or project key as a substitution to the SQL query?

    sql.query=select id, firstname, lastname, city, country from customer where jira_key =

    Unknown macro: {1}

    1. Apr 03

      Wim Deblauwe says:

      Hi Peter, 1) Yes. If you really need it, file an enhancement request in JIRA. I...

      Hi Peter,

      1) Yes. If you really need it, file an enhancement request in JIRA. I'm using the code from JIRA's cascading select which is limited to 2 levels.

      2) Can do. I would propose this syntax:

      sql.query=select id, firstname, lastname, city, country from customer where jira_key = ${jira.project.key}
      

      Where ${jira.project.key} would be replaced by the actual project key of course. Watch http://developer.atlassian.com/jira/browse/JDVP-2 to follow this up.

      What do you mean by the project id?

      regards,

      Wim

      1. Apr 07

        Peter Brandström says:

        Sounds terrific to me\!&nbsp; (y) The project key is better than the internal I...

        Sounds terrific to me! 

        The project key is better than the internal ID because it makes more sense to humans. I was thinking of the internal id since it makes more sense from an SQL point of view (Jira indexes are based on the id, not the key).

         Cheers,

        Peter 

  6. Apr 03

    Alex Schwartz says:

    Hi Wim, cool plugin. Is the source code availabe? Regards, Alex

    Hi Wim,

    cool plugin. Is the source code availabe?

    Regards,
    Alex

    1. Apr 04

      Wim Deblauwe says:

      Hi Alex, it will be available as soon as the Codegeist ends. Do you need someth...

      Hi Alex,

      it will be available as soon as the Codegeist ends. Do you need something extra from the plugin?

      regards,

      Wim

  7. Apr 09

    Peter Brandström says:

    This is getting very very good\! Here is another idea: (on) A configurable URL w...

    This is getting very very good!

    Here is another idea:

    A configurable URL which gets displayed in edit mode, which points to some external web application which allows you to add a new record to the database. I.e. if you can't find the customer you are looking for, you click the URL to add a new customer and then go back and select this customer. Probably need a refresh too?

    If you go for it, include ${jira.project.key} substitution for the URL

    Cheers,
    Peter

    1. Apr 09

      Wim Deblauwe says:

      Thanks. Good idea, add it to JIRA please so it will not be forgotten. How would ...

      Thanks. Good idea, add it to JIRA please so it will not be forgotten. How would you like to specify this in the properties file? Maybe an additional property?

      1. Apr 09

        Peter Brandström says:

        An additional property I guess. Since you ask then obviously I would want a grap...

        An additional property I guess.

        Since you ask then obviously I would want a graphical user interface which shows up when you create the custom field

        1. Apr 09

          Wim Deblauwe says:

          I would like that too :) But there is no documentation on how to do that. If I ...

          I would like that too

          But there is no documentation on how to do that. If I have time left I will try do it, but I want to focus first on making it work with the properties file. Setting the properties through the webinterface is currently secondary, sorry about that.

          1. Apr 10

            Peter Brandström says:

            OK I see. I believe this plugin uses a lot of custom fields, perhaps the source ...

            OK I see. I believe this plugin uses a lot of custom fields, perhaps the source code is useful: 

            http://confluence.atlassian.com/display/JIRAEXT/JIRA+Charting+Plugin

            I think you have achieved a lot of things in a short time, I'm very impressed! Good luck in the competition!

  8. Apr 16

    Dushan Hanuska says:

    Hi Wim! I am one of the JIRA developers and I had a look at your plugin. I must...

    Hi Wim!

    I am one of the JIRA developers and I had a look at your plugin. I must say that I like the idea and also the way you implemented it.

    The plugin itself was a breeze to install and setup. I got it fully working in 10 minutes (including creating a simple DB table and entering some sample data). Then I spent some time playing with different setup options and all worked as expected. What a nice piece of work!

    At some stage I updated my data in the database but this was not reflected immediately. I was going to suggest an improvement, but then I looked at the code. I had to, I am a developer And so I discovered that you already implemented caching and the update frequency is set to 15 minutes by default. Nice work!

    The only thing I would suggest to you is to bullet-proof your custom field. At the moment your field displays raw data. I mean <b>this is bold</b> will be displayed as this is bold. You may think of it as a feature if you want to display some HTML data, but in most cases it is a security bug. If some data contains <script> tag then this script gets executed. Think about HTML encoding the text before you display it. That's all!

    Anyway, this plug-in is well done!

    Cheers,
    Dushan from JIRA Team

    1. Apr 17

      Wim Deblauwe says:

      Hi Dushan, thank you for your kind words! You are absolutely right about the s...

      Hi Dushan,

      thank you for your kind words!

      You are absolutely right about the security issue that might happen, but I consider this a somewhat minor issue, since only a JIRA administrator can setup the custom field. But I will think about it and see what I can do.

      regards,

      Wim

  9. Apr 22

    Hakan Soderstrom says:

    Thanks to Wim for this quality job. Installed and worked as advertised without a...

    Thanks to Wim for this quality job. Installed and worked as advertised without a hitch.

    This tip from Wim might be of general interest: If you want to set a database field from a post-function in a workflow step, the value to assign is the primary key. In my case the field is sometimes edited manually by the user, sometimes set in a workflow transition.

     /Hakan

    1. Jun 27

      Wim Deblauwe says:

      Bug JDVP7

      Bug JDVP-7 has been fixed in SVN. You can have a testbuild if you want to test it. Thanks again for reporting this.

      regards,

      Wim

  10. May 16

    samantha orme says:

    Great job this is a really nice tool to have! Have you considered loading the c...

    Great job – this is a really nice tool to have!

    Have you considered loading the cascading select with AJAX? The SQL query I'm running returns a really large data set (10,000 rows), which really doesn't work well – the browser slows to a crawl for a significant period of time.

    My first dropdown takes the 10,000 and divides it up into manageable groups. If the plug-in could load data for the second dropdown dynamically after the user selects from the first dropdown instead of just hiding/showing based on the first dropdown selection, I think that would prevent the browser hang issue.

    This would be a pretty major change (I suppose you would have to supply two SQL queries, the second of which used the primary key of the first in its where clause.) I'm hoping you'll consider it, though!

    1. May 17

      Wim Deblauwe says:

      Hi Samantha, I'm glad you like the plugin! Have you tried using the regular AJ...

      Hi Samantha,

      I'm glad you like the plugin!

      Have you tried using the regular AJAX support I provide? Does that work better? If not, please file an improvement issue in the JIRA tracker with all details.

      regards,

      Wim

  11. May 30

    Achim Vannahme says:

    Nice plugin, very useful! However, I've found two issues with sorting: In "Fi...

    Nice plugin, very useful!

    However, I've found two issues with sorting:

    • In "Find Issues", the entries seem to be sorted by the primary key, not by sortpattern
    • Sorting is case-sensitive, would be nice to have the option to make it case-insensitive

    regards,
    Achim

    1. May 30

      Wim Deblauwe says:

      Can you please file an issue in the JIRA bug tracker. I will look into it then. ...

      Can you please file an issue in the JIRA bug tracker. I will look into it then.

      regards,

      Wim

  12. Jun 09

    Christoph Ebner von Eschenbach says:

    Hello, I'm trying to set the plugin up, but my field doesnt show up somewhere. ...

    Hello,

    I'm trying to set the plugin up, but my field doesnt show up somewhere.
    I now do not know how to narrow down possible error sources:

    • If there was an error connecting to the database?
    • If there was a syntax error with my sql?

    Is there a possibility to find a possible error-message somewhere in a logfile?
    Or am i able to see somewhere, what sql actually was "used" when displaying the issue?
    (no information about it in the servers jboss log)
    How else could I narrow down the problem?

    Here are my properties (skipped comment lines):

    database.driver=com.mysql.jdbc.Driver
    database.user=XXXXXXXX
    database.password=YYYYYYYY
    database.connection.url=jdbc:mysql://localhost/jiradb
    
    #cache.timeout=900000 
    sql.query=select Schluessel, SchaetzungPreisVorgang from mbfelder where Schluessel = '${jira.project.key}'
    
    primarykey.column.number=0
    rendering.viewpattern={1} €
    rendering.editpattern={1} €
    rendering.searchpattern={1} €
    rendering.sortpattern={1}
    

    ("mbfelder" is my additional table created in the jira-db to hold extended issue information)

    1. Jun 08