From dc7dddfb3707b2942c8a6bae205aad7a8d34f614 Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Wed, 29 Sep 2021 16:05:16 +0200 Subject: [PATCH] check suggested countries --- .../controller/AdminController.java | 15 +++++++++++ .../organizations/utils/DatabaseUtils.java | 6 +++++ .../resources/html/pages/admin/sysConf.html | 4 ++- .../resources/html/pages/admin/utils.html | 25 +++++++++++++++++-- .../static/resources/js/organizations.js | 15 +++++++++-- 5 files changed, 60 insertions(+), 5 deletions(-) diff --git a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/controller/AdminController.java b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/controller/AdminController.java index 47361396..34ff6783 100644 --- a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/controller/AdminController.java +++ b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/controller/AdminController.java @@ -7,6 +7,7 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.DeleteMapping; @@ -145,4 +146,18 @@ public class AdminController extends AbstractDnetController { throw new RuntimeException("User not authorized"); } } + + @GetMapping("/api/verifyCountriesInSuggestions") + public List verifyCountriesInSuggestions(final Authentication authentication) { + if (UserInfo.isSuperAdmin(authentication)) { + final List list = dbUtils.invalidCountriesInSuggestions(); + if (list.isEmpty()) { + return Arrays.asList("All countries are valid"); + } else { + return Arrays.asList("Invalid countries in suggestions: " + StringUtils.join(list, ", ")); + } + } else { + throw new RuntimeException("User not authorized"); + } + } } diff --git a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/utils/DatabaseUtils.java b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/utils/DatabaseUtils.java index 96c3a7ef..4002421d 100644 --- a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/utils/DatabaseUtils.java +++ b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/utils/DatabaseUtils.java @@ -536,4 +536,10 @@ public class DatabaseUtils { return makeRelation(masterId, otherId, RelationType.Merges); } + public List invalidCountriesInSuggestions() { + final String sql = + " select distinct t.oa_country from tmp_dedup_events t left outer join countries c on (t.oa_country = c.val) where c.val is null order by t.oa_country"; + return jdbcTemplate.queryForList(sql, String.class); + } + } diff --git a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/admin/sysConf.html b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/admin/sysConf.html index 6d93832a..de507648 100644 --- a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/admin/sysConf.html +++ b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/admin/sysConf.html @@ -19,7 +19,9 @@
- +
+ +
diff --git a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/admin/utils.html b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/admin/utils.html index f1ef8976..eba71d0e 100644 --- a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/admin/utils.html +++ b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/admin/utils.html @@ -1,6 +1,27 @@

System utilities


+ + + + + + + + + + + + + + + + + + + + + +
CommandStatus
{{fulltextIndexMessage}}
{{consistencyCheckMessage}}
{{invalidSuggestedCountriesMessage}}
+ - - diff --git a/apps/dnet-orgs-database-application/src/main/resources/static/resources/js/organizations.js b/apps/dnet-orgs-database-application/src/main/resources/static/resources/js/organizations.js index ea49bf68..1ca5036c 100644 --- a/apps/dnet-orgs-database-application/src/main/resources/static/resources/js/organizations.js +++ b/apps/dnet-orgs-database-application/src/main/resources/static/resources/js/organizations.js @@ -808,13 +808,24 @@ orgsModule.controller('lastImportCtrl', function ($scope, $http) { }); orgsModule.controller('utilsCtrl', function ($scope, $http) { + + $scope.fulltextIndexMessage = ''; + $scope.consistencyCheckMessage = ''; + $scope.invalidSuggestedCountriesMessage = ''; $scope.refreshFulltextIndex = function() { - call_http_get($http, 'api/refreshFulltextIndex', function(res) { alert(res.data[0]); }); + $scope.fulltextIndexMessage = '...'; + call_http_get($http, 'api/refreshFulltextIndex', function(res) { $scope.fulltextIndexMessage = res.data[0]; }); } $scope.performConsistencyCheck = function() { - call_http_get($http, 'api/performConsistencyCheck', function(res) { alert(res.data[0]); }); + $scope.consistencyCheckMessage = '...'; + call_http_get($http, 'api/performConsistencyCheck', function(res) { $scope.consistencyCheckMessage = res.data[0]; }); + } + + $scope.verifyCountriesInSuggestions = function() { + $scope.invalidSuggestedCountriesMessage = '...'; + call_http_get($http, 'api/verifyCountriesInSuggestions', function(res) { $scope.invalidSuggestedCountriesMessage = res.data[0]; }); } });