diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionEntity.java index 833d6215f..59ccd8c68 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionEntity.java @@ -64,7 +64,6 @@ public class DescriptionEntity implements DataEntity { public static final String _isActive = "isActive"; @Column(name = "\"finalized_at\"") - @Convert(converter = DateToUTCConverter.class) private Instant finalizedAt; public static final String _finalizedAt = "finalizedAt"; diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DatasetMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DatasetMigrationService.java new file mode 100644 index 000000000..d65414b96 --- /dev/null +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DatasetMigrationService.java @@ -0,0 +1,99 @@ +package eu.old.eudat.migration; + +import com.fasterxml.jackson.core.JsonProcessingException; +import eu.eudat.commons.JsonHandlingService; +import eu.eudat.commons.enums.*; +import eu.eudat.data.DescriptionEntity; +import eu.old.eudat.data.entities.Dataset; +import eu.old.eudat.logic.services.operations.DatabaseRepository; +import eu.old.eudat.models.data.datasetwizard.DatasetWizardModel; +import eu.old.eudat.queryable.QueryableList; +import jakarta.persistence.EntityManager; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class DatasetMigrationService { + + private final DatabaseRepository databaseRepository; + + private final JsonHandlingService jsonHandlingService; + + private final EntityManager entityManager; + + public DatasetMigrationService(DatabaseRepository databaseRepository, JsonHandlingService jsonHandlingService, EntityManager entityManager) { + this.databaseRepository = databaseRepository; + this.jsonHandlingService = jsonHandlingService; + this.entityManager = entityManager; + } + + public QueryableList datasetQueryableList() { + return databaseRepository.getDatasetDao().asQueryable(); + } + + public List getDatasets(Integer skip, Integer take) { + List datasets = datasetQueryableList() + .orderBy((builder, root) -> builder.desc(root.get("created"))) + .skip(skip) + .take(take) + .toList(); + + return datasets.stream().map(x -> { + DatasetWizardModel dataset = new DatasetWizardModel(); + dataset.fromDataModel(x); + return dataset; + }).toList(); + } + + public List collectDatasetsInfo() throws JsonProcessingException { + List collectedInfoList = new ArrayList<>(); + List datasets = getDatasets(0, 4); + for (DatasetWizardModel datasetWizardModel : datasets) { + DatasetMigrationCollectedInfo datasetMigrationCollectedInfo = new DatasetMigrationCollectedInfo(); + + //Collect basic dataset information + DescriptionEntity descriptionEntity = new DescriptionEntity(); + descriptionEntity.setId(datasetWizardModel.getId()); + descriptionEntity.setDescription(datasetWizardModel.getDescription()); + descriptionEntity.setCreatedById(datasetWizardModel.getCreatedBy()); + descriptionEntity.setDmpId(datasetWizardModel.getDmp().getId()); + descriptionEntity.setLabel(datasetWizardModel.getLabel()); + if (datasetWizardModel.getCreated() != null) + descriptionEntity.setCreatedAt(datasetWizardModel.getCreated().toInstant()); + if (datasetWizardModel.getModified() != null) + descriptionEntity.setUpdatedAt(datasetWizardModel.getModified().toInstant()); + if (datasetWizardModel.getFinalized() != null) + descriptionEntity.setFinalizedAt(datasetWizardModel.getFinalized().toInstant()); + if (datasetWizardModel.getStatus() == 99) { + descriptionEntity.setIsActive(IsActive.Inactive); + descriptionEntity.setStatus(DescriptionStatus.Canceled); + } else { + descriptionEntity.setIsActive(IsActive.Active); + descriptionEntity.setStatus(DescriptionStatus.of(datasetWizardModel.getStatus())); + } +// descriptionEntity.setDmpDescriptionTemplateId(); //TODO MIGRATE DMPDESCRIPTIONTEMPLATES + + datasetMigrationCollectedInfo.descriptionEntity = descriptionEntity; + + collectedInfoList.add(datasetMigrationCollectedInfo); + } + return collectedInfoList; + } + + public String migrate() throws JsonProcessingException { + for (DatasetMigrationCollectedInfo collectedInfo : collectDatasetsInfo()) { + this.entityManager.persist(collectedInfo.descriptionEntity); + } + this.entityManager.flush(); + return "Migrated dmps"; + } + + public static class DatasetMigrationCollectedInfo { + + public DescriptionEntity descriptionEntity; + + } + +} diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpDatasetProfileMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpDatasetProfileMigrationService.java new file mode 100644 index 000000000..8dab50b20 --- /dev/null +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpDatasetProfileMigrationService.java @@ -0,0 +1,102 @@ +package eu.old.eudat.migration; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.core.JsonProcessingException; +import eu.eudat.commons.JsonHandlingService; +import eu.eudat.commons.enums.DescriptionStatus; +import eu.eudat.commons.enums.IsActive; +import eu.eudat.data.DescriptionEntity; +import eu.eudat.data.DmpDescriptionTemplateEntity; +import eu.old.eudat.data.entities.DMPDatasetProfile; +import eu.old.eudat.data.entities.Dataset; +import eu.old.eudat.logic.services.operations.DatabaseRepository; +import eu.old.eudat.models.data.datasetwizard.DatasetWizardModel; +import eu.old.eudat.queryable.QueryableList; +import jakarta.persistence.EntityManager; +import org.springframework.stereotype.Service; + +import java.time.Instant; +import java.util.ArrayList; +import java.util.List; + +@Service +public class DmpDatasetProfileMigrationService { + + private final DatabaseRepository databaseRepository; + + private final JsonHandlingService jsonHandlingService; + + private final EntityManager entityManager; + + public DmpDatasetProfileMigrationService(DatabaseRepository databaseRepository, JsonHandlingService jsonHandlingService, EntityManager entityManager) { + this.databaseRepository = databaseRepository; + this.jsonHandlingService = jsonHandlingService; + this.entityManager = entityManager; + } + + public QueryableList dmpDatasetProfileQueryableList() { + return databaseRepository.getDmpDatasetProfileDao().asQueryable(); + } + + public List getDatasets(Integer skip, Integer take) { + return dmpDatasetProfileQueryableList() +// .orderBy((builder, root) -> builder.desc(root.get("created"))) + .skip(skip) + .take(take) + .toList(); + } + + public List collectDatasetsInfo() throws JsonProcessingException { + List collectedInfoList = new ArrayList<>(); + List dmpDatasetProfiles = getDatasets(0, 4); + for (DMPDatasetProfile dmpDatasetProfile : dmpDatasetProfiles) { + DmpDatasetProfileMigrationCollectedInfo dmpDatasetProfileMigrationCollectedInfo = new DmpDatasetProfileMigrationCollectedInfo(); + + DmpDatasetProfileData data = jsonHandlingService.fromJson(DmpDatasetProfileData.class, dmpDatasetProfile.getData()); + + //Collect basic information + DmpDescriptionTemplateEntity dmpDescriptionTemplateEntity = new DmpDescriptionTemplateEntity(); + dmpDescriptionTemplateEntity.setDescriptionTemplateId(dmpDatasetProfile.getDatasetprofile().getId()); + dmpDescriptionTemplateEntity.setDmpId(dmpDatasetProfile.getDmp().getId()); + dmpDescriptionTemplateEntity.setCreatedAt(Instant.now()); + dmpDescriptionTemplateEntity.setUpdatedAt(Instant.now()); + dmpDescriptionTemplateEntity.setSectionId(null); //TODO + dmpDescriptionTemplateEntity.setIsActive(IsActive.Active); + + dmpDatasetProfileMigrationCollectedInfo.dmpDescriptionTemplateEntity = dmpDescriptionTemplateEntity; + + collectedInfoList.add(dmpDatasetProfileMigrationCollectedInfo); + } + return collectedInfoList; + } + + public String migrate() throws JsonProcessingException { + for (DmpDatasetProfileMigrationCollectedInfo collectedInfo : collectDatasetsInfo()) { +// this.entityManager.persist(collectedInfo.dmpDescriptionTemplateEntity); + } + this.entityManager.flush(); + return "Migrated dmps"; + } + + public static class DmpDatasetProfileMigrationCollectedInfo { + + public DmpDescriptionTemplateEntity dmpDescriptionTemplateEntity; + + } + + @JsonIgnoreProperties({"validationErrorModel"}) + public static class DmpDatasetProfileData { + + private List dmpSectionIndex; + + public List getDmpSectionIndex() { + return dmpSectionIndex; + } + + public void setDmpSectionIndex(List dmpSectionIndex) { + this.dmpSectionIndex = dmpSectionIndex; + } + + } + +} diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpMigrationService.java index 5a176a6a2..857b793af 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpMigrationService.java @@ -13,12 +13,9 @@ import eu.eudat.data.DmpEntity; import eu.old.eudat.data.entities.DMP; import eu.old.eudat.logic.services.operations.DatabaseRepository; import eu.old.eudat.models.data.dmp.DataManagementPlan; -import eu.old.eudat.publicapi.migration.MigrationController; import eu.old.eudat.queryable.QueryableList; import jakarta.persistence.EntityManager; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import java.util.ArrayList; @@ -44,7 +41,7 @@ public class DmpMigrationService { return databaseRepository.getDmpDao().asQueryable(); } - public List getDmps(@PathVariable("skip") Integer skip, @PathVariable("take") Integer take) { + public List getDmps(Integer skip, Integer take) { List dmps = dmpQueryableList() .orderBy((builder, root) -> builder.desc(root.get("created"))) .skip(skip) @@ -70,7 +67,7 @@ public class DmpMigrationService { //Collect basic dmp information DmpEntity dmpEntity = new DmpEntity(); - dmpEntity.setId(UUID.randomUUID()); + dmpEntity.setId(dataManagementPlan.getId()); dmpEntity.setLabel(dataManagementPlan.getLabel()); dmpEntity.setDescription(dataManagementPlan.getDescription()); if (dataManagementPlan.getCreator() != null) @@ -120,7 +117,6 @@ public class DmpMigrationService { return collectedInfoList; } - @Transactional public String migrate() throws JsonProcessingException { for (DmpMigrationCollectedInfo collectedInfo : collectDmpsInfo()) { this.entityManager.persist(collectedInfo.dmpEntity); diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/models/data/datasetwizard/DatasetWizardModel.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/models/data/datasetwizard/DatasetWizardModel.java index 4fb8ee7f4..e4170bdfe 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/models/data/datasetwizard/DatasetWizardModel.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/models/data/datasetwizard/DatasetWizardModel.java @@ -22,6 +22,7 @@ public class DatasetWizardModel implements DataModel(); this.services = entity.getServices() != null ? entity.getServices().stream().map(item -> new eu.old.eudat.models.data.dataset.Service().fromDataModel(item.getService())).collect(Collectors.toList()) : new ArrayList<>(); this.created = entity.getCreated(); + this.createdBy = entity.getCreator().getId(); this.dmp = new DataManagementPlan().fromDataModelNoDatasets(entity.getDmp()); this.dmpSectionIndex = entity.getDmpSectionIndex(); this.externalDatasets = entity.getDatasetExternalDatasets() != null ? entity.getDatasetExternalDatasets().stream().map(item -> { @@ -196,6 +213,7 @@ public class DatasetWizardModel implements DataModel(); this.modified = entity.getModified(); + this.finalized = entity.getFinalizedAt(); return this; } @@ -251,7 +269,11 @@ public class DatasetWizardModel implements DataModel