Collections in Polarion

Problem

  • For some reason you need a java.util.Set (f.i. HashSet) or a simple java.util.List (f.i. ArrayList).
  • In Polarion Classic Wiki Pages you can’t instantiate Java Collections by your own.

Solution

To obtain a collection you have to steal it. Since you can’t write

#set($test = new java.util.ArrayList())

you have to use a trick to get a fresh collection. Some of the Polarion services and objects are returning Java collections. Thus you only have to force them return an empty collection. Below you will find two examples (HashSet and ArrayList) for this solution.

Obtain a clean java.util.HashSet<IWorkItem>

In some cases i need a free of duplicates list by simply using a Set. To get a Set/HashSet I use the method filterWorkItems from IModule. For a clean HashSet I use a senseless lucene query. For a valid instance of a IModule I just search for a WorkItem.

##Example Code for retrieving a workitem
#set($proId = "ExampleProjectID")
#set($wiId = "WorkItemID")
#set($pro = $projectService.getProject($proId))
#set($tpro = $trackerService.getTrackerProject($pro))
#set($WIobject = $tpro.getWorkItem($wiId))

##Getting a HashSet
#set($hs = $WIobject.getModule().filterWorkItems(“status:YYY”))

##Add an item to the HashSet
#set($bla = $hs.add($someWorkItem))

Obtain a clean java.util.ArrayList<IWorkItem>


##Getting an ArrayList
#set($al = $WIobject.getModule().getExternalWorkItems())

Other instances of Collection

If you need Collections with different generic types you should simply use Google (or your prefered search engine).

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s