I'm trying to add a groovy script to custom listener (Admin -> Script Listeners), But it looks something I'm missing since the project lead was not added automatically to watcher list. Any help would be much appreciated! Thank you!!!
Below is the groovy script I'm using:
package com.custom
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.watchers.WatcherManager
import com.atlassian.jira.util.ErrorCollection
import com.onresolve.jira.groovy.canned.CannedScript
import com.onresolve.jira.groovy.canned.utils.ConditionUtils
import org.apache.log4j.Category
import com.atlassian.crowd.embedded.api.User
import org.ofbiz.core.entity.GenericValue
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.project.Project
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
class AddProjectLeadAsWatcher extends AbstractIssueEventListener {
//Category log = Category.getInstance(AddWatcher.class)
String getName() {
"Adds the project lead as a watcher"
}
public String getHelpUrl() {
"https://studio.plugins.atlassian.com/wiki/display/GRV/Listeners#Listeners-AddWatcher"
}
String getDescription() {
"Adds the project lead as a watcher, if condition applies"
}
List getCategories() {
["Function", "Listener"]
}
List getParameters(Map params) {
[
ConditionUtils.getConditionParameter()
]
}
ErrorCollection doValidate(Map params, boolean forPreview) {
null
}
Map doScript(Map params) {
MutableIssue issue = params['issue'] as MutableIssue
Boolean doIt = ConditionUtils.processCondition(params[ConditionUtils.FIELD_CONDITION] as String, issue, false, params)
if (! doIt) {
return [:]
}
ComponentManager componentManager = ComponentManager.getInstance()
WatcherManager watcherManager = componentManager.getWatcherManager()
IssueManager issueManager=componentManager.getIssueManager()
def projectid=issue.project
ProjectManager projectManager=componentManager.getProjectManager()
Project project=projectManager.getProjectObj(projectid)
User projectlead=project.getProjectLead()
watcherManager.startWatching(projectlead, issue.genericValue)
params
}
String getDescription(Map params, boolean forPreview) {
StringBuffer sb = new StringBuffer()
sb << "Project lead user will be added to watcher list of issue"
if (params[ConditionUtils.FIELD_CONDITION]) {
sb << " if this condition is true:<br><pre>${params[ConditionUtils.FIELD_CONDITION]}</pre>"
}
else {
sb << "."
}
}
Boolean isFinalParamsPage(Map params) {
true
}
}