How to: Post processing exported Work Items
Scenario
- The customer stores some documents in PDF and other formats outside of codebeamer
- These documents are referenced using links from the Work items' descriptions like this: [specification.pdf|http://codebeamer.com/1234]
- The customer wants to create a summary of all of such referenced documents on this server (codebeamer.com in this example)
- This summary should appear at the end of the Word report
This guide explains how to make such reports by post-processing the exported Work Items and producing a custom report.
The key elements of implementation:
- Create a custom template, where during the export to Word process you capture the HTML output of the Work Item's description
- Parse this HTML description using JSOUP Java HTML parser
- From the Parsed HTML search and find HTML links which are point to the doc-server.com, and collect such links to a Map object
- When the last Work item is processed print out the collected HTML links in the summary part
The implementation is the following script, which is added to the end of the Description part of the Word export template. A complete template document is here.
#*
This is a velocity template
Renders the „description” part of the exported entities
*#
## capture the HTML form of the Work item's description to a variable
#set($html = $wikiMarkupProcessor.transformToHtml(${describable.description}, ${describable.descriptionFormat}, false, false, $wikiContext))
## print out the description
$!{html}
<!-- ## Trick: adding an html comment block around this script to avoid any output appearing from here
## parse the HTML output of the item’s description using JSOUP
## calls the static method: JSoup.parse(String)
#set($Jsoup = $Class.forName(“org.jsoup.Jsoup”))
#set($doc = $Jsoup.parse($html))
## initialize a map of which will contain the links found in the descriptions
#if (! $collectedLinks)
#set($collectedLinks = {})
#end
## collect links by scanning the html for <A HREF=”…”>…</A> tags
## find the <a href="..."> ...</a> elements
#set($links = ${doc.select("a[href]")})
#foreach ($link in $links)
#set($href=${link.attr(“href”)})
#set($text=${link.text()})
#if ($href.indexOf(“codebeamer.com”) !=-1)
$!{collectedLinks.put($href, $text)}
#end
#end
-->
## print out links to codebeamer.com at the end of the last item
#if (! $index)
#set ($index = 0)
#end
#set($index = $index + 1)
#set ($numberOfExportItems = ${requirements.size()})
#set ($isLast = $numberOfExportItems == $index)
#if ($isLast)
<h3>Links to codebeamer.com</h3>
#foreach ($link in $collectedLinks.entrySet())
<a href=”${link.key}”>${link.value}</a><br/>
#end
#end