Removing applications links with Scriptrunner.

Łukasz Sielski priv January 5, 2021

Hi,

I have the following Scriptrunner Script that used to remove applications links from jira:

 

import com.atlassian.jira.component.ComponentAccessorimport com.onresolve.scriptrunner.runner.customisers.PluginModule

import com.onresolve.scriptrunner.runner.customisers.WithPluginimport com.atlassian.applinks.api.ApplicationLinkService

import com.atlassian.applinks.spi.link.ApplicationLinkDetails
ApplicationLinkService applicationLinkService = ComponentAccessor.getComponent(ApplicationLinkService)

@WithPlugin('com.atlassian.applinks.applinks-plugin')

import com.atlassian.applinks.core.DefaultApplicationLinkService

@PluginModuleDefaultApplicationLinkService defaultApplicationLinkService
applicationLinkService.getApplicationLinks().each{   defaultApplicationLinkService.deleteApplicationLink(it)}

 

It worked in jira 8.5 but stopped working in jira 8.13, in 8.13 I get error 

java.lang.Exception: Can't find plugin module or OSGi service for class: com.atlassian.applinks.core.DefaultApplicationLinkService, check the plugin is installed / enabled / licensed. at com.onresolve.scriptrunner.runner.ScriptRunnerImpl.getPluginComponent(ScriptRunnerImpl.groovy:94) at com.onresolve.scriptrunner.runner.ScriptRunnerImpl$getPluginComponent$2.callStatic(Unknown Source) at Script168.run(Script168.groovy:13)

 

Adaptavist support only mentioned that com.atlassian.applinks.applinks-plugin have less modules (94 instead of 127) but I have jira code downloaded and DefaultApplicationLinkService is still under:

com.atlassian.applinks.core.DefaultApplicationLinkService in applinks-plugin-8.0.0-sources.jar file.

 

What more, Code Completions in scriptrunner works and I can see and pick methods from DefaultApplicationLinkService .

 

also I've try with other class in this jar:

 

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.applinks.api.ApplicationLinkService
import com.atlassian.applinks.spi.link.ApplicationLinkDetails

ApplicationLinkService applicationLinkService = ComponentAccessor.getComponent(ApplicationLinkService)

@WithPlugin('com.atlassian.applinks.applinks-plugin')
//import com.atlassian.applinks.core.DefaultApplicationLinkService
import com.atlassian.applinks.core.ApplinkStatusService

@PluginModule
//DefaultApplicationLinkService defaultApplicationLinkService
ApplinkStatusService applinkStatusService

applicationLinkService.getApplicationLinks().each{
log.error applinkStatusService.getApplinkStatus(it.getId())
// defaultApplicationLinkService.deleteApplicationLink(it)
}

 

and this worked, what is the difference between DefaultApplicationLinkService and ApplinkStatusService? location is almost the same:

2021-01-05_17-19-41.png

 

Any idea why this import stopped working and how properly import DefaultApplicationLinkService?

 

Best Regards,

Lukasz

 

 

 

1 answer

1 accepted

0 votes
Answer accepted
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 7, 2021

Hi @Łukasz Sielski priv just fast check, what about line:

  • @WithPlugin('com.atlassian.applinks.applinks-plugin

it should be

  • @WithPlugin('com.atlassian.applinks.applinks-plugin')

Łukasz Sielski priv January 7, 2021

Hi @Martin Bayer _MoroSystems_ s_r_o__ 

That was of course mistake during copy paste in here, in such case scriptrunner console would report an error in code which is not the case, the code is correct, at lease according to this build in code review function of SC 

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 8, 2021

Hi @Łukasz Sielski priv I checked source code of 8.0.1 version and it looks like you are looking for 

com.atlassian.applinks.spi.link.MutatingApplicationLinkService

from  com.atlassian.applinks.applinks-spi artifact.

I have no 8.13. environment available but can you try to change your code to:

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.applinks.api.ApplicationLinkService
import com.atlassian.applinks.spi.link.ApplicationLinkDetails

@WithPlugin('com.atlassian.applinks.applinks-spi')
import com.atlassian.applinks.spi.link.MutatingApplicationLinkService

MutatingApplicationLinkService applicationLinkService = ComponentAccessor.getComponent(MutatingApplicationLinkService)
applicationLinkService.getApplicationLinks().each{ applicationLinkService.deleteApplicationLink(it)}
Łukasz Sielski priv January 11, 2021

Hello @Martin Bayer _MoroSystems_ s_r_o__ 

 

Thank you this worked. 

 

actually in case of jira 8.5 and 8.13 I needed to do it like that:

 

import com.onresolve.scriptrunner.runner.customisers.PluginModule

import com.atlassian.applinks.spi.link.MutatingApplicationLinkService

@PluginModule

MutatingApplicationLinkService applicationLinkService
applicationLinkService.getApplicationLinks().each{ applicationLinkService.deleteApplicationLink(it)}

 

because ComponentAccesspr didn't import class at all. 

 

Additional question, how did you find that? I'm using Intelij and for some reason can't search text in all files in project. 

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 11, 2021

Hi @Łukasz Sielski priv I downloaded source of the ApplicationLink library (https://mvnrepository.com/artifact/com.atlassian.applinks/applinks-plugin/8.0.1) and I decompiled it online. So I found out the service DefaultApplicationLInkService implements MutatingApplicationLinkService. But to be honest, it is enought to check online docs:

Like Łukasz Sielski priv likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events