简体   繁体   English

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

[英]Jira plugin development how to get RapidViewServiceImpl instance

I am developing a Jira report plugin using Java and I need to get an instance of RapidViewServiceImpl class.我正在使用 Java 开发 Jira 报告插件,我需要获取RapidViewServiceImpl类的实例。 If I use the constructor I get a nullPtrException and I think there is another way to get this instance.如果我使用构造函数,我会得到一个 nullPtrException 并且我认为还有另一种方法来获取这个实例。 For example I had exactly the same problem with SprintManager and SprintManagerImpl , and I get the instance as the following:例如,我在SprintManagerSprintManagerImpl遇到了完全相同的问题,我得到的实例如下:

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() .在主函数中,我调用了SprintManager spManager = getSprintManager() I tried the same thing with RapidViewServiceImpl :我用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 ".但是我收到一个错误,说没有名为“ 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?有人可以帮我解决这个问题吗?

I solved the problem by using the class ProjectRapidViewServiceImpl, and I got the instance of this class using the bundle named "projectRapidViewServiceImpl"我通过使用类 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;
}

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.这个类有一个名为findRapidViewsByProject(com.atlassian.jira.user.ApplicationUser user, com.atlassian.jira.project.Project project)的函数findRapidViewsByProject(com.atlassian.jira.user.ApplicationUser user, com.atlassian.jira.project.Project project)它返回与项目相关的 RapidViews 列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM