Following is my code which retrieves Rally data.
public static void main(String[] args) throws URISyntaxException, IOException {
String host = "examplehost";
String username = "exampleuser";
String password = "password";
String projectRef = "project";
String workspaceRef = "workspace";
String applicationName = "";
int queryLimit = 4000;
Connection conn = null;
String propertiesFile = "";
String projectValue = "";
String columnValue = "";
String returnValue = "";
RallyRestApi restApi = new RallyRestApi(
new URI(host),
username,
password);
restApi.setApplicationName(applicationName);
System.out.println(restApi.getWsapiVersion());
try{
QueryRequest projectRequest = new QueryRequest("Project");
projectRequest.setFetch(new Fetch("Name", "TeamMembers"));
projectRequest.setWorkspace(workspaceRef);
projectRequest.setProject(projectRef);
projectRequest.setScopedDown(true);
projectRequest.setQueryFilter(new QueryFilter("Name", "contains", "DT-"));
projectRequest.setLimit(queryLimit);
QueryResponse projectQueryResponse = restApi.query(projectRequest);
int count = projectQueryResponse.getResults().size();
System.out.println(count);
if(count > 0){
for (int i=0;i<count;i++){
JsonObject projectObject = projectQueryResponse.getResults().get(i).getAsJsonObject();
JsonObject obj = projectObject.getAsJsonObject();
projectValue = JsonUtil.getJsonValue(obj, "_refObjectName");
System.out.println("Project: " + projectValue);
int numberOfTeamMembers = projectObject.getAsJsonObject("TeamMembers").get("Count").getAsInt();
if(numberOfTeamMembers > 0) {
QueryRequest teamRequest = new QueryRequest(projectObject.getAsJsonObject("TeamMembers"));
JsonArray teammates = restApi.query(teamRequest).getResults();
//JsonObject teammates = restApi.query(teamRequest).getResults();
if (teammates instanceof JsonArray) {
JsonArray jsonarr = teammates.getAsJsonArray();
//returnValue += squote;
for (int j=0; j<jsonarr.size(); j++) {
if (j>0)
returnValue += "\n";
JsonObject tobj = jsonarr.get(j).getAsJsonObject();
if (obj.has("Name"))
columnValue = getJsonValue(tobj, "Name");
if (obj.has("_refObjectName"))
columnValue = JsonUtil.getJsonValue(tobj, "_refObjectName");
returnValue += columnValue;
System.out.println(columnValue);
}
//returnValue += squote;
}
//columnValue = JsonUtil.getJsonString(teammates);
//for (int j=0;j<numberOfTeamMembers;j++){
//JsonObject teamObject = teamQueryResponse.getResults().get(j).getAsJsonObject();
//System.out.println(teammates.get(j).getAsJsonObject().get("_refObjectName").getAsString());
//}
}
}
}
}catch(Exception e){
e.printStackTrace();
} finally{
restApi.close();
}
}
I'm trying to insert Project ID and the associated team members into db. For one Project ID there may be 1- 10 members, The count may differ for each project. In DB, there would be only two Column holding Project ID and User name. Could anyone help me with this request?
Hope it helps.
If you need more details, please do reply
Thanks
Sreer