add blueprint description templates on import
This commit is contained in:
parent
17b6a39c74
commit
15efa81131
|
@ -2475,12 +2475,32 @@ public class PlanServiceImpl implements PlanService {
|
||||||
return persist;
|
return persist;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<PlanDescriptionTemplatePersist> xmlPlanDescriptionTemplatesToPersist(PlanImportExport planXml){
|
private List<PlanDescriptionTemplatePersist> xmlPlanDescriptionTemplatesToPersist(PlanImportExport planXml) throws InvalidApplicationException {
|
||||||
if (!this.conventionService.isListNullOrEmpty(planXml.getDescriptionTemplates())) {
|
if (!this.conventionService.isListNullOrEmpty(planXml.getDescriptionTemplates())) {
|
||||||
List<PlanDescriptionTemplatePersist> descriptionTemplates = new ArrayList<>();
|
List<PlanDescriptionTemplatePersist> descriptionTemplates = new ArrayList<>();
|
||||||
for (PlanDescriptionTemplateImportExport descriptionTemplate : planXml.getDescriptionTemplates()) {
|
for (PlanDescriptionTemplateImportExport descriptionTemplate : planXml.getDescriptionTemplates()) {
|
||||||
descriptionTemplates.add(this.xmlPlanDescriptionTemplateToPersist(descriptionTemplate));
|
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 descriptionTemplates.stream().filter(Objects::nonNull).toList();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -2611,12 +2631,32 @@ public class PlanServiceImpl implements PlanService {
|
||||||
return plan;
|
return plan;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<PlanDescriptionTemplatePersist> commonModelPlanDescriptionTemplatesToPersist(PlanModel commonModel){
|
private List<PlanDescriptionTemplatePersist> commonModelPlanDescriptionTemplatesToPersist(PlanModel commonModel) throws InvalidApplicationException {
|
||||||
if (!this.conventionService.isListNullOrEmpty(commonModel.getDescriptionTemplates())) {
|
if (!this.conventionService.isListNullOrEmpty(commonModel.getDescriptionTemplates())) {
|
||||||
List<PlanDescriptionTemplatePersist> descriptionTemplates = new ArrayList<>();
|
List<PlanDescriptionTemplatePersist> descriptionTemplates = new ArrayList<>();
|
||||||
for (PlanDescriptionTemplateModel descriptionTemplate : commonModel.getDescriptionTemplates()) {
|
for (PlanDescriptionTemplateModel descriptionTemplate : commonModel.getDescriptionTemplates()) {
|
||||||
descriptionTemplates.add(this.commonModelPlanDescriptionTemplateToPersist(descriptionTemplate));
|
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 descriptionTemplates.stream().filter(Objects::nonNull).toList();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue