diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DataRepositoryMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DataRepositoryMigrationService.java index abcd4ef57..f61421759 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DataRepositoryMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DataRepositoryMigrationService.java @@ -1,8 +1,13 @@ package eu.old.eudat.migration; +import eu.eudat.commons.XmlHandlingService; import eu.eudat.commons.enums.IsActive; +import eu.eudat.commons.enums.ReferenceFieldDataType; import eu.eudat.commons.enums.ReferenceSourceType; import eu.eudat.commons.enums.ReferenceType; +import eu.eudat.commons.types.reference.DefinitionEntity; +import eu.eudat.commons.types.reference.FieldEntity; +import eu.eudat.convention.ConventionService; import eu.eudat.data.ReferenceEntity; import eu.old.eudat.data.dao.entities.DataRepositoryDao; import eu.old.eudat.data.entities.DataRepository; @@ -23,9 +28,13 @@ public class DataRepositoryMigrationService { private static final String InternalReferenceSource = "dmp"; private final DatabaseRepository databaseRepository; private final EntityManager entityManager; - public DataRepositoryMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) { + private final ConventionService conventionService; + private final XmlHandlingService xmlHandlingService; + public DataRepositoryMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager, ConventionService conventionService, XmlHandlingService xmlHandlingService) { this.databaseRepository = databaseRepository; this.entityManager = entityManager; + this.conventionService = conventionService; + this.xmlHandlingService = xmlHandlingService; } public void migrate(){ @@ -49,6 +58,8 @@ public class DataRepositoryMigrationService { String[] referenceParts = item.getReference().split(":", 2); boolean isInternal = referenceParts[0].equals(InternalReferenceSource); + + ReferenceEntity data = new ReferenceEntity(); data.setId(item.getId()); @@ -61,6 +72,16 @@ public class DataRepositoryMigrationService { data.setReference(referenceParts[1]); data.setSource(isInternal? "Internal" : referenceParts[0]); data.setSourceType(isInternal? ReferenceSourceType.Internal : ReferenceSourceType.External); + if (!this.conventionService.isNullOrEmpty(item.getUri())){ + DefinitionEntity definitionEntity = new DefinitionEntity(); + FieldEntity fieldEntity = new FieldEntity(); + fieldEntity.setCode("uri"); + fieldEntity.setDataType(ReferenceFieldDataType.Text); + fieldEntity.setValue(item.getUri()); + definitionEntity.setFields(List.of(fieldEntity)); + data.setDefinition(this.xmlHandlingService.toXmlSafe(definitionEntity)); + } + this.entityManager.persist(data); } this.entityManager.flush(); diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/ExternalDatasetMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/ExternalDatasetMigrationService.java index f2b97d288..ae447b40b 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/ExternalDatasetMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/ExternalDatasetMigrationService.java @@ -54,6 +54,7 @@ public class ExternalDatasetMigrationService { ReferenceEntity data = new ReferenceEntity(); data.setId(item.getId()); data.setLabel(item.getLabel()); + data.setAbbreviation(item.getAbbreviation()); data.setIsActive(IsActive.Active); data.setType(ReferenceType.Datasets); data.setCreatedAt(item.getCreated().toInstant()); diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/FunderMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/FunderMigrationService.java index d295e10c6..75b187400 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/FunderMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/FunderMigrationService.java @@ -54,7 +54,7 @@ public class FunderMigrationService { ReferenceEntity data = new ReferenceEntity(); data.setId(item.getId()); data.setLabel(item.getLabel()); - data.setIsActive(DMP.DMPStatus.fromInteger(item.getStatus()).equals(DMP.DMPStatus.DELETED) ? IsActive.Inactive : IsActive.Active); + data.setIsActive(IsActive.Active); data.setType(ReferenceType.Funder); data.setCreatedAt(item.getCreated().toInstant()); data.setUpdatedAt(item.getModified().toInstant()); diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/GrantMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/GrantMigrationService.java index 52f0f3656..8abcbb886 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/GrantMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/GrantMigrationService.java @@ -1,11 +1,15 @@ package eu.old.eudat.migration; +import eu.eudat.commons.XmlHandlingService; import eu.eudat.commons.enums.IsActive; +import eu.eudat.commons.enums.ReferenceFieldDataType; import eu.eudat.commons.enums.ReferenceSourceType; import eu.eudat.commons.enums.ReferenceType; +import eu.eudat.commons.types.reference.DefinitionEntity; +import eu.eudat.commons.types.reference.FieldEntity; +import eu.eudat.convention.ConventionService; import eu.eudat.data.ReferenceEntity; import eu.old.eudat.data.dao.entities.GrantDao; -import eu.old.eudat.data.entities.DMP; import eu.old.eudat.data.entities.Grant; import eu.old.eudat.logic.services.operations.DatabaseRepository; import gr.cite.tools.logging.LoggerService; @@ -13,6 +17,7 @@ import jakarta.persistence.EntityManager; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -24,9 +29,13 @@ public class GrantMigrationService { private static final String InternalReferenceSource = "dmp"; private final DatabaseRepository databaseRepository; private final EntityManager entityManager; - public GrantMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) { + private final ConventionService conventionService; + private final XmlHandlingService xmlHandlingService; + public GrantMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager, ConventionService conventionService, XmlHandlingService xmlHandlingService) { this.databaseRepository = databaseRepository; this.entityManager = entityManager; + this.conventionService = conventionService; + this.xmlHandlingService = xmlHandlingService; } public void migrate(){ @@ -54,7 +63,8 @@ public class GrantMigrationService { data.setId(item.getId()); data.setLabel(item.getLabel()); data.setDescription(item.getDescription()); - data.setIsActive(DMP.DMPStatus.fromInteger(item.getStatus()).equals(DMP.DMPStatus.DELETED) ? IsActive.Inactive : IsActive.Active); + data.setAbbreviation(item.getAbbreviation()); + data.setIsActive(IsActive.Active); data.setType(ReferenceType.Grants); data.setCreatedAt(item.getCreated().toInstant()); data.setUpdatedAt(item.getModified().toInstant()); @@ -62,6 +72,37 @@ public class GrantMigrationService { data.setReference(referenceParts[1]); data.setSource(isInternal? "Internal" : referenceParts[0]); data.setSourceType(isInternal ? ReferenceSourceType.Internal : ReferenceSourceType.External); + + DefinitionEntity definitionEntity = new DefinitionEntity(); + definitionEntity.setFields(new ArrayList<>()); + if (!this.conventionService.isNullOrEmpty(item.getUri())){ + FieldEntity fieldEntity = new FieldEntity(); + fieldEntity.setCode("uri"); + fieldEntity.setDataType(ReferenceFieldDataType.Text); + fieldEntity.setValue(item.getUri()); + definitionEntity.getFields().add(fieldEntity); + } + + if (item.getStartdate() != null){ + FieldEntity fieldEntity = new FieldEntity(); + fieldEntity.setCode("startDate"); + fieldEntity.setDataType(ReferenceFieldDataType.Date); + fieldEntity.setValue(item.getStartdate().toInstant().toString()); + definitionEntity.getFields().add(fieldEntity); + } + + if (item.getEnddate() != null){ + FieldEntity fieldEntity = new FieldEntity(); + fieldEntity.setCode("endDate"); + fieldEntity.setDataType(ReferenceFieldDataType.Date); + fieldEntity.setValue(item.getEnddate().toInstant().toString()); + definitionEntity.getFields().add(fieldEntity); + } + + if (!definitionEntity.getFields().isEmpty()){ + data.setDefinition(this.xmlHandlingService.toXmlSafe(definitionEntity)); + } + this.entityManager.persist(data); } this.entityManager.flush(); diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/OrganizationMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/OrganizationMigrationService.java index b26fd3719..220c489dd 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/OrganizationMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/OrganizationMigrationService.java @@ -1,11 +1,15 @@ package eu.old.eudat.migration; +import eu.eudat.commons.XmlHandlingService; import eu.eudat.commons.enums.IsActive; +import eu.eudat.commons.enums.ReferenceFieldDataType; import eu.eudat.commons.enums.ReferenceSourceType; import eu.eudat.commons.enums.ReferenceType; +import eu.eudat.commons.types.reference.DefinitionEntity; +import eu.eudat.commons.types.reference.FieldEntity; +import eu.eudat.convention.ConventionService; import eu.eudat.data.ReferenceEntity; import eu.old.eudat.data.dao.entities.OrganisationDao; -import eu.old.eudat.data.entities.DMP; import eu.old.eudat.data.entities.Organisation; import eu.old.eudat.logic.services.operations.DatabaseRepository; import gr.cite.tools.logging.LoggerService; @@ -13,7 +17,6 @@ import jakarta.persistence.EntityManager; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; -import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -25,9 +28,13 @@ public class OrganizationMigrationService { private static final String InternalReferenceSource = "Internal"; private final DatabaseRepository databaseRepository; private final EntityManager entityManager; - public OrganizationMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) { + private final ConventionService conventionService; + private final XmlHandlingService xmlHandlingService; + public OrganizationMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager, ConventionService conventionService, XmlHandlingService xmlHandlingService) { this.databaseRepository = databaseRepository; this.entityManager = entityManager; + this.conventionService = conventionService; + this.xmlHandlingService = xmlHandlingService; } public void migrate(){ @@ -56,7 +63,8 @@ public class OrganizationMigrationService { ReferenceEntity data = new ReferenceEntity(); data.setId(item.getId()); data.setLabel(item.getLabel()); - data.setIsActive(DMP.DMPStatus.fromInteger(item.getStatus()).equals(DMP.DMPStatus.DELETED) ? IsActive.Inactive : IsActive.Active); + data.setAbbreviation(item.getAbbreviation()); + data.setIsActive(IsActive.Active); data.setType(ReferenceType.Organizations); data.setCreatedAt(item.getCreated().toInstant()); data.setUpdatedAt(item.getModified().toInstant()); @@ -64,6 +72,15 @@ public class OrganizationMigrationService { data.setAbbreviation(item.getAbbreviation()); data.setSource(isInternal? "Internal" : referenceParts[0]); data.setSourceType(isInternal? ReferenceSourceType.Internal : ReferenceSourceType.External); + if (!this.conventionService.isNullOrEmpty(item.getUri())){ + DefinitionEntity definitionEntity = new DefinitionEntity(); + FieldEntity fieldEntity = new FieldEntity(); + fieldEntity.setCode("uri"); + fieldEntity.setDataType(ReferenceFieldDataType.Text); + fieldEntity.setValue(item.getUri()); + definitionEntity.setFields(List.of(fieldEntity)); + data.setDefinition(this.xmlHandlingService.toXmlSafe(definitionEntity)); + } this.entityManager.persist(data); } this.entityManager.flush(); diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/ProjectMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/ProjectMigrationService.java index d6424013e..56e49ac8d 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/ProjectMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/ProjectMigrationService.java @@ -1,11 +1,15 @@ package eu.old.eudat.migration; +import eu.eudat.commons.XmlHandlingService; import eu.eudat.commons.enums.IsActive; +import eu.eudat.commons.enums.ReferenceFieldDataType; import eu.eudat.commons.enums.ReferenceSourceType; import eu.eudat.commons.enums.ReferenceType; +import eu.eudat.commons.types.reference.DefinitionEntity; +import eu.eudat.commons.types.reference.FieldEntity; +import eu.eudat.convention.ConventionService; import eu.eudat.data.ReferenceEntity; import eu.old.eudat.data.dao.entities.ProjectDao; -import eu.old.eudat.data.entities.DMP; import eu.old.eudat.data.entities.Project; import eu.old.eudat.logic.services.operations.DatabaseRepository; import gr.cite.tools.logging.LoggerService; @@ -13,6 +17,7 @@ import jakarta.persistence.EntityManager; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -24,9 +29,13 @@ public class ProjectMigrationService { private static final String InternalReferenceSource = "dmp"; private final DatabaseRepository databaseRepository; private final EntityManager entityManager; - public ProjectMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) { + private final ConventionService conventionService; + private final XmlHandlingService xmlHandlingService; + public ProjectMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager, ConventionService conventionService, XmlHandlingService xmlHandlingService) { this.databaseRepository = databaseRepository; this.entityManager = entityManager; + this.conventionService = conventionService; + this.xmlHandlingService = xmlHandlingService; } public void migrate(){ @@ -54,8 +63,9 @@ public class ProjectMigrationService { ReferenceEntity data = new ReferenceEntity(); data.setId(item.getId()); data.setLabel(item.getLabel()); + data.setAbbreviation(item.getAbbreviation()); data.setDescription(item.getDescription()); - data.setIsActive(DMP.DMPStatus.fromInteger(item.getStatus()).equals(DMP.DMPStatus.DELETED) ? IsActive.Inactive : IsActive.Active); + data.setIsActive(IsActive.Active); data.setType(ReferenceType.Project); data.setCreatedAt(item.getCreated().toInstant()); data.setUpdatedAt(item.getModified().toInstant()); @@ -63,6 +73,36 @@ public class ProjectMigrationService { data.setReference(referenceParts[1]); data.setSource(isInternal? "Internal" : referenceParts[0]); data.setSourceType(Project.ProjectType.INTERNAL.getValue().equals(item.getType())? ReferenceSourceType.Internal : ReferenceSourceType.External); + + DefinitionEntity definitionEntity = new DefinitionEntity(); + definitionEntity.setFields(new ArrayList<>()); + if (!this.conventionService.isNullOrEmpty(item.getUri())){ + FieldEntity fieldEntity = new FieldEntity(); + fieldEntity.setCode("uri"); + fieldEntity.setDataType(ReferenceFieldDataType.Text); + fieldEntity.setValue(item.getUri()); + definitionEntity.getFields().add(fieldEntity); + } + + if (item.getStartdate() != null){ + FieldEntity fieldEntity = new FieldEntity(); + fieldEntity.setCode("startDate"); + fieldEntity.setDataType(ReferenceFieldDataType.Date); + fieldEntity.setValue(item.getStartdate().toInstant().toString()); + definitionEntity.getFields().add(fieldEntity); + } + + if (item.getEnddate() != null){ + FieldEntity fieldEntity = new FieldEntity(); + fieldEntity.setCode("endDate"); + fieldEntity.setDataType(ReferenceFieldDataType.Date); + fieldEntity.setValue(item.getEnddate().toInstant().toString()); + definitionEntity.getFields().add(fieldEntity); + } + + if (!definitionEntity.getFields().isEmpty()){ + data.setDefinition(this.xmlHandlingService.toXmlSafe(definitionEntity)); + } this.entityManager.persist(data); } this.entityManager.flush(); diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/RegistryMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/RegistryMigrationService.java index b1f775ce2..f12d3a08b 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/RegistryMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/RegistryMigrationService.java @@ -1,11 +1,15 @@ package eu.old.eudat.migration; +import eu.eudat.commons.XmlHandlingService; import eu.eudat.commons.enums.IsActive; +import eu.eudat.commons.enums.ReferenceFieldDataType; import eu.eudat.commons.enums.ReferenceSourceType; import eu.eudat.commons.enums.ReferenceType; +import eu.eudat.commons.types.reference.DefinitionEntity; +import eu.eudat.commons.types.reference.FieldEntity; +import eu.eudat.convention.ConventionService; import eu.eudat.data.ReferenceEntity; import eu.old.eudat.data.dao.entities.RegistryDao; -import eu.old.eudat.data.entities.DMP; import eu.old.eudat.data.entities.Registry; import eu.old.eudat.logic.services.operations.DatabaseRepository; import gr.cite.tools.logging.LoggerService; @@ -24,9 +28,13 @@ public class RegistryMigrationService { private static final String InternalReferenceSource = "dmp"; private final DatabaseRepository databaseRepository; private final EntityManager entityManager; - public RegistryMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) { + private final ConventionService conventionService; + private final XmlHandlingService xmlHandlingService; + public RegistryMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager, ConventionService conventionService, XmlHandlingService xmlHandlingService) { this.databaseRepository = databaseRepository; this.entityManager = entityManager; + this.conventionService = conventionService; + this.xmlHandlingService = xmlHandlingService; } public void migrate(){ @@ -54,7 +62,8 @@ public class RegistryMigrationService { ReferenceEntity data = new ReferenceEntity(); data.setId(item.getId()); data.setLabel(item.getLabel()); - data.setIsActive(DMP.DMPStatus.fromInteger(item.getStatus()).equals(DMP.DMPStatus.DELETED) ? IsActive.Inactive : IsActive.Active); + data.setAbbreviation(item.getAbbreviation()); + data.setIsActive(IsActive.Active); data.setType(ReferenceType.Registries); data.setCreatedAt(item.getCreated().toInstant()); data.setUpdatedAt(item.getModified().toInstant()); @@ -62,6 +71,15 @@ public class RegistryMigrationService { data.setReference(referenceParts[1]); data.setSource(isInternal? "Internal" : referenceParts[0]); data.setSourceType(isInternal? ReferenceSourceType.Internal : ReferenceSourceType.External); + if (!this.conventionService.isNullOrEmpty(item.getUri())){ + DefinitionEntity definitionEntity = new DefinitionEntity(); + FieldEntity fieldEntity = new FieldEntity(); + fieldEntity.setCode("uri"); + fieldEntity.setDataType(ReferenceFieldDataType.Text); + fieldEntity.setValue(item.getUri()); + definitionEntity.setFields(List.of(fieldEntity)); + data.setDefinition(this.xmlHandlingService.toXmlSafe(definitionEntity)); + } this.entityManager.persist(data); } this.entityManager.flush(); diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/ResearcherMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/ResearcherMigrationService.java index 0285ba0c2..d128042da 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/ResearcherMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/ResearcherMigrationService.java @@ -1,13 +1,15 @@ package eu.old.eudat.migration; +import eu.eudat.commons.XmlHandlingService; import eu.eudat.commons.enums.IsActive; +import eu.eudat.commons.enums.ReferenceFieldDataType; import eu.eudat.commons.enums.ReferenceSourceType; import eu.eudat.commons.enums.ReferenceType; +import eu.eudat.commons.types.reference.DefinitionEntity; +import eu.eudat.commons.types.reference.FieldEntity; +import eu.eudat.convention.ConventionService; import eu.eudat.data.ReferenceEntity; -import eu.old.eudat.data.dao.entities.OrganisationDao; import eu.old.eudat.data.dao.entities.ResearcherDao; -import eu.old.eudat.data.entities.DMP; -import eu.old.eudat.data.entities.Organisation; import eu.old.eudat.data.entities.Researcher; import eu.old.eudat.logic.services.operations.DatabaseRepository; import gr.cite.tools.logging.LoggerService; @@ -15,6 +17,7 @@ import jakarta.persistence.EntityManager; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -26,9 +29,13 @@ public class ResearcherMigrationService { private static final String InternalReferenceSource = "dmp"; private final DatabaseRepository databaseRepository; private final EntityManager entityManager; - public ResearcherMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) { + private final ConventionService conventionService; + private final XmlHandlingService xmlHandlingService; + public ResearcherMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager, ConventionService conventionService, XmlHandlingService xmlHandlingService) { this.databaseRepository = databaseRepository; this.entityManager = entityManager; + this.conventionService = conventionService; + this.xmlHandlingService = xmlHandlingService; } public void migrate(){ @@ -56,7 +63,7 @@ public class ResearcherMigrationService { ReferenceEntity data = new ReferenceEntity(); data.setId(item.getId()); data.setLabel(item.getLabel()); - data.setIsActive(DMP.DMPStatus.fromInteger(item.getStatus()).equals(DMP.DMPStatus.DELETED) ? IsActive.Inactive : IsActive.Active); + data.setIsActive(IsActive.Active); data.setType(ReferenceType.Researcher); data.setCreatedAt(item.getCreated().toInstant()); data.setUpdatedAt(item.getModified().toInstant()); @@ -64,6 +71,29 @@ public class ResearcherMigrationService { data.setReference(referenceParts[1]); data.setSource(isInternal? "Internal" : referenceParts[0]); data.setSourceType(isInternal? ReferenceSourceType.Internal : ReferenceSourceType.External); + + DefinitionEntity definitionEntity = new DefinitionEntity(); + definitionEntity.setFields(new ArrayList<>()); + if (!this.conventionService.isNullOrEmpty(item.getUri())){ + FieldEntity fieldEntity = new FieldEntity(); + fieldEntity.setCode("uri"); + fieldEntity.setDataType(ReferenceFieldDataType.Text); + fieldEntity.setValue(item.getUri()); + definitionEntity.getFields().add(fieldEntity); + } + if (!this.conventionService.isNullOrEmpty(item.getPrimaryEmail())){ + FieldEntity fieldEntity = new FieldEntity(); + fieldEntity.setCode("primaryEmail"); + fieldEntity.setDataType(ReferenceFieldDataType.Text); + fieldEntity.setValue(item.getPrimaryEmail()); + definitionEntity.getFields().add(fieldEntity); + } + + + if (!definitionEntity.getFields().isEmpty()){ + data.setDefinition(this.xmlHandlingService.toXmlSafe(definitionEntity)); + } + this.entityManager.persist(data); } this.entityManager.flush(); diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/ServiceMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/ServiceMigrationService.java index 30ab922dd..e03bda9d5 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/ServiceMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/ServiceMigrationService.java @@ -1,11 +1,15 @@ package eu.old.eudat.migration; +import eu.eudat.commons.XmlHandlingService; import eu.eudat.commons.enums.IsActive; +import eu.eudat.commons.enums.ReferenceFieldDataType; import eu.eudat.commons.enums.ReferenceSourceType; import eu.eudat.commons.enums.ReferenceType; +import eu.eudat.commons.types.reference.DefinitionEntity; +import eu.eudat.commons.types.reference.FieldEntity; +import eu.eudat.convention.ConventionService; import eu.eudat.data.ReferenceEntity; import eu.old.eudat.data.dao.entities.ServiceDao; -import eu.old.eudat.data.entities.DMP; import eu.old.eudat.logic.services.operations.DatabaseRepository; import gr.cite.tools.logging.LoggerService; import jakarta.persistence.EntityManager; @@ -23,9 +27,13 @@ public class ServiceMigrationService { private static final String InternalReferenceSource = "dmp"; private final DatabaseRepository databaseRepository; private final EntityManager entityManager; - public ServiceMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) { + private final ConventionService conventionService; + private final XmlHandlingService xmlHandlingService; + public ServiceMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager, ConventionService conventionService, XmlHandlingService xmlHandlingService) { this.databaseRepository = databaseRepository; this.entityManager = entityManager; + this.conventionService = conventionService; + this.xmlHandlingService = xmlHandlingService; } public void migrate(){ @@ -53,8 +61,8 @@ public class ServiceMigrationService { ReferenceEntity data = new ReferenceEntity(); data.setId(item.getId()); data.setLabel(item.getLabel()); - data.setDescription(item.getLabel()); - data.setIsActive(DMP.DMPStatus.fromInteger(item.getStatus()).equals(DMP.DMPStatus.DELETED) ? IsActive.Inactive : IsActive.Active); + data.setAbbreviation(item.getAbbreviation()); + data.setIsActive(IsActive.Active); data.setType(ReferenceType.Services); data.setCreatedAt(item.getCreated().toInstant()); data.setUpdatedAt(item.getModified().toInstant()); @@ -62,6 +70,16 @@ public class ServiceMigrationService { data.setReference(referenceParts[1]); data.setSource(isInternal? "Internal" : referenceParts[0]); data.setSourceType(isInternal? ReferenceSourceType.Internal : ReferenceSourceType.External); + if (!this.conventionService.isNullOrEmpty(item.getUri())){ + DefinitionEntity definitionEntity = new DefinitionEntity(); + FieldEntity fieldEntity = new FieldEntity(); + fieldEntity.setCode("uri"); + fieldEntity.setDataType(ReferenceFieldDataType.Text); + fieldEntity.setValue(item.getUri()); + definitionEntity.setFields(List.of(fieldEntity)); + data.setDefinition(this.xmlHandlingService.toXmlSafe(definitionEntity)); + } + this.entityManager.persist(data); } this.entityManager.flush();