diff --git a/application-licensing-licensor/application-licensing-licensor-api/src/main/java/com/xwiki/licensing/internal/upgrades/NewExtensionVersionAvailableManager.java b/application-licensing-licensor/application-licensing-licensor-api/src/main/java/com/xwiki/licensing/internal/upgrades/NewExtensionVersionAvailableManager.java index a7d8d390..323b82d6 100644 --- a/application-licensing-licensor/application-licensing-licensor-api/src/main/java/com/xwiki/licensing/internal/upgrades/NewExtensionVersionAvailableManager.java +++ b/application-licensing-licensor/application-licensing-licensor-api/src/main/java/com/xwiki/licensing/internal/upgrades/NewExtensionVersionAvailableManager.java @@ -79,42 +79,40 @@ public void checkLicensedExtensionsAvailableVersions() InstalledExtension installedExtension = installedRepository.getInstalledExtension(extensionId); Collection namespaces = installedExtension.getNamespaces(); if (namespaces == null) { - notifyExtensionAvailableVersion(installedExtension.getId(), null); + notifyExtensionVersionAvailable(installedExtension.getId(), null); } else { for (String namespace : installedExtension.getNamespaces()) { - notifyExtensionAvailableVersion(installedExtension.getId(), namespace); + notifyExtensionVersionAvailable(installedExtension.getId(), namespace); } } } - } - private void notifyExtensionAvailableVersion(ExtensionId extensionId, String namespace) + private void notifyExtensionVersionAvailable(ExtensionId extensionId, String namespace) { InstalledExtension installedExtension = installedRepository.getInstalledExtension(extensionId.getId(), namespace); + // Get the list of versions that can be installed, with the first one being the most recent. List installableVersions = upgradeExtensionHandler.getInstallableVersions(installedExtension.getId()); - if (installableVersions.size() <= 0) { + if (installableVersions.isEmpty()) { return; } List newVersionNotifiedExtensions = new ArrayList<>(licensingConfig.getNewVersionNotifiedExtensions()); String namespaceName = namespace != null ? namespace : "root"; - // Create an identified for the extension, by consider also the version and namespace. - String verifiedExtensionId = + // Create an identifier for the extension, by consider also the version and namespace. + String currentExtensionId = String.format("%s-%s-%s", extensionId.getId(), namespaceName, installableVersions.get(0)); - if (!newVersionNotifiedExtensions.contains(verifiedExtensionId)) { - newVersionNotifiedExtensions.add(verifiedExtensionId); + if (!newVersionNotifiedExtensions.contains(currentExtensionId)) { + newVersionNotifiedExtensions.add(currentExtensionId); licensingConfig.setNewVersionNotifiedExtensions(newVersionNotifiedExtensions); - String message = - String.format("%s - %s - %s", installedExtension.getName(), namespaceName, installableVersions.get(0)); - this.observationManager - .notify( - new NewExtensionVersionAvailableEvent( - new ExtensionId(extensionId.getId(), installableVersions.get(0)), namespace), - extensionId.getId(), message); + String message = String.format("{\"extensionName\":\"%s\", \"namespace\": \"%s\", \"version\": \"%s\"}", + installedExtension.getName(), namespaceName, installableVersions.get(0)); + this.observationManager.notify( + new NewExtensionVersionAvailableEvent(new ExtensionId(extensionId.getId(), installableVersions.get(0)), + namespace), extensionId.getId(), message); } } } diff --git a/application-licensing-licensor/application-licensing-licensor-api/src/main/resources/templates/newVersionAvailable.vm b/application-licensing-licensor/application-licensing-licensor-api/src/main/resources/templates/newVersionAvailable.vm index 0d317d3e..2035e40b 100644 --- a/application-licensing-licensor/application-licensing-licensor-api/src/main/resources/templates/newVersionAvailable.vm +++ b/application-licensing-licensor/application-licensing-licensor-api/src/main/resources/templates/newVersionAvailable.vm @@ -4,14 +4,13 @@ #set ($smallIcon = "arrow_up") #set ($compositeEventDate = $escapetool.xml($datetool.whenIs($event.dates.get(0)))) -#macro (getExtensionUpgradeURL $event) - ## The event body contains information about the extension id, version and targeted namespace. - #set ($extensionInfo = $event.getBody().split(' - ')) - #set ($extensionNamespace = "#if ($extensionInfo[1] == 'root')$xcontext.mainWikiName#{else}$extensionInfo[1]#end") +#macro (getExtensionUpgradeURL $extensionInfo) + #set ($extensionNamespace = + "#if ($extensionInfo.namespace == 'root')$xcontext.mainWikiName#{else}$extensionInfo.namespace#end") #set ($queryParams = $escapetool.url({ 'section': 'XWiki.Extensions', 'extensionId': $event.getApplication(), - 'extensionVersion': $extensionInfo[2], + 'extensionVersion': $extensionInfo.version, 'extensionNamespace': $extensionNamespace })) $xwiki.getURL($services.model.createDocumentReference($xcontext.mainWikiName, 'XWiki', 'XWikiPreferences'), @@ -23,9 +22,12 @@ $escapetool.xml($event.user.name) - ## The notification message is stored directly on the event body. + ## The event body contains information about the extension name, version and targeted namespace. + #set ($extensionInfo = $jsontool.fromString($event.getBody())) - $escapetool.xml($event.getBody()) + + $extensionInfo.extensionName - $extensionInfo.namespace - $extensionInfo.version + $escapetool.xml($datetool.whenIs($event.date))