Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Problem when searching issues from the code base of an add-on for Jira Data Center

Long Nguyen-Thanh October 2, 2024

Hi every one

I'm a member of a Jira Datacenter  add-on development team.

I am facing the following problem:

From the code base in the back-end of the add-on, I have a scheduled task that is called every 60 seconds. Inside the content of this schedule task, there is a JQL statement that searches for issues that satisfy a certain condition X. Initially, my Jira only has one project A.

The problem is that after I launch Jira Data center with the add-on, the JQL statement in the code base cannot search for issues that satisfy condition X, which are in a newly created project (project B) after lauching Jira Data center. Issues in project A can still be searched. If after creating project B, I restart Jira Data Center, then after restarting I can find all issues in both projects A and B.

1 answer

1 accepted

0 votes
Answer accepted
Sergei Troshin
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.
October 3, 2024

Hi @Long Nguyen-Thanh

Welcome to Atlassian Community!

It looks like there are problems with indexing. I hope this code helps or gives some insights:

import com.atlassian.jira.jql.parser.JqlParseException
import groovy.transform.Field
import com.atlassian.query.Query
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.index.IssueIndexManager
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.util.thread.JiraThreadLocalUtils

import com.atlassian.jira.issue.index.ThreadLocalSearcherCache
@Field final SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
@Field final IssueIndexManager indexManager = ComponentAccessor.getComponentOfType(IssueIndexManager.class)
@Field final JqlQueryParser jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)

getIssuesByJQL("project = ABC AND created >= startOfMonth()")

Collection<Issue> getIssuesByJQL(String jql) throws Exception {
    Query query = parseQuery(jql)
    return getIssuesByJQL(query, ComponentAccessor.jiraAuthenticationContext.getLoggedInUser())
}

Collection<Issue> getIssuesByJQL(Query query, ApplicationUser user) throws Exception {
    if (!indexManager.isIndexAvailable()) {
        return new ArrayList<>();
    }

    if (ThreadLocalSearcherCache.inSearcherContext()) {
        return searchService.search(user, query, PagerFilter.getUnlimitedFilter()).getResults();
    } else {
        return JiraThreadLocalUtils.wrap(
                () ->
                        searchService.search(user, query, PagerFilter.getUnlimitedFilter()).getResults())
                .call();
    }

}

Query parseQuery(String jql) throws JqlParseException {
    return jqlQueryParser.parseQuery(jql);
}
Long Nguyen-Thanh October 6, 2024

Hi @Sergei Troshin ,

if (ThreadLocalSearcherCache.inSearcherContext()) {
        return searchService.search(user, query, PagerFilter.getUnlimitedFilter()).getResults();
    } else {
        return JiraThreadLocalUtils.wrap(
                () ->
                        searchService.search(user, query, PagerFilter.getUnlimitedFilter()).getResults())
                .call();
    }

 Thanks for your help! Your code block has given me the solution for my problem!

 

Suggest an answer

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

Atlassian Community Events