From c237de889cd3ac5c527492a4c90d22270fa09b93 Mon Sep 17 00:00:00 2001 From: amentis Date: Wed, 29 May 2024 14:41:58 +0300 Subject: [PATCH] dmp new version backend fix --- .../opencdmp/service/dmp/DmpServiceImpl.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/backend/core/src/main/java/org/opencdmp/service/dmp/DmpServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/dmp/DmpServiceImpl.java index 4ede31ab1..3f5eb1517 100644 --- a/backend/core/src/main/java/org/opencdmp/service/dmp/DmpServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/dmp/DmpServiceImpl.java @@ -47,6 +47,7 @@ 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.dmp.importexport.*; +import org.opencdmp.commons.types.dmpblueprint.DescriptionTemplateEntity; import org.opencdmp.commons.types.dmpblueprint.ExtraFieldEntity; import org.opencdmp.commons.types.dmpblueprint.ReferenceTypeFieldEntity; import org.opencdmp.commons.types.dmpblueprint.SectionEntity; @@ -485,6 +486,11 @@ public class DmpServiceImpl implements DmpService { this.entityManager.flush(); if (model.getDescriptions() != null){ + DmpBlueprintEntity blueprintEntity = this.entityManager.find(DmpBlueprintEntity.class, model.getBlueprintId(), true); + if (blueprintEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getBlueprintId(), DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale())); + + org.opencdmp.commons.types.dmpblueprint.DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(org.opencdmp.commons.types.dmpblueprint.DefinitionEntity.class, blueprintEntity.getDefinition()); + List dmpDescriptionTemplateEntities = this.queryFactory.query(DmpDescriptionTemplateQuery.class).disableTracking().dmpIds(newDmp.getId()).isActive(IsActive.Active).collect(); List descriptionEntities = this.queryFactory.query(DescriptionQuery.class).disableTracking().ids(model.getDescriptions().stream().map(NewVersionDmpDescriptionPersist::getDescriptionId).distinct().collect(Collectors.toList())).isActive(IsActive.Active).collect(); @@ -513,6 +519,30 @@ public class DmpServiceImpl implements DmpService { } } } + + if (!oldDmpEntity.getBlueprintId().equals(blueprintEntity.getId())){ + // add description templates if exists in new blueprint + List sections = definition.getSections().stream().filter(x -> x.getHasTemplates()).collect(Collectors.toList()); + if (!this.conventionService.isListNullOrEmpty(sections)){ + for (SectionEntity section: sections) { + if (!this.conventionService.isListNullOrEmpty(section.getDescriptionTemplates())){ + for (DescriptionTemplateEntity blueprintDescriptionTemplate: section.getDescriptionTemplates()) { + if (model.getDescriptions().stream().map(x -> x.getBlueprintSectionId()).collect(Collectors.toList()).contains(section.getId())){ + DmpDescriptionTemplateEntity newTemplate = new DmpDescriptionTemplateEntity(); + newTemplate.setId(UUID.randomUUID()); + newTemplate.setDmpId(newDmp.getId()); + newTemplate.setDescriptionTemplateGroupId(blueprintDescriptionTemplate.getDescriptionTemplateGroupId()); + newTemplate.setSectionId(section.getId()); + newTemplate.setCreatedAt(Instant.now()); + newTemplate.setUpdatedAt(Instant.now()); + newTemplate.setIsActive(IsActive.Active); + this.entityManager.persist(newTemplate); + } + } + } + } + } + } } this.entityManager.flush();