0

Here's my code:

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

I get an IllegalArgumentException when I try using the LBAPI. Can anyone help me on this please?

Trever Shick
  • 1,734
  • 16
  • 17
Rohan Dalvi
  • 1,215
  • 1
  • 16
  • 38

1 Answers1

2

I think the example in the README for Rally-Lookback-Toolkit is misleading/erroneous in the way it specifies a Workspace by name:

lookbackApi.setWorkspace("myworkspace");

When I do this, I see the following error from LBAPI:

Lookback Exception com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1

What's needed in the REST URL is actually the Workspace ObjectID instead of the name. Thus, if you set the Workspace ObjectID in your code:

this.lookback.setWorkspace("12345678910");

I think the query should work for you.

  • I get this warning when I run the script: `org.apache.http.client.protocol.ResponseProcessCookies processCookies WARNING: Cookie rejected: "[version: 0][name: JSESSIONID][value: 1gusjyuoy3dzidvsqv3p0m3ta][domain: rally1.rallydev.com][path: /analytics-api][expiry: null]". Illegal path attribute "/analytics-api". Path of origin: "/analytics/v2.0/service/rally/workspace/2154600806/artifact/snapshot/query.js" Feb 23, 2014 7:44:34 PM org.apache.http.client.protocol.ResponseProcessCookies processCookies WARNING: Cookie rejected: "[version: 0][name: ZSESSIONID]` – Rohan Dalvi Feb 24 '14 at 00:46
  • Good catch. My example is doing this also. It looks like LBAPI is in fact returning a cookie referencing an invalid path. I'll check with the engineering team about this. However, as a warning-level error from the apache http client, I'm finding that I can still retrieve the needed results. –  Feb 24 '14 at 01:01
  • also the value of "ObjectID" returned by the Lookback api in the result set is of type double which is strange. – Rohan Dalvi Feb 24 '14 at 01:31
  • 1
    This will at least temporarily quiet down the code. Logger.getLogger("org.apache.http.client.protocol.ResponseProcessCookies").setLevel(Level.SEVERE); – Trever Shick Feb 24 '14 at 01:48
  • Thanks Trever! Rohan - the Double for the ObjectID is simply how GSON handles de-serialization of numbers contained in JSON data - Double is the most generic return type that can handle multiple types of numeric data represented as strings. See http://stackoverflow.com/questions/15507997/how-to-prevent-gson-from-expressing-integers-as-floats. –  Feb 24 '14 at 02:00
  • @MarkW, I need to pass this ObjectID value to another query, can I just pass it directly as it is? Or do I need to change the format to BigInteger and then pass it to the next query function? – Rohan Dalvi Feb 24 '14 at 03:23
  • If it's another Lookback query, you should be able to pass as-is. addFindClause looks like this: public LookbackQuery addFindClause(String field, Object value). So a Double should work just fine. –  Feb 24 '14 at 03:35
  • @MarkW I tried to cast this into BigInteger and I got some good values but in some cases, it just gives me a `NoSuchElementException` even though I see the ObjectID value in the JsonObject. Here's an example: `Object {ObjectID=1.7082234625E10, Iteration=1.6859830862E10, Name=Child of US5690: Epic} Lookback Exception java.util.NoSuchElementException` This is my code that causes that Exception: `Double d = Double.parseDouble(m.get("ObjectID").toString()); System.out.println("Double "+d);` – Rohan Dalvi Feb 24 '14 at 14:23