From aa0a86b4d12676e8ad59aeedfa500132cdd65ed0 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Fri, 24 Nov 2023 18:19:22 +0200 Subject: [PATCH] migration changes --- .../src/main/java/eu/eudat/data/DmpUserEntity.java | 2 +- .../00.01.008_Add_DescriptionReference_table.sql | 2 +- .../migration/DmpDatasetProfileMigrationService.java | 11 +++++------ .../old/eudat/migration/DmpUserMigrationService.java | 6 +++--- .../publicapi/migration/MigrationController.java | 7 +++++-- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/DmpUserEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/DmpUserEntity.java index 25b0267ff..4d86386b6 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/DmpUserEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/DmpUserEntity.java @@ -26,7 +26,7 @@ public class DmpUserEntity { public static final String _dmp = "dmp"; - @Column(name = "user", columnDefinition = "uuid", nullable = false) + @Column(name = "\"user\"", columnDefinition = "uuid", nullable = false) private UUID userId; public static final String _userId = "userId"; diff --git a/dmp-db-scema/updates/00.01.008_Add_DescriptionReference_table.sql b/dmp-db-scema/updates/00.01.008_Add_DescriptionReference_table.sql index 0fd7b879f..b4c47f5cc 100644 --- a/dmp-db-scema/updates/00.01.008_Add_DescriptionReference_table.sql +++ b/dmp-db-scema/updates/00.01.008_Add_DescriptionReference_table.sql @@ -7,7 +7,7 @@ BEGIN CREATE TABLE IF NOT EXISTS public."DescriptionReference" ( "id" uuid NOT NULL, - "data" text COLLATE pg_catalog."default" NOT NULL, + "data" text COLLATE pg_catalog."default", "description_id" uuid NOT NULL, "reference_id" uuid NOT NULL, "created_at" timestamp without time zone NOT NULL DEFAULT now(), diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpDatasetProfileMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpDatasetProfileMigrationService.java index 3ccb551c4..9f304a958 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpDatasetProfileMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpDatasetProfileMigrationService.java @@ -115,7 +115,7 @@ public class DmpDatasetProfileMigrationService { } } while (items != null && !items.isEmpty() && !TestMode); - //removeDuplicates(); + removeDuplicates(); } private void removeDuplicates() { @@ -128,8 +128,8 @@ public class DmpDatasetProfileMigrationService { CriteriaBuilder b = this.entityManager.getCriteriaBuilder(); CriteriaQuery criteria = b.createQuery(Tuple.class); Root root = criteria.from(DmpDescriptionTemplateEntity.class); - criteria.groupBy(Arrays.asList(root.get("dmp"), root.get("descriptionTemplateGroupId"), root.get("sectionId"))); - criteria.multiselect(root.get("dmp"), root.get("descriptionTemplateGroupId"), root.get("sectionId"), b.count(root)); + criteria.groupBy(Arrays.asList(root.get(DmpDescriptionTemplateEntity._dmpId), root.get(DmpDescriptionTemplateEntity._descriptionTemplateGroupId), root.get(DmpDescriptionTemplateEntity._sectionId))); + criteria.multiselect(root.get(DmpDescriptionTemplateEntity._dmpId), root.get(DmpDescriptionTemplateEntity._descriptionTemplateGroupId), root.get(DmpDescriptionTemplateEntity._sectionId), b.count(root)); List resultList = this.entityManager.createQuery(criteria).getResultList(); List duplicatesList = resultList.stream().filter(x -> (long) x.get(3) > 1).toList(); @@ -143,9 +143,8 @@ public class DmpDatasetProfileMigrationService { .collect(); List toDelete = new ArrayList<>(duplicateEntities.stream().map(DmpDescriptionTemplateEntity::getId).toList()); - int random = new SecureRandom().nextInt(0, toDelete.size()); - toDelete.remove(random); - delete.where(root1.get("id").in(toDelete)); + toDelete.remove(0); + delete.where(root1.get(DmpDescriptionTemplateEntity._id).in(toDelete)); this.entityManager.createQuery(delete).executeUpdate(); } diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpUserMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpUserMigrationService.java index fb0ebaa33..2731a3eee 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpUserMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpUserMigrationService.java @@ -44,15 +44,15 @@ public class DmpUserMigrationService { if (items != null && !items.isEmpty()) { logger.debug("Migrate UserDMP " + page * PageSize + " of " + total); for (UserDMP item : items) { - entityManager.detach(item); + //entityManager.detach(item); DmpUserEntity data = new DmpUserEntity(); data.setId(item.getId()); data.setDmp(item.getDmp().getId()); data.setUserId(item.getUser().getId()); data.setRole(DmpUserRole.of(item.getRole().shortValue())); - data.setCreatedAt(Instant.now()); - data.setUpdatedAt(Instant.now()); + data.setCreatedAt(item.getDmp().getCreated() != null ? item.getDmp().getCreated().toInstant() : Instant.now()); + data.setUpdatedAt(item.getDmp().getModified() != null ? item.getDmp().getModified().toInstant() : Instant.now()); data.setIsActive(IsActive.Active); this.entityManager.persist(data); } diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/publicapi/migration/MigrationController.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/publicapi/migration/MigrationController.java index c81f3523c..4cc73b4b9 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/publicapi/migration/MigrationController.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/publicapi/migration/MigrationController.java @@ -86,12 +86,15 @@ public class MigrationController { this.dmpDatasetProfileMigrationService.migrate(); this.datasetMigrationService.migrate(); + this.dmpUserMigrationService.migrate(); + + this.referenceMigrationService.migrateDatasetReferences(); + this.referenceMigrationService.migrateDmpReferences(); + this.userContactInfoMigrationService.migrate(); return true; } - - @GetMapping("contacts") @Transactional public boolean migrateContacts() {