From fe74691fca00408ddd6d07dbcc318d4709b8e5f7 Mon Sep 17 00:00:00 2001 From: Francois Prunayre Date: Tue, 22 Aug 2023 16:32:28 +0200 Subject: [PATCH] INSPIRE / Validation / Add API usage. When using the JRC INSPIRE validator, users can follow their API usage and check if the quota of request is over or not. The usage API return the number of validation per day. Usage seems to not be updated right after triggering validation, and the API reflect the usage after some time. --- .../components/utility/UtilityDirective.js | 35 ++++++++++++++ .../utility/partials/inspireapiusage.html | 15 ++++++ .../js/admin/SystemSettingsController.js | 15 +++++- .../main/resources/catalog/locales/en-v4.json | 3 ++ .../templates/admin/settings/system.html | 47 ++++++++++--------- 5 files changed, 93 insertions(+), 22 deletions(-) create mode 100644 web-ui/src/main/resources/catalog/components/utility/partials/inspireapiusage.html diff --git a/web-ui/src/main/resources/catalog/components/utility/UtilityDirective.js b/web-ui/src/main/resources/catalog/components/utility/UtilityDirective.js index 91495553f00..8ad4d6483ea 100644 --- a/web-ui/src/main/resources/catalog/components/utility/UtilityDirective.js +++ b/web-ui/src/main/resources/catalog/components/utility/UtilityDirective.js @@ -2596,6 +2596,41 @@ } ]); + module.directive("gnInspireUsageDetails", [ + "$http", + function ($http) { + return { + restrict: "A", + replace: true, + scope: { + inspireApiUrl: "=gnInspireUsageDetails", + inspireApiKey: "=apiKey" + }, + templateUrl: "../../catalog/components/utility/partials/inspireapiusage.html", + link: function (scope, element, attrs) { + scope.inspireApiUsage = undefined; + if ( + scope.inspireApiUrl && + scope.inspireApiUrl.length > 0 && + scope.inspireApiKey && + scope.inspireApiKey.length > 0 + ) { + $http + .get(scope.inspireApiUrl + "/v2/Usages/" + scope.inspireApiKey + "/") + .then( + function (response) { + scope.inspireApiUsage = response.data; + }, + function (error) { + console.warn("Error while retrieving INSPIRE API quotas: ", error); + } + ); + } + } + }; + } + ]); + module.directive("gnSuggest", [ "gnMetadataManager", function (gnMetadataManager) { diff --git a/web-ui/src/main/resources/catalog/components/utility/partials/inspireapiusage.html b/web-ui/src/main/resources/catalog/components/utility/partials/inspireapiusage.html new file mode 100644 index 00000000000..14d3d044b21 --- /dev/null +++ b/web-ui/src/main/resources/catalog/components/utility/partials/inspireapiusage.html @@ -0,0 +1,15 @@ +
+ inspireApiQuotaCurrentValue
+ {{inspireApiUsage.body}} + + +
diff --git a/web-ui/src/main/resources/catalog/js/admin/SystemSettingsController.js b/web-ui/src/main/resources/catalog/js/admin/SystemSettingsController.js index 2d81d091a75..310ef2ad805 100644 --- a/web-ui/src/main/resources/catalog/js/admin/SystemSettingsController.js +++ b/web-ui/src/main/resources/catalog/js/admin/SystemSettingsController.js @@ -223,6 +223,9 @@ $scope.settings = data; angular.copy(data, $scope.initalSettings); + $scope.inspireApiUrl = undefined; + $scope.inspireApiKey = undefined; + for (var i = 0; i < $scope.settings.length; i++) { if ($scope.settings[i].name == "metadata/workflow/enable") { $scope.workflowEnable = $scope.settings[i].value == "true"; @@ -236,9 +239,19 @@ ) { $scope.isGroupPublicationNotificationLevel = $scope.settings[i].value === "recordGroupEmail"; - } else if ("system/localrating/notificationLevel") { + } else if ( + $scope.settings[i].name == "system/localrating/notificationLevel" + ) { $scope.isGroupLocalRatingNotificationLevel = $scope.settings[i].value === "recordGroupEmail"; + } else if ( + $scope.settings[i].name == "system/inspire/remotevalidation/url" + ) { + $scope.inspireApiUrl = $scope.settings[i].value; + } else if ( + $scope.settings[i].name == "system/inspire/remotevalidation/apikey" + ) { + $scope.inspireApiKey = $scope.settings[i].value; } var tokens = $scope.settings[i].name.split("/"); diff --git a/web-ui/src/main/resources/catalog/locales/en-v4.json b/web-ui/src/main/resources/catalog/locales/en-v4.json index 27163df800d..efb3d051c3c 100644 --- a/web-ui/src/main/resources/catalog/locales/en-v4.json +++ b/web-ui/src/main/resources/catalog/locales/en-v4.json @@ -130,6 +130,9 @@ "valid_inspire-0": "Invalid", "valid_inspire-3": "No rule applies", "valid_inspire--1": "Unknown", + "inspireApiQuotaCurrentValue": "JRC INSPIRE validator API usage information", + "inspireApiQuotaValidation": "Number of validation:", + "inspireApiQuotaRemaining": "Remaining:", "facet-OrgForResource": "Organizations", "facet-sourceCatalogue": "Catalogues", "facet-groupOwner": "Record groups", diff --git a/web-ui/src/main/resources/catalog/templates/admin/settings/system.html b/web-ui/src/main/resources/catalog/templates/admin/settings/system.html index a321dab04b3..841fa02afd6 100644 --- a/web-ui/src/main/resources/catalog/templates/admin/settings/system.html +++ b/web-ui/src/main/resources/catalog/templates/admin/settings/system.html @@ -626,27 +626,32 @@