これは、RESTを使用してリビジョン履歴を取得して表示する方法です。
import com.google.gson.JsonObject;
import com.rallydev.rest.RallyRestApi;
import com.rallydev.rest.request.QueryRequest;
import com.rallydev.rest.response.QueryResponse;
import com.rallydev.rest.util.Fetch;
import com.rallydev.rest.util.QueryFilter;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Comparator;
import java.util.HashMap;
import java.util.TreeSet;
public class revisions {
public static void main(String[] args) throws URISyntaxException, IOException {
// Configure RallyRestApi
final String rallyURL = "https://rally1.rallydev.com";
final String wsapiVersion = "v2.0";
final RallyRestApi restApi = new RallyRestApi(new URI(rallyURL), "RallyID", "password"); // TODO: update id / password
restApi.setWsapiVersion(wsapiVersion);
// Select and query project information
final String myProject = "A Project Name"; // TODO: update project name
QueryRequest projectRequest = new QueryRequest("Project");
projectRequest.setFetch(new Fetch("Name", "Iterations"));
projectRequest.setQueryFilter(new QueryFilter("Name", "=", myProject));
QueryResponse projectQueryResponse = restApi.query(projectRequest);
String iterationListRef = projectQueryResponse.getResults().get(0).getAsJsonObject().get("Iterations").getAsJsonObject().get("_ref").toString().replaceAll("\"", "");
iterationListRef = iterationListRef.substring(iterationListRef.indexOf("Project"));
// Query and store iteration information
QueryRequest iterationRequest = new QueryRequest(iterationListRef);
QueryResponse iterationQueryResponse = restApi.query(iterationRequest);
HashMap<String, String> iterations = new HashMap<String, String>();
String iterationName = "", iterationStartDate="";
int irc = iterationQueryResponse.getTotalResultCount();
for (int iter = 0; iter < irc; iter++) {
JsonObject iterationObj = iterationQueryResponse.getResults().get(iter).getAsJsonObject();
iterationName = iterationObj.get("_refObjectName").toString();
iterationName = iterationName.substring(1, iterationName.length()-1);
iterationStartDate = iterationObj.get("StartDate").toString().replaceAll("\"", "").substring(0, 10);
iterations.put(iterationName, iterationStartDate);
}
// Query and store story information
QueryRequest storyRequest = new QueryRequest("HierarchicalRequirement");
String ir = iterationRequest.toUrl();
storyRequest.setProject(ir.substring(0, ir.indexOf("/iterations")));
QueryResponse storyQueryResponse = restApi.query(storyRequest);
TreeSet<StoryInfo> stories = new TreeSet<StoryInfo>(new StoryComp());
String refIteration = "", storyID = "", storyName = "", revHistory = "";
int src = storyQueryResponse.getTotalResultCount();
for (int story = 0; story < src; story++) {
JsonObject storyOjb = storyQueryResponse.getResults().get(story).getAsJsonObject();
refIteration = storyOjb.get("Iteration").toString();
if (refIteration.contains("_refObjectName"))
refIteration = storyOjb.get("Iteration").getAsJsonObject().get("_refObjectName").toString().replaceAll("\"", "");
storyID = storyOjb.get("FormattedID").toString();
storyID = storyID.substring(1, storyID.length()-1);
storyName = storyOjb.get("_refObjectName").toString().replaceAll("\"", "");
revHistory = storyOjb.get("RevisionHistory").getAsJsonObject().get("_ref").toString().replaceAll("\"", "");
revHistory = revHistory.substring(revHistory.indexOf("revisionhistory"))+"/Revisions";
stories.add(new StoryInfo(refIteration, ""+iterations.get(refIteration), storyID, storyName, revHistory));
}
System.out.println("Project: "+myProject);
for (StoryInfo s:stories) {
// Print the story iteration, id, name and revisions!
System.out.println('\n'+s.iteration+" - "+s.id+" "+s.name);
QueryRequest historyRequest = new QueryRequest(s.revHist);
QueryResponse historyResponse = restApi.query(historyRequest);
final int hrc = historyResponse.getTotalResultCount();
for (int rev = 1; rev < hrc; rev++) {
JsonObject historyObj = historyResponse.getResults().get(rev).getAsJsonObject();
// System.out.println(historyObj); // BINGO !!!
System.out.println(historyObj.get("RevisionNumber")+" "+historyObj.get("CreationDate")+" "+historyObj.get("Description"));
}
}
restApi.close();
}
static class StoryComp implements Comparator<StoryInfo> {
public int compare(StoryInfo i1, StoryInfo i2) {
return (i1.startDate+i1.id).compareTo(i2.startDate+i2.id);
}
}
static class StoryInfo {
String iteration, startDate, id, name, revHist;
StoryInfo(String it, String sd, String i, String n, String rh) {
iteration = it; startDate = sd; id = i; name = n; revHist = rh;
}
}
}