Jira插件开发如何获取RapidViewServiceImpl实例

huangapple 未分类评论60阅读模式
标题翻译

Jira plugin development how to get RapidViewServiceImpl instance

问题

以下是您提供的代码的翻译:

我正在使用Java开发一个Jira报告插件,我需要获取RapidViewServiceImpl类的实例。
如果我使用构造函数,我会得到一个nullPtrException,我认为有另一种方法可以获取这个实例。
例如,我曾经遇到过与SprintManagerSprintManagerImpl相同的问题,我以下面的方式获取实例:

  1. private com.atlassian.greenhopper.service.sprint.SprintManager getSprintManager() throws InvalidSyntaxException {
  2. ApplicationContext appCtx = (ApplicationContext) getGreenHopperAppCtx();
  3. if (appCtx != null) {
  4. return (com.atlassian.greenhopper.service.sprint.SprintManager) appCtx.getBean("sprintManagerImpl");
  5. }
  6. return null;
  7. }
  8. private Object getGreenHopperAppCtx() throws InvalidSyntaxException {
  9. OsgiContainerManager osgi = ComponentAccessor.getComponentOfType(OsgiContainerManager.class);
  10. if (osgi == null) {
  11. java.lang.System.out.println("OSGI Not Found");
  12. return null;
  13. }
  14. Bundle[] bundles = osgi.getBundles();
  15. for (int i = 0; i < bundles.length; i++) {
  16. Bundle bundle = bundles[i];
  17. if ("com.pyxis.greenhopper.jira".equals(bundle.getSymbolicName())) {
  18. BundleContext bctx = bundle.getBundleContext();
  19. ServiceReference[] refs = bctx.getAllServiceReferences(null, null);
  20. if (refs != null) {
  21. for (int j = 0; j < refs.length; j++) {
  22. Object prop = refs[j].getProperty("org.springframework.context.service.name");
  23. if ("com.pyxis.greenhopper.jira".equals(prop)) {
  24. return bctx.getService(refs[j]);
  25. }
  26. }
  27. }
  28. }
  29. }
  30. return null;
  31. }

在主函数中,我调用了 SprintManager spManager = getSprintManager()
我尝试了同样的方法来获取RapidViewServiceImpl

  1. private Object getGreenHopperAppCtx() throws InvalidSyntaxException {
  2. OsgiContainerManager osgi = ComponentAccessor.getComponentOfType(OsgiContainerManager.class);
  3. if (osgi == null) {
  4. java.lang.System.out.println("OSGI Not Found");
  5. return null;
  6. }
  7. Bundle[] bundles = osgi.getBundles();
  8. for (int i = 0; i < bundles.length; i++) {
  9. Bundle bundle = bundles[i];
  10. if ("com.pyxis.greenhopper.jira".equals(bundle.getSymbolicName())) {
  11. BundleContext bctx = bundle.getBundleContext();
  12. ServiceReference[] refs = bctx.getAllServiceReferences(null, null);
  13. if (refs != null) {
  14. for (int j = 0; j < refs.length; j++) {
  15. Object prop = refs[j].getProperty("org.springframework.context.service.name");
  16. if ("com.pyxis.greenhopper.jira".equals(prop)) {
  17. return bctx.getService(refs[j]);
  18. }
  19. }
  20. }
  21. }
  22. }
  23. return null;
  24. }
  25. private com.atlassian.greenhopper.service.rapid.view.RapidViewService getRapidViewManager() throws InvalidSyntaxException {
  26. ApplicationContext appCtx = (ApplicationContext) getGreenHopperAppCtx();
  27. if (appCtx != null) {
  28. return (RapidViewService) appCtx.getBean("rapidViewService");
  29. }
  30. return null;
  31. }

但是我得到了一个错误,说没有名为"rapidViewService"的 bundle。
这是错误的一部分,因为整个错误太长无法发布:

  1. Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'rapidViewService' is defined
  2. at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:698) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
  3. at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1175) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
  4. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:284) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
  5. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
  6. at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1054) [spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
  7. at com.jiraPlugin.utility.SprintManager.getRapidViewManager(SprintManager.java:72) [?:?]
  8. at com.jiraPlugin.utility.SprintManager.getListOfSprints(SprintManager.java:95) [?:?]
  9. at com.jiraPlugin.utility.GetSprintsForUI.getValues(GetSprintsForUI.java:35) [?:?]
  10. at com.atlassian.configurable.ValuesGeneratorObjectConfigurationProperty.getInternalValues(ValuesGeneratorObjectConfigurationProperty.java:75) [classes/:?]
  11. at com.atlassian.configurable.ObjectConfigurationPropertyImpl.entrySet(ObjectConfigurationPropertyImpl.java:266) [classes/:?]
  12. at com.atlassian.jira.plugin.corereports.web.action.ConfigureReport.mapAndConvertToList(ConfigureReport.java:383) [?:?]
  13. at com.atlassian.jira.plugin.corereports.web.action.ConfigureReport.access$000(ConfigureReport.java:53) [?:?]
  14. at com.atlassian.jira.plugin.corereports.web.action.ConfigureReport$ObjectConfigurationField.getValues(ConfigureReport.java:440) [?:?]
  15. ... 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:

  1. private com.atlassian.greenhopper.service.sprint.SprintManager getSprintManager() throws InvalidSyntaxException {
  2. ApplicationContext appCtx = (ApplicationContext) getGreenHopperAppCtx();
  3. if (appCtx != null) {
  4. return (com.atlassian.greenhopper.service.sprint.SprintManager) appCtx.getBean(&quot;sprintManagerImpl&quot;);
  5. }
  6. return null;
  7. }
  8. private Object getGreenHopperAppCtx() throws InvalidSyntaxException {
  9. OsgiContainerManager osgi = ComponentAccessor.getComponentOfType(OsgiContainerManager.class);
  10. if (osgi == null) {
  11. java.lang.System.out.println(&quot;OSGI Not Found&quot;);
  12. return null;
  13. }
  14. Bundle[] bundles = osgi.getBundles();
  15. for (int i = 0; i &lt; bundles.length; i++) {
  16. Bundle bundle = bundles[i];
  17. if (&quot;com.pyxis.greenhopper.jira&quot;.equals(bundle.getSymbolicName())) {
  18. BundleContext bctx = bundle.getBundleContext();
  19. ServiceReference[] refs = bctx.getAllServiceReferences(null, null);
  20. if (refs != null) {
  21. for (int j = 0; j &lt; refs.length; j++) {
  22. Object prop = refs[j].getProperty(&quot;org.springframework.context.service.name&quot;);
  23. if (&quot;com.pyxis.greenhopper.jira&quot;.equals(prop)) {
  24. return bctx.getService(refs[j]);
  25. }
  26. }
  27. }
  28. }
  29. }
  30. return null;
  31. }

And in the main function I called SprintManager spManager = getSprintManager().
I tried the same thing with RapidViewServiceImpl:

  1. private Object getGreenHopperAppCtx() throws InvalidSyntaxException {
  2. OsgiContainerManager osgi = ComponentAccessor.getComponentOfType(OsgiContainerManager.class);
  3. if (osgi == null) {
  4. java.lang.System.out.println(&quot;OSGI Not Found&quot;);
  5. return null;
  6. }
  7. Bundle[] bundles = osgi.getBundles();
  8. for (int i = 0; i &lt; bundles.length; i++) {
  9. Bundle bundle = bundles[i];
  10. if (&quot;com.pyxis.greenhopper.jira&quot;.equals(bundle.getSymbolicName())) {
  11. BundleContext bctx = bundle.getBundleContext();
  12. ServiceReference[] refs = bctx.getAllServiceReferences(null, null);
  13. if (refs != null) {
  14. for (int j = 0; j &lt; refs.length; j++) {
  15. Object prop = refs[j].getProperty(&quot;org.springframework.context.service.name&quot;);
  16. if (&quot;com.pyxis.greenhopper.jira&quot;.equals(prop)) {
  17. return bctx.getService(refs[j]);
  18. }
  19. }
  20. }
  21. }
  22. }
  23. return null;
  24. }
  25. //------------------------------------------------------------------------------------------------------------------
  26. private com.atlassian.greenhopper.service.rapid.view.RapidViewService getRapidViewManager() throws InvalidSyntaxException {
  27. ApplicationContext appCtx = (ApplicationContext) getGreenHopperAppCtx();
  28. if (appCtx != null) {
  29. return (RapidViewService) appCtx.getBean(&quot;rapidViewService&quot;);
  30. }
  31. return null;
  32. }

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:

  1. Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named &#39;rapidViewService&#39; is defined
  2. at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:698) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
  3. at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1175) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
  4. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:284) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
  5. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) [spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
  6. at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1054) [spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
  7. at com.jiraPlugin.utility.SprintManager.getRapidViewManager(SprintManager.java:72) [?:?]
  8. at com.jiraPlugin.utility.SprintManager.getListOfSprints(SprintManager.java:95) [?:?]
  9. at com.jiraPlugin.utility.GetSprintsForUI.getValues(GetSprintsForUI.java:35) [?:?]
  10. at com.atlassian.configurable.ValuesGeneratorObjectConfigurationProperty.getInternalValues(ValuesGeneratorObjectConfigurationProperty.java:75) [classes/:?]
  11. at com.atlassian.configurable.ObjectConfigurationPropertyImpl.entrySet(ObjectConfigurationPropertyImpl.java:266) [classes/:?]
  12. at com.atlassian.jira.plugin.corereports.web.action.ConfigureReport.mapAndConvertToList(ConfigureReport.java:383) [?:?]
  13. at com.atlassian.jira.plugin.corereports.web.action.ConfigureReport.access$000(ConfigureReport.java:53) [?:?]
  14. at com.atlassian.jira.plugin.corereports.web.action.ConfigureReport$ObjectConfigurationField.getValues(ConfigureReport.java:440) [?:?]
  15. ... 387 more

Can someone please help me to solve this problem?

答案1

得分: 0

我通过使用类别名为 "projectRapidViewServiceImpl" 的捆绑包来解决了这个问题,使用了类 ProjectRapidViewServiceImpl 的实例。

  1. private com.atlassian.greenhopper.service.rapid.ProjectRapidViewService getRapidViewManager() throws InvalidSyntaxException {
  2. ApplicationContext appCtx = (ApplicationContext) getGreenHopperAppCtx();
  3. if (appCtx != null) {
  4. return (ProjectRapidViewServiceImpl) appCtx.getBean("projectRapidViewServiceImpl");
  5. }
  6. return null;
  7. }

而这个类拥有一个名为 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"

  1. private com.atlassian.greenhopper.service.rapid.ProjectRapidViewService getRapidViewManager() throws InvalidSyntaxException {
  2. ApplicationContext appCtx = (ApplicationContext) getGreenHopperAppCtx();
  3. if (appCtx != null) {
  4. return (ProjectRapidViewServiceImpl) appCtx.getBean(&quot;projectRapidViewServiceImpl&quot;);
  5. }
  6. return null;
  7. }

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.

huangapple
  • 本文由 发表于 2020年3月16日 22:40:57
  • 转载请务必保留本文链接:https://java.coder-hub.com/60707988.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定