Wiki zdrojový kód pre License JSON
Naposledy upravil Admin-metais MetaIS 2025/05/28 21:41
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | {{include reference="Licenses.Code.VelocityMacros"/}} | ||
2 | |||
3 | {{velocity output="false"}} | ||
4 | #macro(getExtensionParentNames $licensedExtensionParents $extensionParentNames) | ||
5 | #set ($extensionParents = $collectiontool.set) | ||
6 | #foreach ($parent in $licensedExtensionParents) | ||
7 | #set ($discard = $extensionParents.add($parent.getExtensionName())) | ||
8 | #end | ||
9 | #set ($extensionParentNames = $stringtool.join($extensionParents, ', ')) | ||
10 | #end | ||
11 | #macro (addPaidExtensionRow $extension $rows $licensedDependenciesMap) | ||
12 | #set ($license = $services.licensing.licensor.getLicenseForExtension($extension.id)) | ||
13 | ## | ||
14 | ## Expiration Date | ||
15 | ## | ||
16 | #if (!$license || $license.expirationDate == 0) | ||
17 | #set ($expDateStatus = 'danger') | ||
18 | #set ($expDate = $services.localization.render('licensor.status.noLicenseAvailable')) | ||
19 | #elseif ($license.expirationDate == $LONG_MAX_VALUE) | ||
20 | #set ($expDateStatus = 'success') | ||
21 | #set ($expDate = $services.localization.render('licensor.status.infinite')) | ||
22 | #else | ||
23 | #set ($expDateStatus = "#if ($license.expirationDate > $datetool.date.time)success#{else}danger#end") | ||
24 | #set ($expDate = $datetool.format('dd/MM/yyyy', $license.expirationDate)) | ||
25 | #end | ||
26 | #set ($expDate = "<span class=""text-$!expDateStatus"">$!escapetool.xml($expDate)</span>") | ||
27 | ## | ||
28 | ## Support | ||
29 | ## | ||
30 | #set ($support = $license.licensee.support) | ||
31 | #if ("$!support" != '') | ||
32 | #set ($translationKey = 'licensor.support.' + $support.toLowerCase()) | ||
33 | #if ($services.localization.get($translationKey)) | ||
34 | #set ($support = $services.localization.render($translationKey)) | ||
35 | #else | ||
36 | #set ($support = $stringtool.capitalize($support)) | ||
37 | #end | ||
38 | #else | ||
39 | #set ($support = $services.localization.render('licensor.support.unspecified')) | ||
40 | #end | ||
41 | ## | ||
42 | ## User Limit | ||
43 | ## | ||
44 | #if (!$license || !$license.maxUserCount || $license.maxUserCount == $LONG_MAX_VALUE | ||
45 | || ($license.maxUserCount == 0 && $license.expirationDate == 0)) | ||
46 | ## The default value for the maxUserCount field of a license is Long.MAX_VALUE so when we encounter this value | ||
47 | ## we consider that the max user count was not specified. | ||
48 | #set ($userLimitStatus = 'muted') | ||
49 | #set ($userLimit = $services.localization.render('licensor.userLimit.unspecified')) | ||
50 | #elseif ($license.maxUserCount < 0) | ||
51 | #set ($userLimitStatus = 'success') | ||
52 | #set ($userLimit = $services.localization.render('licensor.userLimit.unlimited')) | ||
53 | #else | ||
54 | #set ($userLimitStatus = "#if ($userCount <= $license.maxUserCount)success#{else}danger#end") | ||
55 | #set ($userLimit = "$!userCount / $!license.maxUserCount") | ||
56 | #end | ||
57 | #set ($userLimit = "<span class=""text-$!userLimitStatus"">$!escapetool.xml($userLimit)</span>") | ||
58 | ## | ||
59 | ## Namespaces and Version | ||
60 | ## | ||
61 | #set ($namespaces = []) | ||
62 | #foreach ($namespace in $extension.namespaces) | ||
63 | #if ($namespace) | ||
64 | #set ($wikiPrettyName = $services.wiki.getById($namespace.split(':')[1]).prettyName) | ||
65 | #else | ||
66 | ## Create a pretty name for the extensions installed at root level (Installed on Farm). | ||
67 | #set ($wikiPrettyName = $services.localization.render('licensor.wiki.installedOnFarm')) | ||
68 | #end | ||
69 | #set ($discard = $namespaces.add($wikiPrettyName)) | ||
70 | #end | ||
71 | #set ($namespaces = $collectiontool.sort($namespaces)) | ||
72 | ## | ||
73 | ## Extension name. A warning will be displayed for extensions installed as depedencies.Note | ||
74 | ## that we consider optional depedencies as being not covered by the license of the parent | ||
75 | ## extension, as they can be uninstalled, so a warning will be displayed for them. | ||
76 | ## | ||
77 | #set ($queryString = $escapetool.url({ | ||
78 | 'instanceId': $services.instance.instanceId, | ||
79 | 'featureId': $extension.id.id, | ||
80 | 'extensionVersion': $extension.id.version, | ||
81 | 'firstName': $ownerObj.getValue('firstName'), | ||
82 | 'lastName': $ownerObj.getValue('lastName'), | ||
83 | 'email': $ownerObj.getValue('email') | ||
84 | })) | ||
85 | #set ($documentationURL = "${storeAccessURL}?${queryString}") | ||
86 | #set ($extensionName = "<a href=""$documentationURL"" target='_blank'>$extension.name</a>") | ||
87 | #set ($licensedExtensionParents = $licensedDependenciesMap.get($extension.id.id)) | ||
88 | #if ($licensedExtensionParents && $licensedExtensionParents.size() > 0) | ||
89 | #getExtensionParentNames($licensedExtensionParents $extensionParentNames) | ||
90 | #set ($requiredByTitle = $escapetool.xml($services.localization.render( | ||
91 | 'licensor.installedAsDependency.value.requiredBy')) + $extensionParentNames) | ||
92 | #set ($extensionNameValue = "$services.icon.renderHTML('warning') ${extensionName}") | ||
93 | #set ($extensionName = "<span class='required-by-info' data-parent-extensions=""$extensionParentNames"" | ||
94 | title=""$requiredByTitle"">${extensionNameValue}</span>") | ||
95 | #end | ||
96 | ## | ||
97 | ## Rows | ||
98 | ## | ||
99 | #set ($discard = $rows.add({ | ||
100 | 'doc_viewable': true, | ||
101 | 'name': $extensionName, | ||
102 | 'name_url': $documentationURL, | ||
103 | 'version': $extension.id.version.toString(), | ||
104 | 'status': $expDate, | ||
105 | 'support': $support, | ||
106 | 'userLimit': $userLimit, | ||
107 | 'installedAsDependency': $installedAsDependency, | ||
108 | 'wiki': $stringtool.join($namespaces, ', '), | ||
109 | 'actions': "#licenseActions($license $extension)" | ||
110 | })) | ||
111 | #end | ||
112 | {{/velocity}} | ||
113 | |||
114 | {{velocity wiki="false"}} | ||
115 | #if ($xcontext.action == 'get') | ||
116 | #set ($discard = $response.setContentType('application/json')) | ||
117 | #end | ||
118 | #getVisiblePaidExtensions | ||
119 | #if ($request.showTopLevelExtensions == true) | ||
120 | #set ($extensions = $visiblePaidExtensions) | ||
121 | #else | ||
122 | #getPaidExtensions | ||
123 | #set ($extensions = $paidExtensions) | ||
124 | #end | ||
125 | #set ($licensedDependenciesMap = $services.licensing.licensor.getLicensedExtensionManager().getLicensedDependenciesMap()) | ||
126 | #set ($rows = []) | ||
127 | #foreach ($extension in $extensions) | ||
128 | #if ($extension.type != 'jar') | ||
129 | #addPaidExtensionRow($extension $rows $licensedDependenciesMap) | ||
130 | #end | ||
131 | #end | ||
132 | #set ($rows = $collectiontool.sort($rows, 'name')) | ||
133 | #set ($offset = $mathtool.sub($numbertool.toNumber($request.offset).intValue(), 1)) | ||
134 | #if ("$!offset" == '') | ||
135 | #set ($offset = 0) | ||
136 | #end | ||
137 | #set ($offset = $mathtool.max($mathtool.min($offset, $mathtool.sub($rows.size(), 1)), 0)) | ||
138 | #set ($limit = $numbertool.toNumber($request.limit).intValue()) | ||
139 | #if ("$!limit" == '') | ||
140 | #set ($limit = 10) | ||
141 | #elseif ($limit <= 0) | ||
142 | #set ($limit = $rows.size()) | ||
143 | #end | ||
144 | #set ($limit = $mathtool.min($limit, $mathtool.sub($rows.size(), $offset))) | ||
145 | $jsontool.serialize({ | ||
146 | 'reqNo': $request.reqNo, | ||
147 | 'totalrows': $rows.size(), | ||
148 | 'returnedrows': $limit, | ||
149 | 'offset': $mathtool.add($offset, 1), | ||
150 | 'rows': $rows.subList($offset, $mathtool.add($offset, $limit)) | ||
151 | }) | ||
152 | {{/velocity}} |