From 5965acc4aa10b567ffd422f8bd7e6ed910ec76b0 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Thu, 30 Nov 2023 14:09:20 +0200 Subject: [PATCH] migration changes --- .../service/keycloak/KeycloakServiceImpl.java | 2 +- .../eu/old/eudat/data/entities/UserRole.java | 2 +- .../migration/ReferenceMigrationService.java | 79 +++++++++++++++++++ .../config/application-devel.properties | 6 ++ 4 files changed, 87 insertions(+), 2 deletions(-) diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/keycloak/KeycloakServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/keycloak/KeycloakServiceImpl.java index 6fd2d40a4..04ca067e0 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/keycloak/KeycloakServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/keycloak/KeycloakServiceImpl.java @@ -26,7 +26,7 @@ public class KeycloakServiceImpl implements KeycloakService { public KeycloakServiceImpl(KeycloakAdminRestApi api, KeycloakResourcesConfiguration configuration) { this.api = api; this.configuration = configuration; - logger.info("Keycloak service initialized. Tenant authorities configured -> {}", configuration.getProperties().getAuthorities().size()); + //logger.info("Keycloak service initialized. Tenant authorities configured -> {}", configuration.getProperties().getAuthorities().size()); } @Override diff --git a/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/entities/UserRole.java b/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/entities/UserRole.java index 5a8171548..6c0a4fd95 100644 --- a/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/entities/UserRole.java +++ b/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/entities/UserRole.java @@ -23,7 +23,7 @@ public class UserRole implements DataEntity { private int role; @ManyToOne(fetch = FetchType.EAGER) - @JoinColumn(name = "user", nullable = false) + @JoinColumn(name = "\"user\"", nullable = false) private UserInfo userInfo; public UUID getId() { diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/ReferenceMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/ReferenceMigrationService.java index d7b6d2e5b..445d3af34 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/ReferenceMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/ReferenceMigrationService.java @@ -35,6 +35,8 @@ public class ReferenceMigrationService { public void migrateDmpReferences() { migrateDmpOrganizations(); migrateDmpResearchers(); + migrateDmpProjects(); + migrateDmpGrantsAndFounders(); } public void migrateDatasetReferences() { @@ -110,6 +112,83 @@ public class ReferenceMigrationService { } while (items != null && !items.isEmpty()); } + public void migrateDmpProjects() { + ProjectDao projectDao = databaseRepository.getProjectDao(); + long total = projectDao.asQueryable().count(); + logger.debug("Migrate Dmp Project (from Project) Total : " + total); + int page = 0; + + List items; + do { + items = projectDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("created"))).orderBy((builder, root) -> builder.asc(root.get("ID"))).skip(page * PageSize).take(PageSize).toList(); + if (items != null && !items.isEmpty()) { + logger.debug("Migrate Dmp Project " + page * PageSize + " of " + total); + + for (Project item : items) { +// entityManager.detach(item); + + for (DMP dmp : item.getDmps()) { + DmpReferenceEntity data = new DmpReferenceEntity(); + data.setId(UUID.randomUUID()); + data.setDmpId(dmp.getId()); + data.setReferenceId(item.getId()); + data.setCreatedAt(dmp.getCreated() != null ? dmp.getCreated().toInstant() : Instant.now()); + data.setUpdatedAt(dmp.getModified() != null ? dmp.getModified().toInstant() : Instant.now()); + data.setIsActive(IsActive.Active); + this.entityManager.persist(data); + } + } + this.entityManager.flush(); + + page++; + } + } while (items != null && !items.isEmpty()); + } + + public void migrateDmpGrantsAndFounders() { + GrantDao grantDao = databaseRepository.getGrantDao(); + long total = grantDao.asQueryable().count(); + logger.debug("Migrate Dmp Grants (from Grants) Total : " + total); + int page = 0; + + List items; + do { + items = grantDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("created"))).orderBy((builder, root) -> builder.asc(root.get("ID"))).skip(page * PageSize).take(PageSize).toList(); + if (items != null && !items.isEmpty()) { + logger.debug("Migrate Dmp Grants " + page * PageSize + " of " + total); + + for (Grant item : items) { +// entityManager.detach(item); + + for (DMP dmp : item.getDmps()) { + DmpReferenceEntity data = new DmpReferenceEntity(); + data.setId(UUID.randomUUID()); + data.setDmpId(dmp.getId()); + data.setReferenceId(item.getId()); + data.setCreatedAt(dmp.getCreated() != null ? dmp.getCreated().toInstant() : Instant.now()); + data.setUpdatedAt(dmp.getModified() != null ? dmp.getModified().toInstant() : Instant.now()); + data.setIsActive(IsActive.Active); + this.entityManager.persist(data); + + if (item.getFunder() != null){ + DmpReferenceEntity founder = new DmpReferenceEntity(); + founder.setId(UUID.randomUUID()); + founder.setDmpId(dmp.getId()); + founder.setReferenceId(item.getFunder().getId()); + founder.setCreatedAt(dmp.getCreated() != null ? dmp.getCreated().toInstant() : Instant.now()); + founder.setUpdatedAt(dmp.getModified() != null ? dmp.getModified().toInstant() : Instant.now()); + founder.setIsActive(IsActive.Active); + this.entityManager.persist(founder); + } + } + } + this.entityManager.flush(); + + page++; + } + } while (items != null && !items.isEmpty()); + } + public void migrateDatasetDataRepositories() { DatasetDataRepositoryDao datasetDataRepositoryDao = databaseRepository.getDatasetDataRepositoryDao(); long total = datasetDataRepositoryDao.asQueryable().count(); diff --git a/dmp-migration-tool/web/src/main/resources/config/application-devel.properties b/dmp-migration-tool/web/src/main/resources/config/application-devel.properties index e753abceb..c22ba097c 100644 --- a/dmp-migration-tool/web/src/main/resources/config/application-devel.properties +++ b/dmp-migration-tool/web/src/main/resources/config/application-devel.properties @@ -8,6 +8,12 @@ spring.datasource.maxIdle=10 spring.datasource.minIdle=5 spring.datasource.maxActive=10 +keycloak-client.serverUrl="" +keycloak-client.realm="" +keycloak-client.username="" +keycloak-client.password="" +keycloak-client.clientId="" + ####################ELASTIIC SEARCH TAGS OVERRIDES CONFIGURATIONS########## elasticsearch.host = localhost elasticsearch.port = 9200