How to get IssueManager properly ?

Albert Cameron August 1, 2021

I always got the IssueManager the following way:

ComponentAccessor.getIssueManager()

Now in my friend's code I saw another way:

@JiraImport
private IssueManager issueManager;

 So is there any difference in the 2 approaches ? What is better ? I really liked using ComponentAccessor.

In general I find it quite interesting that there are always at least 2 ways to get a specific object.  For example to get the attachments of an issue , you can get it from issue itself all via the AttachmentManager.

 

1 answer

0 votes
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 1, 2021

Hi @Albert Cameron the second way is clearer as it uses dependency injection principle of OSGi  framework which is used by Jira (https://dzone.com/articles/osgi-dependency-injection). So I really suggest you to use @JiraImport annotation :)

More information about annotations, OSGi and Spring Scanner is here: https://bitbucket.org/atlassian/atlassian-spring-scanner/src/master/

Albert Cameron August 10, 2021
public class MyClassextends AbstractJiraFunctionProvider
{
private static final Logger LOGGER = LoggerFactory.getLogger(MyClass.class);

@JiraImport
private WorkflowManager workflowManager;
@JiraImport
private JiraAuthenticationContext authenficationContext;
@JiraImport
private IssueManager issueManager;
@JiraImport
private AttachmentManager attachmentManager;

 In this case all the @JiraImport annotations were not working. All the objects were null. So I had to use ComponentAccessor. Am I missing an annotation above the class. Is the class not registered as a possible bean ? 

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 10, 2021

Can you check what spring-scanner dependencies do you use in your pom.xml file? It should be something like:


<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-annotation</artifactId>
<version>${atlassian.spring.scanner.version}</version>
<scope>provided</scope>
</dependency>
Albert Cameron August 10, 2021
<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-annotation</artifactId>
<version>${atlassian.spring.scanner.version}</version>
<scope>provided</scope>
</dependency>
<atlassian.spring.scanner.version>2.0.0</atlassian.spring.scanner.version>

 and also I use this:

<plugin>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-maven-plugin</artifactId>
<version>${atlassian.spring.scanner.version}</version>
<executions>
<execution>
<goals>
<goal>atlassian-spring-scanner</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
<configuration>
<scannedDependencies>
<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-external-jar</artifactId>
</dependency>
</scannedDependencies>
<verbose>false</verbose>
</configuration>
</plugin>
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 10, 2021

Ok, I'm using version 2.1.3 on one of our older projects. First question is, what version of Jira do you use?

I found one postfuncion which uses @Autowired annotation on constructor and it looks like


import com.atlassian.jira.workflow.WorkflowManager;
import com.atlassian.jira.workflow.function.issue.AbstractJiraFunctionProvider;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import com.opensymphony.module.propertyset.PropertySet;
import com.opensymphony.workflow.WorkflowException;

import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;


public class ApprovalPostFunction extends AbstractJiraFunctionProvider {

private final WorkflowManager workflowManager;

@Autowired
public ApprovalPostFunction(@ComponentImport final WorkflowManager workflowManager) {

this.workflowManager = workflowManager;
}

@Override
public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
// execute function here
}
}
Albert Cameron August 11, 2021

We are using   Jira V8.8.1.

@JiraImport should really work. I do not wanna do Constructor Injection

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 11, 2021
Albert Cameron August 11, 2021

Ok thanks. Maybe it is more important to have an annotation above the class 

issuecrud/IssueCRUD.java at master · loganrobertclemons/issuecrud · GitHub

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 11, 2021

@Scanned annotation is not used for SpringScanner 2.x.x

2021-08-12_07-03.png

Suggest an answer

Log in or Sign up to answer