From dc381c197df5bcd00d2417ed46e4fc1f49ecbb22 Mon Sep 17 00:00:00 2001 From: Thomas Georgios Giannos Date: Tue, 21 Nov 2023 17:33:54 +0200 Subject: [PATCH] Adding properties to the migrated dmps --- .../migration/MigrationController.java | 50 +++++++++++++++---- 1 file changed, 39 insertions(+), 11 deletions(-) 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 2fad20958..2a9697bc1 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,15 +1,20 @@ package eu.old.eudat.publicapi.migration; +import com.fasterxml.jackson.core.JsonProcessingException; +import eu.eudat.commons.JsonHandlingService; import eu.eudat.commons.enums.*; +import eu.eudat.commons.types.dmp.DmpBlueprintValueEntity; +import eu.eudat.commons.types.dmp.DmpContactEntity; +import eu.eudat.commons.types.dmp.DmpPropertiesEntity; import eu.eudat.data.DmpEntity; import eu.eudat.data.ReferenceEntity; -import eu.old.eudat.data.dao.criteria.DataManagementPlanCriteria; -import eu.old.eudat.data.dao.criteria.OrganisationCriteria; -import eu.old.eudat.data.dao.entities.DMPDao; +import eu.eudat.model.persist.dmpproperties.DmpBlueprintValuePersist; +import eu.eudat.model.persist.dmpproperties.DmpPropertiesPersist; import eu.old.eudat.data.entities.DMP; import eu.old.eudat.data.entities.Organisation; import eu.old.eudat.logic.services.operations.DatabaseRepository; import eu.old.eudat.models.data.dmp.DataManagementPlan; +import eu.old.eudat.models.data.dynamicfields.DynamicFieldWithValue; import eu.old.eudat.queryable.QueryableList; import io.swagger.annotations.Api; import jakarta.persistence.EntityManager; @@ -17,6 +22,7 @@ import jakarta.persistence.PersistenceContext; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; +import java.time.Instant; import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -29,11 +35,14 @@ public class MigrationController { private final DatabaseRepository databaseRepository; + private final JsonHandlingService jsonHandlingService; + @PersistenceContext private final EntityManager entityManager; - public MigrationController(DatabaseRepository databaseRepository, EntityManager entityManager) { + public MigrationController(DatabaseRepository databaseRepository, JsonHandlingService jsonHandlingService, EntityManager entityManager) { this.databaseRepository = databaseRepository; + this.jsonHandlingService = jsonHandlingService; this.entityManager = entityManager; } @@ -66,18 +75,21 @@ public class MigrationController { } @GetMapping("dmps/collectInfo") - public List collectDmpsInfo() { + public List collectDmpsInfo() throws JsonProcessingException { List collectedInfoList = new ArrayList<>(); List dmps = getDmps(0, 4); for (DataManagementPlan dataManagementPlan : dmps) { DmpMigrationCollectedInfo dmpMigrationCollectedInfo = new DmpMigrationCollectedInfo(); + DmpPropertiesEntity dmpProperties = new DmpPropertiesEntity(); + dmpProperties.setDmpBlueprintValues(new ArrayList<>()); + dmpProperties.setContacts(new ArrayList<>()); + //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); if (dataManagementPlan.getCreator() != null) dmpEntity.setCreatorId(dataManagementPlan.getCreator().getId()); dmpEntity.setGroupId(dataManagementPlan.getGroupId()); @@ -90,20 +102,36 @@ public class MigrationController { if (dataManagementPlan.getFinalized() != null) dmpEntity.setFinalizedAt(dataManagementPlan.getFinalized().toInstant()); dmpEntity.setBlueprintId(dataManagementPlan.getProfile().getId()); - if (dataManagementPlan.getExtraProperties().containsKey("language") && dataManagementPlan.getExtraProperties().get("language") != null) - dmpEntity.setLanguage((String) dataManagementPlan.getExtraProperties().get("language")); + if (dataManagementPlan.getExtraProperties() != null) { + if (dataManagementPlan.getExtraProperties().containsKey("language") && dataManagementPlan.getExtraProperties().get("language") != null) + dmpEntity.setLanguage((String) dataManagementPlan.getExtraProperties().get("language")); + if (dataManagementPlan.getExtraProperties().containsKey("visible") && dataManagementPlan.getExtraProperties().get("visible") != null) + dmpEntity.setAccessType((boolean) dataManagementPlan.getExtraProperties().get("visible") ? DmpAccessType.Public : DmpAccessType.Restricted); + if (dataManagementPlan.getExtraProperties().containsKey("contact") && dataManagementPlan.getExtraProperties().get("contact") != null) { + DmpContactEntity contactEntity = new DmpContactEntity(); + contactEntity.setUserId((String) dataManagementPlan.getExtraProperties().get("contact")); + dmpProperties.getContacts().add(contactEntity); + } + } + if (dataManagementPlan.getProperties() != null) { + dataManagementPlan.getProperties().forEach((key,val) -> { + DmpBlueprintValueEntity valueEntity = new DmpBlueprintValueEntity(); + valueEntity.setFieldId(key); + valueEntity.setValue((String) val); + dmpProperties.getDmpBlueprintValues().add(valueEntity); + }); + } if (dataManagementPlan.getStatus() == 99) { dmpEntity.setIsActive(IsActive.Inactive); } else { dmpEntity.setIsActive(IsActive.Active); dmpEntity.setStatus(DmpStatus.of((short) dataManagementPlan.getStatus())); } + dmpEntity.setProperties(jsonHandlingService.toJson(dmpProperties)); dmpMigrationCollectedInfo.dmpEntity = dmpEntity; //Collect dmp Organization info - - collectedInfoList.add(dmpMigrationCollectedInfo); } return collectedInfoList; @@ -111,7 +139,7 @@ public class MigrationController { @GetMapping("dmps/migrate") @Transactional - public String migrate() { + public String migrate() throws JsonProcessingException { for (DmpMigrationCollectedInfo collectedInfo : collectDmpsInfo()) { this.entityManager.persist(collectedInfo.dmpEntity); }