Jira REST API 时间跟踪空

Jira REST API Time Tracking Null

当我尝试为我的问题获取时间跟踪时,我的以下代码使我出现空指针异常,即使该问题具有时间跟踪,我正在使用此 api:

        <groupId>com.atlassian.jira</groupId>

        <artifactId>jira-rest-java-client-api</artifactId>

        <version>2.0.0-m19</version>

    </dependency>

    <dependency>

        <groupId>com.atlassian.jira</groupId>

        <artifactId>jira-rest-java-client-core</artifactId>

        <version>2.0.0-m19</version>

    </dependency>

//

for (JiraFixVersion jiraFixVersion : listJiraFixVersionsProject) {
        Iterator<Issue> issues = JiraClientManager.getInstance().getSearchResultSet("project='" + jiraProject.getProjectName()
                + "' AND fixVersion =" + "'" + jiraFixVersion.getName() + "'").iterator();
        Integer sumEstimatedTimeHours = 0;
        while (issues.hasNext()) {
            Issue issue = issues.next();
            Integer estimatedTime =0;
            try {
//Here is NullPointerException
                TimeTracking timeTracking = issue.getTimeTracking();

                estimatedTime = timeTracking.getOriginalEstimateMinutes();
                System.out.println("ok "+issue.getKey());
            }catch(NullPointerException e){
                System.out.println("Time Tracking null "+ issue.getKey());
            }
            sumEstimatedTimeHours += estimatedTime;
        }
        returnMap.put(jiraFixVersion, sumEstimatedTimeHours);
    }

我通过以下方法解决了这个问题:

for (JiraFixVersion jiraFixVersion : listJiraFixVersionsProject) {

        Iterator<Issue> issues = JiraClientManager.getInstance().getSearchResultSet("project='" + jiraProject.getProjectName() + "' AND fixVersion =" + "'" + jiraFixVersion.getName() + "'" + " AND cf[10002] !=null").iterator();
        Double sumStoryPoints = 0.0;
        while (issues.hasNext()) {
            Issue issue = issues.next();
            String storyPoints = issue.getField("customfield_10002").getValue().toString();
            Double storyPointIssue = Double.parseDouble(storyPoints);
            sumStoryPoints += storyPointIssue;
        }
        returnMap.put(jiraFixVersion, sumStoryPoints);
    }

'customfield_1002' 是我想要的字段,但如果你真的想要那个对象 TimeTracking 你必须发出另一个服务器请求,这将持续一些宝贵的时间,我不建议这样做,但我会展示代码:

while (issues.hasNext()) {

            Issue issue = issues.next();
            try {
                Issue claim = JiraClientManager.getInstance().getRestClient().getIssueClient().getIssue(issue.getKey()).claim();
                TimeTracking timeTracking = claim.getTimeTracking();
                Integer estimatedTimeSeconds =(Integer) issue.getField("timeoriginalestimate").getValue();
                Double estimatedTimeHours = (estimatedTimeSeconds.doubleValue())/3600;
                System.out.println(estimatedTimeHours+" "+issue.getKey());
                sumEstimatedTimeHours += estimatedTimeHours;
            }catch(NullPointerException e){
                System.out.println("Time Tracking null "+ issue.getKey());
            }
        }

我这里也有同样的问题,我找到了针对这种情况的其他解决方案,使用:

issue.getField("timeoriginalestimate")

类似于 Mars 选项和 Cosmin 的答案,这(现在)是可能的,并确保通过搜索查询获得完整的 Timetracking 对象,您只需要明确请求“timetracking”字段,但您还需要确保添加核心字段,以便客户端可以构建 Issue 实例。

是这样的(列表也可能是一个集合,不要因为语法错误而钉死我,目前手头没有IDE)。

 restClient.getSearchClient()
           .searchJql(q.getQuery(), q.getLimit(), q.getOffset(),
                       Lists.newArraylist(
                            "timetracking",
                            "summary",
                            "issuetype",
                            "created",
                            "updated",
                            "project",
                            "status"));