如何使用Jira Rest java客户端更新Jira问题解决方案

时间:2016-04-04 14:42:33

标签: java jira jira-rest-java-api

我正在使用Jira Rest java客户端来创建/更新问题,并且需要在关闭时更新问题的解决方案。我尝试了以下代码:

 public static void main(String[] args) {
    try {
        Issue issue = restClient.getIssueClient().getIssue("CER-3").get();
        Iterator<Transition> transitions =
                restClient.getIssueClient().getTransitions(issue).get().iterator();
        int transitionId = 0;
        while (transitions.hasNext()) {
            Transition transition = transitions.next();
            if (transition.getName().contains("Closed")
                    || transition.getName().contains("Done")) {
                transitionId = transition.getId();
            }
        }
        final Collection<FieldInput> fieldInputs;
        fieldInputs =
                Arrays.asList(new FieldInput("resolution", ComplexIssueInputFieldValue.with(
                        "name", "Won't Fix")));
        TransitionInput tInput =
                new TransitionInput(transitionId, fieldInputs, Comment.valueOf("My comment"));

        restClient.getIssueClient().transition(issue, tInput).claim();
    } catch (Exception e) {
        e.printStackTrace();
    }

运行上述代码后,收到以下异常:

RestClientException{statusCode=Optional.of(400), errorCollections=[ErrorCollection{status=400, errors={Resolution=Field 'Resolution' cannot be set. It is not on the appropriate screen, or unknown.}, errorMessages=[]}]}
at com.atlassian.jira.rest.client.internal.async.DelegatingPromise.claim(DelegatingPromise.java:47)
at com.instigatemobile.cerebro.clients.JiraRestClientModule.main(JiraRestClientModule.java:157)
Caused by: RestClientException{statusCode=Optional.of(400), errorCollections=[ErrorCollection{status=400, errors={Resolution=Field 'Resolution' cannot be set. It is not on the appropriate screen, or unknown.}, errorMessages=[]}]}
at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$2.apply(AbstractAsynchronousRestClient.java:166)
at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$2.apply(AbstractAsynchronousRestClient.java:160)
at com.atlassian.httpclient.api.ResponsePromiseMapFunction.apply(ResponsePromiseMapFunction.java:48)
at com.atlassian.httpclient.api.ResponsePromiseMapFunction.apply(ResponsePromiseMapFunction.java:12)
at com.atlassian.util.concurrent.Promises$Of$3.apply(Promises.java:285)
at com.atlassian.util.concurrent.Promises$2.onSuccess(Promises.java:162)
at com.google.common.util.concurrent.Futures$7.run(Futures.java:1072)
at com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:253)
at com.google.common.util.concurrent.ExecutionList$RunnableExecutorPair.execute(ExecutionList.java:161)
at com.google.common.util.concurrent.ExecutionList.execute(ExecutionList.java:146)
at com.google.common.util.concurrent.AbstractFuture.done(AbstractFuture.java:235)
at com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:172)
at com.google.common.util.concurrent.SettableFuture.set(SettableFuture.java:53)
at com.atlassian.util.concurrent.Promises$Of$3.apply(Promises.java:285)
at com.atlassian.util.concurrent.Promises$2.onSuccess(Promises.java:162)
at com.google.common.util.concurrent.Futures$7.run(Futures.java:1072)
at com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:253)
at com.google.common.util.concurrent.ExecutionList$RunnableExecutorPair.execute(ExecutionList.java:161)
at com.google.common.util.concurrent.ExecutionList.execute(ExecutionList.java:146)
at com.google.common.util.concurrent.AbstractFuture.done(AbstractFuture.java:235)
at com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:172)
at com.google.common.util.concurrent.SettableFuture.set(SettableFuture.java:53)
at com.atlassian.httpclient.apache.httpcomponents.SettableFuturePromiseHttpPromiseAsyncClient$1$1.run(SettableFuturePromiseHttpPromiseAsyncClient.java:46)
at com.atlassian.httpclient.apache.httpcomponents.SettableFuturePromiseHttpPromiseAsyncClient$ThreadLocalDelegateRunnable$1.run(SettableFuturePromiseHttpPromiseAsyncClient.java:197)
at com.atlassian.httpclient.apache.httpcomponents.SettableFuturePromiseHttpPromiseAsyncClient.runInContext(SettableFuturePromiseHttpPromiseAsyncClient.java:90)
at com.atlassian.httpclient.apache.httpcomponents.SettableFuturePromiseHttpPromiseAsyncClient$ThreadLocalDelegateRunnable.run(SettableFuturePromiseHttpPromiseAsyncClient.java:192)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

1 个答案:

答案 0 :(得分:1)

Java错误提示字段Resolution不属于目标屏幕。如果Jira中的“编辑问题”屏幕不包含名为“分辨率”的字段,则会发生这种情况。直接在Jira中打开目标问题并尝试添加“解决方案”字段,您会看到以下弹出式消息:

enter image description here

然后,您需要使用管理员权限登录Jira,然后编辑“编辑问题”屏幕以添加该字段。