From c03594f74aeba76d1b793bb940596c52c27b4f17 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Tue, 28 May 2024 18:39:20 +0300 Subject: [PATCH] migration changes --- ...eXmlCleanInvalidReferenceTypesService.java | 2 +- ...escriptionTemplateXmlMigrationService.java | 10 +-- .../eudat/migration/DmpMigrationService.java | 27 ++++++-- .../migration/MigrationController.java | 61 +++++++++++++++++++ 4 files changed, 89 insertions(+), 11 deletions(-) diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DescriptionTemplateXmlCleanInvalidReferenceTypesService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DescriptionTemplateXmlCleanInvalidReferenceTypesService.java index f51cb3872..f11214ccb 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DescriptionTemplateXmlCleanInvalidReferenceTypesService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DescriptionTemplateXmlCleanInvalidReferenceTypesService.java @@ -155,7 +155,7 @@ public class DescriptionTemplateXmlCleanInvalidReferenceTypesService { data.setId(persist.getId()); data.setOrdinal(persist.getOrdinal()); - data.setSchematics(persist.getSchematics()); + data.setSemantics(persist.getSemantics()); data.setDefaultValue(persist.getDefaultValue()); data.setValidations(persist.getValidations()); data.setIncludeInExport(persist.getIncludeInExport()); diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DescriptionTemplateXmlMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DescriptionTemplateXmlMigrationService.java index 3ba162d43..4f9c5b20f 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DescriptionTemplateXmlMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DescriptionTemplateXmlMigrationService.java @@ -193,7 +193,7 @@ public class DescriptionTemplateXmlMigrationService { data.setId(persist.getId().trim()); data.setOrdinal(persist.getOrdinal()); - data.setSchematics(persist.getSchematics()); + data.setSemantics(persist.getSchematics()); if (persist.getValidations() != null) data.setValidations(persist.getValidations().stream().map(x-> { switch (x){ case NONE -> { @@ -218,11 +218,11 @@ public class DescriptionTemplateXmlMigrationService { type = FieldDataExternalDatasetType.of(((ExternalDatasetsData)persist.getData()).getType()); } catch (Exception e) { type = FieldDataExternalDatasetType.Other; } if (type == null) type = FieldDataExternalDatasetType.Other; - if (data.getSchematics() == null) data.setSchematics(new ArrayList<>()); + if (data.getSemantics() == null) data.setSemantics(new ArrayList<>()); switch (type){ - case Other -> data.getSchematics().add("referencetype.externaldataset.type.other"); - case ProducedDataset -> data.getSchematics().add("referencetype.externaldataset.type.produced"); - case ReusedDataset -> data.getSchematics().add("referencetype.externaldataset.type.reused"); + case Other -> data.getSemantics().add("referencetype.externaldataset.type.other"); + case ProducedDataset -> data.getSemantics().add("referencetype.externaldataset.type.produced"); + case ReusedDataset -> data.getSemantics().add("referencetype.externaldataset.type.reused"); default -> throw new MyApplicationException("Invalid type " + type); } } 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 1601bc0f2..159a96d4a 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 @@ -1,6 +1,7 @@ package eu.old.eudat.migration; import com.fasterxml.jackson.core.JsonProcessingException; +import eu.old.eudat.data.dao.entities.UserInfoDao; import org.opencdmp.commonmodels.models.dmp.DmpModel; import org.opencdmp.commonmodels.models.dmpblueprint.SectionModel; import org.opencdmp.commons.JsonHandlingService; @@ -67,6 +68,7 @@ public class DmpMigrationService { } public void migrate() throws IOException, NoSuchFieldException, IllegalAccessException, JAXBException, ParserConfigurationException, InstantiationException, SAXException { + UserInfoDao userInfoDao = databaseRepository.getUserInfoDao(); DMPDao dmpDao = databaseRepository.getDmpDao(); long total = dmpDao.asQueryable().count(); logger.debug("Migrate Dmp Total : " + total); @@ -83,7 +85,8 @@ public class DmpMigrationService { if (!groupDmpMap.containsKey(dmp.getGroupId())) groupDmpMap.put(dmp.getGroupId(), new ArrayList<>()); groupDmpMap.get(dmp.getGroupId()).add(dmp); } - + Map oldUsers = userInfoDao.asQueryable().toList().stream().collect(Collectors.toMap(UserInfo::getId, x-> x)); + if (items != null && !items.isEmpty()) { logger.debug("Migrate Dmp " + page * PageSize + " of " + total); @@ -153,9 +156,23 @@ public class DmpMigrationService { if (model.getExtraProperties().containsKey("visible") && model.getExtraProperties().get("visible") != null) data.setAccessType((boolean) model.getExtraProperties().get("visible") ? DmpAccessType.Public : DmpAccessType.Restricted); if (model.getExtraProperties().containsKey("contact") && model.getExtraProperties().get("contact") != null) { - DmpContactEntity contactEntity = new DmpContactEntity(); - contactEntity.setUserId(UUID.fromString((String)model.getExtraProperties().get("contact"))); - dmpProperties.getContacts().add(contactEntity); + UserInfo userInfo = oldUsers.getOrDefault(UUID.fromString((String)model.getExtraProperties().get("contact")), null); + if (userInfo != null) { + DmpContactEntity contactEntity = new DmpContactEntity(); + contactEntity.setEmail(userInfo.getEmail()); + contactEntity.setFirstName(userInfo.getName()); + dmpProperties.getContacts().add(contactEntity); + } else { + throw new MyApplicationException("Contact not found " + UUID.fromString((String)model.getExtraProperties().get("contact")) + " Dmp " + item.getId()); + } + + } + if (model.getExtraProperties().containsKey("costs") && model.getExtraProperties().get("costs") != null) { + //if (!((String)model.getExtraProperties().get("costs")).equals("[]")) throw new MyApplicationException("ExtraProperties Cost value found. Migration not implemented"); + if (!((ArrayList)model.getExtraProperties().get("costs")).isEmpty()) throw new MyApplicationException("ExtraProperties Cost value found. Migration not implemented"); + } + if (model.getExtraProperties().containsKey("ethicalIssues") && model.getExtraProperties().get("ethicalIssues") != null) { + throw new MyApplicationException("ExtraProperties ethicalIssues value found. Migration not implemented"); } } if (model.getProperties() != null) { @@ -163,7 +180,7 @@ public class DmpMigrationService { DmpBlueprintValueEntity valueEntity = new DmpBlueprintValueEntity(); valueEntity.setFieldId(UUID.fromString(key)); org.opencdmp.commons.types.dmpblueprint.FieldEntity fieldEntity = this.getFieldOfId(definitionEntity, valueEntity.getFieldId()); - if (fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.Extra)){ + if (fieldEntity != null && fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.Extra)){ ExtraFieldEntity extraFieldEntity = (ExtraFieldEntity) fieldEntity; switch (extraFieldEntity.getType()){ case Date -> valueEntity.setDateValue(Instant.parse((String) val)); 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 6eeb6991f..a67f48cf6 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 @@ -2,8 +2,10 @@ package eu.old.eudat.publicapi.migration; import com.fasterxml.jackson.core.JsonProcessingException; import eu.old.eudat.migration.*; +import gr.cite.tools.logging.LoggerService; import io.swagger.annotations.Api; import jakarta.xml.bind.JAXBException; +import org.slf4j.LoggerFactory; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; @@ -23,6 +25,7 @@ import java.net.URISyntaxException; @RequestMapping(value = {"/api/public/migration"}) public class MigrationController { + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(MigrationController.class)); private final DmpMigrationService dmpMigrationService; private final DataRepositoryMigrationService dataRepositoryMigrationService; private final ExternalDatasetMigrationService externalDatasetMigrationService; @@ -121,10 +124,68 @@ public class MigrationController { // this.storageFileMigrationService.migrate(); + logger.info("Completed!!!"); + // throw new RuntimeException(""); return true; } + @GetMapping("step_1") + @Transactional + public boolean step1() throws IOException, JAXBException, ParserConfigurationException, InstantiationException, IllegalAccessException, SAXException, NoSuchFieldException, InvalidApplicationException, TransformerException, URISyntaxException { + //Reference + this.dataRepositoryMigrationService.migrate(); + this.externalDatasetMigrationService.migrate(); + this.funderMigrationService.migrate(); + this.grantMigrationService.migrate(); + this.organizationMigrationService.migrate(); + this.projectMigrationService.migrate(); + this.registryMigrationService.migrate(); + this.researcherMigrationService.migrate(); + this.serviceMigrationService.migrate(); + + //User + this.userContactInfoMigrationService.migrate(); + this.userMigrationService.migrate(); + + //XML recreate + this.dmpBlueprintXmlMigrationService.migrate(); + this.descriptionTemplateXmlMigrationService.migrate(); + + logger.info("Completed!!!"); + + return true; + } + + @GetMapping("step_2") + @Transactional + public boolean step2() throws IOException, JAXBException, ParserConfigurationException, InstantiationException, IllegalAccessException, SAXException, NoSuchFieldException, InvalidApplicationException, TransformerException, URISyntaxException { + //Dmp + this.dmpMigrationService.migrate(); + this.dmpDatasetProfileMigrationService.migrate(); + this.dmpUserMigrationService.migrate(); + + logger.info("Completed!!!"); + + return true; + } + + @GetMapping("step_3") + @Transactional + public boolean step3() throws IOException, JAXBException, ParserConfigurationException, InstantiationException, IllegalAccessException, SAXException, NoSuchFieldException, InvalidApplicationException, TransformerException, URISyntaxException { + //Description + this.datasetMigrationService.migrate(); + this.datasetReferenceMigrationService.migrateDatasetReferences(); + this.tagMigrationService.migrate(); + + this.storageFileMigrationService.migrate(); + + logger.info("Completed!!!"); + + return true; + } + + @GetMapping("dmp-blueprints-xml") @Transactional public boolean migrateDmpBlueprint() throws JAXBException, InvalidApplicationException, IOException, ParserConfigurationException, NoSuchFieldException, TransformerException, IllegalAccessException, InstantiationException, SAXException {