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

Adding IssueTypes to CustomField during creation without using deprecated com.atlassian.jira.config.ConstantsManager.getConstantByName

Max Göbel October 6, 2013

Dear Atlassian Community,

currently, I am developing a plugin for jira 6.1.

On Event "afterPropertiesSet" it defines own Issue Types and Customfields, as described here:
https://answers.atlassian.com/questions/43232/how-to-create-a-plugin-that-packages-custom-issue-types-to-add-to-jira-instance-is-it-possible

After I created my IssueTypes:

com.atlassian.jira.config.ConstantsManager constantsManager;
constantsManager.insertIssueType(getName(), getSequencenumber(), getStyle(), getDescription(), getIconURL());

I want to add them as parameters to a new CustomField:

com.atlassian.jira.issue.CustomFieldManager customFieldManager;
customFieldManager.createCustomField(
                        getCustomFieldName(),
                        getCustomFieldDescription(),
                        customFieldManager.getCustomFieldType(getCustomFieldType()),
                        customFieldManager.getCustomFieldSearcher(getCustomFieldSearcher()),
                        getContexts(), getIssueTypes());

Thats why I want to retrieve the issueTypes from the customFieldManager again, before giving them as Arguments to the new created customField:

This Way it works (but its deprecated):

constantsManager.getConstantByName(constantsManager.ISSUE_TYPE_CONSTANT_TYPE, getName())

This Way it does not work (but it should be right from my point of view):

constantsManager.getConstantByNameIgnoreCase(constantsManager.ISSUE_TYPE_CONSTANT_TYPE, getName());

If I do it the right way, I am running into an internal class cast exception at "customFieldManager.createCustomField". It really wants the issueTypes-List as "org.ofbiz.core.entity.GenericValue" instead of "com.atlassian.jira.issue.IssueConstant".

Here is the Stacktrace:

[INFO] [talledLocalContainer] java.lang.ClassCastException: com.atlassian.jira.issue.issuetype.IssueTypeImpl cannot be cast to org.ofbiz.core.entity.GenericValue
[INFO] [talledLocalContainer]   at com.atlassian.jira.issue.fields.config.manager.FieldConfigSchemeManagerImpl.createDefaultScheme(FieldConfigSchemeManagerImpl.java:157)
[INFO] [talledLocalContainer]   at com.atlassian.jira.issue.managers.DefaultCustomFieldManager.associateCustomFieldContext(DefaultCustomFieldManager.java:213)
[INFO] [talledLocalContainer]   at com.atlassian.jira.issue.managers.DefaultCustomFieldManager.createCustomField(DefaultCustomFieldManager.java:195)
[INFO] [talledLocalContainer]   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[INFO] [talledLocalContainer]   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[INFO] [talledLocalContainer]   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[INFO] [talledLocalContainer]   at java.lang.reflect.Method.invoke(Method.java:597)
[INFO] [talledLocalContainer]   at com.atlassian.plugin.osgi.hostcomponents.impl.DefaultComponentRegistrar$ContextClassLoaderSettingInvocationHandler.invoke(DefaultComponentRegistrar.java:129)
[INFO] [talledLocalContainer]   at com.sun.proxy.$Proxy225.createCustomField(Unknown Source)
[INFO] [talledLocalContainer]   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[INFO] [talledLocalContainer]   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[INFO] [talledLocalContainer]   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[INFO] [talledLocalContainer]   at java.lang.reflect.Method.invoke(Method.java:597)
[INFO] [talledLocalContainer]   at com.atlassian.plugin.osgi.bridge.external.HostComponentFactoryBean$DynamicServiceInvocationHandler.invoke(HostComponentFactoryBean.java:154)
[INFO] [talledLocalContainer]   at com.sun.proxy.$Proxy225.createCustomField(Unknown Source)
[INFO] [talledLocalContainer]   at com.myplugin.service.WrapperCustomFieldService.persistOwnJiraObject(WrapperCustomFieldService.java:88)
[INFO] [talledLocalContainer]   at com.myplugin.testsuite.domain.CustomFieldFactory.createAllCustomFields(CustomFieldFactory.java:62)
[INFO] [talledLocalContainer]   at com.myplugin.testsuite.controller.Main.init(Main.java:62)
[INFO] [talledLocalContainer]   at com.myplugin.testsuite.lifecycle.PluginListener.afterPropertiesSet(PluginListener.java:45)
[INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
[INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
[INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
[INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
[INFO] [talledLocalContainer]   at java.security.AccessController.doPrivileged(Native Method)
[INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
[INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
[INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
[INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
[INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
[INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
[INFO] [talledLocalContainer]   at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
[INFO] [talledLocalContainer]   at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
[INFO] [talledLocalContainer]   at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69)
[INFO] [talledLocalContainer]   at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355)
[INFO] [talledLocalContainer]   at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
[INFO] [talledLocalContainer]   at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)
[INFO] [talledLocalContainer]   at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132)
[INFO] [talledLocalContainer]   at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
[INFO] [talledLocalContainer]   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)

My Question is: Do you know any smarter way instead of using a deprecated Method?

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Eloy Brodin December 15, 2013

I supose this is an useless answer for you now (2 months later), but i hope it will be useful if anybody (like me) reads this in the future.

I had the same problem. It seems that createCustomField just works with a GenericValue list (I use jira 6.1.4), but you can get the GenericValue from an IssueConstant with getGenericValue().

It works if you change your function:

public List<GenericValue> getIssueTypes() {

    ArrayList<GenericValue> its = new ArrayList<GenericValue>();

    its.add(constantsManager.getConstantByNameIgnoreCase(constantsManager.ISSUE_TYPE_CONSTANT_TYPE, "myIssueType").getGenericValue());

    return its;

}


Max Göbel January 5, 2014

Your are right, the project has been finished but we will consider it in the future.

I will accept it untested for now so take the "Karma" and regards in advance ;)

0 votes
Bharadwaj Jannu
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.
October 6, 2013

I think the createCustomField require a list of IssueTypes

how getIssueTypes method is written to get the list?

Max Göbel October 13, 2013

I think the createCustomField require a list of IssueTypes

how getIssueTypes method is written to get the list?

Like I wrote before, simplified it works like this:

void myAddMethod() {
	customFieldManager.createCustomField(
                        getCustomFieldName(),
                        getCustomFieldDescription(),
                        customFieldManager.getCustomFieldType(getCustomFieldType()),
                        customFieldManager.getCustomFieldSearcher(getCustomFieldSearcher()),
                        getContexts(), getIssueTypes());
}
						

public List<GenericValue> getIssueTypes() {
	ArrayList<GenericValue> its = new ArrayList<GenericValue>();
	its.add(constantsManager.getConstantByName(constantsManager.ISSUE_TYPE_CONSTANT_TYPE, "myIssueType"));
	return its;
}

Bharadwaj Jannu
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.
October 13, 2013
public List<GenericValue> getIssueTypes() {
    ArrayList<GenericValue> its = new ArrayList<GenericValue>();
    its.add(constantsManager.getConstantByName(constantsManager.ISSUE_TYPE_CONSTANT_TYPE, "myIssueType"));
    return its;
}

change the code as
public List<IssueConstant> getIssueTypes() {
    ArrayList<IssueConstant> its = new ArrayList<IssueConstant>();
    its.add(constantsManager.getConstantByName(constantsManager.ISSUE_TYPE_CONSTANT_TYPE, "myIssueType"));
    return its;
}

now you can use
getIssueConstantByName(String constantType,String name)
Max Göbel October 13, 2013

Sry but that is what rambanam prasad also told me (see first answer on Oct 07 at 06:02 AM).

It leads to excactly the same error.

Bharadwaj Jannu
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.
October 14, 2013

after changing the return type of getIssueTypes() method i.e List<IssueConstant>, is getIssueConstantByName(...) throwing error?

public List&lt;IssueConstant&gt; getIssueTypes() {
ArrayList&lt;IssueConstant&gt; its = new ArrayList&lt;IssueConstant&gt;();
its.add(ComponentAccessor.getConstantsManager().getIssueConstantByName(ComponentAccessor.getConstantsManager().ISSUE_TYPE_CONSTANT_TYPE, "myIssueType"));
return its;
}

Max Göbel October 14, 2013

The error is thrown at

customFieldManager.createCustomField(
                        getCustomFieldName(),
                        getCustomFieldDescription(),
                        customFieldManager.getCustomFieldType(getCustomFieldType()),
                        customFieldManager.getCustomFieldSearcher(getCustomFieldSearcher()),
                        getContexts(), getIssueTypes());

If "getIssueTypes()" returns "List<IssueConstant>".

If "getIssueTypes()" returns "List<GenericValue>" everything is ok.

For the Stacktrace please read the description on top of this page.

Bharadwaj Jannu
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.
October 14, 2013

you need to add try/catch or throws clause to createCustomField.

If you added and even getting error, then is it showing on method call itself? or at run time?

if at all runtime then could you paste the log error message?

0 votes
RambanamP
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.
October 6, 2013

did you tried with this method

getIssueConstantByName(String constantType,String name)

check this doc

https://docs.atlassian.com/jira/6.1/com/atlassian/jira/config/ConstantsManager.html#getIssueConstantByName(java.lang.String, java.lang.String)

Max Göbel October 6, 2013

unfortunately it leads to the same error

TAGS
AUG Leaders

Atlassian Community Events