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.
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;
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);
Hello,
use ComponentAccessor instead
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.