How use ValuesGenerator to genarate values for my Jira Service?

Ana Gonzalez February 27, 2018

I have custom service in my plugin and I need to have a parameter on the service config tha lets me select some versions .

This is what i have so far, the service is working fine but I can't see the version values when edit the service, all I see is this message ---> Could not find any values for field 'My Versions:'.

<service id="myservice">
<description>My service.</description>
<properties>
<property>
<key>myVersions</key>
<name>My Versions:</name>
<type>multiselect</type>
<values class="com.mycompany.services.mySelect"/>
</property>
</properties>
</service>

 

public class mySelect implements ValuesGenerator{

private static final Logger log = LoggerFactory.getLogger(mySelect.class);

public mySelect(){

}

@Override
public Map<String, String> getValues(final Map params)
{
VersionManager versionmanager = ComponentManager.getComponentInstanceOfType(VersionManager.class);
Map<String, String> values = versionmanager.getAllVersions().stream().collect(Collectors.toMap(Version::getName, Version::getName ));

return values;
}
}

 

1 answer

0 votes
Gaston Valente
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.
February 27, 2018

Hi!

Here you can check a working example:

//Class
import com.atlassian.configurable.ValuesGenerator;
import java.util.LinkedHashMap;
import java.util.Map;

public class MesValuesGenerator implements ValuesGenerator {
private static Map<String,String> map;

private static Map<String,String> getList()
{
if( map == null)
{
map = new LinkedHashMap<String,String>();

map.put("0", "Seleccione");
map.put("1","Enero");
map.put("2","Febrero");
map.put("3","Marzo");
map.put("4","Abril");
map.put("5","Mayo");
map.put("6","Junio");
map.put("7","Julio");
map.put("8","Agosto");
map.put("9","Septiempre");
map.put("10","Octubre");
map.put("11","Noviembre");
map.put("12","Diciembre");
}

return map;
}

public Map<String,String> getValues(Map params)
{
return getList();
}
}
//XML
<property>
<key>mes</key>
<name>reporte.operaciones.mes.name</name>
<description>reporte.operaciones.mes.description</description>
<type>select</type>
<values class="jira.plugin.reporteoperaciones.MesValuesGenerator"/>
</property>
Ana Gonzalez February 27, 2018

Tried yours and same problem, I think Im missing some config detail.
I have the XML inside \src\main\resources
And I have the class in src\main\java\com\mycompany\services

When I change my ValuesGenerator class for this one for example 

com.atlassian.jira.portal.FilterValuesGenerator

it works ok. It's almost like it doesn't know where my class is :(
besides of the actual service class(also in src\main\java\com\mycompany\services), do I need to config somethig else, like atlassian-plugin.xml?

Gaston Valente
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.
March 5, 2018

Ana,

Can you post the error your getting? 

Aktarel July 4, 2018

Hello guys, did you resolved your issue ?

Sorry I am doing some archeology 

I have clearly the same issue Ana raised.

My class is in a type 2 JIRA plugin

Here is the log when trying to create my service in JIRA server 7.1.4. 

Could not create class: fr.nlebec.jira.plugins.database.model.GroupListValueGenerator
java.lang.ClassNotFoundException: fr.nlebec.jira.plugins.database.model.GroupListValueGenerator
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1305)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1157)


I just saw this issue : https://jira.atlassian.com/browse/JRASERVER-21430

My ValuesGenerator load if and only if i add the following class in the following folder

<JIRA_INSTALL>\atlassian-jira\WEB-INF\classes\fr\nlebec\jira\plugins\database\model\GroupListValueGenerator.class

Issue still opened and last comment of this issue :

I did some new test with JIRA 7.0.5, and it seems to be correct.
May we know from which version it has been fixed ?

I am on version 7.1.4 and I still have the issue.

This thing is annoying since you won't ask people using your plugin to move in JIRA installation your own classes and restart !

Maybe load dynamically in webappClassloader your specific classes in some plugin initializer ?

JIRA guru , I am invoking you in this post, please give us a workaround ! \o/

Christian Vieweg November 6, 2018

This problem still occurs in Jira 7.8.0. Any workarounds available?

Christian_Schönert August 29, 2019

I'd also love a solution to that. I have implemented a custom service that performs automatic workflow actions with given parameters.

One of the parameters is the workflow name. Up until now, you just enter the name by hand, leaving the possibility to misspell and other problems. So the Idea was to make it a dropdown list that would get its values from a custom ValuesGenerator. Nice in theory, but as all the comments above state, it doesn't work with custom generator classes as the class is not loaded on startup.

 

I tried it with Jira 8.3.1 so at this point I am just frustrated, that such a bug just wouldnt be fixed for years and years to come. (see https://jira.atlassian.com/browse/JRASERVER-21430).

If anyone knows a decent workaround I'm happy to receive it. I will now try the very unhandy solution that Aktarel suggested.

Regards

Chris

Suggest an answer

Log in or Sign up to answer