Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Adding fields before generating report

Christian Cavallo June 20, 2013

Hello,

I am developing a report plugin on JIRA.
Before generating the report, the method 'generateReportHtml(ProjectActionSupport action, Map params)' is called. The parameter 'params' contains information given by users (i.e start date, project id, filter...).

My goal is to add new fields that would permit to gather more informations from users.
I have tried to edit 'atlassian-plugin.xml' (<property> tag) and 'report.properties' files but I didn't manage to add new fields.

Could you, please, give me a hand?

10 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Christian Cavallo June 24, 2013

Ok, we found out how to resolve this issue: restart the server before uploading the new plugin.

We don't know yet if the server is keeping a copy of the 'atlassian-plugin.xml' file or if it's a versioning problem or something like that... If we modify the source code in Java, we don't need to restart the server.

Steps I followed: execute the 3 'atlas-xxx' commands, uninstall current plugin on Jira, upload the new one, refresh the page of the project and test the report.

Thank you for your help! :)

Ryan Pelletier May 25, 2016

This works, it is an unfortunate workaround though. There seem to be too many little glitches like these with the Atlassian SDK.

1 vote
Sergey Shubin March 28, 2017

We did found a solution, which doesn't require to restart JIRA instance smile

The problem is that on first load of report configuration page JIRA load's configuration from ObjectConfigurationFactory, which keeps all report configs in memory and does not invalidate them on reload of plugin, so I've wrote small code snippet, which manually reloads all of the descriptors. It require some Java Reflections magic to get all the required fields, but it works. Use at your own risk btw smile

import com.atlassian.configurable.ObjectConfigurationFactory;
import com.atlassian.configurable.ObjectDescriptor;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.plugin.AbstractConfigurableModuleDescriptor;
import com.atlassian.jira.plugin.report.ReportModuleDescriptor;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.plugin.Plugin;
import org.dom4j.Element;
import java.lang.reflect.Field;
import java.util.*;
import java.util.stream.Collectors;
 
void reloadReportParameters() {
    Collection&lt;Plugin&gt; pluginList = ComponentAccessor.getPluginAccessor().getEnabledPlugins();
    ObjectConfigurationFactory objectConfigurationFactory = ComponentAccessor.getComponent(ObjectConfigurationFactory.class);
    Collection&lt;ReportModuleDescriptor&gt; reportModuleDescriptors = new ArrayList&lt;&gt;();
    for (Plugin plugin : pluginList) {
        reportModuleDescriptors.addAll(getReportDescriptors(plugin));
    }
    List&lt;ReloadedReportParametersInfo&gt; reloadedReportParametersInfoList = new ArrayList&lt;&gt;();
    for (ReportModuleDescriptor descriptor : reportModuleDescriptors) {
        Element element = getFieldValue(AbstractConfigurableModuleDescriptor.class, "element", descriptor);
        ObjectDescriptor objectDescriptor = getFieldValue(AbstractConfigurableModuleDescriptor.class, "objectDescriptor", descriptor);
        objectConfigurationFactory.loadObjectConfigurationFromElement(element,
                    objectDescriptor, descriptor.getCompleteKey(), descriptor.getPlugin().getClassLoader());
    }
}
 
private &lt;T, P&gt; T getFieldValue(Class&lt;? extends P&gt; clazz, String fieldName, P object)
            throws NoSuchFieldException, IllegalAccessException {
    Field field = clazz.getDeclaredField(fieldName);
    boolean accessibility = field.isAccessible();
    field.setAccessible(true);
    T value = ((T) field.get(object));
    field.setAccessible(accessibility);
    return value;
}

private Collection&lt;ReportModuleDescriptor&gt; getReportDescriptors(Plugin plugin) {
    return plugin.getModuleDescriptors().stream()
            .filter(descriptor -&gt; descriptor instanceof ReportModuleDescriptor)
            .map(descriptor -&gt; ((ReportModuleDescriptor) descriptor))
            .collect(Collectors.toList());
}
0 votes
Christian Cavallo June 23, 2013

I searched in the whole project folder and found 2 'atlassian-plugin.xml', but the 2nd one is in <project>\target\classes (which is created after doing 'atlas-package', I think). If I delete it, I can't load the plugin on Jira.

After I have modified the code, I execute 'atlas-clean', then 'atlas-compile', then 'atlas-package'. I can't use 'atlas-run' because of maven configuration...

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 23, 2013

That sounds correct to me, but what I'm trying to get at is that in your running Jira, I'm not sure you are looking at the right report - an older version of it could be obscuring your code.

Atlas-run should work fine, but I'm not going to get into debugging that here. Once you've run atlas-package, then what do you do? There's several more steps needed before you can get to a report, so we're wondering if you're following all of them, or if there's something in one of them going wrong.

0 votes
Christian Cavallo June 23, 2013

1. Yes

2. 3. It doesn't change anything :/

There is something weird: if all <property> in <properties> are deleted, there are still the 3 fields.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 23, 2013

The only time I can think I've seen these symptoms was when I was looking at completely the wrong report. I'd copied a report plugin with the intention of expanding it, changed the name slightly and could not work out why my new parameters would not change. Took ages to realise the old plugin was still in place, and it was still taking me to that.

Could this have happened here? Could you describe the steps you take after you've modified the code? (e.g. atlas-clean; atlas-run)?

0 votes
Christian Cavallo June 23, 2013

Hi Nic!

After a full restart, the report configuration screen is still the same:

http://hpics.li/28d210f

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 23, 2013

Ok, so your new property is fully enclosed between the <properties> tags in the xml, same as the other three fields? (That's something I've done before - it compiled and worked, and didn't display my fields because they were correct, but in totally the wrong place, so it ignored them)

I also have a vague memory about errors in one field stopping the rest appearing - could you try moving the missing field definition up, so it falls between endDate and startDate (temporarily of course - this is just to see if it changes the behaviour)

Finally, the field is defined as select, but is missing it's <values> tag - could you add something in there? Even if it's just the same class line you've got for the interval field.

0 votes
Christian Cavallo June 23, 2013

I would like to add a new to field (a TextField in HTML) so that an user can give information before generating the report. I add these properties in 'atlassian-plugin.xml' file:

&lt;property&gt;
   &lt;key&gt;test&lt;/key&gt;
   &lt;name&gt;test.label&lt;/name&gt;
   &lt;description&gt;test.description&lt;/description&gt;
   &lt;type&gt;select&lt;/type&gt;
&lt;/property&gt;

I also modified the 'report.properties' file:

test.label = Test label
test.description = Test description

But nothing happened. Do you know if there is an other file to modify?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 23, 2013

No, if you've got that property in atlassian-plugin.xml, then I'd expect them to appear.

Can you tell us exactly what you DO see on the report configuration screen at the moment? (Also, could you be 100% clean - restart your development Jira - sometimes it seems to need a full restart to pick up code changes, despite the fast-dev settings)

0 votes
Christian Cavallo June 23, 2013

I'd like to add a new field, so that a user can give informations before generating the report, so I put a new tag, but nothing happened:

&lt;property&gt;
   &lt;key&gt;test&lt;/key&gt; 
   &lt;name&gt;test.label&lt;/name
   &lt;description&gt;test.description&lt;/description&gt;
   &lt;type&gt;select&lt;/type&gt;
&lt;/property&gt;

I also add these properties in the 'report.properties' file:

stop.label = End date
stop.description = End date for report

start.label = Start date
start.description = Start date for report

interval.label = Interval
interval.description = Issue statusses measurements interval

test.label = Test label
test.description = Test description

Do you know if there is an other file to modify?

0 votes
Robert Jahrling
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 20, 2013

Christian, that looks right. What problem are you having? Where are you expecting to see the fields?

0 votes
Christian Cavallo June 20, 2013

Hi Robert, thanks for answering :)

Here is the report module:

&lt;report key="reportIssuesCumulative" name="Example: group by report extended" class="com.thalesgroup.nl.jira.plugins.reports.cumulativestatusses.CumulativeStatussesChartPlugin"&gt;
   &lt;description key="report.singlelevelgroupby.description"&gt;i18n description&lt;/description&gt;

   &lt;resource type="velocity" name="view" location="templates/chart.vm"/&gt;
   &lt;resource type="i18n" name="i18n" location="properties/report"/&gt;

   &lt;label key="report.singlelevelgroupby.label.extended"/&gt;

   &lt;properties&gt;

      &lt;property&gt;
         &lt;key&gt;endDate&lt;/key&gt;
         &lt;name&gt;stop.label&lt;/name&gt;
         &lt;description&gt;stop.description&lt;/description&gt;
         &lt;type&gt;select&lt;/type&gt;
      &lt;/property&gt;
            
      &lt;property&gt;
         &lt;key&gt;startDate&lt;/key&gt;
         &lt;name&gt;start.label&lt;/name&gt;
         &lt;description&gt;start.description&lt;/description&gt;
         &lt;type&gt;date&lt;/type&gt;
      &lt;/property&gt;
            
      &lt;property&gt;
         &lt;key&gt;interval&lt;/key&gt;
         &lt;name&gt;interval.label&lt;/name&gt;
         &lt;description&gt;intervale.description&lt;/description&gt;
         &lt;type&gt;select&lt;/type&gt;    
         &lt;values class="com.thalesgroup.nl.jira.plugins.reports.cumulativestatusses.IntervalTypeValuesGenerator"/&gt;
      &lt;/property&gt;
           	
   &lt;/properties&gt;
&lt;/report&gt;

I tried to delete these 3 properties but it didn't change anything: the fields are still there!
Also, I have only 1 .vm file: which one permits to 'draw' the result of the report (a chart).

0 votes
Robert Jahrling
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 20, 2013

From the sound of it, you're starting out right. Can you post your report module from atlassian-plugin.xml?

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events