Rally Software

  • 1.  Data Extraction issue on Agile Central

    Posted Aug 08, 2017 06:50 AM

    User - UserProfile- DefaultProject -Project

    I want to get the details of Project information which is under DefaultProject which is child of UserProfile and extends User.

    Can somebody help how to query in java to get the inner object information in rally.



  • 2.  Re: Data Extraction issue on Agile Central

    Posted Aug 08, 2017 10:04 AM

    Avi12Apr2017,

     

    Here is an example.  There may be a better way to do this, but this works in my testing.

     

     GetRequest getRequest;
    GetResponse getResponse;
    JsonObject profileObj;
    JsonObject userJsonObject;

    // Get the Users. Request only what is necessary.
    QueryRequest request = new QueryRequest("User");
    request.setFetch(new Fetch("UserName","UserProfile"));
    request.setPageSize(10);
    QueryResponse response = restApi.query(request);

    if (response.wasSuccessful() && response.getResults().size() > 0) {
        for (int i=0; i<response.getResults().size();i++){
          userJsonObject = response.getResults().get(i).getAsJsonObject();

          // Get the Reference to the User Profile Object and then query for it.
          getRequest = new GetRequest(userJsonObject.get("UserProfile").getAsJsonObject().get("_ref").getAsString());
          getRequest.setFetch(new Fetch("DefaultProject"));
          getResponse = restApi.get(getRequest);
          profileObj = getResponse.getObject();

          // List the Default Project or set it to None.
          if(profileObj.get("DefaultProject").isJsonObject()) {
             System.out.println(String.format("Default Project Name for %s is %s", userJsonObject.get("UserName"),profileObj.get("DefaultProject").getAsJsonObject().get("_refObjectName")));
          } else {
             System.out.println(String.format("No default Project set for: %s", userJsonObject.get("UserName")));
          }
       }
    } else {
       System.out.println("Could not find the User.");
       for (String error : response.getErrors()) {
          System.out.println("Error: " + error);
       }
    }

    Hope that helps.


    Michael