Can anyone help me move away from jira.componentManager

Nicole Downes
Contributor
November 5, 2020

Can anyone help me move away from jira.componentManager,  and replace with alternative in the appropriate places, particularly lines 1 and 20 (and any others which you deem necessary)

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.security.roles.ProjectRole
import com.atlassian.jira.security.roles.ProjectRoleActors
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue


String projectField = "Architect"

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def field = customFieldManager.getCustomFieldObjectByName(projectField)

def projectAffected = customFieldManager.getCustomFieldObjectByName("Affected Project")
def projectAffectedValue = (issue.getCustomFieldValue(projectAffected).toString()).replaceAll("<[^>]+>| |\n", "")
ComponentManager componentManager = ComponentManager.getInstance()
ProjectManager projectManager = ComponentAccessor.getProjectManager()
ProjectRoleManager projectRoleManager = ComponentManager.getComponentInstanceOfType(ProjectRoleManager.class) as ProjectRoleManager

// name of role here
ProjectRole projectRole = projectRoleManager.getProjectRole(projectField)
ProjectRoleActors actors = null

def valueField = issue.getCustomFieldValue(field)

IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
String projectSetName = "empty"
String fred = "empty"

if(projectAffectedValue.toString() in null) {}
else {
projectManager.getProjectObjects().each {
Project project ->
projectSetName = project.getName()
if (projectSetName.equalsIgnoreCase(projectAffectedValue.toString())) {
fred = "in"
actors = projectRoleManager.getProjectRoleActors(projectRole, project)
}
}
if (actors in null) { }
else {
fred = "else"
field.updateValue(null, issue, new ModifiedValue(actors.getUsers().toList()?.first(),actors.getUsers().toList()?.first()), changeHolder);
}

}

I am using datacenter 8.4.2 and scriptrunner 6.13.0

1 answer

0 votes
Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 6, 2020

Hi @Nicole Downes,

below code may help you

1. import statement --> import com.atlassian.jira.bc.projectroles.ProjectRoleService

2. Getting Project Role Service/Manager

def projectRoleService =ComponentAccessor.getComponent(ProjectRoleService);
def projectRoleManager =ComponentAccessor.getComponent(ProjectRoleManager);
def projectManager =ComponentAccessor.getComponent(ProjectManager);

 BR,

Leo

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events