英文:
Jira plugin development how to get RapidViewServiceImpl instance
问题
以下是您提供的代码的翻译:
我正在使用Java开发一个Jira报告插件,我需要获取RapidViewServiceImpl
类的实例。
如果我使用构造函数,我会得到一个nullPtrException,我认为有另一种方法可以获取这个实例。
例如,我曾经遇到过与SprintManager
和SprintManagerImpl
相同的问题,我以下面的方式获取实例:
private com.atlassian.greenhopper.service.sprint.SprintManager getSprintManager() throws InvalidSyntaxException {
ApplicationContext appCtx = (ApplicationContext) getGreenHopperAppCtx();
if (appCtx != null) {
return (com.atlassian.greenhopper.service.sprint.SprintManager) appCtx.getBean("sprintManagerImpl");
}
return null;
}
private Object getGreenHopperAppCtx() throws InvalidSyntaxException {
OsgiContainerManager osgi = ComponentAccessor.getComponentOfType(OsgiContainerManager.class);
if (osgi == null) {
java.lang.System.out.println("OSGI Not Found");
return null;
}
Bundle[] bundles = osgi.getBundles();
for (int i = 0; i < bundles.length; i++) {
Bundle bundle = bundles[i];
if ("com.pyxis.greenhopper.jira".equals(bundle.getSymbolicName())) {
BundleContext bctx = bundle.getBundleContext();
ServiceReference[] refs = bctx.getAllServiceReferences(null, null);
if (refs != null) {
for (int j = 0; j < refs.length; j++) {
Object prop = refs[j].getProperty("org.springframework.context.service.name");
if ("com.pyxis.greenhopper.jira".equals(prop)) {
return bctx.getService(refs[j]);
}
}
}
}
}
return null;
}
在主函数中,我调用了 SprintManager spManager = getSprintManager()
。
我尝试了同样的方法来获取RapidViewServiceImpl
:
private Object getGreenHopperAppCtx() throws InvalidSyntaxException {
OsgiContainerManager osgi = ComponentAccessor.getComponentOfType(OsgiContainerManager.class);
if (osgi == null) {
java.lang.System.out.println("OSGI Not Found");
return null;
}
Bundle[] bundles = osgi.getBundles();
for (int i = 0; i < bundles.length; i++) {
Bundle bundle = bundles[i];
if ("com.pyxis.greenhopper.jira".equals(bundle.getSymbolicName())) {
BundleContext bctx = bundle.getBundleContext();
ServiceReference[] refs = bctx.getAllServiceReferences(null, null);
if (refs != null) {
for (int j = 0; j < refs.length; j++) {
Object prop = refs[j].getProperty("org.springframework.context.service.name");
if ("com.pyxis.greenhopper.jira".equals(prop)) {
return bctx.getService(refs[j]);
}
}
}
}
}
return null;
}
private com.atlassian.greenhopper.service.rapid.view.RapidViewService getRapidViewManager() throws InvalidSyntaxException {
ApplicationContext appCtx = (ApplicationContext) getGreenHopperAppCtx();
if (appCtx != null) {
return (RapidViewService) appCtx.getBean("rapidViewService");
}
return null;
}
但是我得到了一个错误,说没有名为"rapidViewService
"的 bundle。
这是错误的一部分,因为整个错误太长无法发布:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'rapidViewService' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:698) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1175) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:284) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1054) [spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at com.jiraPlugin.utility.SprintManager.getRapidViewManager(SprintManager.java:72) [?:?]
at com.jiraPlugin.utility.SprintManager.getListOfSprints(SprintManager.java:95) [?:?]
at com.jiraPlugin.utility.GetSprintsForUI.getValues(GetSprintsForUI.java:35) [?:?]
at com.atlassian.configurable.ValuesGeneratorObjectConfigurationProperty.getInternalValues(ValuesGeneratorObjectConfigurationProperty.java:75) [classes/:?]
at com.atlassian.configurable.ObjectConfigurationPropertyImpl.entrySet(ObjectConfigurationPropertyImpl.java:266) [classes/:?]
at com.atlassian.jira.plugin.corereports.web.action.ConfigureReport.mapAndConvertToList(ConfigureReport.java:383) [?:?]
at com.atlassian.jira.plugin.corereports.web.action.ConfigureReport.access$000(ConfigureReport.java:53) [?:?]
at com.atlassian.jira.plugin.corereports.web.action.ConfigureReport$ObjectConfigurationField.getValues(ConfigureReport.java:440) [?:?]
... 387 more
请问是否可以帮助我解决这个问题?
英文:
I am developing a Jira report plugin using Java and I need to get an instance of RapidViewServiceImpl
class.
If I use the constructor I get a nullPtrException and I think there is another way to get this instance.
For example I had exactly the same problem with SprintManager
and SprintManagerImpl
, and I get the instance as the following:
private com.atlassian.greenhopper.service.sprint.SprintManager getSprintManager() throws InvalidSyntaxException {
ApplicationContext appCtx = (ApplicationContext) getGreenHopperAppCtx();
if (appCtx != null) {
return (com.atlassian.greenhopper.service.sprint.SprintManager) appCtx.getBean("sprintManagerImpl");
}
return null;
}
private Object getGreenHopperAppCtx() throws InvalidSyntaxException {
OsgiContainerManager osgi = ComponentAccessor.getComponentOfType(OsgiContainerManager.class);
if (osgi == null) {
java.lang.System.out.println("OSGI Not Found");
return null;
}
Bundle[] bundles = osgi.getBundles();
for (int i = 0; i < bundles.length; i++) {
Bundle bundle = bundles[i];
if ("com.pyxis.greenhopper.jira".equals(bundle.getSymbolicName())) {
BundleContext bctx = bundle.getBundleContext();
ServiceReference[] refs = bctx.getAllServiceReferences(null, null);
if (refs != null) {
for (int j = 0; j < refs.length; j++) {
Object prop = refs[j].getProperty("org.springframework.context.service.name");
if ("com.pyxis.greenhopper.jira".equals(prop)) {
return bctx.getService(refs[j]);
}
}
}
}
}
return null;
}
And in the main function I called SprintManager spManager = getSprintManager()
.
I tried the same thing with RapidViewServiceImpl
:
private Object getGreenHopperAppCtx() throws InvalidSyntaxException {
OsgiContainerManager osgi = ComponentAccessor.getComponentOfType(OsgiContainerManager.class);
if (osgi == null) {
java.lang.System.out.println("OSGI Not Found");
return null;
}
Bundle[] bundles = osgi.getBundles();
for (int i = 0; i < bundles.length; i++) {
Bundle bundle = bundles[i];
if ("com.pyxis.greenhopper.jira".equals(bundle.getSymbolicName())) {
BundleContext bctx = bundle.getBundleContext();
ServiceReference[] refs = bctx.getAllServiceReferences(null, null);
if (refs != null) {
for (int j = 0; j < refs.length; j++) {
Object prop = refs[j].getProperty("org.springframework.context.service.name");
if ("com.pyxis.greenhopper.jira".equals(prop)) {
return bctx.getService(refs[j]);
}
}
}
}
}
return null;
}
//------------------------------------------------------------------------------------------------------------------
private com.atlassian.greenhopper.service.rapid.view.RapidViewService getRapidViewManager() throws InvalidSyntaxException {
ApplicationContext appCtx = (ApplicationContext) getGreenHopperAppCtx();
if (appCtx != null) {
return (RapidViewService) appCtx.getBean("rapidViewService");
}
return null;
}
But I get an error which says there is no bundle named "rapidViewService
".
This is a part of the error, I can't post the entire error because is too long:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'rapidViewService' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:698) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1175) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:284) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1054) [spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at com.jiraPlugin.utility.SprintManager.getRapidViewManager(SprintManager.java:72) [?:?]
at com.jiraPlugin.utility.SprintManager.getListOfSprints(SprintManager.java:95) [?:?]
at com.jiraPlugin.utility.GetSprintsForUI.getValues(GetSprintsForUI.java:35) [?:?]
at com.atlassian.configurable.ValuesGeneratorObjectConfigurationProperty.getInternalValues(ValuesGeneratorObjectConfigurationProperty.java:75) [classes/:?]
at com.atlassian.configurable.ObjectConfigurationPropertyImpl.entrySet(ObjectConfigurationPropertyImpl.java:266) [classes/:?]
at com.atlassian.jira.plugin.corereports.web.action.ConfigureReport.mapAndConvertToList(ConfigureReport.java:383) [?:?]
at com.atlassian.jira.plugin.corereports.web.action.ConfigureReport.access$000(ConfigureReport.java:53) [?:?]
at com.atlassian.jira.plugin.corereports.web.action.ConfigureReport$ObjectConfigurationField.getValues(ConfigureReport.java:440) [?:?]
... 387 more
Can someone please help me to solve this problem?
答案1
得分: 0
我通过使用类别名为 "projectRapidViewServiceImpl" 的捆绑包来解决了这个问题,使用了类 ProjectRapidViewServiceImpl 的实例。
private com.atlassian.greenhopper.service.rapid.ProjectRapidViewService getRapidViewManager() throws InvalidSyntaxException {
ApplicationContext appCtx = (ApplicationContext) getGreenHopperAppCtx();
if (appCtx != null) {
return (ProjectRapidViewServiceImpl) appCtx.getBean("projectRapidViewServiceImpl");
}
return null;
}
而这个类拥有一个名为 findRapidViewsByProject(com.atlassian.jira.user.ApplicationUser user, com.atlassian.jira.project.Project project)
的函数,该函数返回与项目相关的 RapidViews 列表。
英文:
I solved the problem by using the class ProjectRapidViewServiceImpl, and I got the instance of this class using the bundle named "projectRapidViewServiceImpl"
private com.atlassian.greenhopper.service.rapid.ProjectRapidViewService getRapidViewManager() throws InvalidSyntaxException {
ApplicationContext appCtx = (ApplicationContext) getGreenHopperAppCtx();
if (appCtx != null) {
return (ProjectRapidViewServiceImpl) appCtx.getBean("projectRapidViewServiceImpl");
}
return null;
}
And this class has a function named findRapidViewsByProject(com.atlassian.jira.user.ApplicationUser user, com.atlassian.jira.project.Project project)
which returns a list of RapidViews related to a project.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论