0
這裏是我的代碼:拉力賽的Java API回溯期
import com.google.gson.JsonElement;
import com.rallydev.lookback.LookbackApi;
import com.rallydev.lookback.LookbackQuery;
import com.rallydev.lookback.LookbackResult;
import java.math.BigInteger;
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.*;
import java.net.URI;
import javax.management.Query;
import com.google.gson.JsonObject;
public class dIterationPsiAutomation {
public String rallyURI;
public String appName;
public String username;
public String password;
public RallyRestApi restApi;
public LookbackApi lookback;
public dIterationPsiAutomation(String rallyURL,String username,String password, String applicationName) {
// TODO Auto-generated constructor stub
this.rallyURI = rallyURL;
this.appName = applicationName;
this.username = username;
this.password = password;
this.connect(this.rallyURI, this.appName, this.username, this.password);
}
public void connect(String uri,String app,String username,String password){
try //Unhandled URI Exception occurs here
{
this.restApi = new RallyRestApi(new URI(uri),username,password);
this.restApi.setApplicationName("v2.0");
this.restApi.setApplicationName(app);
this.lookback = new LookbackApi();
this.lookback.setCredentials(username, password);
this.lookback.setWorkspace("Workspace 1");
}
catch(Exception e){
System.out.println("Exception occured "+e);
}
}
public void getFeatureInfo(String featureName) throws IOException {
QueryRequest feature = new QueryRequest("portfolioitem/feature");
feature.setFetch(new Fetch("FormattedID","ObjectID","Name"));
feature.setQueryFilter(new QueryFilter("Name","=",featureName));
QueryResponse queryResponse = this.restApi.query(feature);
}
public void get_formattedID(JsonElement ObjectID){
}
public void get_prefixed_stories(String prefix){
try{
QueryRequest stories = new QueryRequest("hierarchicalrequirement");
stories.setFetch(new Fetch("Children","Name","Iteration","FormattedID","ObjectID"));
stories.setQueryFilter(new QueryFilter("Name","contains",prefix));
QueryResponse response = this.restApi.query(stories);
if(response.wasSuccessful()){
System.out.println(String.format("Total result count %d", response.getTotalResultCount()));
for(JsonElement result: response.getResults()){
JsonObject story = result.getAsJsonObject();
System.out.println(String.format("%s - %s: ObjectID: %s", story.get("FormattedID").getAsString(), story.get("Name").getAsString(), story.get("ObjectID").getAsBigInteger()));
get_all_leaf_stories(story.get("ObjectID").getAsBigInteger());
}
}
}
catch(Exception e){
System.out.println("Caught an exception in get_prefixed_stories method");
System.out.println("More details "+e);
}
}
public void get_all_leaf_stories(BigInteger oID){
try{
LookbackQuery query = this.lookback.newSnapshotQuery();
query.addFindClause("_TypeHierarchy", "HierarchicalRequirement");
query.addFindClause("_ItemHierarchy", oID);
query.addFindClause("Children", null);
query.addFindClause("__At", "current");
query.requireFields("Iteration","ObjectID","Name");
query.sortBy("Iteration", -1);
LookbackResult resultSet = query.execute();
if(resultSet.hasWarnings()){
System.out.println("Errors in lookback "+resultSet.Errors);
}
int resultCount = resultSet.Results.size();
System.out.println("Lookback resultset is "+resultCount);
}
catch(Exception e){
System.out.println("Lookback Exception "+e);
}
}
}
我得到一個IllegalArgumentException,當我嘗試使用LBAPI。任何人都可以幫助我嗎?
當我運行該腳本,我得到這樣的警告: 'org.apache.http.client.protocol.ResponseProcessCookies processCookies 警告:Cookie的拒絕:「[版本:0] [名稱:JSESSIONID] [值:1gusjyuoy3dzidvsqv3p0m3ta] [域:rally1.rallydev.com] [路徑:/ analytics-api] [expiry:null]「。非法路徑屬性「/ analytics-api」。來源路徑:「/analytics/v2.0/service/rally/workspace/2154600806/artifact/snapshot/query.js」 2014年2月23日下午7:44:34 org.apache.http.client.protocol.ResponseProcessCookies processCookies 警告:Cookie被拒絕:「[version:0] [name:ZSESSIONID]' –
好的catch。我的例子也是這樣做的。看起來LBAPI實際上是返回一個引用無效路徑的cookie。但是,作爲來自apache http客戶端的警告級別錯誤,我發現我仍然可以檢索所需的結果。 – 2014-02-24 01:01:57
也是結果集中Lookback api返回的「ObjectID」的值是奇怪的類型double。 –