Page History
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
//change the projectKey! if(firstSync){ // Set type name from source entity, if not found set a default workItem.projectKey = "Mathieu" workItem.typeName = nodeHelper.getIssueType(replica.type?.name)?.name ?: "Task"; } workItem.summary = replica.summary workItem.attachments = attachmentHelper.mergeAttachments(workItem, replica) workItem.labels = replica.labels workItem.priority = replica.priority def processInlineImages = { str -> def processUnescapedLtGtTags = { setInlineImage(def comment){ // List of possible regex paterns def counterpatternList = 0 while (counter < 1000) { [ //def pattern = /filename=#(.+?)# -->/ def matcher = (str =~ /<p><!-- inline image filename=#(.+*?)##<\/a> -->/) if (matcher.size() < 1) { break; } ><\/p>/, def match = matcher[0] if (match.size() < 2) { break; } //log.error("replica.attachments=${replica.attachments}") def attId = replica.attachments.find { it.filename?.equals(match[1]) }?.remoteId if (!attId) { log.error("""Could not find attachment with name ${match[1]}, known names: ${replica.attachments.filename}, match: ${replica.attachments.find { it.filename?.equals(match[1]) }} """) str = str.replace(match[0], """?s)<!-- inline processed image filename=#${match[1]}# -->""".toString()) } else { def tmpStr = str.replace(match[0], """<img src="/secure/attachment/${attId}/${attId}_${match[1]}" />""".toString()) if (tmpStr == str) { break; } str = tmpStr } counter++ } str } def processLtGtTags = { def counter = 0 while (counter < 1000) { def matcher = (str =~ /filename=#(.+?)# -->/) if (matcher.size() < 1) { break; } def match = matcher[0] if (match.size() < 2) { break; } def attId = replica.attachments.find { it.filename?.equals(match[1]) }?.remoteId if (!attId) { log.error("""Could not find attachment with name ${match[1]}.*?)-->/ , known names: ${replica.attachments.filename}, match: ${replica.attachments.find { it.filename?.equals(match[1]) }} """) str = str.replace(match[0], """</<p><!-- inline processed image filename=#${match[1]}# -->""".toString()) } else { def tmpStr = str.replace(match[0], """<img src="/secure/attachment/${attId}/${attId}_${match[1]}" />""".toString()) if (tmpStr == str) { break; } str = tmpStr#(.*?)#<\/a> --><\/p>/, } counter++ } str } def processNoImage = { def counter = 0 while (counter < 1000) { def matcher = (str =~ /filename=#(.+?)# -->/) if (matcher.size() < 1) { break;] def pattern } = null def matchmatcher = matcher[0]null if (match.size() < 2) { break;patternList.each{ p -> } def filename = match[2] def attId = replica.attachments.find { it.filename?.equals(filename) }?.remoteId matcher = comment =~ p if (!attId) { log.error("""Could not find attachment with name ${filename}, known names: ${replica.attachments.filename}, match: ${replica.attachments.find { it.filename?.equals(filename) }} """) str = str.replace(match[0], """<img src="/images/icons/attach/noimage.png" processed imagetext="$filename|thumbnail" align="absmiddle" border="0" />""".toString()) } else (matcher.find()){ def tmpStrmatcher = str.replace(match[0], """<img src="/secure/attachment/${attId}/${attId}_${filename}" />""".toString()) if (tmpStr == str) { break; } str = tmpStr comment =~ p } counter++ } str } def processImgTagsWithIdsinlineImage = { def counter = 0 while (counter < 1000) { def matcher = (str =~ /filename=#(.+?)# -->/) "" if (matcher.sizefind() < 1) { return str } def match = matcher[0] //println("match[1]=$match[1]") if (match.size() < 2) { // match[0]=<img src="/rest/api/3/attachment/content/36820"> match[1]=36820 return str } def attId = match[1] def attachment = replica.attachments.find { (it.remoteId as String) == ( attId as String ) } if (!attachment) { log.error("""Could not find attachment with id ${attId}, known ids: ${replica.attachments.remoteId}, match: ${replica.attachments.find { (it.remoteId as String) == ( attId as String ) }} """) str = str.replace(match[0], """<img src="/rest/api/3/attachment/content/${attId}" processed />""".toString())it.filename?.equals(match[1]) }?.remoteId } else { def tmpStr = strinlineImage = comment.replace(match[0], """<img src="/secure/attachment/${attId}/${attId}_${attachment.filenamematch[1]}" />""".toString()) if (tmpStr == str) }else{ break; return comment } str = tmpStr } counter++ } str } //log.error("#processimages 0 $str") str = processUnescapedLtGtTags() //log.error("#processimages 1 $str") str = processLtGtTags() //log.error("#processimages 2 $str") str = processNoImage() //log.error("#processimages 3 $strinlineImage = inlineImage.replaceAll("<!-- inline image", "").replaceAll("<!-- inline image", "") str = processImgTagsWithIds() log.error("#processimages $str") str } return inlineImage } workItem.comments = commentHelper.mergeComments(workItem, replica, { comment -> def attrAuthor = comment.author?.displayName ?: "Default-" comment.body = "<b> ${attrAuthor} said:</b> " + comment.body comment.body = processInlineImages setInlineImage(comment.body) comment }) workItem.description = processInlineImages(replica.description) |
Thank you.
Kind regards,
Mathieu Lepoutre
...