Java 在Rally中,如何使用web service v2.0获取属性类型为的字段列表

Java 在Rally中,如何使用web service v2.0获取属性类型为的字段列表,java,web-services,rally,Java,Web Services,Rally,例如,仅使用Rally的web service v2.0获取属性类型为JSON格式的field Environment。以下是一段Java代码,用于打印缺陷的严重性值: public class GetSeverityValues { public static void main(String[] args) throws URISyntaxException, IOException { String host = "https://rally1.rallyde


例如,仅使用Rally的web service v2.0获取属性类型为JSON格式的field Environment。

以下是一段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();
            }
        }

    }
}
公共类GetSeverityValue{
公共静态void main(字符串[]args)抛出URISyntaxException、IOException{
字符串主机=”https://rally1.rallydev.com";
字符串用户名=”user@co.com";
字符串password=“secret”;
字符串projectRef=“/project/12352608219”;
字符串workspaceRef=“/workspace/12352608129”;
String applicationName=“RESTExampleFindSeverityValues”;
RallyRestApi restApi=null;
试一试{
restApi=新的RallyRestApi(
新URI(主机),
用户名,
密码);
restApi.setApplicationName(applicationName);
QueryRequest typeDefRequest=新的QueryRequest(“类型定义”);
setFetch(新的Fetch(“ObjectID”,“Attributes”));
typeDefRequest.setWorkspace(workspaceRef);
setQueryFilter(新的QueryFilter(“名称”、“=”、“缺陷”);
QueryResponse typeDefQueryResponse=restApi.query(typeDefRequest);
JsonObject typeDefJsonObject=typeDefQueryResponse.getResults().get(0.getAsJsonObject();
System.out.println(typeDefJsonObject.get(“\u ref”);
System.out.println(typeDefJsonObject.get(“属性”);
int numberOfAttributes=typeDefJsonObject.getAsJsonObject(“属性”).get(“计数”).getAsInt();
QueryRequest attributeRequest=新的QueryRequest(typeDefJsonObject.getAsJsonObject(“属性”));
setFetch(新的Fetch(“AllowedValues”、“ElementName”、“Name”);
QueryResponse属性QueryResponse=restApi.query(attributeRequest);

对于(int i=0;i)您的问题被标记为java-您是否正在寻找一个如何使用Rally Rest Toolkit for java实现这一点的示例?