migration changes

This commit is contained in:
Efstratios Giannopoulos 2023-11-30 14:09:20 +02:00
parent 3a70b4d700
commit 5965acc4aa
4 changed files with 87 additions and 2 deletions

View File

@ -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

View File

@ -23,7 +23,7 @@ public class UserRole implements DataEntity<UserRole, UUID> {
private int role;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "user", nullable = false)
@JoinColumn(name = "\"user\"", nullable = false)
private UserInfo userInfo;
public UUID getId() {

View File

@ -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<Project> 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<Grant> 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();

View File

@ -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