How can I clone (or add) attachements with new CreateAttachmentParamsBean ?

Michel KATZ July 6, 2014

Hello,

I'm trying to clone attachments from issue to newIssue with this function.

I'm in Jira 6.2

But I receive an error.

Function

CopyAttach = { Issue issue, MutableIssue newIssue ->
attachmentManager = componentManager.getAttachmentManager()
pathManager = componentManager.getAttachmentPathManager()
attachmentManager.getAttachments(issue).each {attachment ->
filePath = PathUtils.joinPaths(pathManager.attachmentPath, issue.projectObject.key, issue.key, attachment.id.toString())
log.debug("*** CopyIssue :: filePath = $filePath")
atFile = new File(filePath)
log.debug("*** CopyIssue :: New : OK")
if (atFile.exists()) {
try {
if (atFile.canRead()) {
log.debug("*** CopyIssue :: read : OK")
CreateAttachmentParamsBean bean = new CreateAttachmentParamsBean(atFile,attachment.filename,attachment.mimetype, attachment.author, newIssue , false , false, null, attachment.created, true)
attachmentManager.createAttachment(bean)
log.debug("*** CopyIssue :: attachment : OK")
}
}
catch (SecurityException se) {
log.debug("*** CopyIssue :: Could not read attachment file. Not copying. (${se.message})")
}
}
else {
log.debug("*** CopyIssue :: Attachment file does not exist where it should. Not copying.")
}
}
}

Error

2014-07-07 17:13:03,842 http-bio-8080-exec-19 ERROR FAB055 1033x8965x1 1y2tkcp 172.24.21.108 /secure/CommentAssignIssue.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.atlassian.jira.issue.attachment.CreateAttachmentParamsBean(java.io.File, java.lang.String, java.lang.String, java.lang.String, com.atlassian.jira.issue.IssueImpl, java.lang.Boolean, java.lang.Boolean, java.util.LinkedHashMap, java.sql.Timestamp, java.lang.Boolean)
2014-07-07 17:13:03,842 http-bio-8080-exec-19 ERROR FAB055 1033x8965x1 1y2tkcp 172.24.21.108 /secure/CommentAssignIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Script post-function failed on DMI-8882: \\jira\Jira\AppData\Scripts\CopyIssue.groovy
javax.script.ScriptException: javax.script.ScriptException: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.atlassian.jira.issue.attachment.CreateAttachmentParamsBean(java.io.File, java.lang.String, java.lang.String, java.lang.String, com.atlassian.jira.issue.IssueImpl, java.lang.Boolean, java.lang.Boolean, java.util.LinkedHashMap, java.sql.Timestamp, java.lang.Boolean)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:103)
at javax.script.AbstractScriptEngine.eval(Unknown Source)
at com.onresolve.jira.groovy.GroovyRunner.runFile(GroovyRunner.java:102)
at com.onresolve.jira.groovy.GroovyRunner.run(GroovyRunner.java:62)
at com.onresolve.jira.groovy.GroovyFunctionPlugin.execute(GroovyFunctionPlugin.java:38)
at com.opensymphony.workflow.AbstractWorkflow.executeFunction(AbstractWorkflow.java:1050)
at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1446)
at com.opensymphony.workflow.AbstractWorkflow.doAction(AbstractWorkflow.java:564)
at com.atlassian.jira.workflow.OSWorkflowManager.doWorkflowActionInsideTxn(OSWorkflowManager.java:957)
at com.atlassian.jira.workflow.OSWorkflowManager.doWorkflowAction(OSWorkflowManager.java:912)
at com.atlassian.jira.bc.issue.DefaultIssueService.transition(DefaultIssueService.java:450)

What is missing ?

Thx

1 answer

1 accepted

0 votes
Answer accepted
Andreas Ebert
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 7, 2014

In the constructor of CreateAttachmentParamsBean you are using attachment.author to get the user. That method returns the user name as String, but the constructor expects an ApplicationUser. Use attachment.authorObject instead.

Michel KATZ July 7, 2014

Great, Thank you.

br,

Michel Katz

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events