diff --git a/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/entities/DMPProfile.java b/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/entities/DMPProfile.java index d8ccbdb4b..17165af0b 100644 --- a/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/entities/DMPProfile.java +++ b/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/entities/DMPProfile.java @@ -14,7 +14,7 @@ import java.util.UUID; @Entity -@Table(name = "\"DmpBlueprint\"") +@Table(name = "\"PlanBlueprint\"") public class DMPProfile implements DataEntity { public enum Status { 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 index 172310e31..c7473824c 100644 --- 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 @@ -1,7 +1,6 @@ package eu.old.eudat.migration; import eu.old.eudat.data.entities.DMP; -import eu.old.eudat.elastic.entities.Tag; import org.opencdmp.commons.JsonHandlingService; import org.opencdmp.commons.XmlHandlingService; import org.opencdmp.commons.enums.*; @@ -9,12 +8,12 @@ import org.opencdmp.commons.types.description.*; import org.opencdmp.commons.types.descriptionreference.DescriptionReferenceDataEntity; import org.opencdmp.commons.types.descriptiontemplate.FieldSetEntity; import org.opencdmp.commons.types.descriptiontemplate.fielddata.ReferenceTypeDataEntity; -import org.opencdmp.commons.types.dmpblueprint.DefinitionEntity; +import org.opencdmp.commons.types.planblueprint.DefinitionEntity; import org.opencdmp.commons.types.externalfetcher.ExternalFetcherApiSourceConfigurationEntity; import org.opencdmp.commons.types.referencetype.ReferenceTypeDefinitionEntity; import org.opencdmp.convention.ConventionService; import org.opencdmp.data.*; -import org.opencdmp.model.dmp.Dmp; +import org.opencdmp.model.plan.Plan; import org.opencdmp.model.reference.Reference; import org.opencdmp.model.referencetype.ReferenceType; import org.opencdmp.query.*; @@ -48,7 +47,7 @@ import java.util.stream.Stream; @Service public class DatasetMigrationService { - private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpDatasetProfileMigrationService.class)); + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DatasetMigrationService.class)); private final DatabaseRepository databaseRepository; private final JsonHandlingService jsonHandlingService; private final QueryFactory queryFactory; @@ -96,11 +95,11 @@ public class DatasetMigrationService { if (items != null && !items.isEmpty()) { logger.debug("Migrate Dataset " + page * PageSize + " of " + total); - List dmpBlueprints = this.queryFactory.query(DmpBlueprintQuery.class).ids(items.stream().map(x-> x.getDmp().getProfile().getId()).distinct().toList()).collect(); - Map dmpBlueprintsMap = new HashMap<>(); - for (DmpBlueprintEntity dmpBlueprint : dmpBlueprints) { - DefinitionEntity definitionEntity = this.xmlHandlingService.fromXml(DefinitionEntity.class, dmpBlueprint.getDefinition()); - dmpBlueprintsMap.put(dmpBlueprint.getId(), definitionEntity); + List planBlueprints = this.queryFactory.query(PlanBlueprintQuery.class).ids(items.stream().map(x-> x.getDmp().getProfile().getId()).distinct().toList()).collect(); + Map planBlueprintsMap = new HashMap<>(); + for (PlanBlueprintEntity planBlueprint : planBlueprints) { + DefinitionEntity definitionEntity = this.xmlHandlingService.fromXml(DefinitionEntity.class, planBlueprint.getDefinition()); + planBlueprintsMap.put(planBlueprint.getId(), definitionEntity); } List changeTemplateToH2020 = Stream.of("0c82f2ce-5ff7-4ca9-a500-9f3062adf550", "7acd3b36-e598-459c-8170-87c51ac80efb", @@ -118,8 +117,8 @@ public class DatasetMigrationService { UUID horizon2020UUID = UUID.fromString("6ddde24b-e7a0-477f-a2cd-0a8fad915dc8"); UUID horizonGroupId = UUID.fromString("3689bcce-405a-4d55-9854-669597b79c0a"); - List dmpDescriptionTemplateEntities = this.queryFactory.query(DmpDescriptionTemplateQuery.class).dmpIds(items.stream().map(x-> x.getDmp().getId()).distinct().toList()).collect(); - Map creatorsByDmp = this.queryFactory.query(DmpQuery.class).ids(items.stream().map(x-> x.getDmp().getId()).distinct().toList()).collectAs(new BaseFieldSet().ensure(Dmp._id).ensure(Dmp._creator)).stream().collect(Collectors.toMap(DmpEntity::getId, DmpEntity::getCreatorId)); + List planDescriptionTemplateEntities = this.queryFactory.query(PlanDescriptionTemplateQuery.class).planIds(items.stream().map(x-> x.getDmp().getId()).distinct().toList()).collect(); + Map creatorsByPlan = this.queryFactory.query(PlanQuery.class).ids(items.stream().map(x-> x.getDmp().getId()).distinct().toList()).collectAs(new BaseFieldSet().ensure(Plan._id).ensure(Plan._creator)).stream().collect(Collectors.toMap(PlanEntity::getId, PlanEntity::getCreatorId)); List profileIds = new ArrayList<>(items.stream().map(x -> x.getProfile().getId()).distinct().toList()); profileIds.add(horizon2020UUID); @@ -137,7 +136,7 @@ public class DatasetMigrationService { profileGroupId = horizonGroupId; } - DefinitionEntity definition = dmpBlueprintsMap.getOrDefault(item.getDmp().getProfile().getId(), null); + DefinitionEntity definition = planBlueprintsMap.getOrDefault(item.getDmp().getProfile().getId(), null); if (definition == null || definition.getSections() == null || definition.getSections().size() <= item.getDmpSectionIndex()) { throw new MyApplicationException("Migrate Dataset " + item.getId() + " cannot found section id for section " + item.getDmpSectionIndex()); @@ -147,10 +146,10 @@ public class DatasetMigrationService { throw new MyApplicationException("Migrate Dataset " + item.getId() + " cannot found section id for section " + item.getDmpSectionIndex()); } - List itemDescriptionTemplates = this.getOrCreateDmpDescriptionTemplateEntity(item, sectionId, profileGroupId, dmpDescriptionTemplateEntities); + List itemDescriptionTemplates = this.getOrCreatePlanDescriptionTemplateEntity(item, sectionId, profileGroupId, planDescriptionTemplateEntities); if (itemDescriptionTemplates.size() > 1) { - throw new MyApplicationException("Migrate Dataset " + item.getId() + " multiple DmpDescriptionTemplateEntity for section " + item.getDmpSectionIndex()); + throw new MyApplicationException("Migrate Dataset " + item.getId() + " multiple PlanDescriptionTemplateEntity for section " + item.getDmpSectionIndex()); } DescriptionEntity data = new DescriptionEntity(); @@ -159,11 +158,11 @@ public class DatasetMigrationService { if (item.getCreator() != null) { data.setCreatedById(item.getCreator().getId()); } else { - data.setCreatedById(creatorsByDmp.getOrDefault(item.getDmp().getId(), null)); + data.setCreatedById(creatorsByPlan.getOrDefault(item.getDmp().getId(), null)); } - data.setDmpId(item.getDmp().getId()); + data.setPlanId(item.getDmp().getId()); data.setLabel(item.getLabel()); - data.setDmpDescriptionTemplateId(itemDescriptionTemplates.getFirst().getId()); + data.setPlanDescriptionTemplateId(itemDescriptionTemplates.getFirst().getId()); data.setDescriptionTemplateId(profileId); data.setCreatedAt(item.getCreated() != null ? item.getCreated().toInstant() : Instant.now()); data.setUpdatedAt(item.getModified() != null ? item.getModified().toInstant() : Instant.now()); @@ -196,16 +195,16 @@ public class DatasetMigrationService { } while (items != null && !items.isEmpty() && !TestMode); } - private List getOrCreateDmpDescriptionTemplateEntity(Dataset item, UUID sectionId, UUID groupId, List dmpDescriptionTemplateEntities){ - List itemDescriptionTemplates = dmpDescriptionTemplateEntities.stream().filter(x-> x.getDescriptionTemplateGroupId().equals(groupId) && x.getDmpId().equals(item.getDmp().getId()) && x.getSectionId().equals(sectionId)).toList(); + private List getOrCreatePlanDescriptionTemplateEntity(Dataset item, UUID sectionId, UUID groupId, List dmpDescriptionTemplateEntities){ + List itemDescriptionTemplates = dmpDescriptionTemplateEntities.stream().filter(x-> x.getDescriptionTemplateGroupId().equals(groupId) && x.getPlanId().equals(item.getDmp().getId()) && x.getSectionId().equals(sectionId)).toList(); if (itemDescriptionTemplates.isEmpty()) { boolean isDeleted = item.getStatus().equals(Dataset.Status.CANCELED.getValue()) ||item.getStatus().equals(Dataset.Status.DELETED.getValue()) || item.getDmp().getStatus().equals(DMP.DMPStatus.DELETED.getValue()); - if (!isDeleted) logger.warn("Migrate Dataset " + item.getId() + " cannot found DmpDescriptionTemplateEntity for section " + item.getDmpSectionIndex()); - if (dmpDescriptionTemplateEntities.stream().anyMatch(x -> x.getDmpId().equals(item.getDmp().getId()) && x.getSectionId().equals(sectionId))) { - DmpDescriptionTemplateEntity dmpDescriptionTemplateEntity = new DmpDescriptionTemplateEntity(); + if (!isDeleted) logger.warn("Migrate Dataset " + item.getId() + " cannot found PlanDescriptionTemplateEntity for section " + item.getDmpSectionIndex()); + if (dmpDescriptionTemplateEntities.stream().anyMatch(x -> x.getPlanId().equals(item.getDmp().getId()) && x.getSectionId().equals(sectionId))) { + PlanDescriptionTemplateEntity dmpDescriptionTemplateEntity = new PlanDescriptionTemplateEntity(); dmpDescriptionTemplateEntity.setId(UUID.randomUUID()); dmpDescriptionTemplateEntity.setDescriptionTemplateGroupId(groupId); - dmpDescriptionTemplateEntity.setDmpId(item.getDmp().getId()); + dmpDescriptionTemplateEntity.setPlanId(item.getDmp().getId()); dmpDescriptionTemplateEntity.setCreatedAt(item.getCreated() != null ? item.getCreated().toInstant() : Instant.now()); dmpDescriptionTemplateEntity.setUpdatedAt(item.getModified() != null ? item.getModified().toInstant() : Instant.now()); dmpDescriptionTemplateEntity.setSectionId(sectionId); @@ -214,7 +213,7 @@ public class DatasetMigrationService { this.entityManager.flush(); itemDescriptionTemplates = List.of(dmpDescriptionTemplateEntity); } else { - throw new MyApplicationException("Migrate Dataset " + item.getId() + " " + item.getLabel() + " cannot found DmpDescriptionTemplateEntity for section " + item.getDmpSectionIndex()); + throw new MyApplicationException("Migrate Dataset " + item.getId() + " " + item.getLabel() + " cannot found PlanDescriptionTemplateEntity for section " + item.getDmpSectionIndex()); } } return itemDescriptionTemplates; @@ -327,10 +326,10 @@ public class DatasetMigrationService { keyParts = newKey.split("_"); } } - String fieldSetId = ""; - String groupId = ""; + String fieldSetId; + String groupId; int ordinal = Integer.MIN_VALUE; - String fieldId = ""; + String fieldId; if (keyParts.length == 4) { fieldSetId = keyParts[0].trim(); @@ -405,7 +404,7 @@ public class DatasetMigrationService { propertyDefinitionEntity.getFieldSets().put(currentFieldSet.getId().trim(), propertyDefinitionFieldSetEntity); } - PropertyDefinitionFieldSetItemEntity propertyDefinitionFieldSetItemEntity = null; + PropertyDefinitionFieldSetItemEntity propertyDefinitionFieldSetItemEntity; if (this.conventionService.isListNullOrEmpty(propertyDefinitionFieldSetEntity.getItems())){ propertyDefinitionFieldSetItemEntity = new PropertyDefinitionFieldSetItemEntity(); propertyDefinitionFieldSetItemEntity.setFields(new HashMap<>()); @@ -427,7 +426,7 @@ public class DatasetMigrationService { propertyDefinitionEntity.getFieldSets().put(currentFieldSet.getId().trim(), propertyDefinitionFieldSetEntity); } - PropertyDefinitionFieldSetItemEntity propertyDefinitionFieldSetItemEntity = null; + PropertyDefinitionFieldSetItemEntity propertyDefinitionFieldSetItemEntity; if (this.conventionService.isListNullOrEmpty(propertyDefinitionFieldSetEntity.getItems())){ propertyDefinitionFieldSetItemEntity = new PropertyDefinitionFieldSetItemEntity(); propertyDefinitionFieldSetItemEntity.setFields(new HashMap<>()); @@ -509,7 +508,7 @@ public class DatasetMigrationService { } } - case INTERNAL_ENTRIES_DMPS -> throw new MyApplicationException("Found INTERNAL_ENTRIES_DMPS into description"); + case INTERNAL_ENTRIES_PLANS -> throw new MyApplicationException("Found INTERNAL_ENTRIES_DMPS into description"); case INTERNAL_ENTRIES_DESCRIPTIONS -> throw new MyApplicationException("Found INTERNAL_ENTRIES_DMPS into description"); case VALIDATION -> throw new MyApplicationException("Found VALIDATION into description"); case REFERENCE_TYPES -> { @@ -603,7 +602,7 @@ public class DatasetMigrationService { if (this.conventionService.isListNullOrEmpty(referenceTypeDefinition.getSources())) throw new MyApplicationException("Could not find reference source for reference : " + this.jsonHandlingService.toJsonSafe(textValue)); //if (referenceTypeDefinition.getSources().size() > 1) throw new MyApplicationException("Multiple reference source for reference : " + this.jsonHandlingService.toJsonSafe(textValue)); String source = referenceTypeDefinition.getSources().getFirst().getKey(); - String[] parts = null; + String[] parts; if (textValue.startsWith("[\"")){ parts = migrationTools.tryParseJsonAsObjectString(String[].class, textValue); } else{ @@ -623,7 +622,7 @@ public class DatasetMigrationService { items.add(ref); } if (items.isEmpty()) break; - references = items.toArray(new Map[items.size()]); + references = items.toArray(new Map[0]); } } } @@ -686,7 +685,7 @@ public class DatasetMigrationService { items.add(ref); } if (items.isEmpty()) break; - references = items.toArray(new Map[items.size()]); + references = items.toArray(new Map[0]); } } if (references == null && (ReferenceTypeIds.Datasets.equals(referenceTypeDataEntity.getReferenceTypeId()) @@ -697,7 +696,7 @@ public class DatasetMigrationService { if (textValue.equals("[\".\"]")){ break; } else if (!textValue.contains("{")) { - String[] parts = null; + String[] parts; if (textValue.startsWith("[\"")){ parts = migrationTools.tryParseJsonAsObjectString(String[].class, textValue); } else{ @@ -719,7 +718,7 @@ public class DatasetMigrationService { items.add(ref); } if (items.isEmpty()) break; - references = items.toArray(new Map[items.size()]); + references = items.toArray(new Map[0]); } } } diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DatasetReferenceMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DatasetReferenceMigrationService.java index a79208988..2be33ac70 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DatasetReferenceMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DatasetReferenceMigrationService.java @@ -17,7 +17,7 @@ import java.util.UUID; @Service public class DatasetReferenceMigrationService { - private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpDatasetProfileMigrationService.class)); + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DatasetReferenceMigrationService.class)); private final DatabaseRepository databaseRepository; private static final int PageSize = 500; private final EntityManager entityManager; 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 f2bbb9c62..13f390b6b 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 @@ -304,7 +304,7 @@ public class DescriptionTemplateXmlMigrationService { if (renderStyle.equals("internalDmpEntities")){ switch (((InternalDmpEntitiesData)persist).getType()){ case "dmps": - return this.buildLabelAndMultiplicityDataEntity(persist.getLabel(), ((DMPsAutoCompleteData)persist).getMultiAutoComplete(),FieldType.INTERNAL_ENTRIES_DMPS); + return this.buildLabelAndMultiplicityDataEntity(persist.getLabel(), ((DMPsAutoCompleteData)persist).getMultiAutoComplete(),FieldType.INTERNAL_ENTRIES_PLANS); case "datasets": return this.buildLabelAndMultiplicityDataEntity(persist.getLabel(), ((DatasetsAutoCompleteData)persist).getMultiAutoComplete(),FieldType.INTERNAL_ENTRIES_DESCRIPTIONS); case "researchers": @@ -439,7 +439,7 @@ public class DescriptionTemplateXmlMigrationService { case UPLOAD -> throw new NotSupportedException("Upload validator not supported"); case TAGS -> throw new NotSupportedException("Tags validator not supported"); - case INTERNAL_ENTRIES_DMPS -> throw new NotSupportedException("INTERNAL_ENTRIES_DMPS validator not supported for description template " + descriptionTemplateId); + case INTERNAL_ENTRIES_PLANS -> throw new NotSupportedException("INTERNAL_ENTRIES_PLANS validator not supported for description template " + descriptionTemplateId); case INTERNAL_ENTRIES_DESCRIPTIONS -> throw new NotSupportedException("INTERNAL_ENTRIES_DESCRIPTIONS validator not supported for description template " + descriptionTemplateId); case REFERENCE_TYPES -> throw new NotSupportedException("REFERENCE_TYPES validator not supported for description template " + descriptionTemplateId); default -> throw new MyApplicationException("unrecognized type " + fieldType); @@ -493,7 +493,7 @@ public class DescriptionTemplateXmlMigrationService { case UPLOAD -> throw new NotSupportedException("Upload validator not supported"); case TAGS -> throw new NotSupportedException("Tags validator not supported"); - case INTERNAL_ENTRIES_DMPS -> throw new NotSupportedException("INTERNAL_ENTRIES_DMPS validator not supported"); + case INTERNAL_ENTRIES_PLANS -> throw new NotSupportedException("INTERNAL_ENTRIES_PLANS validator not supported"); case INTERNAL_ENTRIES_DESCRIPTIONS -> throw new NotSupportedException("INTERNAL_ENTRIES_DESCRIPTIONS validator not supported"); case REFERENCE_TYPES -> throw new NotSupportedException("REFERENCE_TYPES validator not supported"); default -> throw new MyApplicationException("unrecognized type " + fieldType); diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/FunderMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/FunderMigrationService.java index 4f538f9b7..5173ab480 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/FunderMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/FunderMigrationService.java @@ -1,10 +1,7 @@ package eu.old.eudat.migration; import org.opencdmp.commons.enums.IsActive; -import org.opencdmp.commons.enums.ReferenceFieldDataType; import org.opencdmp.commons.enums.ReferenceSourceType; -import org.opencdmp.commons.types.reference.DefinitionEntity; -import org.opencdmp.commons.types.reference.FieldEntity; import org.opencdmp.data.ReferenceEntity; import eu.old.eudat.data.dao.entities.FunderDao; import eu.old.eudat.data.entities.Funder; @@ -14,7 +11,6 @@ import jakarta.persistence.EntityManager; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; -import java.util.ArrayList; import java.util.List; import java.util.Locale; diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpBlueprintXmlMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/PlanBlueprintXmlMigrationService.java similarity index 73% rename from dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpBlueprintXmlMigrationService.java rename to dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/PlanBlueprintXmlMigrationService.java index f59b1c224..e157593af 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpBlueprintXmlMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/PlanBlueprintXmlMigrationService.java @@ -1,16 +1,16 @@ package eu.old.eudat.migration; import org.opencdmp.commons.XmlHandlingService; -import org.opencdmp.commons.enums.DmpBlueprintExtraFieldDataType; -import org.opencdmp.commons.enums.DmpBlueprintFieldCategory; -import org.opencdmp.commons.enums.DmpBlueprintSystemFieldType; -import org.opencdmp.commons.types.dmpblueprint.*; +import org.opencdmp.commons.enums.PlanBlueprintExtraFieldDataType; +import org.opencdmp.commons.enums.PlanBlueprintFieldCategory; +import org.opencdmp.commons.enums.PlanBlueprintSystemFieldType; +import org.opencdmp.commons.types.planblueprint.*; import org.opencdmp.convention.ConventionService; import org.opencdmp.data.DescriptionTemplateEntity; -import org.opencdmp.data.DmpBlueprintEntity; -import org.opencdmp.model.dmpblueprint.DmpBlueprint; +import org.opencdmp.data.PlanBlueprintEntity; +import org.opencdmp.model.planblueprint.PlanBlueprint; import org.opencdmp.query.DescriptionTemplateQuery; -import org.opencdmp.query.DmpBlueprintQuery; +import org.opencdmp.query.PlanBlueprintQuery; import eu.old.eudat.logic.utilities.builders.XmlBuilder; import eu.old.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.*; import eu.old.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.types.FieldCategory; @@ -36,9 +36,9 @@ import java.io.IOException; import java.util.*; @Service -public class DmpBlueprintXmlMigrationService { +public class PlanBlueprintXmlMigrationService { - private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpBlueprintXmlMigrationService.class)); + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(PlanBlueprintXmlMigrationService.class)); private final EntityManager entityManager; private final ConventionService conventionService; private final XmlHandlingService xmlHandlingService; @@ -47,7 +47,7 @@ public class DmpBlueprintXmlMigrationService { private static final int PageSize = 500; private static final boolean TestMode = false; - public DmpBlueprintXmlMigrationService(EntityManager entityManager, ConventionService conventionService, XmlHandlingService xmlHandlingService, QueryFactory queryFactory) { + public PlanBlueprintXmlMigrationService(EntityManager entityManager, ConventionService conventionService, XmlHandlingService xmlHandlingService, QueryFactory queryFactory) { this.entityManager = entityManager; this.conventionService = conventionService; this.xmlHandlingService = xmlHandlingService; @@ -55,31 +55,31 @@ public class DmpBlueprintXmlMigrationService { } public void migrate() throws IOException, NoSuchFieldException, IllegalAccessException, JAXBException, ParserConfigurationException, InstantiationException, SAXException, InvalidApplicationException, TransformerException { - long total = this.queryFactory.query(DmpBlueprintQuery.class).count(); - logger.debug("Migrate DmpBlueprint Total : " + total); + long total = this.queryFactory.query(PlanBlueprintQuery.class).count(); + logger.debug("Migrate PlanBlueprint Total : " + total); int page = 0; - List items; + List items; List descriptionTemplateEntities = this.queryFactory.query(DescriptionTemplateQuery.class).collectAs(new BaseFieldSet().ensure(org.opencdmp.model.descriptiontemplate.DescriptionTemplate._id).ensure(org.opencdmp.model.descriptiontemplate.DescriptionTemplate._groupId)); Map descriptionTemplateGroupMap = new HashMap<>(); for (DescriptionTemplateEntity descriptionTemplateEntity: descriptionTemplateEntities) { descriptionTemplateGroupMap.put(descriptionTemplateEntity.getId(), descriptionTemplateEntity.getGroupId()); } do { - DmpBlueprintQuery query = this.queryFactory.query(DmpBlueprintQuery.class); - query.setOrder(new Ordering().addDescending(DmpBlueprint._createdAt)); + PlanBlueprintQuery query = this.queryFactory.query(PlanBlueprintQuery.class); + query.setOrder(new Ordering().addDescending(PlanBlueprint._createdAt)); query.setPage(new Paging(page * PageSize, PageSize)); items = query.collect(); if (items != null && !items.isEmpty()) { - logger.debug("Migrate DmpBlueprint " + page * PageSize + " of " + total); + logger.debug("Migrate PlanBlueprint " + page * PageSize + " of " + total); - for (DmpBlueprintEntity item : items) { + for (PlanBlueprintEntity item : items) { if (this.conventionService.isNullOrEmpty(item.getDefinition())) continue; Document document = XmlBuilder.fromXml(item.getDefinition()); if (document == null){ - logger.error("Migrate DmpBlueprint " + item.getId() + " failed read xml"); + logger.error("Migrate PlanBlueprint " + item.getId() + " failed read xml"); continue; } @@ -94,8 +94,8 @@ public class DmpBlueprintXmlMigrationService { } while (items != null && !items.isEmpty() && !TestMode); } - private @NotNull org.opencdmp.commons.types.dmpblueprint.DefinitionEntity buildDefinitionEntity(DataManagementPlanBlueprint dataManagementPlanBlueprint, Map descriptionTemplateGroupMap ) { - org.opencdmp.commons.types.dmpblueprint.DefinitionEntity data = new DefinitionEntity(); + private @NotNull org.opencdmp.commons.types.planblueprint.DefinitionEntity buildDefinitionEntity(DataManagementPlanBlueprint dataManagementPlanBlueprint, Map descriptionTemplateGroupMap ) { + org.opencdmp.commons.types.planblueprint.DefinitionEntity data = new DefinitionEntity(); if (dataManagementPlanBlueprint == null) return data; if (!this.conventionService.isListNullOrEmpty(dataManagementPlanBlueprint.getSections())) { @@ -135,13 +135,13 @@ public class DmpBlueprintXmlMigrationService { return data; } - private @NotNull org.opencdmp.commons.types.dmpblueprint.DescriptionTemplateEntity buildDescriptionTemplateEntity(DescriptionTemplate itm, Map descriptionTemplateGroupMap ) { - org.opencdmp.commons.types.dmpblueprint.DescriptionTemplateEntity data = new org.opencdmp.commons.types.dmpblueprint.DescriptionTemplateEntity(); + private @NotNull org.opencdmp.commons.types.planblueprint.DescriptionTemplateEntity buildDescriptionTemplateEntity(DescriptionTemplate itm, Map descriptionTemplateGroupMap ) { + org.opencdmp.commons.types.planblueprint.DescriptionTemplateEntity data = new org.opencdmp.commons.types.planblueprint.DescriptionTemplateEntity(); if (itm == null) return data; UUID groupId = descriptionTemplateGroupMap.getOrDefault(itm.getDescriptionTemplateId(), null); if (groupId == null){ - logger.error("Migrate DmpBlueprint, DescriptionTemplate " + itm.getDescriptionTemplateId() + " group not found"); + logger.error("Migrate PlanBlueprint, DescriptionTemplate " + itm.getDescriptionTemplateId() + " group not found"); data.setDescriptionTemplateGroupId(itm.getDescriptionTemplateId()); } else { data.setDescriptionTemplateGroupId(groupId); @@ -154,7 +154,7 @@ public class DmpBlueprintXmlMigrationService { } - private @NotNull org.opencdmp.commons.types.dmpblueprint.FieldEntity buildFieldEntity(FieldModel itm) { + private @NotNull org.opencdmp.commons.types.planblueprint.FieldEntity buildFieldEntity(FieldModel itm) { if (itm == null) return new ExtraFieldEntity(); FieldEntity data; @@ -163,26 +163,26 @@ public class DmpBlueprintXmlMigrationService { ExtraField extraField = itm.toExtraField(); switch (extraField.getType()){ - case TEXT -> dataTyped.setType(DmpBlueprintExtraFieldDataType.Text); - case DATE -> dataTyped.setType(DmpBlueprintExtraFieldDataType.Date); - case NUMBER -> dataTyped.setType(DmpBlueprintExtraFieldDataType.Number); - case RICH_TEXT -> dataTyped.setType(DmpBlueprintExtraFieldDataType.RichTex); + case TEXT -> dataTyped.setType(PlanBlueprintExtraFieldDataType.Text); + case DATE -> dataTyped.setType(PlanBlueprintExtraFieldDataType.Date); + case NUMBER -> dataTyped.setType(PlanBlueprintExtraFieldDataType.Number); + case RICH_TEXT -> dataTyped.setType(PlanBlueprintExtraFieldDataType.RichTex); default -> throw new MyApplicationException("Type not found " + extraField.getType()); } dataTyped.setRequired(extraField.getRequired()); data = dataTyped; - data.setCategory(DmpBlueprintFieldCategory.Extra); + data.setCategory(PlanBlueprintFieldCategory.Extra); } else { SystemFieldEntity dataTyped = new SystemFieldEntity(); ReferenceTypeFieldEntity referenceTypeFieldEntity = new ReferenceTypeFieldEntity(); SystemField systemField = itm.toSystemField(); switch (systemField.getType()){ - case TEXT -> dataTyped.setType(DmpBlueprintSystemFieldType.Title); - case HTML_TEXT -> dataTyped.setType(DmpBlueprintSystemFieldType.Description); - case ACCESS_RIGHTS -> dataTyped.setType(DmpBlueprintSystemFieldType.AccessRights); - case CONTACT -> dataTyped.setType(DmpBlueprintSystemFieldType.Contact); - case LANGUAGE -> dataTyped.setType(DmpBlueprintSystemFieldType.Language); + case TEXT -> dataTyped.setType(PlanBlueprintSystemFieldType.Title); + case HTML_TEXT -> dataTyped.setType(PlanBlueprintSystemFieldType.Description); + case ACCESS_RIGHTS -> dataTyped.setType(PlanBlueprintSystemFieldType.AccessRights); + case CONTACT -> dataTyped.setType(PlanBlueprintSystemFieldType.Contact); + case LANGUAGE -> dataTyped.setType(PlanBlueprintSystemFieldType.Language); case FUNDER -> { referenceTypeFieldEntity.setReferenceTypeId(ReferenceTypeIds.Funder); referenceTypeFieldEntity.setMultipleSelect(false); @@ -219,11 +219,11 @@ public class DmpBlueprintXmlMigrationService { if (referenceTypeFieldEntity.getReferenceTypeId() == null){ data = dataTyped; - data.setCategory(DmpBlueprintFieldCategory.System); + data.setCategory(PlanBlueprintFieldCategory.System); } else{ data = referenceTypeFieldEntity; - data.setCategory(DmpBlueprintFieldCategory.ReferenceType); + data.setCategory(PlanBlueprintFieldCategory.ReferenceType); } } data.setId(itm.getId()); 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/PlanDatasetProfileMigrationService.java similarity index 66% rename from dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpDatasetProfileMigrationService.java rename to dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/PlanDatasetProfileMigrationService.java index 9dfaa0320..c69fa7c68 100644 --- 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/PlanDatasetProfileMigrationService.java @@ -5,10 +5,10 @@ import eu.old.eudat.data.entities.DMP; import org.opencdmp.commons.JsonHandlingService; import org.opencdmp.commons.XmlHandlingService; import org.opencdmp.commons.enums.IsActive; -import org.opencdmp.data.DmpBlueprintEntity; -import org.opencdmp.data.DmpDescriptionTemplateEntity; -import org.opencdmp.query.DmpBlueprintQuery; -import org.opencdmp.query.DmpDescriptionTemplateQuery; +import org.opencdmp.data.PlanBlueprintEntity; +import org.opencdmp.data.PlanDescriptionTemplateEntity; +import org.opencdmp.query.PlanBlueprintQuery; +import org.opencdmp.query.PlanDescriptionTemplateQuery; import eu.old.eudat.data.dao.entities.DmpDatasetProfileDao; import eu.old.eudat.data.entities.DMPDatasetProfile; import eu.old.eudat.logic.services.operations.DatabaseRepository; @@ -25,18 +25,17 @@ import jakarta.xml.bind.JAXBException; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.xml.sax.SAXException; -import org.opencdmp.commons.types.dmpblueprint.DefinitionEntity; +import org.opencdmp.commons.types.planblueprint.DefinitionEntity; import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; -import java.security.SecureRandom; import java.time.Instant; import java.util.*; @Service -public class DmpDatasetProfileMigrationService { +public class PlanDatasetProfileMigrationService { - private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpDatasetProfileMigrationService.class)); + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(PlanDatasetProfileMigrationService.class)); private final DatabaseRepository databaseRepository; private final JsonHandlingService jsonHandlingService; @@ -46,7 +45,7 @@ public class DmpDatasetProfileMigrationService { private static final boolean TestMode = false; private final EntityManager entityManager; - public DmpDatasetProfileMigrationService(DatabaseRepository databaseRepository, JsonHandlingService jsonHandlingService, QueryFactory queryFactory, XmlHandlingService xmlHandlingService, EntityManager entityManager) { + public PlanDatasetProfileMigrationService(DatabaseRepository databaseRepository, JsonHandlingService jsonHandlingService, QueryFactory queryFactory, XmlHandlingService xmlHandlingService, EntityManager entityManager) { this.databaseRepository = databaseRepository; this.jsonHandlingService = jsonHandlingService; this.queryFactory = queryFactory; @@ -57,18 +56,18 @@ public class DmpDatasetProfileMigrationService { public void migrate() throws IOException, JAXBException, ParserConfigurationException, InstantiationException, IllegalAccessException, SAXException { DmpDatasetProfileDao dmpDatasetProfileDao = databaseRepository.getDmpDatasetProfileDao(); long total = dmpDatasetProfileDao.asQueryable().count(); - logger.debug("Migrate DmpDatasetProfile Total : " + total); + logger.debug("Migrate PlanDatasetProfile Total : " + total); int page = 0; List items; do { items = dmpDatasetProfileDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("ID"))).skip(page * PageSize).take(PageSize).toList(); if (items != null && !items.isEmpty()) { - logger.debug("Migrate DmpDatasetProfile " + page * PageSize + " of " + total); + logger.debug("Migrate PlanDatasetProfile " + page * PageSize + " of " + total); - List dmpBlueprints = this.queryFactory.query(DmpBlueprintQuery.class).ids(items.stream().map(x-> x.getDmp().getProfile().getId()).distinct().toList()).collect(); + List dmpBlueprints = this.queryFactory.query(PlanBlueprintQuery.class).ids(items.stream().map(x-> x.getDmp().getProfile().getId()).distinct().toList()).collect(); Map dmpBlueprintsMap = new HashMap<>(); - for (DmpBlueprintEntity dmpBlueprint : dmpBlueprints) { + for (PlanBlueprintEntity dmpBlueprint : dmpBlueprints) { DefinitionEntity definitionEntity = this.xmlHandlingService.fromXml(DefinitionEntity.class, dmpBlueprint.getDefinition()); dmpBlueprintsMap.put(dmpBlueprint.getId(), definitionEntity); } @@ -76,35 +75,35 @@ public class DmpDatasetProfileMigrationService { for (DMPDatasetProfile item : items) { entityManager.detach(item); - DmpDatasetProfileData profileData = jsonHandlingService.fromJson(DmpDatasetProfileData.class, item.getData()); + PlanDatasetProfileData profileData = jsonHandlingService.fromJson(PlanDatasetProfileData.class, item.getData()); if (profileData == null || profileData.dmpSectionIndex == null || profileData.dmpSectionIndex.isEmpty()){ if (profileData != null && item.getDmp() != null && item.getDmp().getProfile() != null && item.getDmp().getProfile().getId() != null && item.getDmp().getProfile().getId().equals(UUID.fromString("86635178-36a6-484f-9057-a934e4eeecd5"))){ profileData.dmpSectionIndex = new ArrayList<>(); profileData.dmpSectionIndex.add(3); - logger.warn("Migrate DmpDatasetProfile " + item.getId() + " failed no section info set to 3"); + logger.warn("Migrate PlanDatasetProfile " + item.getId() + " failed no section info set to 3"); } else { - throw new MyApplicationException("Migrate DmpDatasetProfile " + item.getId() + " failed no section info "); + throw new MyApplicationException("Migrate PlanDatasetProfile " + item.getId() + " failed no section info "); } } DefinitionEntity definition = dmpBlueprintsMap.getOrDefault(item.getDmp().getProfile().getId(), null); if (definition == null){ - throw new MyApplicationException("Migrate DmpDatasetProfile " + item.getId() + " failed blueprint definition not found for blueprint " + item.getDmp().getProfile().getId()); + throw new MyApplicationException("Migrate PlanDatasetProfile " + item.getId() + " failed blueprint definition not found for blueprint " + item.getDmp().getProfile().getId()); } for (int sectionIndex: profileData.dmpSectionIndex) { if (definition.getSections() == null || definition.getSections().size() <= sectionIndex) { - throw new MyApplicationException("Migrate DmpDatasetProfile " + item.getId() + " cannot found section id for section " + sectionIndex); + throw new MyApplicationException("Migrate PlanDatasetProfile " + item.getId() + " cannot found section id for section " + sectionIndex); } UUID sectionId = definition.getSections().get(sectionIndex).getId(); if (sectionId == null) { - throw new MyApplicationException("Migrate DmpDatasetProfile " + item.getId() + " cannot found section id for section " + sectionIndex); + throw new MyApplicationException("Migrate PlanDatasetProfile " + item.getId() + " cannot found section id for section " + sectionIndex); } - DmpDescriptionTemplateEntity data = new DmpDescriptionTemplateEntity(); + PlanDescriptionTemplateEntity data = new PlanDescriptionTemplateEntity(); data.setId(UUID.randomUUID()); data.setDescriptionTemplateGroupId(item.getDatasetprofile().getGroupId()); - data.setDmpId(getDmp(item).getId()); + data.setPlanId(getPlan(item).getId()); data.setCreatedAt(item.getDmp().getCreated() != null ? item.getDmp().getCreated().toInstant() : Instant.now()); data.setUpdatedAt(item.getDmp().getModified() != null ? item.getDmp().getModified().toInstant() : Instant.now()); data.setSectionId(sectionId); @@ -121,37 +120,37 @@ public class DmpDatasetProfileMigrationService { removeDuplicates(); } - private DMP getDmp(DMPDatasetProfile item) { + private DMP getPlan(DMPDatasetProfile item) { return item.getDmp(); } private void removeDuplicates() { - logger.debug("Checking for duplicates on DmpDescriptionTemplate table after migration"); + logger.debug("Checking for duplicates on PlanDescriptionTemplate table after migration"); - DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery = this.queryFactory.query(DmpDescriptionTemplateQuery.class); + PlanDescriptionTemplateQuery dmpDescriptionTemplateQuery = this.queryFactory.query(PlanDescriptionTemplateQuery.class); long total = dmpDescriptionTemplateQuery.count(); logger.debug("Record count to check: {}", total); CriteriaBuilder b = this.entityManager.getCriteriaBuilder(); CriteriaQuery criteria = b.createQuery(Tuple.class); - Root root = criteria.from(DmpDescriptionTemplateEntity.class); - criteria.groupBy(Arrays.asList(root.get(DmpDescriptionTemplateEntity._dmpId), root.get(DmpDescriptionTemplateEntity._descriptionTemplateGroupId), root.get(DmpDescriptionTemplateEntity._sectionId))); - criteria.multiselect(root.get(DmpDescriptionTemplateEntity._dmpId), root.get(DmpDescriptionTemplateEntity._descriptionTemplateGroupId), root.get(DmpDescriptionTemplateEntity._sectionId), b.count(root)); + Root root = criteria.from(PlanDescriptionTemplateEntity.class); + criteria.groupBy(Arrays.asList(root.get(PlanDescriptionTemplateEntity._planId), root.get(PlanDescriptionTemplateEntity._descriptionTemplateGroupId), root.get(PlanDescriptionTemplateEntity._sectionId))); + criteria.multiselect(root.get(PlanDescriptionTemplateEntity._planId), root.get(PlanDescriptionTemplateEntity._descriptionTemplateGroupId), root.get(PlanDescriptionTemplateEntity._sectionId), b.count(root)); List resultList = this.entityManager.createQuery(criteria).getResultList(); List duplicatesList = resultList.stream().filter(x -> (long) x.get(3) > 1).toList(); - CriteriaDelete delete = b.createCriteriaDelete(DmpDescriptionTemplateEntity.class); - Root root1 = delete.from(DmpDescriptionTemplateEntity.class); + CriteriaDelete delete = b.createCriteriaDelete(PlanDescriptionTemplateEntity.class); + Root root1 = delete.from(PlanDescriptionTemplateEntity.class); for (Tuple duplicate : duplicatesList) { - List duplicateEntities = dmpDescriptionTemplateQuery - .dmpIds((UUID) duplicate.get(0)) + List duplicateEntities = dmpDescriptionTemplateQuery + .planIds((UUID) duplicate.get(0)) .descriptionTemplateGroupIds((UUID) duplicate.get(1)) .sectionIds((UUID) duplicate.get(2)) .collect(); - List toDelete = new ArrayList<>(duplicateEntities.stream().map(DmpDescriptionTemplateEntity::getId).toList()); - toDelete.remove(0); - delete.where(root1.get(DmpDescriptionTemplateEntity._id).in(toDelete)); + List toDelete = new ArrayList<>(duplicateEntities.stream().map(PlanDescriptionTemplateEntity::getId).toList()); + toDelete.removeFirst(); + delete.where(root1.get(PlanDescriptionTemplateEntity._id).in(toDelete)); this.entityManager.createQuery(delete).executeUpdate(); } @@ -159,7 +158,7 @@ public class DmpDatasetProfileMigrationService { } @JsonIgnoreProperties({"validationErrorModel"}) - public static class DmpDatasetProfileData { + public static class PlanDatasetProfileData { private List dmpSectionIndex; @@ -170,7 +169,6 @@ public class DmpDatasetProfileMigrationService { 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/PlanMigrationService.java similarity index 76% rename from dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpMigrationService.java rename to dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/PlanMigrationService.java index ad35b0b4d..b328dfb20 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/PlanMigrationService.java @@ -2,25 +2,22 @@ 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; import org.opencdmp.commons.XmlHandlingService; import org.opencdmp.commons.enums.*; -import org.opencdmp.commons.types.dmp.DmpBlueprintValueEntity; -import org.opencdmp.commons.types.dmp.DmpContactEntity; -import org.opencdmp.commons.types.dmp.DmpPropertiesEntity; -import org.opencdmp.commons.types.dmpblueprint.ExtraFieldEntity; -import org.opencdmp.commons.types.dmpblueprint.ReferenceTypeFieldEntity; -import org.opencdmp.commons.types.dmpblueprint.SectionEntity; -import org.opencdmp.commons.types.dmpreference.DmpReferenceDataEntity; +import org.opencdmp.commons.types.plan.PlanBlueprintValueEntity; +import org.opencdmp.commons.types.plan.PlanContactEntity; +import org.opencdmp.commons.types.plan.PlanPropertiesEntity; +import org.opencdmp.commons.types.planblueprint.ExtraFieldEntity; +import org.opencdmp.commons.types.planblueprint.ReferenceTypeFieldEntity; +import org.opencdmp.commons.types.planblueprint.SectionEntity; +import org.opencdmp.commons.types.planreference.PlanReferenceDataEntity; import org.opencdmp.commons.types.reference.DefinitionEntity; import org.opencdmp.commons.types.reference.FieldEntity; import org.opencdmp.convention.ConventionService; import org.opencdmp.data.*; -import org.opencdmp.model.dmp.DmpBlueprintValue; -import org.opencdmp.model.dmpblueprint.DmpBlueprint; -import org.opencdmp.query.DmpBlueprintQuery; +import org.opencdmp.model.planblueprint.PlanBlueprint; +import org.opencdmp.query.PlanBlueprintQuery; import eu.old.eudat.data.dao.entities.DMPDao; import eu.old.eudat.data.entities.*; import eu.old.eudat.logic.services.operations.DatabaseRepository; @@ -46,9 +43,9 @@ import java.util.*; import java.util.stream.Collectors; @Service -public class DmpMigrationService { +public class PlanMigrationService { - private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpMigrationService.class)); + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(PlanMigrationService.class)); private final DatabaseRepository databaseRepository; private final JsonHandlingService jsonHandlingService; private final EntityManager entityManager; @@ -60,7 +57,7 @@ public class DmpMigrationService { private static final int PageSize = 500; private static final boolean TestMode = false; - public DmpMigrationService(DatabaseRepository databaseRepository, JsonHandlingService jsonHandlingService, EntityManager entityManager, ConventionService conventionService, XmlHandlingService xmlHandlingService, Environment environment, QueryFactory queryFactory) { + public PlanMigrationService(DatabaseRepository databaseRepository, JsonHandlingService jsonHandlingService, EntityManager entityManager, ConventionService conventionService, XmlHandlingService xmlHandlingService, Environment environment, QueryFactory queryFactory) { this.databaseRepository = databaseRepository; this.jsonHandlingService = jsonHandlingService; this.entityManager = entityManager; @@ -74,7 +71,7 @@ public class DmpMigrationService { UserInfoDao userInfoDao = databaseRepository.getUserInfoDao(); DMPDao dmpDao = databaseRepository.getDmpDao(); long total = dmpDao.asQueryable().count(); - logger.debug("Migrate Dmp Total : " + total); + logger.debug("Migrate Plan Total : " + total); int page = 0; Map licenseIdByName = new HashMap<>(); @@ -82,54 +79,54 @@ public class DmpMigrationService { do { items = dmpDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("created"))).orderBy((builder, root) -> builder.asc(root.get("ID"))).skip(page * PageSize).take(PageSize).toList(); List finalItems = items; - List groupDmps = dmpDao.asQueryable().where((builder, root) -> root.get("groupId").in(finalItems.stream().map(DMP::getGroupId).distinct().collect(Collectors.toList()))).toList(); - Map> groupDmpMap = new HashMap<>(); - for (DMP dmp: groupDmps) { - if (!groupDmpMap.containsKey(dmp.getGroupId())) groupDmpMap.put(dmp.getGroupId(), new ArrayList<>()); - groupDmpMap.get(dmp.getGroupId()).add(dmp); + List groupPlans = dmpDao.asQueryable().where((builder, root) -> root.get("groupId").in(finalItems.stream().map(DMP::getGroupId).distinct().collect(Collectors.toList()))).toList(); + Map> groupPlanMap = new HashMap<>(); + for (DMP dmp: groupPlans) { + if (!groupPlanMap.containsKey(dmp.getGroupId())) groupPlanMap.put(dmp.getGroupId(), new ArrayList<>()); + groupPlanMap.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); - List dmpBlueprintEntities = this.queryFactory.query(DmpBlueprintQuery.class).ids(items.stream().filter(x-> x.getProfile() != null).map(x-> x.getProfile().getId()).distinct().collect(Collectors.toList())).collectAs(new BaseFieldSet().ensure(DmpBlueprint._definition).ensure(DmpBlueprint._id)); - Map blueprintDefinitionMap = new HashMap<>(); - Map> referenceTypeFieldsByDmpBlueprintId = new HashMap<>(); - for (DmpBlueprintEntity dmpBlueprintEntity : dmpBlueprintEntities) { - org.opencdmp.commons.types.dmpblueprint.DefinitionEntity definition = this.xmlHandlingService.fromXml(org.opencdmp.commons.types.dmpblueprint.DefinitionEntity.class, dmpBlueprintEntity.getDefinition()); + logger.debug("Migrate Plan " + page * PageSize + " of " + total); + List dmpBlueprintEntities = this.queryFactory.query(PlanBlueprintQuery.class).ids(items.stream().filter(x-> x.getProfile() != null).map(x-> x.getProfile().getId()).distinct().collect(Collectors.toList())).collectAs(new BaseFieldSet().ensure(PlanBlueprint._definition).ensure(PlanBlueprint._id)); + Map blueprintDefinitionMap = new HashMap<>(); + Map> referenceTypeFieldsByPlanBlueprintId = new HashMap<>(); + for (PlanBlueprintEntity dmpBlueprintEntity : dmpBlueprintEntities) { + org.opencdmp.commons.types.planblueprint.DefinitionEntity definition = this.xmlHandlingService.fromXml(org.opencdmp.commons.types.planblueprint.DefinitionEntity.class, dmpBlueprintEntity.getDefinition()); blueprintDefinitionMap.put(dmpBlueprintEntity.getId(), definition); - List referenceTypeFieldEntities = definition.getSections().stream().filter(x-> x.getFields() != null).map(SectionEntity::getFields).flatMap(List::stream).filter(x-> x.getCategory().equals(DmpBlueprintFieldCategory.ReferenceType)).map(x-> (ReferenceTypeFieldEntity)x) + List referenceTypeFieldEntities = definition.getSections().stream().filter(x-> x.getFields() != null).map(SectionEntity::getFields).flatMap(List::stream).filter(x-> x.getCategory().equals(PlanBlueprintFieldCategory.ReferenceType)).map(x-> (ReferenceTypeFieldEntity)x) .filter(x-> x.getReferenceTypeId().equals(ReferenceTypeIds.License) || x.getReferenceTypeId().equals(ReferenceTypeIds.Project) || x.getReferenceTypeId().equals(ReferenceTypeIds.Researcher) || x.getReferenceTypeId().equals(ReferenceTypeIds.Grants) || x.getReferenceTypeId().equals(ReferenceTypeIds.Organizations) || x.getReferenceTypeId().equals(ReferenceTypeIds.Funder)) .collect(Collectors.toList()); - referenceTypeFieldsByDmpBlueprintId.put(dmpBlueprintEntity.getId() , referenceTypeFieldEntities); + referenceTypeFieldsByPlanBlueprintId.put(dmpBlueprintEntity.getId() , referenceTypeFieldEntities); } for (DMP item : items) { //entityManager.detach(item); - org.opencdmp.commons.types.dmpblueprint.DefinitionEntity definitionEntity = blueprintDefinitionMap.get(item.getProfile().getId()); + org.opencdmp.commons.types.planblueprint.DefinitionEntity definitionEntity = blueprintDefinitionMap.get(item.getProfile().getId()); DataManagementPlan model = new DataManagementPlan(); model.fromDataModel(item); - List itemGroupDmps = groupDmpMap.get(item.getGroupId()); - DMP currentVersionDmp = itemGroupDmps.stream().filter(x-> DmpStatus.Finalized.getValue().equals(x.getStatus())).max(Comparator.comparing(DMP::getVersion)).orElse(null); + List itemGroupPlans = groupPlanMap.get(item.getGroupId()); + DMP currentVersionPlan = itemGroupPlans.stream().filter(x-> PlanStatus.Finalized.getValue().equals(x.getStatus())).max(Comparator.comparing(DMP::getVersion)).orElse(null); - DmpPropertiesEntity dmpProperties = new DmpPropertiesEntity(); - dmpProperties.setDmpBlueprintValues(new ArrayList<>()); + PlanPropertiesEntity dmpProperties = new PlanPropertiesEntity(); + dmpProperties.setPlanBlueprintValues(new ArrayList<>()); dmpProperties.setContacts(new ArrayList<>()); - DmpEntity data = new DmpEntity(); + PlanEntity data = new PlanEntity(); data.setId(model.getId()); data.setLabel(model.getLabel()); data.setDescription(model.getDescription()); if (model.getCreator() != null && model.getCreator().getId() != null) { data.setCreatorId(model.getCreator().getId()); } else { - for (DMP groupDmp: itemGroupDmps) { - DataManagementPlan groupDmpModel = new DataManagementPlan(); - groupDmpModel.fromDataModel(groupDmp); - if (groupDmpModel.getCreator() != null) { - data.setCreatorId(groupDmpModel.getCreator().getId()); + for (DMP groupPlan: itemGroupPlans) { + DataManagementPlan groupPlanModel = new DataManagementPlan(); + groupPlanModel.fromDataModel(groupPlan); + if (groupPlanModel.getCreator() != null) { + data.setCreatorId(groupPlanModel.getCreator().getId()); break; } } @@ -139,14 +136,14 @@ public class DmpMigrationService { } data.setGroupId(model.getGroupId()); data.setVersion((short) model.getVersion()); - if (currentVersionDmp != null && currentVersionDmp.getId().equals(item.getId())){ - data.setVersionStatus(DmpVersionStatus.Current); + if (currentVersionPlan != null && currentVersionPlan.getId().equals(item.getId())){ + data.setVersionStatus(PlanVersionStatus.Current); } else { - if (DmpStatus.Finalized.getValue().equals(item.getStatus())){ - if (currentVersionDmp == null) throw new MyApplicationException("Found Finalized Dmp out of the group "); - data.setVersionStatus(DmpVersionStatus.Previous); + if (PlanStatus.Finalized.getValue().equals(item.getStatus())){ + if (currentVersionPlan == null) throw new MyApplicationException("Found Finalized Plan out of the group "); + data.setVersionStatus(PlanVersionStatus.Previous); } else { - data.setVersionStatus(DmpVersionStatus.NotFinalized); + data.setVersionStatus(PlanVersionStatus.NotFinalized); } } if (model.getCreated() != null) @@ -160,16 +157,16 @@ public class DmpMigrationService { if (model.getExtraProperties().containsKey("language") && model.getExtraProperties().get("language") != null) data.setLanguage((String) model.getExtraProperties().get("language")); if (model.getExtraProperties().containsKey("visible") && model.getExtraProperties().get("visible") != null) - data.setAccessType((boolean) model.getExtraProperties().get("visible") ? DmpAccessType.Public : DmpAccessType.Restricted); + data.setAccessType((boolean) model.getExtraProperties().get("visible") ? PlanAccessType.Public : PlanAccessType.Restricted); if (model.getExtraProperties().containsKey("contact") && model.getExtraProperties().get("contact") != null) { UserInfo userInfo = oldUsers.getOrDefault(UUID.fromString((String)model.getExtraProperties().get("contact")), null); if (userInfo != null) { - DmpContactEntity contactEntity = new DmpContactEntity(); + PlanContactEntity contactEntity = new PlanContactEntity(); 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()); + throw new MyApplicationException("Contact not found " + UUID.fromString((String)model.getExtraProperties().get("contact")) + " Plan " + item.getId()); } } @@ -183,10 +180,10 @@ public class DmpMigrationService { } if (model.getProperties() != null) { model.getProperties().forEach((key,val) -> { - DmpBlueprintValueEntity valueEntity = new DmpBlueprintValueEntity(); + PlanBlueprintValueEntity valueEntity = new PlanBlueprintValueEntity(); valueEntity.setFieldId(UUID.fromString(key)); - org.opencdmp.commons.types.dmpblueprint.FieldEntity fieldEntity = this.getFieldOfId(definitionEntity, valueEntity.getFieldId()); - if (fieldEntity != null && val != null && fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.Extra)){ + org.opencdmp.commons.types.planblueprint.FieldEntity fieldEntity = this.getFieldOfId(definitionEntity, valueEntity.getFieldId()); + if (fieldEntity != null && val != null && fieldEntity.getCategory().equals(PlanBlueprintFieldCategory.Extra)){ ExtraFieldEntity extraFieldEntity = (ExtraFieldEntity) fieldEntity; switch (extraFieldEntity.getType()){ case Date -> { @@ -204,23 +201,23 @@ public class DmpMigrationService { } else { valueEntity.setValue((String) val); } - dmpProperties.getDmpBlueprintValues().add(valueEntity); + dmpProperties.getPlanBlueprintValues().add(valueEntity); }); } if (model.getStatus() == 99) { data.setIsActive(IsActive.Inactive); - data.setStatus(DmpStatus.Draft); + data.setStatus(PlanStatus.Draft); } else { data.setIsActive(IsActive.Active); - data.setStatus(DmpStatus.of((short) model.getStatus())); + data.setStatus(PlanStatus.of((short) model.getStatus())); } data.setProperties(jsonHandlingService.toJson(dmpProperties)); - if (data.getAccessType() == null && item.getStatus().equals(DmpStatus.Finalized.getValue())) { + if (data.getAccessType() == null && item.getStatus().equals(PlanStatus.Finalized.getValue())) { logger.warn("AccessType not found set to default for dmp " + item.getId()); - data.setAccessType(item.isPublic() ? DmpAccessType.Public : DmpAccessType.Restricted); + data.setAccessType(item.isPublic() ? PlanAccessType.Public : PlanAccessType.Restricted); } - if ((data.getLanguage() == null || data.getLanguage().isBlank()) && item.getStatus().equals(DmpStatus.Finalized.getValue())) { + if ((data.getLanguage() == null || data.getLanguage().isBlank()) && item.getStatus().equals(PlanStatus.Finalized.getValue())) { logger.warn("Language not found set to default for dmp " + item.getId()); data.setLanguage("en"); } @@ -231,13 +228,13 @@ public class DmpMigrationService { this.entityManager.persist(data); this.entityManager.flush(); - boolean shouldCreateOwner = item.getUsers() == null || item.getUsers().stream().noneMatch(x-> x.getUser() != null && data.getCreatorId().equals(x.getUser().getId()) && DmpUserRole.Owner.getValue().equals(x.getRole().shortValue())); + boolean shouldCreateOwner = item.getUsers() == null || item.getUsers().stream().noneMatch(x-> x.getUser() != null && data.getCreatorId().equals(x.getUser().getId()) && PlanUserRole.Owner.getValue().equals(x.getRole().shortValue())); if (shouldCreateOwner) { - DmpUserEntity dmpUserEntity = new DmpUserEntity(); + PlanUserEntity dmpUserEntity = new PlanUserEntity(); dmpUserEntity.setId(UUID.randomUUID()); - dmpUserEntity.setDmpId(data.getId()); + dmpUserEntity.setPlanId(data.getId()); dmpUserEntity.setUserId(data.getCreatorId()); - dmpUserEntity.setRole(DmpUserRole.Owner); + dmpUserEntity.setRole(PlanUserRole.Owner); dmpUserEntity.setCreatedAt(data.getCreatedAt()); dmpUserEntity.setUpdatedAt(data.getCreatedAt()); dmpUserEntity.setIsActive(IsActive.Active); @@ -245,11 +242,11 @@ public class DmpMigrationService { this.entityManager.flush(); } - licenseIdByName = this.migrateLicense(item, model, licenseIdByName, referenceTypeFieldsByDmpBlueprintId.getOrDefault(data.getBlueprintId(), null)); - this.migrateOrganizations(item, referenceTypeFieldsByDmpBlueprintId.getOrDefault(data.getBlueprintId(), null)); - this.migrateResearchers(item, referenceTypeFieldsByDmpBlueprintId.getOrDefault(data.getBlueprintId(), null)); - this.migrateProjects(item, referenceTypeFieldsByDmpBlueprintId.getOrDefault(data.getBlueprintId(), null)); - this.migrateGrantAndFunder(item, referenceTypeFieldsByDmpBlueprintId.getOrDefault(data.getBlueprintId(), null)); + licenseIdByName = this.migrateLicense(item, model, licenseIdByName, referenceTypeFieldsByPlanBlueprintId.getOrDefault(data.getBlueprintId(), null)); + this.migrateOrganizations(item, referenceTypeFieldsByPlanBlueprintId.getOrDefault(data.getBlueprintId(), null)); + this.migrateResearchers(item, referenceTypeFieldsByPlanBlueprintId.getOrDefault(data.getBlueprintId(), null)); + this.migrateProjects(item, referenceTypeFieldsByPlanBlueprintId.getOrDefault(data.getBlueprintId(), null)); + this.migrateGrantAndFunder(item, referenceTypeFieldsByPlanBlueprintId.getOrDefault(data.getBlueprintId(), null)); } page++; @@ -257,11 +254,11 @@ public class DmpMigrationService { } while (items != null && !items.isEmpty() && !TestMode); } - private org.opencdmp.commons.types.dmpblueprint.FieldEntity getFieldOfId(org.opencdmp.commons.types.dmpblueprint.DefinitionEntity definition, UUID fieldId){ + private org.opencdmp.commons.types.planblueprint.FieldEntity getFieldOfId(org.opencdmp.commons.types.planblueprint.DefinitionEntity definition, UUID fieldId){ if (definition == null || definition.getSections() == null) return null; for (SectionEntity sectionModel : definition.getSections()){ if (sectionModel.getFields() != null){ - org.opencdmp.commons.types.dmpblueprint.FieldEntity fieldModel = sectionModel.getFields().stream().filter(x-> x.getId().equals(fieldId)).findFirst().orElse(null); + org.opencdmp.commons.types.planblueprint.FieldEntity fieldModel = sectionModel.getFields().stream().filter(x-> x.getId().equals(fieldId)).findFirst().orElse(null); if (fieldModel != null) return fieldModel; } } @@ -281,13 +278,13 @@ public class DmpMigrationService { } for (Organisation organisation : organisations) { - DmpReferenceEntity data = new DmpReferenceEntity(); + PlanReferenceEntity data = new PlanReferenceEntity(); data.setId(UUID.randomUUID()); - data.setDmpId(item.getId()); + data.setPlanId(item.getId()); data.setReferenceId(organisation.getId()); data.setCreatedAt(item.getCreated() != null ? item.getCreated().toInstant() : Instant.now()); data.setUpdatedAt(item.getModified() != null ? item.getModified().toInstant() : Instant.now()); - data.setData(this.jsonHandlingService.toJsonSafe(this.buildDmpReferenceDataEntity(referenceTypeFieldEntity))); + data.setData(this.jsonHandlingService.toJsonSafe(this.buildPlanReferenceDataEntity(referenceTypeFieldEntity))); data.setIsActive(IsActive.Active); this.entityManager.persist(data); } @@ -304,14 +301,14 @@ public class DmpMigrationService { throw new MyApplicationException("Migration failed Project field not found " + item.getId()); } - DmpReferenceEntity data = new DmpReferenceEntity(); + PlanReferenceEntity data = new PlanReferenceEntity(); data.setId(UUID.randomUUID()); - data.setDmpId(item.getId()); + data.setPlanId(item.getId()); data.setReferenceId(project.getId()); data.setCreatedAt(item.getCreated() != null ? item.getCreated().toInstant() : Instant.now()); data.setUpdatedAt(item.getModified() != null ? item.getModified().toInstant() : Instant.now()); data.setIsActive(IsActive.Active); - data.setData(this.jsonHandlingService.toJsonSafe(this.buildDmpReferenceDataEntity(referenceTypeFieldEntity))); + data.setData(this.jsonHandlingService.toJsonSafe(this.buildPlanReferenceDataEntity(referenceTypeFieldEntity))); this.entityManager.persist(data); } @@ -327,13 +324,13 @@ public class DmpMigrationService { } for (Researcher researcher : researchers) { - DmpReferenceEntity data = new DmpReferenceEntity(); + PlanReferenceEntity data = new PlanReferenceEntity(); data.setId(UUID.randomUUID()); - data.setDmpId(item.getId()); + data.setPlanId(item.getId()); data.setReferenceId(researcher.getId()); data.setCreatedAt(item.getCreated() != null ? item.getCreated().toInstant() : Instant.now()); data.setUpdatedAt(item.getModified() != null ? item.getModified().toInstant() : Instant.now()); - data.setData(this.jsonHandlingService.toJsonSafe(this.buildDmpReferenceDataEntity(referenceTypeFieldEntity))); + data.setData(this.jsonHandlingService.toJsonSafe(this.buildPlanReferenceDataEntity(referenceTypeFieldEntity))); data.setIsActive(IsActive.Active); this.entityManager.persist(data); } @@ -351,13 +348,13 @@ public class DmpMigrationService { throw new MyApplicationException("Migration failed Grant field not found " + item.getId()); } - DmpReferenceEntity data = new DmpReferenceEntity(); + PlanReferenceEntity data = new PlanReferenceEntity(); data.setId(UUID.randomUUID()); - data.setDmpId(item.getId()); + data.setPlanId(item.getId()); data.setReferenceId(grant.getId()); data.setCreatedAt(item.getCreated() != null ? item.getCreated().toInstant() : Instant.now()); data.setUpdatedAt(item.getModified() != null ? item.getModified().toInstant() : Instant.now()); - data.setData(this.jsonHandlingService.toJsonSafe(this.buildDmpReferenceDataEntity(referenceTypeFieldEntity))); + data.setData(this.jsonHandlingService.toJsonSafe(this.buildPlanReferenceDataEntity(referenceTypeFieldEntity))); data.setIsActive(IsActive.Active); this.entityManager.persist(data); if (grant.getFunder() != null){ @@ -365,13 +362,13 @@ public class DmpMigrationService { if (funderField == null) { throw new MyApplicationException("Migration failed Funder field not found " + item.getId()); } - DmpReferenceEntity founder = new DmpReferenceEntity(); + PlanReferenceEntity founder = new PlanReferenceEntity(); founder.setId(UUID.randomUUID()); - founder.setDmpId(item.getId()); + founder.setPlanId(item.getId()); founder.setReferenceId(grant.getFunder().getId()); founder.setCreatedAt(item.getCreated() != null ? item.getCreated().toInstant() : Instant.now()); founder.setUpdatedAt(item.getModified() != null ? item.getModified().toInstant() : Instant.now()); - founder.setData(this.jsonHandlingService.toJsonSafe(this.buildDmpReferenceDataEntity(funderField))); + founder.setData(this.jsonHandlingService.toJsonSafe(this.buildPlanReferenceDataEntity(funderField))); founder.setIsActive(IsActive.Active); this.entityManager.persist(founder); } @@ -456,13 +453,13 @@ public class DmpMigrationService { licenseIdByName.put(licensePid, referenceEntity.getId()); } - DmpReferenceEntity dmpReferenceEntity = new DmpReferenceEntity(); + PlanReferenceEntity dmpReferenceEntity = new PlanReferenceEntity(); dmpReferenceEntity.setId(UUID.randomUUID()); - dmpReferenceEntity.setDmpId(item.getId()); + dmpReferenceEntity.setPlanId(item.getId()); dmpReferenceEntity.setReferenceId(licenseIdByName.get(licensePid)); dmpReferenceEntity.setCreatedAt(Instant.now()); dmpReferenceEntity.setUpdatedAt(Instant.now()); - dmpReferenceEntity.setData(this.jsonHandlingService.toJsonSafe(this.buildDmpReferenceDataEntity(referenceTypeFieldEntity))); + dmpReferenceEntity.setData(this.jsonHandlingService.toJsonSafe(this.buildPlanReferenceDataEntity(referenceTypeFieldEntity))); dmpReferenceEntity.setIsActive(IsActive.Active); if (!licenseExists) entityManager.persist(referenceEntity); @@ -473,8 +470,8 @@ public class DmpMigrationService { return licenseIdByName; } - private DmpReferenceDataEntity buildDmpReferenceDataEntity(ReferenceTypeFieldEntity referenceTypeFieldEntity){ - DmpReferenceDataEntity data = new DmpReferenceDataEntity(); + private PlanReferenceDataEntity buildPlanReferenceDataEntity(ReferenceTypeFieldEntity referenceTypeFieldEntity){ + PlanReferenceDataEntity data = new PlanReferenceDataEntity(); data.setBlueprintFieldId(referenceTypeFieldEntity.getId()); return data; } diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpUserMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/PlanUserMigrationService.java similarity index 81% rename from dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpUserMigrationService.java rename to dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/PlanUserMigrationService.java index bdd808786..1ddf1ff7a 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpUserMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/PlanUserMigrationService.java @@ -1,8 +1,8 @@ package eu.old.eudat.migration; -import org.opencdmp.commons.enums.DmpUserRole; +import org.opencdmp.commons.enums.PlanUserRole; import org.opencdmp.commons.enums.IsActive; -import org.opencdmp.data.DmpUserEntity; +import org.opencdmp.data.PlanUserEntity; import eu.old.eudat.data.dao.entities.UserDmpDao; import eu.old.eudat.data.entities.UserDMP; import eu.old.eudat.logic.services.operations.DatabaseRepository; @@ -15,9 +15,9 @@ import java.time.Instant; import java.util.List; @Service -public class DmpUserMigrationService { +public class PlanUserMigrationService { - private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpUserMigrationService.class)); + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(PlanUserMigrationService.class)); private final DatabaseRepository databaseRepository; @@ -27,7 +27,7 @@ public class DmpUserMigrationService { private static final boolean TestMode = false; - public DmpUserMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) { + public PlanUserMigrationService(DatabaseRepository databaseRepository, EntityManager entityManager) { this.databaseRepository = databaseRepository; this.entityManager = entityManager; } @@ -46,11 +46,11 @@ public class DmpUserMigrationService { for (UserDMP item : items) { //entityManager.detach(item); - DmpUserEntity data = new DmpUserEntity(); + PlanUserEntity data = new PlanUserEntity(); data.setId(item.getId()); - data.setDmpId(item.getDmp().getId()); + data.setPlanId(item.getDmp().getId()); data.setUserId(item.getUser().getId()); - data.setRole(DmpUserRole.of(item.getRole().shortValue())); + data.setRole(PlanUserRole.of(item.getRole().shortValue())); data.setCreatedAt(item.getDmp().getCreated() != null ? item.getDmp().getCreated().toInstant() : Instant.now()); data.setUpdatedAt(item.getDmp().getModified() != null ? item.getDmp().getModified().toInstant() : Instant.now()); data.setIsActive(IsActive.Active); 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 091efe744..bfb3555e6 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 @@ -26,7 +26,7 @@ import java.net.URISyntaxException; public class MigrationController { private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(MigrationController.class)); - private final DmpMigrationService dmpMigrationService; + private final PlanMigrationService planMigrationService; private final DataRepositoryMigrationService dataRepositoryMigrationService; private final ExternalDatasetMigrationService externalDatasetMigrationService; private final FunderMigrationService funderMigrationService; @@ -37,21 +37,21 @@ public class MigrationController { private final ServiceMigrationService serviceMigrationService; private final DatasetMigrationService datasetMigrationService; private final TagMigrationService tagMigrationService; - private final DmpDatasetProfileMigrationService dmpDatasetProfileMigrationService; + private final PlanDatasetProfileMigrationService planDatasetProfileMigrationService; private final OrganizationMigrationService organizationMigrationService; private final DatasetReferenceMigrationService datasetReferenceMigrationService; private final UserContactInfoMigrationService userContactInfoMigrationService; - private final DmpUserMigrationService dmpUserMigrationService; + private final PlanUserMigrationService planUserMigrationService; private final UserMigrationService userMigrationService; - private final DmpBlueprintXmlMigrationService dmpBlueprintXmlMigrationService; + private final PlanBlueprintXmlMigrationService planBlueprintXmlMigrationService; private final DescriptionTemplateXmlMigrationService descriptionTemplateXmlMigrationService; private final DescriptionTemplateXmlCleanInvalidReferenceTypesService descriptionTemplateXmlCleanInvalidReferenceTypesService; private final StorageFileMigrationService storageFileMigrationService; public MigrationController( - DmpMigrationService dmpMigrationService, + PlanMigrationService planMigrationService, DatasetMigrationService datasetMigrationService, - DmpDatasetProfileMigrationService dmpDatasetProfileMigrationService, + PlanDatasetProfileMigrationService planDatasetProfileMigrationService, DataRepositoryMigrationService dataRepositoryMigrationService, ExternalDatasetMigrationService externalDatasetMigrationService, FunderMigrationService funderMigrationService, @@ -63,13 +63,13 @@ public class MigrationController { OrganizationMigrationService organizationMigrationService, DatasetReferenceMigrationService datasetReferenceMigrationService, UserContactInfoMigrationService userContactInfoMigrationService, - DmpUserMigrationService dmpUserMigrationService, + PlanUserMigrationService planUserMigrationService, UserMigrationService userMigrationService, - DmpBlueprintXmlMigrationService dmpBlueprintXmlMigrationService, + PlanBlueprintXmlMigrationService planBlueprintXmlMigrationService, DescriptionTemplateXmlMigrationService descriptionTemplateXmlMigrationService, DescriptionTemplateXmlCleanInvalidReferenceTypesService descriptionTemplateXmlCleanInvalidReferenceTypesService, StorageFileMigrationService storageFileMigrationService) { - this.dmpMigrationService = dmpMigrationService; + this.planMigrationService = planMigrationService; this.datasetMigrationService = datasetMigrationService; - this.dmpDatasetProfileMigrationService = dmpDatasetProfileMigrationService; + this.planDatasetProfileMigrationService = planDatasetProfileMigrationService; this.dataRepositoryMigrationService = dataRepositoryMigrationService; this.externalDatasetMigrationService = externalDatasetMigrationService; this.funderMigrationService = funderMigrationService; @@ -82,9 +82,9 @@ public class MigrationController { this.organizationMigrationService = organizationMigrationService; this.datasetReferenceMigrationService = datasetReferenceMigrationService; this.userContactInfoMigrationService = userContactInfoMigrationService; - this.dmpUserMigrationService = dmpUserMigrationService; + this.planUserMigrationService = planUserMigrationService; this.userMigrationService = userMigrationService; - this.dmpBlueprintXmlMigrationService = dmpBlueprintXmlMigrationService; + this.planBlueprintXmlMigrationService = planBlueprintXmlMigrationService; this.descriptionTemplateXmlMigrationService = descriptionTemplateXmlMigrationService; this.descriptionTemplateXmlCleanInvalidReferenceTypesService = descriptionTemplateXmlCleanInvalidReferenceTypesService; this.storageFileMigrationService = storageFileMigrationService; @@ -149,7 +149,7 @@ public class MigrationController { this.userMigrationService.migrate(); //XML recreate - this.dmpBlueprintXmlMigrationService.migrate(); + this.planBlueprintXmlMigrationService.migrate(); this.descriptionTemplateXmlMigrationService.migrate(); logger.info("Completed!!!"); @@ -161,9 +161,9 @@ public class MigrationController { @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(); + this.planMigrationService.migrate(); + this.planDatasetProfileMigrationService.migrate(); + this.planUserMigrationService.migrate(); logger.info("Completed!!!"); @@ -190,7 +190,7 @@ public class MigrationController { @GetMapping("dmp-blueprints-xml") @Transactional public boolean migrateDmpBlueprint() throws JAXBException, InvalidApplicationException, IOException, ParserConfigurationException, NoSuchFieldException, TransformerException, IllegalAccessException, InstantiationException, SAXException { - this.dmpBlueprintXmlMigrationService.migrate(); + this.planBlueprintXmlMigrationService.migrate(); return true; } @@ -239,7 +239,7 @@ public class MigrationController { @GetMapping("dmps") @Transactional public boolean migrateDmps() throws IOException, NoSuchFieldException, IllegalAccessException, JAXBException, ParserConfigurationException, InstantiationException, SAXException { - this.dmpMigrationService.migrate(); + this.planMigrationService.migrate(); return true; } @@ -260,7 +260,7 @@ public class MigrationController { @GetMapping("dmp-dataset-profiles") @Transactional public boolean migrateDmpDatasetProfiles() throws IOException, JAXBException, ParserConfigurationException, InstantiationException, IllegalAccessException, SAXException { - this.dmpDatasetProfileMigrationService.migrate(); + this.planDatasetProfileMigrationService.migrate(); return true; } @@ -282,7 +282,7 @@ public class MigrationController { @GetMapping("dmp-users") @Transactional public boolean migrateDmpUsers() { - this.dmpUserMigrationService.migrate(); + this.planUserMigrationService.migrate(); return true; }