Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,554,146
Community Members
 
Community Events
184
Community Groups

Read Structure from another thread

Edited

I prepare listener of rank change event with scriptrunner. I change rank from Structure by drag&drop of rows, structure is sorted by rank.

When I read structure in main thread in listener and get data, then I see that sequence of rows is old. If then I run the same script from console then sequence of rows is new.

Now I think script from listener executes before rebuild of structure in main thread. But if I try to make new thread, make sleep and then try to read structure I get nothing.

Please help. I am not sure that I work in new thread in right way.

In  atlassan-jira.log there is no log entry for line "log.info "Structures - "+structures+"\n"'

Снимок экрана 2020-09-27 в 19.14.23.png

Code

import com.almworks.jira.structure.api.StructureComponents
import com.almworks.jira.structure.api.permissions.PermissionLevel
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import org.apache.log4j.*;
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.util.thread.JiraThreadLocalUtil

Thread.start{
def jtlu = ComponentAccessor.getComponent(JiraThreadLocalUtil)
jtlu.preCall()
try {

@WithPlugin("com.almworks.jira.structure")
@PluginModule

StructureComponents structureComponents


IssueManager issueManager = ComponentAccessor.getIssueManager()

MutableIssue issue = issueManager.getIssueObject(event.getIssueId())

log.setLevel(Level.ALL)
log.info "Start\n"
log.debug("New thread start")
Thread.sleep(1000)
log.debug("New thread start2")


def String structureName="Test"


def structures = structureComponents.getStructureManager().getStructuresByName(structureName, PermissionLevel.VIEW);
log.info "Structures - "+structures+"\n"
def long structureId;




log.info "new structure finished in new thread\n"
}

finally {
jtlu.postCall(log)
}

}
Thread.sleep(3000)

  If I move block below out of new thread block, than structures is empty

@WithPlugin("com.almworks.jira.structure")
@PluginModule

StructureComponents structureComponents

Снимок экрана 2020-09-27 в 19.23.39.png 

1 answer

1 accepted

1 vote
Answer accepted
Egor Tasa [ALM Works]
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.
Sep 28, 2020

I've answered this question in our ServiceDesk, let me publish the answer here as well:

The reason for such behavior is that StructureManager.getStructuresByName returns a list of structures accessible to the current user at some permission level. The current user is kept in a thread-local variable. As the current user is not specified, the list is empty.

To find a user:

import com.atlassian.jira.user.util.UserManager

@PluginModule
UserManager userManager

def user = userManager.getUserByKey("admin")

To execute code under a user authority:

def structures = StructureAuth.sudo(user, false, { structureComponents.getStructureManager().getStructuresByName(structureName, PermissionLevel.VIEW) });

Regards,
Egor Tasa

ALM Works

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events