Hi,
We are using jira 5.1 with Script Runner 2.0.6,
When i tried to upgrade to 2.1.15 ( to enable "issueFunction" in JQL ) i got the follwoing error in a script which we are using :
----------------
2014-02-06 11:45:10,638 TP-Processor3 ERROR odedpr 705x313x1 3xla21 172.17.13.173 /secure/WorkflowUIDispatcher.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
groovy.lang.MissingMethodException: No signature of method: com.onresolve.jira.groovy.canned.workflow.postfunctions.CreateICSubtasks.getUser() is applicable for argument types: (java.util.HashMap) values: [[args:[class.name:com.onresolve.jira.groovy.GroovyFunctionPlugin, ...], ...]]
Possible solutions: getLog(), getUserUtil(), getName(), getAt(java.lang.String)
----------------
I'd appriciate any help.
package com.onresolve.jira.groovy.canned.workflow.postfunctions
import com.atlassian.jira.config.ConstantsManager
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.*
import com.atlassian.jira.issue.issuetype.*
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.ErrorCollection
import com.atlassian.jira.util.SimpleErrorCollection
import com.onresolve.jira.groovy.canned.CannedScript
import com.onresolve.jira.groovy.canned.utils.CannedScriptUtils
import com.opensymphony.workflow.loader.ActionDescriptor
import com.opensymphony.workflow.loader.StepDescriptor
import com.atlassian.jira.ComponentManager
import org.ofbiz.core.entity.GenericValue
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.security.roles.ProjectRole
class CreateICSubtasks extends AbstractCloneIssue implements CannedScript {
public final static String FIELD_ROLE_NAME = "Assigned Role"
public final static String FIELD_UPDATE_TYPE = "Update Type"
private def toOpen = [
"New Installer": [["Technical task", "Developer", "IC Developer"], ["Project Setup", "Project Setup", "Project Setup"], ["Offer Flow", "Offer Manager", "Flow Manager"]],
"New DLM": [["Technical task", "Developer", "IC Developer"], ["Project Setup", "Project Setup", "Project Setup"], ["Offer Flow", "Offer Manager", "Flow Manager"]],
"New Offer": [["Technical task", "Developer", "IC Developer"]],
"Update": [["Technical task", "Developer", "IC Developer"]]
]
protected Boolean isUpdate(Issue issue) {
CustomField cf = componentManager.getCustomFieldManager().getCustomFieldObjectByName(FIELD_UPDATE_TYPE)
return (issue?.getCustomFieldValue(cf) != null)
}
String getName() {
return "Auto-creates sub-tasks for installcore projects."
}
String getDescription() {
return "Create subtasks used for InstallCore projects. Only supports New projects."
}
List getCategories() {
["Function"]
}
List getParameters(Map params) {
[]
}
public ErrorCollection doValidate(Map params, boolean forPreview) {
SimpleErrorCollection errorCollection = new SimpleErrorCollection()
return errorCollection
}
protected IssueType getIssueTypeByName(String name) {
IssueType rv = null
componentManager.getConstantsManager().getAllIssueTypeObjects().each() {
type ->
if (type.name == name) {
rv = type
}
}
return rv
}
void AddIssue(MutableIssue oldIssue, IssueType issueType, User assignee, ProjectRole role, User reporter, User currentUserObj) {
if (issueType == null) {
return
}
IssueManager issueMgr = componentManager.getIssueManager()
def wasIndexing = ImportUtils.indexIssues
ImportUtils.indexIssues = true
IssueFactory issueFactory = ComponentManager.getInstance().getIssueFactory()
MutableIssue newIssue = issueFactory.getIssue()
newIssue.projectObject = oldIssue.projectObject
newIssue.issueTypeObject = issueType
newIssue.priorityObject = oldIssue.priorityObject
newIssue.summary = "AUTO-CREATED: " + issueType.name + " - " + oldIssue.summary
if (assignee) {
newIssue.assignee = assignee
}
newIssue.reporter = reporter
def cf = ComponentManager.getInstance().getCustomFieldManager().getCustomFieldObjectByName(FIELD_ROLE_NAME)
newIssue.setCustomFieldValue(cf, role.name)
Issue newIssueGv = issueMgr.createIssueObject(currentUserObj, newIssue)
indexManager.reIndex(newIssueGv);
ImportUtils.indexIssues = wasIndexing
SubTaskManager subTaskManager = componentManager.getSubTaskManager()
subTaskManager.createSubTaskIssueLink(oldIssue, newIssueGv, currentUserObj)
}
Map doScript(Map params) {
Issue issue = params['issue'] as MutableIssue
if (! issue.subTasks.size() == 0) {
log.warn ("This issue ($issue) already had sub-tasks... doing nothing.")
return params
}
if (issue.getIssueTypeObject().isSubTask()) {
log.warn ("This issue ($issue) is already a sub-task... doing nothing.")
return params
}
User currentUserObj = getUser(params)
def cf = ComponentManager.getInstance().getCustomFieldManager().getCustomFieldObjectByName("Account Manager")
User reporter = issue.getCustomFieldValue(cf) ?: currentUserObj
ProjectRoleManager projectRoleManager = (ProjectRoleManager) componentManager.getComponentInstanceOfType(ProjectRoleManager.class);
String type = issue.issueTypeObject.name
type = isUpdate(issue) ? "Update" : type
log.warn("IsUpdate " + isUpdate(issue) + " :--> $type")
toOpen[type].each() {
task ->
String issueTypeName = task[0]
String assigneeField = task[1]
String roleName = task[2]
log.debug("Want to open a $issueTypeName for $assigneeField")
cf = ComponentManager.getInstance().getCustomFieldManager().getCustomFieldObjectByName(assigneeField)
log.debug("Assignee CF is " + cf.inspect())
User assignee = issue.getCustomFieldValue(cf)
ProjectRole role = projectRoleManager.getProjectRole(roleName)
IssueType issueType = getIssueTypeByName(issueTypeName)
log.debug("Really going to open a " + issueType?.name + " for user " + assignee?.name + " and role " + role?.name)
AddIssue(issue, issueType, assignee, role, reporter, currentUserObj)
}
return params
}
String getDescription(Map params, boolean forPreview) {
return "Will create InstallCore subtasks"
}
public Boolean isFinalParamsPage(Map params) {
true
}
}