Wiki zdrojový kód pre License JSON

Naposledy upravil Admin-metais MetaIS 2024/10/30 11:04

Show last authors
1 {{include reference="Licenses.Code.VelocityMacros"/}}
2
3 {{velocity output="false"}}
4 #macro (addPaidExtensionRow $extension $rows)
5 #set ($license = $services.licensing.licensor.getLicenseForExtension($extension.id))
6 ##
7 ## Expiration Date
8 ##
9 #if (!$license || $license.expirationDate == 0)
10 #set ($expDateStatus = 'danger')
11 #set ($expDate = $services.localization.render('licensor.status.noLicenseAvailable'))
12 #elseif ($license.expirationDate == $LONG_MAX_VALUE)
13 #set ($expDateStatus = 'success')
14 #set ($expDate = $services.localization.render('licensor.status.infinite'))
15 #else
16 #set ($expDateStatus = "#if ($license.expirationDate > $datetool.date.time)success#{else}danger#end")
17 #set ($expDate = $datetool.format('dd/MM/yyyy', $license.expirationDate))
18 #end
19 #set ($expDate = "<span class=""text-$!expDateStatus"">$!escapetool.xml($expDate)</span>")
20 ##
21 ## Support
22 ##
23 #set ($support = $license.licensee.support)
24 #if ("$!support" != '')
25 #set ($translationKey = 'licensor.support.' + $support.toLowerCase())
26 #if ($services.localization.get($translationKey))
27 #set ($support = $services.localization.render($translationKey))
28 #else
29 #set ($support = $stringtool.capitalize($support))
30 #end
31 #else
32 #set ($support = $services.localization.render('licensor.support.unspecified'))
33 #end
34 ##
35 ## User Limit
36 ##
37 #if (!$license || !$license.maxUserCount || $license.maxUserCount == $LONG_MAX_VALUE
38 || ($license.maxUserCount == 0 && $license.expirationDate == 0))
39 ## The default value for the maxUserCount field of a license is Long.MAX_VALUE so when we encounter this value
40 ## we consider that the max user count was not specified.
41 #set ($userLimitStatus = 'muted')
42 #set ($userLimit = $services.localization.render('licensor.userLimit.unspecified'))
43 #elseif ($license.maxUserCount < 0)
44 #set ($userLimitStatus = 'success')
45 #set ($userLimit = $services.localization.render('licensor.userLimit.unlimited'))
46 #else
47 #set ($userLimitStatus = "#if ($userCount <= $license.maxUserCount)success#{else}danger#end")
48 #set ($userLimit = "$!userCount / $!license.maxUserCount")
49 #end
50 #set ($userLimit = "<span class=""text-$!userLimitStatus"">$!escapetool.xml($userLimit)</span>")
51 ##
52 ## Namespaces and Version
53 ##
54 #set ($namespaces = [])
55 #foreach ($namespace in $extension.namespaces)
56 #if ($namespace)
57 #set ($wikiPrettyName = $services.wiki.getById($namespace.split(':')[1]).prettyName)
58 #else
59 ## Create a pretty name for the extensions installed at root level (Installed on Farm).
60 #set ($wikiPrettyName = $services.localization.render('licensor.wiki.installedOnFarm'))
61 #end
62 #set ($discard = $namespaces.add($wikiPrettyName))
63 #end
64 #set ($namespaces = $collectiontool.sort($namespaces))
65 ##
66 ## Other
67 ##
68 #set ($queryString = $escapetool.url({
69 'instanceId': $services.instance.instanceId,
70 'featureId': $extension.id.id,
71 'extensionVersion': $extension.id.version,
72 'firstName': $ownerObj.getValue('firstName'),
73 'lastName': $ownerObj.getValue('lastName'),
74 'email': $ownerObj.getValue('email')
75 }))
76 #set ($documentationURL = "${storeAccessURL}?${queryString}")
77 #set ($discard = $rows.add({
78 'doc_viewable': true,
79 'name': $extension.name,
80 'name_url': $documentationURL,
81 'version': $extension.id.version.toString(),
82 'status': $expDate,
83 'support': $support,
84 'userLimit': $userLimit,
85 'wiki': $stringtool.join($namespaces, ', '),
86 'actions': "#licenseActions($license $extension)"
87 }))
88 #end
89 {{/velocity}}
90
91 {{velocity wiki="false"}}
92 #if ($xcontext.action == 'get')
93 #set ($discard = $response.setContentType('application/json'))
94 #end
95 #if ($request.showAllPaidExtensions == 'true')
96 #getPaidExtensions
97 #set ($extensions = $paidExtensions)
98 #else
99 #getVisiblePaidExtensions
100 #set ($extensions = $visiblePaidExtensions)
101 #end
102 #set ($rows = [])
103 #foreach ($extension in $extensions)
104 #addPaidExtensionRow($extension $rows)
105 #end
106 #set ($rows = $collectiontool.sort($rows, 'name'))
107 #set ($offset = $mathtool.sub($numbertool.toNumber($request.offset).intValue(), 1))
108 #if ("$!offset" == '')
109 #set ($offset = 0)
110 #end
111 #set ($offset = $mathtool.max($mathtool.min($offset, $mathtool.sub($rows.size(), 1)), 0))
112 #set ($limit = $numbertool.toNumber($request.limit).intValue())
113 #if ("$!limit" == '')
114 #set ($limit = 10)
115 #elseif ($limit <= 0)
116 #set ($limit = $rows.size())
117 #end
118 #set ($limit = $mathtool.min($limit, $mathtool.sub($rows.size(), $offset)))
119 $jsontool.serialize({
120 'reqNo': $request.reqNo,
121 'totalrows': $rows.size(),
122 'returnedrows': $limit,
123 'offset': $mathtool.add($offset, 1),
124 'rows': $rows.subList($offset, $mathtool.add($offset, $limit))
125 })
126 {{/velocity}}