7

I am facing issue related to Search JQL. I am using the query

(issuefunction in issuesInEpics('key = ABCD-24911') and issuetype=Feature)

In Jira it is returning some record but when I am using this query in JiraRestClient it is not working, but instead returning zero records.

It is working fine for below query :

issuefunction in issuesInEpics("resolution is not empty") and issuetype = Feature

Code Snippet:

String query="issuefunction in issuesInEpics('key = ABCD-24911') and issuetype=Feature";    
Integer resultsLength=50,startAt=0;        
JiraRestClient.getSearchClient().searchJql(query,resultsLength,startAt,null);

My Maven Dependency:

<dependency>
        <groupId>com.atlassian.jira</groupId>
        <artifactId>jira-rest-java-client-api</artifactId>
        <version>4.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.atlassian.jira</groupId>
        <artifactId>jira-rest-java-client-core</artifactId>
        <version>4.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.atlassian.fugue</groupId>
        <artifactId>fugue</artifactId>
        <version>2.2.1</version>
    </dependency>
    <dependency>
    <groupId>com.atlassian.httpclient</groupId>
    <artifactId>atlassian-httpclient-spi</artifactId>
    <version>0.17.0-m01</version>
    </dependency>

Anyone please help me to find the solution.

Sitansu
  • 3,225
  • 8
  • 34
  • 61
  • Removed [tag:atlassian] tag - see https://meta.stackoverflow.com/questions/351480/finally-we-migrated-from-atlassian – Vadim Kotov Sep 19 '19 at 09:12
  • Check the HTTP access logs to verify if the query received by jira matches the one you sent. Maybe there is an issue with the URL encoding – Svetlin Zarev Sep 19 '19 at 12:44
  • Are you login REST client with same user as when you are using UI? – carduque Sep 19 '19 at 14:46
  • @carduque It is working fine for below query : issuefunction in issuesInEpics("resolution is not empty") and issuetype = Feature – Sitansu Sep 19 '19 at 15:01
  • Could you please try to encode the query param ? I would do something like `String query = URLEncoder.encode("issuefunction in issuesInEpics('key = ABCD-24911') and issuetype=Feature", "UTF-8");` – s7vr Sep 19 '19 at 16:17
  • @user2683814 thanks for answering will try this – Sitansu Sep 19 '19 at 16:32
  • Url encoding is already taken care by jira rest client. I was able to pull search results just fine with ` com.atlassian.jira jira-rest-java-client-core 4.0.0 com.atlassian.fugue fugue 2.6.1 `. Not able to reproduce the issue in my test. Are you sure you have the right search criteria ? – s7vr Sep 20 '19 at 01:10
  • @user2683814 thanks for answering I have tried both String query = URLEncoder.encode("issuefunction in issuesInEpics('key = ABCD-24911') and issuetype=Feature", "UTF-8"); and also add this maven dependency both are not working – Sitansu Sep 20 '19 at 08:30
  • @user2683814 For URLEncoder it is giving me RestClientException[ErrorCollection{status=400, errors={}, errorMessages=[Error in the JQL Query: The character '+' is a reserved JQL character. You must enclose it in a string or use the escape '\u002b' instead. (line 1, character 14)]}] – Sitansu Sep 20 '19 at 08:32
  • @user2683814 Can you share your source code how you are implemented – Sitansu Sep 20 '19 at 08:57
  • I used the same code. Something like `try(JiraRestClient client = new AsynchronousJiraRestClientFactory().createWithBasicHttpAuthentication(uri, username, password) {String query="issuefunction in issuesInEpics('key = ABCD-24911') and issuetype=Feature"; Integer resultsLength=50,startAt=0; JiraRestClient.getSearchClient().searchJql(query,resultsLength,startAt,null).claim.getIssues().forEach(issue->System.out.println(issue.getKey()));}` Could you share the exact search criteria that you use instead of one in the post ? – s7vr Sep 20 '19 at 11:29
  • @user2683814 It is working fine. (issuefunction in issuesInEpics("resolution is not empty") and issuetype = Feature) but the above query is not working – Sitansu Sep 20 '19 at 13:31
  • @user2683814 I am not getting which search criteria you are talking about – Sitansu Sep 20 '19 at 13:32
  • Sorry, I mean whatever goes inside parenthesis here `issuesInEpics()`. It looks like there is problem with search criteria since you get zero results back. Are your sure the user id have proper access to the project you are querying ? have you tried to query the any other projects ? – s7vr Sep 20 '19 at 13:53
  • @user2683814 Thanks Same Jira credential use for both search but in direct jira search it is fetching record. Let me check the proper access to the project then I will update the same – Sitansu Sep 20 '19 at 18:13
  • @Sitansu As there is very less support i have seen for JiraRestClient, You have crossed JQL and reached up to using runner script, please consider writing how you are able run runner scripts, is it local server set up or cloud provided. Please consider writing in detail so that others also can benefitted and someone can try this for you. Simply announcing bounty will not help you, unless they had complete set up to try for you. I suggest you to update question with details and upload required code to github and share the link. Thanks – PraveenKumar Lalasangi Sep 21 '19 at 14:29
  • have you tried using any other clients ? like curl or postman to confirm if the issue with jira client specifically or some other user access or jira server issue. – s7vr Sep 25 '19 at 15:36

2 Answers2

2

I think there might be a problem specific to your JIRA instance that is causing your problem. My code below is based on what Anish wrote. It compiles and runs perfectly fine, printing out the exact list of issues I expect it to display.

Maybe this helps you when you can look at two pieces of code side-by-side.

public static void main(String[] args) throws URISyntaxException {
    URI uri = new URI("https://example.com");
    JiraRestClientFactory jiraRestClientFactory = new AsynchronousJiraRestClientFactory();
    try (JiraRestClient jiraRestClient = jiraRestClientFactory.createWithBasicHttpAuthentication(uri, "email", "password")) {
        SearchRestClient searchClient = jiraRestClient.getSearchClient();
        String query = "issueFunction in issuesInEpics('key = PROJ-1234') and issuetype = Task";
        System.out.println(query);
        SearchResult result = searchClient.searchJql(query, 50, 0, null).claim();
        for (Issue issue : result.getIssues()) {
            System.out.println(issue.getKey());
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

I also tried the given JQL using a custom proxy client my company uses and the query definitely works perfectly fine. Please check your environment and JIRA logs..

Michael Ziluck
  • 599
  • 6
  • 19
  • It is giving org.codehaus.jettison.json.JSONException: A JSONObject text must begin with '{' at character 0 of – Sitansu Sep 26 '19 at 09:05
  • @Sitansu On what line? I am not getting that at all. Can you check the Jira logs? – Michael Ziluck Sep 26 '19 at 17:13
  • In this line it is showing SearchResult result = searchClient.searchJql(query, 50, 0, null).claim(); – Sitansu Sep 26 '19 at 18:37
  • I do not know how it is working for you but in my case it is not working. Not able to address the issue in my jira rest client implementation.As I mentioned this query is working fine with my case issuefunction in issuesInEpics("resolution is not empty") and issuetype = Feature – Sitansu Sep 26 '19 at 18:44
  • @Sitansu Are you sure you ran my exact code? Does the stacktrace include a call to the method `AsynchronousSearchRestClient.searchJqlImplPost()` or `AsynchronousSearchRestClient.searchJqlImplGet()`? If it's neither, does the exception originate from `SearchResultJsonParser.parse()` instead? If it's that last one, your problem is that your Jira instance is not returning proper values. – Michael Ziluck Sep 26 '19 at 19:25
0

If I understand https://community.atlassian.com/t5/Jira-questions/How-to-get-a-list-of-quot-issues-in-epic-quot-in-Jira/qaq-p/511549 correctly, a workaround would be to use

String query="issueFunction in linkedIssuesOf('key=ABCD-24911', 'is epic of') 
  AND issuetype=Feature";  

instead of

String query="issuefunction in issuesInEpics('key = ABCD-24911') 
  AND issuetype=Feature";  

Background: It looks like the functions IssuesInEpics() and epicsOf() have been only recently introduced to amend the functionality of linkedIssuesOf().

For more documentation, see https://confluence.atlassian.com/jirasoftwarecloud/advanced-searching-functions-reference-764478342.html

B--rian
  • 5,578
  • 10
  • 38
  • 89
  • getting exception : RestClientException{statusCode=Optional.of(400), errorCollections=[ErrorCollection{status=400, errors={}, errorMessages=[Error in scripted function: linkedIssuesOf, see below, The value 'ABCD-24911' does not exist for the field 'filter'.]}]} – Sitansu Sep 23 '19 at 08:57
  • @Sitansu: Please see my corrected answer. If it still does not work, please check whether `linkedIssueOf` works for you at all via REST-API. – B--rian Sep 23 '19 at 09:44