Advertisement
Guest User

CreateSubTask

a guest
Feb 14th, 2012
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 3.00 KB | None | 0 0
  1. import com.atlassian.jira.ComponentManager
  2. import com.atlassian.jira.issue.CustomFieldManager
  3. import com.atlassian.jira.issue.Issue
  4. import com.opensymphony.user.Group
  5. import com.atlassian.jira.issue.MutableIssue
  6. import com.atlassian.jira.config.SubTaskManager
  7. import org.ofbiz.core.entity.GenericValue
  8. import com.opensymphony.user.User
  9. import com.atlassian.core.user.UserUtils
  10. import com.atlassian.jira.user.util.UserManager
  11. import com.opensymphony.workflow.WorkflowContext
  12. import com.atlassian.jira.security.util.GroupSelectorUtils
  13.  
  14. ComponentManager componentManager = ComponentManager.getInstance()
  15. CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
  16. def issueFactory = componentManager.getIssueFactory()
  17. def issueManager = componentManager.getIssueManager()
  18. def indexManager = componentManager.getIndexManager()
  19. def groupCf = customFieldManager.getCustomFieldObjectByName("Kompetenzcluster") // name of group CF
  20. def UserList = []
  21. String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller()
  22. User currentUserObj = UserUtils.getUser(currentUser)
  23. GroupSelectorUtils util = (GroupSelectorUtils) ComponentManager.getInstance().getContainer().getComponentInstanceOfType(GroupSelectorUtils.class)
  24.  
  25. //Group group = issue.getCustomFieldValue(groupCf) as Group
  26. issue.getCustomFieldValue(groupCf).each {Object group ->
  27.  
  28.         if (group) {
  29.             Group groupObj = util.getGroups((String) group)
  30.             groupObj.getUsers().each {String user ->
  31.  
  32.                 if(!UserList.contains(user) && user != currentUser) {
  33.  
  34.                         MutableIssue newIssue = issueFactory.getIssue()
  35.                         newIssue.summary = "$user: " + issue.summary
  36.                         newIssue.issueTypeId = '71'
  37.                         newIssue.project = issue.project
  38.                         newIssue.reporter = UserUtils.getUser(user)
  39.                         newIssue.assignee = UserUtils.getUser(user)
  40.                         newIssue.assigneeId = user
  41.                         newIssue.priority = issue.priority
  42.                         //newIssue.affectedVersions = issue.affectedVersions
  43.                         //newIssue.fixVersions = issue.fixVersions
  44.  
  45.                         Map<String,Object> newIssueParams = ["issue":newIssue] as Map<String,Object>
  46.                         //User currentUser = componentManager.getJiraAuthenticationContext().getUser()
  47.                         GenericValue newIssueGv = issueManager.createIssue(currentUserObj, newIssueParams)
  48.                         indexManager.reIndex(newIssueGv);
  49.  
  50.                         SubTaskManager subTaskManager = componentManager.getSubTaskManager()
  51.                         subTaskManager.createSubTaskIssueLink(issue, newIssue, componentManager.getJiraAuthenticationContext().getUser())
  52.  
  53.                         indexManager.reIndex(newIssueGv);
  54.                         indexManager.reIndex(issue);
  55.  
  56.                         UserList.add(user)
  57.  
  58.                 }
  59.             }
  60.         }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement