From 8f5eacb409c7a0ea87886256242735502957094d Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Fri, 30 Oct 2020 10:05:23 +0100 Subject: [PATCH] invalidate a group of conflicts --- .../controller/OrganizationController.java | 27 ++++++++++-------- .../organizations/utils/DatabaseUtils.java | 17 +++++++++-- .../html/parts/resolve_conflicts.modal.html | 11 +++++--- .../static/resources/js/organizations.js | 28 +++++++++++++------ 4 files changed, 56 insertions(+), 27 deletions(-) diff --git a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/controller/OrganizationController.java b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/controller/OrganizationController.java index c9282302..a99ba50b 100644 --- a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/controller/OrganizationController.java +++ b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/controller/OrganizationController.java @@ -33,7 +33,6 @@ import eu.dnetlib.organizations.model.view.OpenaireDuplicateView; import eu.dnetlib.organizations.model.view.OrganizationInfoView; import eu.dnetlib.organizations.model.view.OrganizationSimpleView; import eu.dnetlib.organizations.model.view.OrganizationView; -import eu.dnetlib.organizations.repository.OrganizationRepository; import eu.dnetlib.organizations.repository.UserCountryRepository; import eu.dnetlib.organizations.repository.readonly.ConflictGroupViewRepository; import eu.dnetlib.organizations.repository.readonly.DuplicateGroupViewRepository; @@ -49,8 +48,6 @@ import eu.dnetlib.organizations.utils.OrganizationStatus; @RequestMapping("/api/organizations") public class OrganizationController { - @Autowired - private OrganizationRepository organizationRepository; @Autowired private OrganizationViewRepository organizationViewRepository; @Autowired @@ -298,18 +295,24 @@ public class OrganizationController { : databaseUtils.browseTypesForUser(authentication.getName()); } - @PostMapping("/conflicts/fix/{masterId}") - public List fixConflicts(final Authentication authentication, @PathVariable final String masterId, @RequestBody final List otherIds) { - if (UserInfo.isSuperAdmin(authentication) || userCountryRepository.verifyAuthorizationForId(masterId, authentication.getName())) { - final List list = new ArrayList<>(); - list.add(masterId); - list.addAll(otherIds); - final String newOrgId = databaseUtils.fixConflict(list, authentication.getName()); - + @PostMapping("/conflicts/fix/similar") + public List fixConflictSim(final Authentication authentication, @RequestBody final List ids) { + if (ids.size() > 1 && UserInfo.isSuperAdmin(authentication) || userCountryRepository.verifyAuthorizationForId(ids.get(0), authentication.getName())) { + final String newOrgId = databaseUtils.fixConflictSimilars(ids, authentication.getName()); return Arrays.asList(newOrgId); } else { return new ArrayList<>(); } - } + + @PostMapping("/conflicts/fix/different") + public List fixConflictDiff(final Authentication authentication, @RequestBody final List ids) { + if (ids.size() > 1 && UserInfo.isSuperAdmin(authentication) || userCountryRepository.verifyAuthorizationForId(ids.get(0), authentication.getName())) { + databaseUtils.fixConflictDifferents(ids, authentication.getName()); + return ids; + } else { + return new ArrayList<>(); + } + } + } 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 7a3c4469..c6b89581 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 @@ -303,7 +303,7 @@ public class DatabaseUtils { public List listConflictsForId(final String id) { final String sql = - "select o.id, o.name, o.type, o.city, o.country from oa_conflicts c left outer join organizations o on (c.id2 = o.id) where o.id is not null and c.id1 = ?"; + "select o.id, o.name, o.type, o.city, o.country from oa_conflicts c left outer join organizations o on (c.id2 = o.id) where o.id is not null and c.id1 = ? and c.reltype = 'suggested'"; return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(OrganizationConflict.class), id); } @@ -326,7 +326,7 @@ public class DatabaseUtils { } @Transactional - public String fixConflict(final List similarIds, final String user) { + public String fixConflictSimilars(final List similarIds, final String user) { final OffsetDateTime now = OffsetDateTime.now(); @@ -388,6 +388,19 @@ public class DatabaseUtils { return masterId; } + @Transactional + public void fixConflictDifferents(final List differentsIds, final String user) { + + final OffsetDateTime now = OffsetDateTime.now(); + + for (int i = 0; i < differentsIds.size(); i++) { + for (int j = i + 1; j < differentsIds.size(); j++) { + openaireConflictRepository + .updateStatusAndResetGroup(differentsIds.get(i), differentsIds.get(j), SimilarityType.is_different.toString(), user, now); + } + } + } + private String findFirstString(final List views, final Function mapper) { return views.stream().map(mapper).filter(StringUtils::isNotBlank).findFirst().orElse(null); } diff --git a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/parts/resolve_conflicts.modal.html b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/parts/resolve_conflicts.modal.html index 29d5a9d0..d66c80cb 100644 --- a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/parts/resolve_conflicts.modal.html +++ b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/parts/resolve_conflicts.modal.html @@ -9,7 +9,7 @@
-
Suggested organizations
+
Organizations
@@ -23,11 +23,11 @@
New group
- +
-
select master organization
+
select main organization
@@ -37,7 +37,10 @@
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 c341af34..d40da856 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 @@ -101,21 +101,31 @@ orgsModule.directive('resolveConflictsModal', function($http, $route) { angular.forEach(scope.orgs, function(org) { org.show = 'secondary'; }); } - scope.createGroup = function() { - var masterId = ''; - var otherIds = []; + scope.mergeGroup = function() { + var ids = []; angular.forEach(scope.selectedOrgs, function(o, pos) { - if (pos == 0) { masterId = o.id; } - else { otherIds.push(o.id); } + ids.push(o.id); }); - if (masterId && otherIds.length > 0) { - - call_http_post($http, 'api/organizations/conflicts/fix/' + masterId, otherIds, function(res) { + if (ids.length > 0) { + call_http_post($http, 'api/organizations/conflicts/fix/similar', ids, function(res) { $('#' + scope.modalId).modal('hide'); $('#' + scope.modalId).on('hidden.bs.modal', function (e) { $route.reload(); }); }); } - } + } + + scope.invalidateGroup = function() { + var ids = []; + angular.forEach(scope.selectedOrgs, function(o, pos) { + ids.push(o.id); + }); + if (ids.length > 0) { + call_http_post($http, 'api/organizations/conflicts/fix/different', ids, function(res) { + $('#' + scope.modalId).modal('hide'); + $('#' + scope.modalId).on('hidden.bs.modal', function (e) { $route.reload(); }); + }); + } + } } } });