/src/main/resources/com/onresolve/jira/groovy/canned/workflow/postfunctions/CopyIssueWithAttachments.groovy
Groovy | 53 lines | 36 code | 10 blank | 7 comment | 3 complexity | 81fb35e41053a72d5fad85bea599214c MD5 | raw file
- package com.onresolve.jira.groovy.canned.workflow.postfunctions
-
- import com.atlassian.jira.issue.Issue
- import com.atlassian.jira.issue.MutableIssue
- import com.atlassian.jira.util.PathUtils
-
- /**
- * Created by IntelliJ IDEA.
- * User: jechlin2
- * Date: 01/02/12
- * Time: 15:27
- * To change this template use File | Settings | File Templates.
- */
- class CopyIssueWithAttachments extends AbstractCloneIssue {
-
- Map doScript(Map params) {
- log.debug ("CopyIssueWithAttachments.doScript with params: ${params}");
-
- params = super.doScript (params)
-
- MutableIssue newIssue = params['newIssue'] as MutableIssue
- Issue issue = params['issue'] as Issue
-
- copyAttachments (issue, newIssue)
-
- params
- }
-
-
- protected def copyAttachments(Issue issue, MutableIssue newIssue) {
- def attachmentManager = componentManager.getAttachmentManager()
- def pathManager = componentManager.getAttachmentPathManager()
- attachmentManager.getAttachments(issue).each {attachment ->
- def filePath = PathUtils.joinPaths(pathManager.attachmentPath, issue.projectObject.key, issue.key, attachment.id.toString())
- def atFile = new File(filePath)
- if (atFile.exists()) {
- try {
- if (atFile.canRead()) {
- attachmentManager.createAttachmentCopySourceFile(atFile, attachment.filename,
- attachment.mimetype, attachment.author, newIssue, [:], attachment.created)
- }
- }
- catch (SecurityException se) {
- log.warn("Could not read attachment file. Not copying.")
- }
- }
- else {
- log.warn("Attachment file does not exist where it should. Not copying.")
- }
- }
-
- }
- }