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 960e356b..2558d201 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 @@ -162,6 +162,16 @@ public class AdminController extends AbstractDnetController { } } + @GetMapping("/api/clearCache") + public List clearCache(final Authentication authentication) { + if (UserInfo.isSuperAdmin(authentication)) { + dbUtils.clearCache(); + return Arrays.asList("All caches are cleared"); + } else { + throw new RuntimeException("User not authorized"); + } + } + @GetMapping("/api/restartSuggestionsImport") public List restartSuggestionsImport(final Authentication authentication) { if (UserInfo.isSuperAdmin(authentication)) { 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 bc13b26f..f25c1ae9 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 @@ -23,6 +23,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.JdbcTemplate; @@ -330,6 +331,13 @@ public class DatabaseUtils { return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(VocabularyTerm.class), name); } + @CacheEvict(value = { + "vocs", "countries_for_user" + }, allEntries = true) + public void clearCache() { + log.info("All caches cleaned"); + } + @Transactional public void saveUser(@RequestBody final UserView userView) { final User user = userRepository.findById(userView.getEmail()).orElseThrow(() -> new RuntimeException("User not found")); 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 0e20385a..ce3754c1 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 @@ -4,8 +4,8 @@ - - + + @@ -25,6 +25,10 @@ + + + +
CommandStatusCommandStatus
{{suggestionImportMessage}} - to see the current import execution click here
{{cacheMessage}}
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 56e7a3b4..d3d749c5 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 @@ -813,6 +813,7 @@ orgsModule.controller('utilsCtrl', function ($scope, $http) { $scope.consistencyCheckMessage = ''; $scope.invalidSuggestedCountriesMessage = ''; $scope.suggestionImportMessage = ''; + $scope.cacheMessage = ''; $scope.refreshFulltextIndex = function() { $scope.fulltextIndexMessage = '...'; @@ -833,6 +834,12 @@ orgsModule.controller('utilsCtrl', function ($scope, $http) { $scope.suggestionImportMessage = '...'; call_http_get($http, 'api/restartSuggestionsImport', function(res) { $scope.suggestionImportMessage = res.data[0]; }); } + + $scope.clearCache = function() { + $scope.cacheMessage = '...'; + call_http_get($http, 'api/clearCache', function(res) { $scope.cacheMessage = res.data[0]; }); + } + }); diff --git a/apps/dnet-orgs-database-application/src/main/resources/templates/main.html b/apps/dnet-orgs-database-application/src/main/resources/templates/main.html index 870de51c..de2e4874 100644 --- a/apps/dnet-orgs-database-application/src/main/resources/templates/main.html +++ b/apps/dnet-orgs-database-application/src/main/resources/templates/main.html @@ -42,6 +42,11 @@ fieldset > legend { font-size : 1.2rem !important; } color: gray !important; text-decoration: line-through !important; } + +.btn-link { + text-align: left !important; +} +