gpt4 book ai didi

java - 在 Rally 中,如何使用 Web 服务 v2.0 获取具有属性类型的字段列表

转载 作者:行者123 更新时间:2023-11-29 08:53:32 25 4
gpt4 key购买 nike

enter image description here

例如,仅使用 Rally 的 web-service v2.0 获取字段 Environment with Attribute Type in JSON Form。

最佳答案

这是打印缺陷严重性值的 Java 代码:

public class GetSeverityValues {

public static void main(String[] args) throws URISyntaxException, IOException {


String host = "https://rally1.rallydev.com";
String username = "user@co.com";
String password = "secret";
String projectRef = "/project/12352608219";
String workspaceRef = "/workspace/12352608129";
String applicationName = "RESTExampleFindSeverityValues";

RallyRestApi restApi = null;

try {
restApi = new RallyRestApi(
new URI(host),
username,
password);
restApi.setApplicationName(applicationName);

QueryRequest typeDefRequest = new QueryRequest("TypeDefinition");
typeDefRequest.setFetch(new Fetch("ObjectID","Attributes"));
typeDefRequest.setWorkspace(workspaceRef);
typeDefRequest.setQueryFilter(new QueryFilter("Name", "=", "Defect"));

QueryResponse typeDefQueryResponse = restApi.query(typeDefRequest);
JsonObject typeDefJsonObject = typeDefQueryResponse.getResults().get(0).getAsJsonObject();
System.out.println(typeDefJsonObject.get("_ref"));
System.out.println(typeDefJsonObject.get("Attributes"));

int numberOfAttributes = typeDefJsonObject.getAsJsonObject("Attributes").get("Count").getAsInt();

QueryRequest attributeRequest = new QueryRequest(typeDefJsonObject.getAsJsonObject("Attributes"));
attributeRequest.setFetch(new Fetch("AllowedValues","ElementName", "Name"));
QueryResponse attributesQueryResponse = restApi.query(attributeRequest);
for (int i=0; i<attributesQueryResponse.getResults().size();i++){
String fieldName = attributesQueryResponse.getResults().get(i).getAsJsonObject().get("Name").getAsString();
if (fieldName.equals("Severity")){
JsonObject allowedValuesJsonObject = attributesQueryResponse.getResults().get(i).getAsJsonObject();
int numberOfSeverityValues = allowedValuesJsonObject.getAsJsonObject("AllowedValues").get("Count").getAsInt();
//System.out.println(numberOfSeverityValues);
QueryRequest allowedValuesRequest = new QueryRequest(allowedValuesJsonObject.getAsJsonObject("AllowedValues"));
allowedValuesRequest.setFetch(new Fetch("StringValue"));
QueryResponse allowedValuesResponse = restApi.query(allowedValuesRequest);
for (int j = 0; j < numberOfSeverityValues; j++){
JsonObject allowedAttributeValuesJsonObject = allowedValuesResponse.getResults().get(j).getAsJsonObject();
System.out.println(allowedAttributeValuesJsonObject.get("StringValue"));
}
}
}

}
finally{
if (restApi != null) {
restApi.close();
}
}

}
}

关于java - 在 Rally 中,如何使用 Web 服务 v2.0 获取具有属性类型的字段列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21529429/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com