Skip to content

Commit

Permalink
Merge pull request #1114 from Ontotext-AD/GDB-9019-Loading-a-non-exis…
Browse files Browse the repository at this point in the history
…tent-predicate-for-filtering-in-the-RDF-Rank-seems-to-break-the-Workbench-view

GDB-9019 Loading a non-existent predicate for filtering in the RDF Rank seems to break the Workbench view
  • Loading branch information
MartinaDimova authored Nov 3, 2023
2 parents 6087f66 + fa450a4 commit b27fa50
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 79 deletions.
43 changes: 31 additions & 12 deletions src/js/angular/autocomplete/controllers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'angular/rest/autocomplete.rest.service';
import {mapNamespacesResponse} from "../rest/mappers/namespaces-mapper";

const modules = [
'toastr',
Expand All @@ -10,9 +11,9 @@ angular
.controller('AutocompleteCtrl', AutocompleteCtrl)
.controller('AddLabelCtrl', AddLabelCtrl);

AutocompleteCtrl.$inject = ['$scope', '$interval', 'toastr', '$repositories', '$licenseService', '$uibModal', '$timeout', 'AutocompleteRestService', '$autocompleteStatus', '$translate'];
AutocompleteCtrl.$inject = ['$scope', '$interval', 'toastr', '$repositories', '$licenseService', '$uibModal', '$timeout', 'RDF4JRepositoriesRestService', 'UriUtils', 'AutocompleteRestService', '$autocompleteStatus', '$translate'];

function AutocompleteCtrl($scope, $interval, toastr, $repositories, $licenseService, $uibModal, $timeout, AutocompleteRestService, $autocompleteStatus, $translate) {
function AutocompleteCtrl($scope, $interval, toastr, $repositories, $licenseService, $uibModal, $timeout, RDF4JRepositoriesRestService, UriUtils, AutocompleteRestService, $autocompleteStatus, $translate) {

let timer;

Expand Down Expand Up @@ -68,17 +69,22 @@ function AutocompleteCtrl($scope, $interval, toastr, $repositories, $licenseServ

const addLabelConfig = function (label) {
$scope.setLoader(true, $translate.instant('autocomplete.update'));


AutocompleteRestService.addLabelConfig(label)
.success(function () {
refreshLabelConfig();
refreshIndexStatus();
}).error(function (data) {
toastr.error(getError(data));
}).finally(function () {
const labelIriText = label.labelIri;
label.labelIri = UriUtils.expandPrefix(label.labelIri, $scope.namespaces);
if (UriUtils.isValidIri(label, label.labelIri) && label.labelIri !== "") {
AutocompleteRestService.addLabelConfig(label)
.success(function () {
refreshLabelConfig();
refreshIndexStatus();
}).error(function (data) {
toastr.error(getError(data));
}).finally(function () {
$scope.setLoader(false);
});
} else {
toastr.error($translate.instant('not.valid.iri', {value: labelIriText}));
$scope.setLoader(false);
});
}
};

const removeLabelConfig = function (label) {
Expand All @@ -104,6 +110,7 @@ function AutocompleteCtrl($scope, $interval, toastr, $repositories, $licenseServ
.success(function (data) {
$scope.pluginFound = data === true;
if ($scope.pluginFound) {
loadNamespaces();
refreshEnabledStatus();
refreshIndexIRIs();
refreshIndexStatus();
Expand Down Expand Up @@ -257,6 +264,18 @@ function AutocompleteCtrl($scope, $interval, toastr, $repositories, $licenseServ
pullStatus();
});

const loadNamespaces = () => {
RDF4JRepositoriesRestService.getNamespaces($repositories.getActiveRepository())
.then(mapNamespacesResponse)
.then((namespacesModel) => {
$scope.namespaces = namespacesModel;
})
.catch((response) => {
const msg = getError(response);
toastr.error(msg, $translate.instant('error.getting.namespaces.for.repo'));
});
};

init();
}

Expand Down
2 changes: 1 addition & 1 deletion src/js/angular/import/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ importCtrl.controller('SettingsModalCtrl', ['$scope', '$uibModalInstance', 'toas
$scope.addReplaceGraph = function (graph) {
let valid = true;
if (graph !== 'default') {
valid = UriUtils.isValidIri(graph);
valid = UriUtils.isValidIri(graph, graph.toString());
}
$scope.settingsForm.replaceGraph.$setTouched();
$scope.settingsForm.replaceGraph.$setValidity('replaceGraph', valid);
Expand Down
2 changes: 1 addition & 1 deletion src/js/angular/import/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ importDirectives.directive('validateUri', ['UriUtils', function (UriUtils) {
let valid = true;

if (scope.target === 'named') {
valid = UriUtils.isValidIri(value);
valid = UriUtils.isValidIri(value, value.toString());
}

ctrl.$setValidity('validateUri', valid);
Expand Down
63 changes: 18 additions & 45 deletions src/js/angular/rdfrank/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'angular/core/directives';
import 'angular/utils/uri-utils';
import 'angular/rest/rdfrank.rest.service';
import 'ng-tags-input/build/ng-tags-input.min';
import {mapNamespacesResponse} from "../rest/mappers/namespaces-mapper";

const rdfRankApp = angular.module('graphdb.framework.rdfrank', [
'ngRoute',
Expand All @@ -26,7 +27,7 @@ rdfRankApp.controller('RDFRankCtrl', ['$scope', '$interval', 'toastr', '$reposit

$scope.setPluginIsActive = function (isPluginActive) {
$scope.pluginIsActive = isPluginActive;
}
};

const refreshStatus = function () {
RdfRankRestService.getStatus()
Expand All @@ -37,17 +38,15 @@ rdfRankApp.controller('RDFRankCtrl', ['$scope', '$interval', 'toastr', '$reposit
});
};

const initNamespaces = function () {
RDF4JRepositoriesRestService.getNamespaces($scope.getActiveRepository())
.success(function (data) {
const nss = _.map(data.results.bindings, function (o) {
return {'uri': o.namespace.value, 'prefix': o.prefix.value};
});
$scope.namespaces = _.sortBy(nss, function (n) {
return n.uri.length;
});
}).error(function (data) {
toastr.error($translate.instant('get.namespaces.error.msg', {error: getError(data)}));
const loadNamespaces = () => {
RDF4JRepositoriesRestService.getNamespaces($repositories.getActiveRepository())
.then(mapNamespacesResponse)
.then((namespacesModel) => {
$scope.namespaces = namespacesModel;
})
.catch((response) => {
const msg = getError(response);
toastr.error(msg, $translate.instant('error.getting.namespaces.for.repo'));
});
};

Expand All @@ -65,7 +64,7 @@ rdfRankApp.controller('RDFRankCtrl', ['$scope', '$interval', 'toastr', '$reposit
.success(function (data) {
$scope.pluginFound = (data === true);
if ($scope.pluginFound) {
initNamespaces();
loadNamespaces();
refreshPage();
} else {
$scope.loading = false;
Expand All @@ -91,11 +90,7 @@ rdfRankApp.controller('RDFRankCtrl', ['$scope', '$interval', 'toastr', '$reposit
Object.values($scope.filterLists).forEach(function (list) {
RdfRankRestService.filter(list.predicate)
.success(function (data) {
list.elements = data;

list.elements = list.elements.map(function (elem) {
return foldPrefix(elem, $scope.namespaces);
});
return list.elements = data;
}).error(function (data) {
toastr.error(getError(data));
});
Expand Down Expand Up @@ -248,8 +243,10 @@ rdfRankApp.controller('RDFRankCtrl', ['$scope', '$interval', 'toastr', '$reposit
};

$scope.addToList = function (list, iri) {
if (UriUtils.isValidIri(iri.text)) {
_addToList(list, expandPrefix(iri.text, $scope.namespaces));
let iriText = iri.text.toString();
iriText = UriUtils.expandPrefix(iriText, $scope.namespaces);
if (UriUtils.isValidIri(iri, iriText) && iriText !== "") {
_addToList(list, iriText);
} else {
refreshFilteringConfig();
toastr.error($translate.instant('not.valid.iri', {value: iri.text}));
Expand All @@ -270,7 +267,7 @@ rdfRankApp.controller('RDFRankCtrl', ['$scope', '$interval', 'toastr', '$reposit
};

$scope.deleteFromList = function (list, iri) {
_deleteFromList(list, expandPrefix(iri.text, $scope.namespaces));
_deleteFromList(list, iri.text, $scope.namespaces);
};

const pullStatus = function () {
Expand All @@ -286,30 +283,6 @@ rdfRankApp.controller('RDFRankCtrl', ['$scope', '$interval', 'toastr', '$reposit
cancelTimer();
});

function expandPrefix(str, namespaces) {
const ABS_URI_REGEX = /^<?(http|urn).*>?/;
if (!ABS_URI_REGEX.test(str)) {
const uriParts = str.split(':');
const uriPart = uriParts[0];
const localName = uriParts[1];
if (!angular.isUndefined(localName)) {
const expandedUri = ClassInstanceDetailsService.getNamespaceUriForPrefix(namespaces, uriPart);
if (expandedUri) {
return expandedUri + localName;
}
}
}
return str;
}

function foldPrefix(iri, namespaces) {
const localPart = ClassInstanceDetailsService.getLocalName(iri);
const iriPart = iri.replace(new RegExp(localPart + '$', 'i'), '');
const folded = ClassInstanceDetailsService.getNamespacePrefixForUri(namespaces, iriPart);

return folded === '' ? iri : folded + ':' + localPart;
}

const init = function () {
if (!$licenseService.isLicenseValid() ||
!$repositories.getActiveRepository() ||
Expand Down
2 changes: 1 addition & 1 deletion src/js/angular/sparql-template/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ function SparqlTemplateCreateCtrl($scope, $location, toastr, $repositories, $win
}

function validateTemplateID() {
$scope.isInvalidTemplateId = !UriUtils.isValidIri($scope.currentQuery.templateID);
$scope.isInvalidTemplateId = !UriUtils.isValidIri($scope.currentQuery.templateID, $scope.currentQuery.templateID.toString());
}

function saveNewTemplate() {
Expand Down
Loading

0 comments on commit b27fa50

Please sign in to comment.