Skip to content

Commit

Permalink
INSPIRE / Validation / Add API usage.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fxprunayre committed Sep 7, 2023
1 parent 7cb1dd0 commit fe74691
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div data-ng-show="inspireApiUsage">
<span data-translate="">inspireApiQuotaCurrentValue</span><br />
<span data-ng-if="!inspireApiUsage.body.items">{{inspireApiUsage.body}}</span>

<ul data-ng-if="inspireApiUsage.body.items">
<li data-ng-repeat="date in inspireApiUsage.body.items">
<span>{{date.date}}:</span>
<span data-translate="">inspireApiQuotaValidation</span>
<span>{{date.uses}}</span>
<span> / </span>
<span data-translate="">inspireApiQuotaRemaining</span>
<span>{{date.remaining_uses}}</span>
</li>
</ul>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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("/");
Expand Down
3 changes: 3 additions & 0 deletions web-ui/src/main/resources/catalog/locales/en-v4.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,27 +626,32 @@ <h4 class="modal-title" data-translate="">
/>
</div>

<div
class="input-group"
data-ng-switch-when="system/inspire/remotevalidation/url"
>
<input
type="text"
class="form-control"
id="{{s['name']}}"
name="{{s.name}}"
value="{{s.value}}"
placeholder="{{'system/inspire/remotevalidation/url-placeholder' | translate}}"
/>
<span class="input-group-btn">
<div
class="btn btn-default"
onClick="document.getElementById('system/inspire/remotevalidation/url').value = 'https://inspire.ec.europa.eu/validator/';"
data-translate=""
>
validatorUseInspireOne
</div>
</span>
<div data-ng-switch-when="system/inspire/remotevalidation/url">
<div class="input-group">
<input
type="text"
class="form-control"
id="{{s['name']}}"
name="{{s.name}}"
value="{{s.value}}"
placeholder="{{'system/inspire/remotevalidation/url-placeholder' | translate}}"
/>
<span class="input-group-btn">
<div
class="btn btn-default"
onClick="document.getElementById('system/inspire/remotevalidation/url').value = 'https://inspire.ec.europa.eu/validator/';"
data-translate=""
>
validatorUseInspireOne
</div>
</span>
</div>
<br />
<div
class="alert alert-info"
data-gn-inspire-usage-details="inspireApiUrl"
data-api-key="inspireApiKey"
></div>
</div>

<div
Expand Down

0 comments on commit fe74691

Please sign in to comment.