From 90d7bba929719c53b43509363ff9f771d6b3ece8 Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Wed, 21 Oct 2020 12:27:14 +0200 Subject: [PATCH] approve and discard orgs --- .../organizations/utils/DatabaseUtils.java | 27 ++++++++++------ .../main/resources/sql/importDedupEvents.sql | 31 +++++++++++++------ .../resources/html/pages/search/browse.html | 12 +++---- .../static/resources/js/organizations.js | 2 +- 4 files changed, 46 insertions(+), 26 deletions(-) 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 d22af615..49b22108 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 @@ -1,6 +1,7 @@ package eu.dnetlib.organizations.utils; import java.time.OffsetDateTime; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.LinkedHashSet; @@ -140,13 +141,18 @@ public class DatabaseUtils { organizationRepository.updateCreationDate(newId, user, now); makeRelations(newId, orgView, false); if (oldId != null) { - final OpenaireDuplicate dup = new OpenaireDuplicate(); - dup.setLocalId(newId); - dup.setOaOriginalId(oldId); - dup.setRelType(SimilarityType.is_similar.toString()); - openaireDuplicateRepository.save(dup); - openaireDuplicateRepository.updateModificationDate(newId, oldId, user, now); + final List dups = new ArrayList<>(); + + dups.add(new OpenaireDuplicate(newId, oldId, SimilarityType.is_similar.toString())); + dups.addAll(openaireDuplicateRepository.findByLocalId(oldId) + .stream() + .map(d -> new OpenaireDuplicate(newId, d.getOaOriginalId(), SimilarityType.suggested.toString())) + .collect(Collectors.toList())); + + openaireDuplicateRepository.saveAll(dups); + dups.forEach(d -> openaireDuplicateRepository.updateModificationDate(d.getLocalId(), d.getOaOriginalId(), user, now)); + organizationRepository.updateStatus(oldId, OrganizationStatus.duplicate.toString()); organizationRepository.updateModificationDate(oldId, user, now); } @@ -164,10 +170,10 @@ public class DatabaseUtils { list.forEach(d -> { openaireDuplicateRepository.updateModificationDate(d.getLocalId(), d.getOaOriginalId(), user, now); - if (d.getRelType().equals(SimilarityType.is_similar.toString())) { - updateStatus(d.getOaOriginalId(), OrganizationStatus.duplicate, user, now); - } else { + if (d.getRelType().equals(SimilarityType.is_different.toString())) { updateStatus(d.getOaOriginalId(), OrganizationStatus.suggested, user, now); + } else { + updateStatus(d.getOaOriginalId(), OrganizationStatus.duplicate, user, now); } }); @@ -363,6 +369,9 @@ public class DatabaseUtils { public OrganizationView markAsDiscarded(final String id, final String user) { final OffsetDateTime now = OffsetDateTime.now(); updateStatus(id, OrganizationStatus.discarded, user, now); + + openaireDuplicateRepository.findByLocalId(id).forEach(d -> updateStatus(d.getOaOriginalId(), OrganizationStatus.suggested, user, now)); + return organizationViewRepository.findById(id).get(); } diff --git a/apps/dnet-orgs-database-application/src/main/resources/sql/importDedupEvents.sql b/apps/dnet-orgs-database-application/src/main/resources/sql/importDedupEvents.sql index 64c82baf..9df9e8dd 100644 --- a/apps/dnet-orgs-database-application/src/main/resources/sql/importDedupEvents.sql +++ b/apps/dnet-orgs-database-application/src/main/resources/sql/importDedupEvents.sql @@ -1,32 +1,43 @@ BEGIN; -DELETE FROM organizations WHERE status = 'suggested' and created_by = 'dedupWf'; -DELETE FROM oa_duplicates WHERE reltype = 'suggested' and created_by = 'dedupWf'; -DELETE FROM oa_conflicts WHERE reltype = 'suggested' and created_by = 'dedupWf'; +DELETE FROM oa_conflicts WHERE created_by = 'dedupWf' and reltype = 'suggested'; +DELETE FROM oa_duplicates WHERE created_by = 'dedupWf' and reltype = 'suggested'; +DELETE FROM organizations WHERE created_by = 'dedupWf' and modified_by = 'dedupWf'; -- FIX IMPORT DATA UPDATE tmp_dedup_events SET oa_country = 'UNKNOWN' WHERE oa_country = '' OR oa_country IS NULL; -- NEW ORGANIZATIONS -INSERT INTO organizations(id, name, country, status, created_by, modified_by) SELECT oa_original_id, oa_name, oa_country, 'suggested', 'dedupWf', 'dedupWf' FROM tmp_dedup_events WHERE oa_original_id NOT LIKE 'openorgs\_\_\_\_::%' ON CONFLICT DO NOTHING; +INSERT INTO organizations(id, name, country, status, created_by, modified_by) +SELECT oa_original_id, oa_name, oa_country, 'suggested', 'dedupWf', 'dedupWf' +FROM tmp_dedup_events +WHERE oa_original_id NOT LIKE 'openorgs\_\_\_\_::%' AND oa_original_id = local_id +ON CONFLICT DO NOTHING; + +INSERT INTO organizations(id, name, country, status, created_by, modified_by) +SELECT oa_original_id, oa_name, oa_country, 'duplicate', 'dedupWf', 'dedupWf' +FROM tmp_dedup_events +WHERE oa_original_id NOT LIKE 'openorgs\_\_\_\_::%' AND oa_original_id != local_id +ON CONFLICT DO NOTHING; + + INSERT INTO acronyms(id, acronym) SELECT oa_original_id, oa_acronym FROM tmp_dedup_events WHERE oa_original_id NOT LIKE 'openorgs\_\_\_\_::%' ON CONFLICT DO NOTHING; INSERT INTO urls(id, url) SELECT oa_original_id, oa_url FROM tmp_dedup_events WHERE oa_original_id NOT LIKE 'openorgs\_\_\_\_::%' ON CONFLICT DO NOTHING; -- DUPLICATES -INSERT INTO oa_duplicates (local_id, oa_original_id, oa_collectedfrom, created_by) -SELECT local_id, oa_original_id, oa_collectedfrom, 'dedupWf' +INSERT INTO oa_duplicates (local_id, oa_original_id, oa_collectedfrom, created_by, modified_by) +SELECT local_id, oa_original_id, oa_collectedfrom, 'dedupWf', 'dedupWf' FROM tmp_dedup_events WHERE local_id IS NOT NULL AND local_id != '' AND oa_original_id NOT LIKE 'openorgs\_\_\_\_::%' AND local_id != oa_original_id ON CONFLICT DO NOTHING; -- CONFLICTS -INSERT INTO oa_conflicts (id1, id2, idgroup, created_by) -SELECT local_id, oa_original_id, group_id, 'dedupWf' +INSERT INTO oa_conflicts (id1, id2, idgroup, created_by, modified_by) +SELECT local_id, oa_original_id, group_id, 'dedupWf', 'dedupWf' FROM tmp_dedup_events -WHERE local_id LIKE 'openorgs\_\_\_\_::%' AND oa_original_id LIKE 'openorgs\_\_\_\_::%' AND local_id != oa_original_id +WHERE local_id LIKE 'openorgs\_\_\_\_::%' AND oa_original_id LIKE 'openorgs\_\_\_\_::%' AND local_id != oa_original_id AND group_id IS NOT NULL AND group_id != '' ON CONFLICT DO NOTHING; COMMIT; - diff --git a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/search/browse.html b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/search/browse.html index f40b8abb..f2eac3fb 100644 --- a/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/search/browse.html +++ b/apps/dnet-orgs-database-application/src/main/resources/static/resources/html/pages/search/browse.html @@ -10,12 +10,12 @@ {{field}} - # approved - # pending - # deleted - # duplicated - # discarded - # hidden + # approved + # suggested + # deleted + # duplicated + # discarded + # hidden 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 4a1ea532..dc14a670 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 @@ -182,7 +182,7 @@ orgsModule.directive('orgFormMetadata', function($http, $location, $route, $rout alert("Session expired !"); location.reload(true); } else { - alert("Organization marked as deleted !!!"); + alert("Organization marked as discarded !!!"); $route.reload(); } }, function errorCallback(res) {