Fixing issues, resolving column naming conflicts between old and new entity classes

This commit is contained in:
Thomas Georgios Giannos 2023-11-20 16:44:55 +02:00
parent ea7fa62922
commit 3a033a655b
14 changed files with 153 additions and 55 deletions

View File

@ -23,16 +23,16 @@ public class DescriptionTemplateEntity implements DataEntity<DescriptionTemplate
private UUID id;
public static final String _id = "id";
@Column(name = "\"label\"", length = DescriptionTemplateEntity._labelLength, nullable = false)
@Column(name = "label", length = DescriptionTemplateEntity._labelLength, nullable = false)
private String label;
public static final String _label = "label";
public static final int _labelLength = 250;
@Column(name = "\"definition\"", nullable = false)
@Column(name = "definition", nullable = false)
private String definition;
public static final String _definition = "definition";
@Column(name = "\"status\"", nullable = false)
@Column(name = "status", nullable = false)
@Convert(converter = DescriptionTemplateStatusConverter.class)
private DescriptionTemplateStatus status;
public static final String _status = "status";
@ -43,23 +43,23 @@ public class DescriptionTemplateEntity implements DataEntity<DescriptionTemplate
public static final String _isActive = "isActive";
@Column(name = "\"created_at\"", nullable = false)
@Column(name = "created_at", nullable = false)
private Instant createdAt = null;
public static final String _createdAt = "createdAt";
@Column(name = "\"updated_at\"", nullable = false)
@Column(name = "updated_at", nullable = false)
private Instant updatedAt;
public static final String _updatedAt = "updatedAt";
@Column(name = "\"description\"", nullable = false)
@Column(name = "description", nullable = false)
private String description;
public static final String _description = "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;
public static final String _groupId = "groupId";
@Column(name = "\"version\"", nullable = false)
@Column(name = "version", nullable = false)
private Short version;
public static final String _version = "version";
@ -68,11 +68,11 @@ public class DescriptionTemplateEntity implements DataEntity<DescriptionTemplate
private DescriptionTemplateVersionStatus versionStatus;
public static final String _versionStatus = "versionStatus";
@Column(name = "\"language\"", nullable = false)
@Column(name = "language", nullable = false)
private String language;
public static final String _language = "language";
@Column(name = "\"type\"", nullable = false)
@Column(name = "type", nullable = false)
private UUID typeId;
public static final String _typeId = "typeId";

View File

@ -19,17 +19,17 @@ public class DmpBlueprintEntity {
private UUID id;
public static final String _id = "id";
@Column(name = "\"label\"", length = DmpBlueprintEntity._labelLength, nullable = false)
@Column(name = "label", length = DmpBlueprintEntity._labelLength, nullable = false)
private String label;
public static final String _label = "label";
public static final int _labelLength = 250;
@Column(name = "\"definition\"", nullable = true)
@Column(name = "definition", nullable = true)
private String definition;
public static final String _definition = "definition";
@Column(name = "\"status\"", nullable = false)
@Column(name = "status", nullable = false)
@Convert(converter = DmpBlueprintStatusConverter.class)
private DmpBlueprintStatus status;
public static final String _status = "status";
@ -40,11 +40,11 @@ public class DmpBlueprintEntity {
public static final String _isActive = "isActive";
@Column(name = "\"created_at\"", nullable = false)
@Column(name = "created_at", nullable = false)
private Instant createdAt = null;
public static final String _createdAt = "createdAt";
@Column(name = "\"updated_at\"", nullable = false)
@Column(name = "updated_at", nullable = false)
private Instant updatedAt;
public static final String _updatedAt = "updatedAt";

View File

@ -18,12 +18,12 @@ public class UserRoleEntity implements DataEntity<UserRoleEntity, UUID> {
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";

View File

@ -47,7 +47,7 @@ public class DMPProfile implements DataEntity<DMPProfile, UUID> {
@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<DMPProfile, UUID> {
private Set<DMP> 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();

View File

@ -45,46 +45,46 @@ public class DescriptionTemplate implements DataEntity<DescriptionTemplate,UUID>
@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> 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<DMP> 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)

View File

@ -40,13 +40,13 @@ public class DescriptionTemplateType implements DataEntity<DescriptionTemplateTy
@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 = "\"name\"", nullable = false)
@Column(name = "name", nullable = false)
private String name;
@Column(name = "\"status\"", nullable = false)
@Column(name = "status", nullable = false)
private Short status;
public UUID getId() {

View File

@ -19,29 +19,29 @@ public class EntityDoi implements DataEntity<EntityDoi, UUID> {
}
@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() {

View File

@ -16,14 +16,14 @@ public class UserRole implements DataEntity<UserRole, UUID> {
@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() {

View File

@ -42,6 +42,10 @@
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>

View File

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

View File

@ -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<String> managedClassNames = persistenceUnit.getManagedClassNames();
managedClassNames.removeIf(fullClassName -> fullClassName.startsWith("eu.eudat.data.old"));
});
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
em.setJpaProperties(additionalProperties());

View File

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

View File

@ -25,6 +25,7 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
private UUID groupId;
private Tuple<UUID, String> 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<DMP, DataManagementPlan> {
private eu.old.eudat.models.data.userinfo.UserInfo creator;
private Date modified;
private Date created;
private Date finalized;
private List<DynamicFieldWithValue> dynamicFields;
private Map<String, Object> properties;
private List<UserInfoListingModel> users;
@ -89,6 +91,13 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
this.version = version;
}
public int getVersionStatus() {
return versionStatus;
}
public void setVersionStatus(int versionStatus) {
this.versionStatus = versionStatus;
}
public List<Organisation> getOrganisations() {
return organisations;
}
@ -145,6 +154,13 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
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<DMP, DataManagementPlan> {
}
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<DMP, DataManagementPlan> {
}
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<>();

View File

@ -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<DmpEntity> migrateDmps() {
@GetMapping("dmps/collectInfo")
public List<DmpMigrationCollectedInfo> collectDmpsInfo() {
List<DmpMigrationCollectedInfo> collectedInfoList = new ArrayList<>();
List<DataManagementPlan> dmps = getDmps(0, 4);
List<DmpEntity> 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;
}
}