简体   繁体   English

Jira 6.1.6 Java REST API-无法设置自定义下拉值

[英]Jira 6.1.6 Java REST api - Cannot set custom dropdown value


I am using the JRJC jira-rest-java-client-2.0.0-m2. 我正在使用JRJC jira-rest-java-client-2.0.0-m2。
My goal is to be able to copy a custom field from an issue and create a new issue with the value. 我的目标是能够从问题中复制自定义字段并使用该值创建新问题。 This usually works perfectly fine: 这通常可以正常工作:

Field trigger = issue.getFieldByName("Trigger");
if (trigger != null) {
    newIssue.setFieldValue(trigger.getId(), trigger.getValue());
}

(The newIssue is an object of type IssueInputBuilder; the issue of type Issue) (newIssue是类型IssueInputBuilder的对象;类型是Issue的问题)

But it does not work with a dropdown(single-selection), this throws the following exception: 但这不适用于下拉菜单(单选),这会引发以下异常:

com.atlassian.jira.rest.client.domain.input.CannotTransformValueException: Any of available transformers was able to transform given value. Value is: org.codehaus.jettison.json.JSONObject: {"self":"http:\/\/localhost:8080\/rest\/api\/2\/customFieldOption\/10100","value":"SQL Statement","id":"10100"}
    at com.atlassian.jira.rest.client.domain.input.ValueTransformerManager.apply(ValueTransformerManager.java:83)
    at com.atlassian.jira.rest.client.domain.input.IssueInputBuilder.setFieldValue(IssueInputBuilder.java:135)
    at com.sonydadc.lfiala.jira.CopyUtil.copy(CopyUtil.java:152)
    at com.sonydadc.lfiala.jira.JiraUtil.copyTask(JiraUtil.java:90)
    at com.sonydadc.lfiala.jira.Start.main(Start.java:13)

Setting the value directly does not work eiter: 直接设置该值不起作用:

Field trigger = issue.getFieldByName("Trigger");
        if (trigger != null) {
            newIssue.setFieldValue(trigger.getId(), trigger);
        }

When i try this, this exception is thrown: 当我尝试这个时,抛出此异常:

com.atlassian.jira.rest.client.RestClientException: Could not find valid 'id' or 'value' in the Parent Option object.
    at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$2.apply(AbstractAsynchronousRestClient.java:165)
    at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$2.apply(AbstractAsynchronousRestClient.java:159)
    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)
...

These exceptions get thrown when the jira-client tries to set the value to the issueinputbuilder. 当jira-client尝试将值设置为issueinputbuilder时,将引发这些异常。
How do i solve this? 我该如何解决?

Thanks in advance, Laurenz 在此先感谢Laurenz

EDIT i tried the same with the newest m25 versions of jira-rest-java-client-api and jira-rest-java-client-core, and it didn't work either 编辑我尝试使用最新的m25版本的jira-rest-java-client-api和jira-rest-java-client-core进行相同操作,但也没有用

FYI i have already googled. 仅供参考,我已经用谷歌搜索。 a lot. 很多。 i didnt find anything that could solve my issue(at least not on the first few pages :/) 我没有找到任何可以解决我的问题的东西(至少没有在前几页:/)

Okay i have solved it myself :) 好吧,我自己解决了问题:)

If anyone wonders here's how: 如果有人想知道这是怎么回事:

IssueField trigger = issue.getFieldByName("Trigger");
        if (trigger != null) {
            JSONObject triggerJO = (JSONObject) trigger.getValue();
            newIssue.setFieldValue(trigger.getId(), ComplexIssueInputFieldValue.with("value", triggerJO.get("value")));
        }

This runs with the new api versions m25(jira-rest-java-client-api and jira-rest-java-client-core). 这与新的api版本m25(jira-rest-java-client-api和jira-rest-java-client-core)一起运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM