diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionTemplateEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionTemplateEntity.java index 591413e69..9dae0c4ae 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionTemplateEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionTemplateEntity.java @@ -23,16 +23,16 @@ public class DescriptionTemplateEntity implements DataEntity { private UUID id; public static final String _id = "id"; - @Column(name = "\"role\"", length = UserRoleEntity._roleLength, nullable = false) + @Column(name = "role", length = UserRoleEntity._roleLength, nullable = false) private String role; public static final String _role = "role"; public static final int _roleLength = 512; - @Column(name = "\"user\"", nullable = false) + @Column(name = "user", nullable = false) private UUID userId; public static final String _userId = "userId"; diff --git a/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/entities/DMPProfile.java b/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/entities/DMPProfile.java index 319386b26..d8ccbdb4b 100644 --- a/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/entities/DMPProfile.java +++ b/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/entities/DMPProfile.java @@ -47,7 +47,7 @@ public class DMPProfile implements DataEntity { @Id @GeneratedValue @GenericGenerator(name = "uuid2", strategy = "uuid2") - @Column(name = "\"id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") + @Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; @@ -55,22 +55,22 @@ public class DMPProfile implements DataEntity { private Set dmps; - @Column(name = "\"label\"") + @Column(name = "label") private String label; - @Column(name = "\"definition\"", columnDefinition = "xml", nullable = true) + @Column(name = "definition", columnDefinition = "xml", nullable = true) private String definition; - @Column(name = "\"status\"", nullable = false) + @Column(name = "status", nullable = false) private int status; - @Column(name = "\"created_at\"") + @Column(name = "created_at") @Convert(converter = DateToUTCConverter.class) private Date created = null; - @Column(name = "\"updated_at\"") + @Column(name = "updated_at") @Convert(converter = DateToUTCConverter.class) private Date modified = new Date(); diff --git a/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/entities/DescriptionTemplate.java b/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/entities/DescriptionTemplate.java index 90d5c332f..5b93fa109 100644 --- a/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/entities/DescriptionTemplate.java +++ b/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/entities/DescriptionTemplate.java @@ -45,46 +45,46 @@ public class DescriptionTemplate implements DataEntity @Id @GeneratedValue @GenericGenerator(name = "uuid2", strategy = "uuid2") - @Column(name = "\"id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") + @Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; - @Column(name = "\"label\"", nullable = false) + @Column(name = "label", nullable = false) private String label; @OneToMany(fetch = FetchType.LAZY, mappedBy = "profile") private Set dataset; - @Column(name = "\"definition\"", columnDefinition = "xml", nullable = false) + @Column(name = "definition", columnDefinition = "xml", nullable = false) private String definition; - @Column(name = "\"status\"", nullable = false) + @Column(name = "status", nullable = false) private Short status; - @Column(name = "\"created_at\"") + @Column(name = "created_at") @Convert(converter = DateToUTCConverter.class) private Date created; - @Column(name = "\"updated_at\"") + @Column(name = "updated_at") @Convert(converter = DateToUTCConverter.class) private Date modified = new Date(); - @Column(name = "\"description\"") + @Column(name = "description") private String description; - @Column(name = "\"group_id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") + @Column(name = "group_id", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID groupId; - @Column(name = "\"version\"", nullable = false) + @Column(name = "version", nullable = false) private Short version; @OneToMany(fetch = FetchType.LAZY) private Set dmps; - @Column(name = "\"language\"", nullable = false) + @Column(name = "language", nullable = false) private String language; @OneToOne(fetch = FetchType.EAGER) - @JoinColumn(name = "\"type\"", nullable = false) + @JoinColumn(name = "type", nullable = false) private DescriptionTemplateType type; @OneToMany(mappedBy = "descriptionTemplate", fetch = FetchType.LAZY) diff --git a/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/entities/DescriptionTemplateType.java b/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/entities/DescriptionTemplateType.java index 1aad06f61..f8a9f4b94 100644 --- a/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/entities/DescriptionTemplateType.java +++ b/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/entities/DescriptionTemplateType.java @@ -40,13 +40,13 @@ public class DescriptionTemplateType implements DataEntity { } @Id - @Column(name = "\"id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") + @Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; @Enumerated(EnumType.STRING) - @Column(name = "\"entity_type\"", nullable = false) + @Column(name = "entity_type", nullable = false) private EntityType entityType; - @Column(name = "\"repository_id\"", nullable = false) + @Column(name = "repository_id", nullable = false) private String repositoryId; - @Column(name = "\"doi\"", nullable = false) + @Column(name = "doi", nullable = false) private String doi; - @Column(name = "\"created_at\"", nullable = false) + @Column(name = "created_at", nullable = false) @Convert(converter = DateToUTCConverter.class) private Date createdAt; - @Column(name = "\"updated_at\"", nullable = false) + @Column(name = "updated_at", nullable = false) @Convert(converter = DateToUTCConverter.class) private Date updatedAt; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "\"entity_id\"", nullable = false) + @JoinColumn(name = "entity_id", nullable = false) private DMP entityId; public UUID getId() { 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 14c90d5ba..5a8171548 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 @@ -16,14 +16,14 @@ public class UserRole implements DataEntity { @Id @GeneratedValue @GenericGenerator(name = "uuid2", strategy = "uuid2") - @Column(name = "\"id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") + @Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; - @Column(name = "\"role\"", nullable = false) + @Column(name = "role", nullable = false) 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/pom.xml b/dmp-migration-tool/web/pom.xml index ffa743973..df81b7b06 100644 --- a/dmp-migration-tool/web/pom.xml +++ b/dmp-migration-tool/web/pom.xml @@ -42,6 +42,10 @@ 1.0.4 + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + org.springframework.boot diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/EuDatApplication.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/EuDatApplication.java index f08c3d12d..a31b4314e 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/EuDatApplication.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/EuDatApplication.java @@ -1,12 +1,22 @@ package eu.old.eudat; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.Module; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import eu.old.eudat.criteria.entities.Criteria; +import eu.old.eudat.criteria.serialzier.CriteriaSerializer; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableAsync; +import java.util.ArrayList; + @SpringBootApplication(scanBasePackages = {"eu.eudat" ,"eu.old.eudat", "eu.old.eudat.depositinterface", "gr.cite"}) @Configuration @EnableAsync diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/configurations/DevelDatabaseConfiguration.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/configurations/DevelDatabaseConfiguration.java index 28df8faf1..f1bc30e95 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/configurations/DevelDatabaseConfiguration.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/configurations/DevelDatabaseConfiguration.java @@ -1,28 +1,38 @@ package eu.old.eudat.configurations; +import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.context.annotation.*; import org.springframework.core.env.Environment; import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.orm.jpa.JpaVendorAdapter; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo; +import org.springframework.orm.jpa.persistenceunit.PersistenceUnitPostProcessor; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.EnableTransactionManagement; import jakarta.persistence.EntityManagerFactory; import javax.sql.DataSource; +import java.util.List; import java.util.Properties; @Configuration @EnableTransactionManagement @Profile("devel") -@ComponentScan(basePackages = {"eu.old.eudat.data.entities"}) +@EnableJpaRepositories( + basePackages = {"eu.old.eudat.data.entities", "eu.eudat.data"}, + excludeFilters = { + @ComponentScan.Filter(type = FilterType.REGEX, pattern = "eu\\.eudat\\.data\\.old\\..*"), + } +) public class DevelDatabaseConfiguration { @Autowired @@ -32,7 +42,11 @@ public class DevelDatabaseConfiguration { public LocalContainerEntityManagerFactoryBean entityManagerFactory() { LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); em.setDataSource(dataSource()); - em.setPackagesToScan(new String[]{"eu.old.eudat.data.entities"}); + em.setPackagesToScan("eu.old.eudat.data.entities", "eu.eudat.data"); + em.setPersistenceUnitPostProcessors(persistenceUnit -> { + List managedClassNames = persistenceUnit.getManagedClassNames(); + managedClassNames.removeIf(fullClassName -> fullClassName.startsWith("eu.eudat.data.old")); + }); JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); em.setJpaVendorAdapter(vendorAdapter); em.setJpaProperties(additionalProperties()); diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/configurations/JacksonConfiguration.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/configurations/JacksonConfiguration.java index 69a6bc6cb..bbc687dc1 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/configurations/JacksonConfiguration.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/configurations/JacksonConfiguration.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.Module; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import eu.old.eudat.criteria.entities.Criteria; import eu.old.eudat.criteria.serialzier.CriteriaSerializer; import org.springframework.context.annotation.Bean; @@ -20,6 +21,7 @@ public class JacksonConfiguration { SimpleModule criteriaSerializerModule = new SimpleModule(); criteriaSerializerModule.addDeserializer(Criteria.class, new CriteriaSerializer()); modules.add(criteriaSerializerModule); + modules.add(new JavaTimeModule()); return new ObjectMapper() .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/models/data/dmp/DataManagementPlan.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/models/data/dmp/DataManagementPlan.java index 268900201..fa779017c 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/models/data/dmp/DataManagementPlan.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/models/data/dmp/DataManagementPlan.java @@ -25,6 +25,7 @@ public class DataManagementPlan implements DataModel { private UUID groupId; private Tuple profile; private int version; + private int versionStatus; private int status; private boolean lockable; private String description; @@ -38,6 +39,7 @@ public class DataManagementPlan implements DataModel { private eu.old.eudat.models.data.userinfo.UserInfo creator; private Date modified; private Date created; + private Date finalized; private List dynamicFields; private Map properties; private List users; @@ -89,6 +91,13 @@ public class DataManagementPlan implements DataModel { this.version = version; } + public int getVersionStatus() { + return versionStatus; + } + public void setVersionStatus(int versionStatus) { + this.versionStatus = versionStatus; + } + public List getOrganisations() { return organisations; } @@ -145,6 +154,13 @@ public class DataManagementPlan implements DataModel { this.created = created; } + public Date getFinalized() { + return finalized; + } + public void setFinalized(Date finalized) { + this.finalized = finalized; + } + public String getDescription() { return description; } @@ -293,6 +309,7 @@ public class DataManagementPlan implements DataModel { } this.modified = entity.getModified(); this.created = entity.getCreated(); + this.finalized = entity.getFinalizedAt(); this.description = entity.getDescription(); this.status = entity.getStatus(); this.associatedUsers = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList()) : new ArrayList<>(); @@ -405,6 +422,7 @@ public class DataManagementPlan implements DataModel { } this.modified = entity.getModified(); this.created = entity.getCreated(); + this.finalized = entity.getFinalizedAt(); this.description = entity.getDescription(); this.status = entity.getStatus(); this.associatedUsers = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList()) : new ArrayList<>(); 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 92fad28c8..cbd84e3b6 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 @@ -1,12 +1,18 @@ package eu.old.eudat.publicapi.migration; import eu.eudat.commons.enums.DmpAccessType; +import eu.eudat.commons.enums.DmpStatus; +import eu.eudat.commons.enums.DmpVersionStatus; +import eu.eudat.commons.enums.IsActive; import eu.eudat.data.DmpEntity; import eu.old.eudat.data.dao.criteria.DataManagementPlanCriteria; import eu.old.eudat.data.entities.DMP; import eu.old.eudat.logic.services.operations.DatabaseRepository; import eu.old.eudat.models.data.dmp.DataManagementPlan; import io.swagger.annotations.Api; +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; @@ -21,8 +27,12 @@ public class MigrationController { private final DatabaseRepository databaseRepository; - public MigrationController(DatabaseRepository databaseRepository) { + @PersistenceContext + private final EntityManager entityManager; + + public MigrationController(DatabaseRepository databaseRepository, EntityManager entityManager) { this.databaseRepository = databaseRepository; + this.entityManager = entityManager; } @GetMapping("dmps/all/{skip}/{take}") @@ -44,19 +54,59 @@ public class MigrationController { return results; } - @GetMapping("dmps/migrate") - public List migrateDmps() { + @GetMapping("dmps/collectInfo") + public List collectDmpsInfo() { + List collectedInfoList = new ArrayList<>(); List dmps = getDmps(0, 4); - List migratedDmps = new ArrayList<>(); for (DataManagementPlan dataManagementPlan : dmps) { + DmpMigrationCollectedInfo dmpMigrationCollectedInfo = new DmpMigrationCollectedInfo(); + + //Collect basic dmp information DmpEntity dmpEntity = new DmpEntity(); dmpEntity.setId(UUID.randomUUID()); dmpEntity.setLabel(dataManagementPlan.getLabel()); dmpEntity.setDescription(dataManagementPlan.getDescription()); dmpEntity.setAccessType(dataManagementPlan.getPublic() ? DmpAccessType.Public : DmpAccessType.Restricted); - migratedDmps.add(dmpEntity); + if (dataManagementPlan.getCreator() != null) + dmpEntity.setCreator(dataManagementPlan.getCreator().getId()); + dmpEntity.setGroupId(dataManagementPlan.getGroupId()); + dmpEntity.setVersion((short) dataManagementPlan.getVersion()); + dmpEntity.setVersionStatus(DmpVersionStatus.of((short) dataManagementPlan.getVersionStatus())); + if (dataManagementPlan.getCreated() != null) + dmpEntity.setCreatedAt(dataManagementPlan.getCreated().toInstant()); + if (dataManagementPlan.getModified() != null) + dmpEntity.setUpdatedAt(dataManagementPlan.getModified().toInstant()); + if (dataManagementPlan.getFinalized() != null) + dmpEntity.setFinalizedAt(dataManagementPlan.getFinalized().toInstant()); + dmpEntity.setBlueprint(dataManagementPlan.getProfile().getId()); + if (dataManagementPlan.getExtraProperties().containsKey("language") && dataManagementPlan.getExtraProperties().get("language") != null) + dmpEntity.setLanguage((String) dataManagementPlan.getExtraProperties().get("language")); + if (dataManagementPlan.getStatus() == 99) { + dmpEntity.setIsActive(IsActive.Inactive); + } else { + dmpEntity.setIsActive(IsActive.Active); + dmpEntity.setStatus(DmpStatus.of((short) dataManagementPlan.getStatus())); + } + dmpMigrationCollectedInfo.dmpEntity = dmpEntity; + collectedInfoList.add(dmpMigrationCollectedInfo); } - return migratedDmps; + return collectedInfoList; + } + + @GetMapping("dmps/migrate") + @Transactional + public String migrate() { + for (DmpMigrationCollectedInfo collectedInfo : collectDmpsInfo()) { + this.entityManager.persist(collectedInfo.dmpEntity); + } + this.entityManager.flush(); + return "Migrated dmps"; + } + + public static class DmpMigrationCollectedInfo { + + public DmpEntity dmpEntity; + } }