java - How to find the list of user stories under a given iteration and a given project using rally rest api -


i able iterations under project object. how iteration need under project , drill down stories in iteration using java toolkit?

https://sandbox.rallydev.com/slm/webservice/v2.0/project/7191194697/iterations

given project:

string projectref = "/project/1234"; 

you may scope requests follows:

iterationrequest.setproject(projectref); 

or

storyrequest.setproject(projectref); 

if scoped story request project, may query on stories traversing iteration.name if know iteration already:

storyrequest.setqueryfilter(new queryfilter("iteration.name", "=", "my iteration 1")); 

here more complex example returns stories assigned iterations fall within timbox of specific release. if, example, have 4 iterations per release, code return stories assigned 4 iterations.

if code against sandbox, replace value in host variable accordingly.

public class finditerationsbyreleasedateandstories {      public static void main(string[] args) throws urisyntaxexception, ioexception {           string host = "https://rally1.rallydev.com";             string username = "user@co.com";             string password = "secret";             string projectref = "/project/12352608219";             string applicationname = "find iterations release dates , stories";              rallyrestapi restapi = null;          try {                 restapi = new rallyrestapi(                         new uri(host),                         username,                         password);                 restapi.setapplicationname(applicationname);                   system.out.println(restapi.getwsapiversion());                   queryrequest  releaserequest = new queryrequest("release");                 releaserequest.setfetch(new fetch("releasestartdate", "releasedate"));                 releaserequest.setscopeddown(false);                 releaserequest.setscopedup(false);                 releaserequest.setproject(projectref);                 releaserequest.setqueryfilter(new queryfilter("name", "=", "r1"));                  queryresponse releasequeryresponse = restapi.query(releaserequest);                 int numberofreleasesinproject = releasequeryresponse.gettotalresultcount();                 system.out.println(numberofreleasesinproject);                 jsonobject releasejsonobject = releasequeryresponse.getresults().get(0).getasjsonobject();                 system.out.println(releasejsonobject.get("releasestartdate"));                 system.out.println(releasejsonobject.get("releasedate"));                  string rsd = releasejsonobject.get("releasestartdate").getasstring();                 string rd = releasejsonobject.get("releasedate").getasstring();                  queryrequest  iterationrequest = new queryrequest("iteration");                 iterationrequest.setfetch(new fetch("name","startdate","enddate"));                 iterationrequest.setscopeddown(false);                 iterationrequest.setscopedup(false);                 iterationrequest.setproject(projectref);                 iterationrequest.setqueryfilter(new queryfilter("startdate", ">=", rsd).and(new queryfilter("enddate", "<=", rd)));                  queryresponse iterationqueryresponse = restapi.query(iterationrequest);                 int numberofiteraitons = iterationqueryresponse.gettotalresultcount();                 system.out.println("numberofiteraitons " + numberofiteraitons);                 if(numberofiteraitons >0){                     (int i=0;i<numberofiteraitons;i++){                         jsonobject iterationjsonobject = iterationqueryresponse.getresults().get(i).getasjsonobject();                         string iterationname = iterationjsonobject.get("name").getasstring();                         system.out.println("iteration: " + iterationname);                         queryrequest storyrequest = new queryrequest("hierarchicalrequirement");                         storyrequest.setproject(projectref);                         storyrequest.setfetch(new fetch(new string[] {"name", "formattedid","schedulestate"}));                         storyrequest.setlimit(1000);                         storyrequest.setscopeddown(false);                         storyrequest.setscopedup(false);                         storyrequest.setqueryfilter(new queryfilter("iteration.name", "=", iterationname));                          queryresponse storyqueryresponse = restapi.query(storyrequest);                         system.out.println("number of stories in " + iterationname + " :" + storyqueryresponse.gettotalresultcount());                          (int j=0; j<storyqueryresponse.getresults().size();j++){                             jsonobject storyjsonobject = storyqueryresponse.getresults().get(j).getasjsonobject();                             system.out.println("name: " + storyjsonobject.get("name") + " formattedid: " + storyjsonobject.get("formattedid") + " schedulestate: " + storyjsonobject.get("schedulestate"));                         }                     }                 }                }         finally{             if (restapi != null) {                 restapi.close();             }         }      } } 

update: far question in comment, code above equivalent of

https://rally1.rallydev.com/slm/webservice/v2.0/hierarchicalrequirement?query=((iteration.name = i1) , (project = /project/12352608219)) 

there other ways achive same result. iteration name may not unique, hence second condition project ref. in code request's project set first, that's why query uses 1 condition, there two. if know iteration's ref, or objectid same result returned (iteration = /iteration/123456789), , there no need filter project since reference or objectid unique.

ws api doc interactive.test queries in ws api , copy resulting query urls address bar if want see how queries formed:

-query in context of intended object: click on work item type in object model, e.g. defect or hierarchicalrequirement before typing query in query box.

-enter query in box, e.g (iteration.name = i1)

-click on query button

-results displayed in window can copy query url address bar of browser.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -