Jira 7 -> 8 componentmanager problem

Csaba Horváth September 18, 2019

Hello All,

Please help me, we've just upgraded from Jira 7 to Jira 8.

1 of our scripts failed. ComponentManager no longer usable. Could you help me how can I revive the script?

ChangeHistoryManager changeHistoryManager = (ChangeHistoryManager)ComponentManager.getComponentInstanceOfType(ChangeHistoryManager.class);

The error message: [Static type checking] - The variable [ComponentManager] is undeclared.

Screenshot_288.png

Thank you!

 

 

The full script

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.changehistory.ChangeHistory;
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager;
import com.atlassian.jira.issue.status.Status;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.ofbiz.core.entity.GenericValue;

Logger log = LoggerFactory.getLogger("Previous Status Field");

log.debug("Issue " + issue.getKey());
ChangeHistoryManager changeHistoryManager = (ChangeHistoryManager)ComponentManager.getComponentInstanceOfType(ChangeHistoryManager.class);
List changeHistory = changeHistoryManager.getChangeHistories(issue);
for (int i = changeHistory.size() - 1; i >= 0; i--)
{
ChangeHistory changeHistoryItem = (ChangeHistory)changeHistory.get(i);

List changeItemBeans = changeHistoryItem.getChangeItems();
Iterator it = changeItemBeans.iterator();
while (it.hasNext())
{
GenericValue change = (GenericValue)it.next();
String changedField = change.getString("field");
if (changedField.equalsIgnoreCase("status"))
{
String oldStatus = change.getString("oldstring");
return oldStatus;
}
}
}
return null;

2 answers

0 votes
Adarsh Kesharwani
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 1, 2020

Some Details to above:

ComponentManager has been deprecated since JIRA 7.11, which is the reason that you cannot resolve this class any longer.

You should migrate to using ComponentAccessor instead-> https://docs.atlassian.com/software/jira/docs/api/7.11.0/com/atlassian/jira/component/ComponentAccessor.html


getComponent and  getComponentByType are two key methods to load components of a specific type. Sample code is below:

Old Code:

RemoteIssueLinkService remoteIssueLinkService = ComponentManager.getComponentInstanceOfType(RemoteIssueLinkService.class)

RemoteIssueLinkService.RemoteIssueLinkListResult links = remoteIssueLinkService.getRemoteIssueLinksForIssue(currentUser, issue)

New Code:

ComponentAccessor.getComponentOfType(RemoteIssueLinkService.class).getRemoteIssueLinksForIssue(currentUser, issue);

0 votes
Ilya Turov
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.
September 18, 2019

Hello, 

use ComponentAccessor instead

Suggest an answer

Log in or Sign up to answer