PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/resources/com/onresolve/jira/groovy/canned/workflow/postfunctions/CopyIssueWithAttachments.groovy

https://bitbucket.org/sorin/jira-plugin-intellij
Groovy | 53 lines | 36 code | 10 blank | 7 comment | 3 complexity | 81fb35e41053a72d5fad85bea599214c MD5 | raw file
  1. package com.onresolve.jira.groovy.canned.workflow.postfunctions
  2. import com.atlassian.jira.issue.Issue
  3. import com.atlassian.jira.issue.MutableIssue
  4. import com.atlassian.jira.util.PathUtils
  5. /**
  6. * Created by IntelliJ IDEA.
  7. * User: jechlin2
  8. * Date: 01/02/12
  9. * Time: 15:27
  10. * To change this template use File | Settings | File Templates.
  11. */
  12. class CopyIssueWithAttachments extends AbstractCloneIssue {
  13. Map doScript(Map params) {
  14. log.debug ("CopyIssueWithAttachments.doScript with params: ${params}");
  15. params = super.doScript (params)
  16. MutableIssue newIssue = params['newIssue'] as MutableIssue
  17. Issue issue = params['issue'] as Issue
  18. copyAttachments (issue, newIssue)
  19. params
  20. }
  21. protected def copyAttachments(Issue issue, MutableIssue newIssue) {
  22. def attachmentManager = componentManager.getAttachmentManager()
  23. def pathManager = componentManager.getAttachmentPathManager()
  24. attachmentManager.getAttachments(issue).each {attachment ->
  25. def filePath = PathUtils.joinPaths(pathManager.attachmentPath, issue.projectObject.key, issue.key, attachment.id.toString())
  26. def atFile = new File(filePath)
  27. if (atFile.exists()) {
  28. try {
  29. if (atFile.canRead()) {
  30. attachmentManager.createAttachmentCopySourceFile(atFile, attachment.filename,
  31. attachment.mimetype, attachment.author, newIssue, [:], attachment.created)
  32. }
  33. }
  34. catch (SecurityException se) {
  35. log.warn("Could not read attachment file. Not copying.")
  36. }
  37. }
  38. else {
  39. log.warn("Attachment file does not exist where it should. Not copying.")
  40. }
  41. }
  42. }
  43. }