Java中的RallyApi-尝试返回功能的项目层次结构

时间:2018-11-06 19:43:09

标签: rally

鉴于传递给此函数的功能结果集,我试图遍历项目层次结构直至订阅。我不能在projResponse = ...上得到一个空指针。...甚至不确定这种方法。

private static void getProjHierarchyForFeature(RallyRestApi restApi, QueryResponse featureSet,
        Time2Market time2market, Integer featureInSet) {

    String tempHierarchy = "";

    JsonArray tempFeatures = featureSet.getResults();
    //time2market.setProjectName(projectName);

    try {
        JsonObject obj1 = tempFeatures.get(featureInSet).getAsJsonObject();
        JsonObject proj = obj1.get("Project").getAsJsonObject();
        String url = proj.get("_ref").getAsString();
        QueryRequest projQuery = new QueryRequest(url);
        projQuery.setFetch(new Fetch("_ref", "_refObjectUUID", "_refObjectName"));
        QueryResponse projResponse = restApi.query(projQuery);

        if (projResponse.wasSuccessful()) {
            JsonArray tempProj = projResponse.getResults();

            // Here we have the project object, now process Parents...

            Boolean moreParents = true;

            while (moreParents) {
                QueryRequest parentQuery = new QueryRequest(url);
                //projQuery.setFetch(new Fetch("_ref", "_refObjectUUID", "_refObjectName"));
                QueryResponse parentResponse = restApi.query(parentQuery);

                if (parentResponse.wasSuccessful()) {
                    System.out.println ("proj Response... " + parentResponse.toString());

                    JsonArray projParent = parentResponse.getResults();
                    tempHierarchy.concat(projParent.get(0).getAsString());
                    JsonArray tempParent = parentResponse.getResults();
                    proj = tempParent.getAsJsonObject();
                } else {
                    moreParents = false;
                }
            }
        } else {
            System.err.println("The following errors occurred: ");
            for (String err : projResponse.getErrors()) {
                System.err.println("\t" + err);
            }
            throw new java.lang.Error("Rally API Call Error Occurred");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}

1 个答案:

答案 0 :(得分:0)

您可能要使用GetRequest而不是QueryRequest,因为您只读取单个对象。另外,在您的抓取中包括“父母”。然后,您应该具有数据,以便能够确定是否有父级并继续循环。