Get Last Revision of a WorkItem using the SOAP WEB api

Description
dbosman
Posts: 8
Joined: Wed Feb 08, 2017 10:16 am

Get Last Revision of a WorkItem using the SOAP WEB api

Postby dbosman » Wed Oct 11, 2017 2:27 pm

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!

dbosman
Posts: 8
Joined: Wed Feb 08, 2017 10:16 am

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

Postby dbosman » Thu Feb 01, 2018 1:42 pm

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()

ALMighty
Posts: 80
Joined: Wed Apr 27, 2016 10:34 am
Location: Austria

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

Postby ALMighty » Fri Feb 02, 2018 1:38 pm

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
---------------------------------------------------------------------------------------------------
Playing a good game is never lame. :D
Image

dbosman
Posts: 8
Joined: Wed Feb 08, 2017 10:16 am

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

Postby dbosman » Fri Feb 09, 2018 12:23 pm

Thanks for the suggestion!. This already shows quite a speed up.

ALMighty
Posts: 80
Joined: Wed Apr 27, 2016 10:34 am
Location: Austria

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

Postby ALMighty » Wed Feb 14, 2018 4:08 pm

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:


Return to “Polarion Application Lifecycle Management (ALM)”

Who is online

Users browsing this forum: No registered users and 7 guests