Adding properties to the migrated dmps

This commit is contained in:
Thomas Georgios Giannos 2023-11-21 17:33:54 +02:00
parent 08ea46f79b
commit dc381c197d
1 changed files with 39 additions and 11 deletions

View File

@ -1,15 +1,20 @@
package eu.old.eudat.publicapi.migration; 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.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.DmpEntity;
import eu.eudat.data.ReferenceEntity; import eu.eudat.data.ReferenceEntity;
import eu.old.eudat.data.dao.criteria.DataManagementPlanCriteria; import eu.eudat.model.persist.dmpproperties.DmpBlueprintValuePersist;
import eu.old.eudat.data.dao.criteria.OrganisationCriteria; import eu.eudat.model.persist.dmpproperties.DmpPropertiesPersist;
import eu.old.eudat.data.dao.entities.DMPDao;
import eu.old.eudat.data.entities.DMP; import eu.old.eudat.data.entities.DMP;
import eu.old.eudat.data.entities.Organisation; import eu.old.eudat.data.entities.Organisation;
import eu.old.eudat.logic.services.operations.DatabaseRepository; import eu.old.eudat.logic.services.operations.DatabaseRepository;
import eu.old.eudat.models.data.dmp.DataManagementPlan; import eu.old.eudat.models.data.dmp.DataManagementPlan;
import eu.old.eudat.models.data.dynamicfields.DynamicFieldWithValue;
import eu.old.eudat.queryable.QueryableList; import eu.old.eudat.queryable.QueryableList;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManager;
@ -17,6 +22,7 @@ import jakarta.persistence.PersistenceContext;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -29,11 +35,14 @@ public class MigrationController {
private final DatabaseRepository databaseRepository; private final DatabaseRepository databaseRepository;
private final JsonHandlingService jsonHandlingService;
@PersistenceContext @PersistenceContext
private final EntityManager entityManager; private final EntityManager entityManager;
public MigrationController(DatabaseRepository databaseRepository, EntityManager entityManager) { public MigrationController(DatabaseRepository databaseRepository, JsonHandlingService jsonHandlingService, EntityManager entityManager) {
this.databaseRepository = databaseRepository; this.databaseRepository = databaseRepository;
this.jsonHandlingService = jsonHandlingService;
this.entityManager = entityManager; this.entityManager = entityManager;
} }
@ -66,18 +75,21 @@ public class MigrationController {
} }
@GetMapping("dmps/collectInfo") @GetMapping("dmps/collectInfo")
public List<DmpMigrationCollectedInfo> collectDmpsInfo() { public List<DmpMigrationCollectedInfo> collectDmpsInfo() throws JsonProcessingException {
List<DmpMigrationCollectedInfo> collectedInfoList = new ArrayList<>(); List<DmpMigrationCollectedInfo> collectedInfoList = new ArrayList<>();
List<DataManagementPlan> dmps = getDmps(0, 4); List<DataManagementPlan> dmps = getDmps(0, 4);
for (DataManagementPlan dataManagementPlan : dmps) { for (DataManagementPlan dataManagementPlan : dmps) {
DmpMigrationCollectedInfo dmpMigrationCollectedInfo = new DmpMigrationCollectedInfo(); DmpMigrationCollectedInfo dmpMigrationCollectedInfo = new DmpMigrationCollectedInfo();
DmpPropertiesEntity dmpProperties = new DmpPropertiesEntity();
dmpProperties.setDmpBlueprintValues(new ArrayList<>());
dmpProperties.setContacts(new ArrayList<>());
//Collect basic dmp information //Collect basic dmp information
DmpEntity dmpEntity = new DmpEntity(); DmpEntity dmpEntity = new DmpEntity();
dmpEntity.setId(UUID.randomUUID()); dmpEntity.setId(UUID.randomUUID());
dmpEntity.setLabel(dataManagementPlan.getLabel()); dmpEntity.setLabel(dataManagementPlan.getLabel());
dmpEntity.setDescription(dataManagementPlan.getDescription()); dmpEntity.setDescription(dataManagementPlan.getDescription());
dmpEntity.setAccessType(dataManagementPlan.getPublic() ? DmpAccessType.Public : DmpAccessType.Restricted);
if (dataManagementPlan.getCreator() != null) if (dataManagementPlan.getCreator() != null)
dmpEntity.setCreatorId(dataManagementPlan.getCreator().getId()); dmpEntity.setCreatorId(dataManagementPlan.getCreator().getId());
dmpEntity.setGroupId(dataManagementPlan.getGroupId()); dmpEntity.setGroupId(dataManagementPlan.getGroupId());
@ -90,20 +102,36 @@ public class MigrationController {
if (dataManagementPlan.getFinalized() != null) if (dataManagementPlan.getFinalized() != null)
dmpEntity.setFinalizedAt(dataManagementPlan.getFinalized().toInstant()); dmpEntity.setFinalizedAt(dataManagementPlan.getFinalized().toInstant());
dmpEntity.setBlueprintId(dataManagementPlan.getProfile().getId()); dmpEntity.setBlueprintId(dataManagementPlan.getProfile().getId());
if (dataManagementPlan.getExtraProperties() != null) {
if (dataManagementPlan.getExtraProperties().containsKey("language") && dataManagementPlan.getExtraProperties().get("language") != null) if (dataManagementPlan.getExtraProperties().containsKey("language") && dataManagementPlan.getExtraProperties().get("language") != null)
dmpEntity.setLanguage((String) dataManagementPlan.getExtraProperties().get("language")); 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) { if (dataManagementPlan.getStatus() == 99) {
dmpEntity.setIsActive(IsActive.Inactive); dmpEntity.setIsActive(IsActive.Inactive);
} else { } else {
dmpEntity.setIsActive(IsActive.Active); dmpEntity.setIsActive(IsActive.Active);
dmpEntity.setStatus(DmpStatus.of((short) dataManagementPlan.getStatus())); dmpEntity.setStatus(DmpStatus.of((short) dataManagementPlan.getStatus()));
} }
dmpEntity.setProperties(jsonHandlingService.toJson(dmpProperties));
dmpMigrationCollectedInfo.dmpEntity = dmpEntity; dmpMigrationCollectedInfo.dmpEntity = dmpEntity;
//Collect dmp Organization info //Collect dmp Organization info
collectedInfoList.add(dmpMigrationCollectedInfo); collectedInfoList.add(dmpMigrationCollectedInfo);
} }
return collectedInfoList; return collectedInfoList;
@ -111,7 +139,7 @@ public class MigrationController {
@GetMapping("dmps/migrate") @GetMapping("dmps/migrate")
@Transactional @Transactional
public String migrate() { public String migrate() throws JsonProcessingException {
for (DmpMigrationCollectedInfo collectedInfo : collectDmpsInfo()) { for (DmpMigrationCollectedInfo collectedInfo : collectDmpsInfo()) {
this.entityManager.persist(collectedInfo.dmpEntity); this.entityManager.persist(collectedInfo.dmpEntity);
} }