dmp new version backend fix

This commit is contained in:
amentis 2024-05-29 14:41:58 +03:00
parent 72cebd0c9d
commit c237de889c
1 changed files with 30 additions and 0 deletions

View File

@ -47,6 +47,7 @@ import org.opencdmp.commons.types.dmp.DmpBlueprintValueEntity;
import org.opencdmp.commons.types.dmp.DmpContactEntity; import org.opencdmp.commons.types.dmp.DmpContactEntity;
import org.opencdmp.commons.types.dmp.DmpPropertiesEntity; import org.opencdmp.commons.types.dmp.DmpPropertiesEntity;
import org.opencdmp.commons.types.dmp.importexport.*; 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.ExtraFieldEntity;
import org.opencdmp.commons.types.dmpblueprint.ReferenceTypeFieldEntity; import org.opencdmp.commons.types.dmpblueprint.ReferenceTypeFieldEntity;
import org.opencdmp.commons.types.dmpblueprint.SectionEntity; import org.opencdmp.commons.types.dmpblueprint.SectionEntity;
@ -485,6 +486,11 @@ public class DmpServiceImpl implements DmpService {
this.entityManager.flush(); this.entityManager.flush();
if (model.getDescriptions() != null){ 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<DmpDescriptionTemplateEntity> dmpDescriptionTemplateEntities = this.queryFactory.query(DmpDescriptionTemplateQuery.class).disableTracking().dmpIds(newDmp.getId()).isActive(IsActive.Active).collect(); List<DmpDescriptionTemplateEntity> dmpDescriptionTemplateEntities = this.queryFactory.query(DmpDescriptionTemplateQuery.class).disableTracking().dmpIds(newDmp.getId()).isActive(IsActive.Active).collect();
List<DescriptionEntity> descriptionEntities = this.queryFactory.query(DescriptionQuery.class).disableTracking().ids(model.getDescriptions().stream().map(NewVersionDmpDescriptionPersist::getDescriptionId).distinct().collect(Collectors.toList())).isActive(IsActive.Active).collect(); List<DescriptionEntity> 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<SectionEntity> 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(); this.entityManager.flush();