Possibility to sync Jira comments only if the start with a specific string

Originally asked by Gabriele Centinaro on 23 March 2021 (original question)


Hi, I want comments to be sync only if they start with a specific string, something like ‘TO_SYNC’.
Is it possible to do that with some kind of string comparison?


Answer by Gabriele Centinaro on 23 March 2021

I did this in the replica site and it works:

issue.comments = commentHelper.mergeComments(issue, replica,
{
                       comment ->
                       comment.body =
                          comment.author.displayName +
                                  " commented: \n" +
                          comment.body.replaceAll("TO_SYNC", "") + "\n"
                    }
)

Comments:

Francis Martens (Exalate) commented on 23 March 2021

Excellent

You do have the choice to replace the label on the source or the target.
I would prefer to do it on the source, because it might be that you want to change that behaviour in the future. Having this logic on the target creates a dependency which is more difficult to maintain.

Anyway - thanks for finding a solution.

Gabriele Centinaro commented on 23 March 2021

Thanks for the suggestion, will look into it.

Answer by Francis Martens (Exalate) on 23 March 2021

Absolutely.

In the outgoing sync. make sure that replica.comments only contain the comments which have ‘TO_SYNC’

Outgoing SYNC - Untested

replica.comments = issue.comments.findAll { it.body.contains("TO_SYNC") }

Give it a try


Comments:

Gabriele Centinaro commented on 23 March 2021

Additional step, can I remove the “TO_SYNC” from the comment before synchronizing it?

Francis Martens (Exalate) commented on 23 March 2021

Yes you can

Outgoing Sync - Untested

// filter out comments
def transferComments = issue.comments.findAll { it.body.contains("TO_SYNC") }

// remove the to_sync label from the body before sending it
replica.comments = tranferComments.each { it.replaceAll("TO_SYNC", "") }
Gabriele Centinaro commented on 23 March 2021

Great, Thanks!

Gabriele Centinaro commented on 23 March 2021

The sync gives this error on the replaceAll part:

  • Impact: RELATION

  • Local entity: FLOR-29128

  • Remote entity: DMVAEPIC-61

  • Connection: Epic-DMVA_to_FLOR

  • Error type: Incoming script error

  • Error Creation Time: 2021-03-23 11:11:42.0

  • Error Detail Message: No signature of method: com.exalate.basic.domain.hubobject.v1.BasicHubComment.replaceAll() is applicable for argument types: (String, String) values: [TO_SYNC, ]

  • Error Stack Trace: com.exalate.api.exception.script.ScriptException: No signature of method: com.exalate.basic.domain.hubobject.v1.BasicHubComment.replaceAll() is applicable for argument types: (String, String) values: [TO_SYNC, ] at com.exalate.error.services.ScriptExceptionCategoryService.categorizeProcessorAndIssueTrackerExceptionsIntoScriptExceptions(ScriptExceptionCategoryService.scala:32) at com.exalate.processor.ExalateProcessor.executeProcessor(ExalateProcessor.java:47) at com.exalate.processor.jira.JiraCreateReplicaProcessor.executeDataFilter(JiraCreateReplicaProcessor.java:312) at com.exalate.processor.jira.JiraCreateReplicaProcessor.createHubReplica(JiraCreateReplicaProcessor.java:189) at com.exalate.replication.out.schedule.EventSchedulerService.scheduleSyncEvent(EventSchedulerService.java:848) at com.exalate.replication.out.schedule.EventSchedulerService.scheduleSyncEventNoLock(EventSchedulerService.java:739) at com.exalate.replication.out.schedule.EventSchedulerService.scheduleSyncEvents(EventSchedulerService.java:731) at com.exalate.replication.out.schedule.EventSchedulerServiceLockAware.lambda$scheduleSyncEvents$10(EventSchedulerServiceLockAware.java:227) at com.exalate.node.util.concurrent.ClusteredSensitiveExecutorService.executeHandlingLocks(ClusteredSensitiveExecutorService.java:54) at com.exalate.replication.out.schedule.EventSchedulerServiceLockAware.executeHandlingLocksForgetIfNotLocked(EventSchedulerServiceLockAware.java:247) at com.exalate.replication.out.schedule.EventSchedulerServiceLockAware.executeHandlingLocksForgetIfNotLocked(EventSchedulerServiceLockAware.java:236) at com.exalate.replication.out.schedule.EventSchedulerServiceLockAware.scheduleSyncEvents(EventSchedulerServiceLockAware.java:226) at com.exalate.replication.out.eventhandler.IssueEventHandlerService.scheduleDeleteOrUpdateEvents(IssueEventHandlerService.java:198) at com.exalate.replication.out.eventhandler.IssueEventHandlerService.handleEvent(IssueEventHandlerService.java:168) at com.exalate.replication.out.eventhandler.IssueEventHandlerService.handleIssueEvent(IssueEventHandlerService.java:132) at com.exalate.replication.out.eventhandler.IssueEventHandlerTask.run(IssueEventHandlerTask.java:43) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.exalate.basic.domain.hubobject.v1.BasicHubComment.replaceAll() is applicable for argument types: (String, String) values: [TO_SYNC, ] at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:158) at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264) at com.exalate.processor.ExalateProcessor.execute(ExalateProcessor.java:72) at com.exalate.processor.ExalateProcessor.executeProcessor(ExalateProcessor.java:45) … 21 more Caused by: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.exalate.basic.domain.hubobject.v1.BasicHubComment.replaceAll() is applicable for argument types: (String, String) values: [TO_SYNC, ] at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:320) at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:155) … 24 more Caused by: groovy.lang.MissingMethodException: No signature of method: com.exalate.basic.domain.hubobject.v1.BasicHubComment.replaceAll() is applicable for argument types: (String, String) values: [TO_SYNC, ] at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:70) at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:135) at Script182$_run_closure2.doCall(Script182.groovy:19) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:101) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:263) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1041) at groovy.lang.Closure.call(Closure.java:405) at groovy.lang.Closure.call(Closure.java:421) at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2330) at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2315) at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2356) at org.codehaus.groovy.runtime.dgm$186.invoke(Unknown Source) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:244) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:127) at Script182.run(Script182.groovy:19) at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:317) … 25 more

  • **Incoming sync data:**Summary:

      null  
    

Entity Key:

	null(id: null)  

Encoded payload:
null

Francis Martens (Exalate) commented on 23 March 2021

Check out the error message

> com.exalate.basic.domain.hubobject.v1.BasicHubComment.replaceAll() is applicable for argument types: (String, String) values: [TO_SYNC, ]

What is the object replaceAll is being applied on, and what should it be.

Gabriele Centinaro commented on 23 March 2021

I know, I tried the below option, the error goes away but the replace does not work, it transfers also the TO_SYNC part:

replica.comments = transferComments.findAll { it.body.replaceAll(“TO_SYNC”, “”) }

Gabriele Centinaro commented on 23 March 2021

Actually this is what I did but the replace does not work:

:

replica.comments = transferComments.each { it.body.replaceAll(“TO_SYNC”, “”) }

Francis Martens (Exalate) commented on 23 March 2021

Ah

you need to return the object in your each closure like in

replica.comments = transferComments.each {

     it.body.replaceAll("TO_SYNC", "") 
     it
}

(I’m doing this between meetings - so ymmv)

Gabriele Centinaro commented on 23 March 2021

I pasted the above but still it does not remove the TO_SYNC. Whenever you have time, thanks!

Francis Martens (Exalate) commented on 23 March 2021

Try this.

replica.comments = transferComments.each {

     it.body = it.body.replaceAll("TO_SYNC", "") 
     it
}

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.