add blueprint description templates on import

This commit is contained in:
CITE\amentis 2024-08-29 14:47:00 +03:00
parent 17b6a39c74
commit 15efa81131
1 changed files with 42 additions and 2 deletions

View File

@ -2475,12 +2475,32 @@ public class PlanServiceImpl implements PlanService {
return persist;
}
private List<PlanDescriptionTemplatePersist> xmlPlanDescriptionTemplatesToPersist(PlanImportExport planXml){
private List<PlanDescriptionTemplatePersist> xmlPlanDescriptionTemplatesToPersist(PlanImportExport planXml) throws InvalidApplicationException {
if (!this.conventionService.isListNullOrEmpty(planXml.getDescriptionTemplates())) {
List<PlanDescriptionTemplatePersist> descriptionTemplates = new ArrayList<>();
for (PlanDescriptionTemplateImportExport descriptionTemplate : planXml.getDescriptionTemplates()) {
descriptionTemplates.add(this.xmlPlanDescriptionTemplateToPersist(descriptionTemplate));
}
// add description templates from blueprint
if (planXml.getBlueprint() != null && planXml.getBlueprint().getId() != null) {
PlanBlueprintEntity blueprintEntity = this.entityManager.find(PlanBlueprintEntity.class, planXml.getBlueprint().getId(), true);
if (blueprintEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{planXml.getBlueprint().getId(), PlanBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
org.opencdmp.commons.types.planblueprint.DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(org.opencdmp.commons.types.planblueprint.DefinitionEntity.class, blueprintEntity.getDefinition());
List<SectionEntity> sections = definition.getSections().stream().filter(SectionEntity::getHasTemplates).collect(Collectors.toList());
for (SectionEntity section: sections) {
if (section.getHasTemplates() && !this.conventionService.isListNullOrEmpty(section.getDescriptionTemplates())){
for (DescriptionTemplateEntity descriptionTemplateEntity: section.getDescriptionTemplates()){
if (descriptionTemplates.stream().filter(x -> x.getDescriptionTemplateGroupId().equals(descriptionTemplateEntity.getDescriptionTemplateGroupId()) && x.getSectionId().equals(section.getId())).findFirst().orElse(null) == null) {
PlanDescriptionTemplateImportExport model = new PlanDescriptionTemplateImportExport();
model.setDescriptionTemplateGroupId(descriptionTemplateEntity.getDescriptionTemplateGroupId());
model.setSectionId(section.getId());
descriptionTemplates.add(this.xmlPlanDescriptionTemplateToPersist(model));
}
}
}
}
}
return descriptionTemplates.stream().filter(Objects::nonNull).toList();
}
return null;
@ -2611,12 +2631,32 @@ public class PlanServiceImpl implements PlanService {
return plan;
}
private List<PlanDescriptionTemplatePersist> commonModelPlanDescriptionTemplatesToPersist(PlanModel commonModel){
private List<PlanDescriptionTemplatePersist> commonModelPlanDescriptionTemplatesToPersist(PlanModel commonModel) throws InvalidApplicationException {
if (!this.conventionService.isListNullOrEmpty(commonModel.getDescriptionTemplates())) {
List<PlanDescriptionTemplatePersist> descriptionTemplates = new ArrayList<>();
for (PlanDescriptionTemplateModel descriptionTemplate : commonModel.getDescriptionTemplates()) {
descriptionTemplates.add(this.commonModelPlanDescriptionTemplateToPersist(descriptionTemplate));
}
// add description templates from blueprint
if (commonModel.getPlanBlueprint() != null && commonModel.getPlanBlueprint().getId() != null) {
PlanBlueprintEntity blueprintEntity = this.entityManager.find(PlanBlueprintEntity.class, commonModel.getPlanBlueprint().getId(), true);
if (blueprintEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{commonModel.getPlanBlueprint().getId(), PlanBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
org.opencdmp.commons.types.planblueprint.DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(org.opencdmp.commons.types.planblueprint.DefinitionEntity.class, blueprintEntity.getDefinition());
List<SectionEntity> sections = definition.getSections().stream().filter(SectionEntity::getHasTemplates).collect(Collectors.toList());
for (SectionEntity section: sections) {
if (section.getHasTemplates() && !this.conventionService.isListNullOrEmpty(section.getDescriptionTemplates())){
for (DescriptionTemplateEntity descriptionTemplateEntity: section.getDescriptionTemplates()){
if (descriptionTemplates.stream().filter(x -> x.getDescriptionTemplateGroupId().equals(descriptionTemplateEntity.getDescriptionTemplateGroupId()) && x.getSectionId().equals(section.getId())).findFirst().orElse(null) == null) {
PlanDescriptionTemplateModel model = new PlanDescriptionTemplateModel();
model.setDescriptionTemplateGroupId(descriptionTemplateEntity.getDescriptionTemplateGroupId());
model.setSectionId(section.getId());
descriptionTemplates.add(this.commonModelPlanDescriptionTemplateToPersist(model));
}
}
}
}
}
return descriptionTemplates.stream().filter(Objects::nonNull).toList();
}
return null;