Rally Software

  • 1.  RALLY API: get project hierarchy for feature

    Posted Nov 07, 2018 10:55 AM

    I'm trying to collect the project hierarchy into a single, colon separated string . (parent1:parent2:) upto the root project in the subscription.  I cannot determine the call pattern to do this.  

     

    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();

                

                QueryRequest projQuery = new QueryRequest("HierarchicalRequirement");

                

                projQuery.setQueryFilter(new QueryFilter("ObjectID", "=", proj.get("_refObjectUUID").getAsString()));

                projQuery.setFetch(new Fetch("_ref", "_refObjectUUID", "_refObjectName"));

                projQuery.setStart(1);

                projQuery.setPageSize(1);

                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("HierarchicalRequirment");

                        //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();

            }

            

        }



  • 2.  Re: RALLY API: get project hierarchy for feature
    Best Answer

    Broadcom Employee
    Posted Nov 07, 2018 02:38 PM

    What output are you getting?

     

    I haven't tried your code in my environment but I feel like that your parentQuery QueryRequest should be to Project. 

     

    (Though, if it is supposed to be HierarchicalRequirement, I did notice a typo on that line)



  • 3.  Re: RALLY API: get project hierarchy for feature

    Posted Nov 09, 2018 05:14 PM

    Empty project collection is the result.

     

    I got a recommendation from Stack Exchange also.  The recommendation was to use GetRequest rather than QuerryRequest as the result is a Singleton.  The process worked with:

     

    GetRequest projRequest = new GetRequest("/project/" + parentUUID);

     

    Also, David was correct,  to go after /project/ rather than a HierarchicalRequirement.