Forums

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

Resolve an Issue using Java Rest Client API

stuck
Contributor
June 18, 2018

Hi,

I am trying to resolve an issue which status is "In Progress". I got an error called "Time Spent is required". How can I solve that?

The code snip that I tried:

TransitionInput transitionInput = new TransitionInput(21, Comment.valueOf("The comment for completion"));
restClient.getIssueClient().transition(theIssue.getTransitionUri(), transitionInput).claim(); // restClient is JiraRestClient object. theIssue is in type Issue

I tried adding FieldInput object with key "timeSpent" and it did not work, too.

 

Thanks already for your answers.

1 answer

2 votes
Gonchik Tsymzhitov
Community Champion
June 18, 2018

Hi! 

 

Let's input worklog first, WorklogInput will help you

https://docs.atlassian.com/jira-rest-java-client-api/2.0.0-m31/jira-rest-java-client-api/apidocs/

 

like this 

public boolean addWorklog(IssueEx issue, String comment) {
try {
URI worklogUri = getIssue(issue.id).getWorklogUri();

WorklogInputBuilder wlBuilder = new WorklogInputBuilder(worklogUri);
wlBuilder.setMinutesSpent(issue.timeSpent);
wlBuilder.setComment(comment);

jiraRestClient.getIssueClient().addWorklog( worklogUri, wlBuilder.build() );
return true;
} catch (Exception e) {
LOGGER.warning( "jira rest client update issue error. cause: " + e.getMessage() );
return false;
}
}

 

Hope it helps 

Cheers,

Gonchik Tsymzhitov

stuck
Contributor
June 18, 2018

Hi, Gonchik. Thanks for your comment.

I tried the code that you gave and I got an error as follows. What should I do?

Exception in thread "Thread-1" java.util.concurrent.RejectedExecutionException: Task com.atlassian.httpclient.apache.httpcomponents.SettableFuturePromiseHttpPromiseAsyncClient$ThreadLocalDelegateRunnable@3f10924d rejected from java.util.concurrent.ThreadPoolExecutor@39e30c40[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 1]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2063)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:830)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1379)
at com.atlassian.httpclient.apache.httpcomponents.SettableFuturePromiseHttpPromiseAsyncClient$ThreadLocalDelegateExecutor.execute(SettableFuturePromiseHttpPromiseAsyncClient.java:171)
at com.atlassian.httpclient.apache.httpcomponents.SettableFuturePromiseHttpPromiseAsyncClient$1.doCancelled(SettableFuturePromiseHttpPromiseAsyncClient.java:68)
at com.atlassian.httpclient.apache.httpcomponents.SettableFuturePromiseHttpPromiseAsyncClient$ThreadLocalContextAwareFutureCallback$3.run(SettableFuturePromiseHttpPromiseAsyncClient.java:152)
at com.atlassian.httpclient.apache.httpcomponents.SettableFuturePromiseHttpPromiseAsyncClient.runInContext(SettableFuturePromiseHttpPromiseAsyncClient.java:90)
at com.atlassian.httpclient.apache.httpcomponents.SettableFuturePromiseHttpPromiseAsyncClient$ThreadLocalContextAwareFutureCallback.cancelled(SettableFuturePromiseHttpPromiseAsyncClient.java:147)
at org.apache.http.impl.client.cache.CachingHttpAsyncClient$2.cancelled(CachingHttpAsyncClient.java:636)
at org.apache.http.concurrent.BasicFuture.cancel(BasicFuture.java:135)
at org.apache.http.impl.nio.client.DefaultResultCallback.cancelled(DefaultResultCallback.java:57)
at org.apache.http.impl.nio.client.DefaultAsyncRequestDirector.cancel(DefaultAsyncRequestDirector.java:533)
at org.apache.http.impl.nio.client.AbstractHttpAsyncClient.doExecute(AbstractHttpAsyncClient.java:471)
at org.apache.http.impl.nio.client.AbstractHttpAsyncClient.access$000(AbstractHttpAsyncClient.java:101)
at org.apache.http.impl.nio.client.AbstractHttpAsyncClient$1.run(AbstractHttpAsyncClient.java:485)
stuck
Contributor
June 18, 2018

I claimed it and the problem solved.

Thanks a lot Gonchik! 

stuck
Contributor
June 18, 2018

I can add the worklog like you said Gonchik, thanks.

However, I cannot still resolve the issue. It says "Time Spent is required", again :(

Gonchik Tsymzhitov
Community Champion
June 18, 2018

Okay, have you checked in UI worklog has been added? 

Also can you confirm, is it possible resolve issue from UI? 

Looks like your validator in Jira does not work 

stuck
Contributor
June 18, 2018

Yeap, worklog(s) has added and I can resolve issue from UI.

"Time Spent" fields is required in "Required Close Screen". Because of that I got "Time Spent is required" error.

Also, in UI, if I don't enter any value in "Time Spent" field, I got the same error in UI, too.

Gonchik Tsymzhitov
Community Champion
June 18, 2018

Okay, after addWorkLog method have you seen any changes in UI? 

stuck
Contributor
June 18, 2018

Yes, in issue's page, a work log added after addWorkLog method. For that, additionally I add a ".claim()" at the end of the 

jiraRestClient.getIssueClient().addWorklog( worklogUri, wlBuilder.build() );

line.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events