#set ($layout="json.vm")
#set ($dummy = $dbtool)
#set ($res=${response.setContentType("application/json")})
#if($params.key)
#set ($pl=$packagelists)
#set ($res=$pl.load($params.key))
#set ($lists=[ $pl ])
#{else}[
#if($params.profile)
#set ($res=$profiles.load($params.profile))
#set ($lists=$profiles.getPackageLists())
#else
#set ($lists=$packagelists.fetchAll())
#end
#end
#set ($count=$lists.size())
#foreach ($pl in $sorter.sort($lists,"name"))
#if ($count!=$velocityCount)
#set ($sep=",")
#else
#set ($sep="")
#end
#set ($diffcount = $pl.diffPackages($pl.origin).size())
#set ($origin_pl = [])
#set ($origin_pl = $pl.originPackageList)
#if (!$origin_pl.name)
#set ($origin="null")
#else
#set ($origin='"'+"$origin_pl.name"+'"')
#end
#set ($repos=$pl.repositories)
{ "name": "$pl.name", "description": "$!pl.description", "origin": $origin, "priority": "$pl.priority", "approvalRequired": $pl.approvalRequired, "approved": $pl.approved, "atomic": $pl.atomic, "autoUpdate": $pl.autoUpdate, "diffcount": $diffcount, "repositories": [#foreach($repo in $sorter.sort($repos,"name")) "$repo.name"#if ($velocityCount!=$repos.size()),#{end}#{end}] }$!sep
#end
#if(!$params.key)
]
#end
