Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.atlassian.jira.ComponentManager
- import com.atlassian.jira.issue.CustomFieldManager
- import com.atlassian.jira.issue.Issue
- import com.opensymphony.user.Group
- import com.atlassian.jira.issue.MutableIssue
- import com.atlassian.jira.config.SubTaskManager
- import org.ofbiz.core.entity.GenericValue
- import com.opensymphony.user.User
- import com.atlassian.core.user.UserUtils
- import com.atlassian.jira.user.util.UserManager
- import com.opensymphony.workflow.WorkflowContext
- import com.atlassian.jira.security.util.GroupSelectorUtils
- ComponentManager componentManager = ComponentManager.getInstance()
- CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
- def issueFactory = componentManager.getIssueFactory()
- def issueManager = componentManager.getIssueManager()
- def indexManager = componentManager.getIndexManager()
- def groupCf = customFieldManager.getCustomFieldObjectByName("Kompetenzcluster") // name of group CF
- def UserList = []
- String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller()
- User currentUserObj = UserUtils.getUser(currentUser)
- GroupSelectorUtils util = (GroupSelectorUtils) ComponentManager.getInstance().getContainer().getComponentInstanceOfType(GroupSelectorUtils.class)
- //Group group = issue.getCustomFieldValue(groupCf) as Group
- issue.getCustomFieldValue(groupCf).each {Object group ->
- if (group) {
- Group groupObj = util.getGroups((String) group)
- groupObj.getUsers().each {String user ->
- if(!UserList.contains(user) && user != currentUser) {
- MutableIssue newIssue = issueFactory.getIssue()
- newIssue.summary = "$user: " + issue.summary
- newIssue.issueTypeId = '71'
- newIssue.project = issue.project
- newIssue.reporter = UserUtils.getUser(user)
- newIssue.assignee = UserUtils.getUser(user)
- newIssue.assigneeId = user
- newIssue.priority = issue.priority
- //newIssue.affectedVersions = issue.affectedVersions
- //newIssue.fixVersions = issue.fixVersions
- Map<String,Object> newIssueParams = ["issue":newIssue] as Map<String,Object>
- //User currentUser = componentManager.getJiraAuthenticationContext().getUser()
- GenericValue newIssueGv = issueManager.createIssue(currentUserObj, newIssueParams)
- indexManager.reIndex(newIssueGv);
- SubTaskManager subTaskManager = componentManager.getSubTaskManager()
- subTaskManager.createSubTaskIssueLink(issue, newIssue, componentManager.getJiraAuthenticationContext().getUser())
- indexManager.reIndex(newIssueGv);
- indexManager.reIndex(issue);
- UserList.add(user)
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement