Based on some input from a table, have to create JIRA ticket, most of the parameters i am able to fetch, and create the ticket as well. But not able to proceed further while trying to set the component. Here is the code i am using. And below is the exception while trying to set the component value.
import groovy.sql.Sql
import java.sql.Driver
import com.atlassian.mail.Email
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.web.bean.PagerFilter
import org.ofbiz.core.entity.ConnectionFactory
import org.ofbiz.core.entity.DelegatorInterface
import java.sql.Connection
import java.util.Date
import java.time.*
import java.lang.String
import java.util.Calendar;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.issue.context.IssueContext
import com.atlassian.jira.issue.context.IssueContextImpl
import com.atlassian.jira.issue.fields.config.manager.PrioritySchemeManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.bc.project.component.ProjectComponentManager;
def delegator = (DelegatorInterface) ComponentAccessor.getComponent(DelegatorInterface)
String helperName = delegator.getGroupHelperName("default")
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def project
def issueContext
def priorityId
def issueInputParameters
def validationResult
def issueType
String assignee
def description
// user with that user key will be the reporter of the issue
final reporterKey = 'auser'
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def prioritySchemeManager = ComponentAccessor.getComponent(PrioritySchemeManager)
def issueService = ComponentAccessor.issueService
def constantsManager = ComponentAccessor.constantsManager
def reporter = ComponentAccessor.userManager.getUserByKey(reporterKey) ?: loggedInUser
try{
Connection conn1 = ConnectionFactory.getConnection(helperName)
Sql sql2 = new Sql(conn1)
output = sql2.rows("select id, reporter, project, component, summary, description, issuetype, priority, request_dt, status, nvl(assignee,'-1') assignee from tickletTable where status = 'R'")
output.each {
result = it as Map<String,String>
project = ComponentAccessor.projectManager.getProjectObjByKey(result[2])
assert project : "Could not find project with key $projectKey"
issueContext = new IssueContextImpl(project, issueType) as IssueContext
priorityId = constantsManager.priorities.findByName(result[7])?.id ?: prioritySchemeManager.getDefaultOption(issueContext)
issueType = constantsManager.allIssueTypeObjects.findByName(result[6])
def component = ComponentAccessor.getProjectComponentManager().findByComponentName(project.getId(),result[3])
if (component != null)
{
log.warn(" component Found")
issueInputParameters = issueService.newIssueInputParameters().with {
setProjectId(project.id)
setIssueTypeId(issueType.id)
setReporterId(result[1])
setSummary(result[4])
setPriorityId(priorityId)
setAssigneeId(result[10])
setDescription(result[5])
setComponent([component])
}
}
else //when no component found for the project
{
issueInputParameters = issueService.newIssueInputParameters().with {
setProjectId(project.id)
setIssueTypeId(issueType.id)
setReporterId(result[1])
setSummary(result[4])
setPriorityId(priorityId)
setAssigneeId(result[10])
setDescription(result[5])
}
}
validationResult = issueService.validateCreate(loggedInUser, issueInputParameters)
assert validationResult.valid : validationResult.errorCollection
// def result = issueService.create(loggedInUser, validationResult)
//assert result.valid : result.errorCollection
}
sql2.close()
}
catch(Exception e) {
log.warn( e)
}
Exception :
2021-05-28 08:30:54,108 WARN [runner.ScriptBindingsManager]: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.setComponent() is applicable for argument types: (ArrayList) values: [[ProjectComponentImpl { name='C1', description='C1', lead='', assigneeType='1', projectId='10000', id='10500', archived='false' }]]