Page 1 of 1

Get Last Revision of a WorkItem using the SOAP WEB api

Posted: Wed Oct 11, 2017 2:27 pm
by dbosman
How can I retrieve the last revision id of a work item using the SOAP WEB api?

It is possible via the trackerService generateHistory method, but this retrieves all revisions and change information which is very slow.

May be its possible using one of the TrackerSevice methods, unfortunately the API javadoc documentation is not very helpful with respect to Revision objects.

Any ideas would be appreciated!

Re: Get Last Revision of a WorkItem using the SOAP WEB api

Posted: Thu Feb 01, 2018 1:42 pm
by dbosman
I'm using this code to obtain the last revision

Change[] changes = trackerService.generateHistory(wi.getUri(),null,null);
List<Change> changes_l = Arrays.asList(changes);
Collections.reverse(changes_l);.
String revision = changes_l.get(0).getRevision();

But as said this traverses the complete history. Is there a way to get the latest revision more directly? eg.

wi.getLastRevision()

Re: Get Last Revision of a WorkItem using the SOAP WEB api

Posted: Fri Feb 02, 2018 1:38 pm
by ALMighty
dbosman wrote:But as said this traverses the complete history. Is there a way to get the latest revision more directly? eg.


Maybe not more direct but probably faster concerning runtime. :wink:

You can get all Revision ids as a String array of a workitem with the getRevisions() method, which requires the URI of a work item, Testrun, Plan or any type of object in Polarion (as long as it has a URI) as a parameter. In this String array, the last cell contains the id of the last revision, so you can access it directly like that:

Code: Select all

// Note: revisionIDs ist just an example name of that array
String lastRevisionID = revisionIDs[revisionIDs.length -1];


This id can then be used for the getRevision() method, which returns a Revision object and requires the repository name and the id of a revison as parameter. As repo name you can use "default". This revision object contains all the information you probably need (the work items that were included, the commit date and so on).

NOTE: You could also use the getRevisionByUri() method if you like, as you can create the URI with a little bit of String building. A revision URI looks like this, the numbers after the last curly bracket represent the revision id:

Code: Select all

subterra:data-service:objects:/default/${Revision}1234616

Re: Get Last Revision of a WorkItem using the SOAP WEB api

Posted: Fri Feb 09, 2018 12:23 pm
by dbosman
Thanks for the suggestion!. This already shows quite a speed up.

Re: Get Last Revision of a WorkItem using the SOAP WEB api

Posted: Wed Feb 14, 2018 4:08 pm
by ALMighty
dbosman wrote:Thanks for the suggestion!. This already shows quite a speed up.


I am grateful for your feedback. Thank you! :D
I am happy to read that I could help. :wink: