new version changes

This commit is contained in:
amentis 2024-07-22 14:00:59 +03:00
parent a88bb0a58e
commit 5e6c42ffdf
1 changed files with 37 additions and 21 deletions

View File

@ -446,7 +446,7 @@ public class PlanServiceImpl implements PlanService {
.planIds(model.getId())
.isActives(IsActive.Active)
.collect();
List<PlanDescriptionTemplateEntity> planDescriptionTemplates = this.queryFactory.query(PlanDescriptionTemplateQuery.class).disableTracking()
List<PlanDescriptionTemplateEntity> oldPlanDescriptionTemplates = this.queryFactory.query(PlanDescriptionTemplateQuery.class).disableTracking()
.planIds(model.getId())
.isActive(IsActive.Active)
.collect();
@ -514,20 +514,50 @@ public class PlanServiceImpl implements PlanService {
}
}
List<PlanDescriptionTemplateEntity> newPlanDescriptionTemplateEntities = this.queryFactory.query(PlanDescriptionTemplateQuery.class).disableTracking().planIds(newPlan.getId()).isActive(IsActive.Active).collect();
List<PlanDescriptionTemplateEntity> newPlanDescriptionTemplateEntitiesEntities = this.queryFactory.query(PlanDescriptionTemplateQuery.class).disableTracking().planIds(newPlan.getId()).isActive(IsActive.Active).collect();
List<SectionEntity> sections = definition.getSections().stream().filter(SectionEntity::getHasTemplates).collect(Collectors.toList());
if (!this.conventionService.isListNullOrEmpty(oldPlanDescriptionTemplates)) {
for (PlanDescriptionTemplateEntity oldPlanDescriptionTemplate : oldPlanDescriptionTemplates) {
for (SectionEntity section : sections) {
if (section.getId().equals(oldPlanDescriptionTemplate.getSectionId())) {
PlanDescriptionTemplateEntity oldDescriptionTemplateEntity = oldPlanDescriptionTemplates.stream().filter(x -> x.getSectionId().equals(section.getId()) && x.getDescriptionTemplateGroupId().equals(oldPlanDescriptionTemplate.getDescriptionTemplateGroupId())).findFirst().orElse(null);
boolean isDescriptionTemplateAlreadyInPlan = false;
if (!this.conventionService.isListNullOrEmpty(newPlanDescriptionTemplateEntitiesEntities)) {
PlanDescriptionTemplateEntity existingBlueprintDescriptionTemplateEntity = newPlanDescriptionTemplateEntitiesEntities.stream().filter(x -> x.getSectionId().equals(section.getId()) && x.getDescriptionTemplateGroupId().equals(oldPlanDescriptionTemplate.getDescriptionTemplateGroupId())).findFirst().orElse(null);
isDescriptionTemplateAlreadyInPlan = existingBlueprintDescriptionTemplateEntity != null;
}
if (oldDescriptionTemplateEntity != null && !isDescriptionTemplateAlreadyInPlan) {
PlanDescriptionTemplateEntity newTemplate = new PlanDescriptionTemplateEntity();
newTemplate.setId(UUID.randomUUID());
newTemplate.setPlanId(newPlan.getId());
newTemplate.setDescriptionTemplateGroupId(oldPlanDescriptionTemplate.getDescriptionTemplateGroupId());
newTemplate.setSectionId(section.getId());
newTemplate.setCreatedAt(Instant.now());
newTemplate.setUpdatedAt(Instant.now());
newTemplate.setIsActive(IsActive.Active);
this.entityManager.persist(newTemplate);
this.entityManager.flush();
newPlanDescriptionTemplateEntitiesEntities.add(newTemplate);
}
}
}
}
}
if (!oldPlanEntity.getBlueprintId().equals(blueprintEntity.getId())){
// add description templates if exists in new blueprint
List<SectionEntity> sections = definition.getSections().stream().filter(SectionEntity::getHasTemplates).collect(Collectors.toList());
if (!this.conventionService.isListNullOrEmpty(sections)){
for (SectionEntity section: sections) {
if (!this.conventionService.isListNullOrEmpty(section.getDescriptionTemplates())){
if (!this.conventionService.isListNullOrEmpty(section.getDescriptionTemplates()) && section.getHasTemplates()){
// new blueprint templates
for (DescriptionTemplateEntity blueprintDescriptionTemplate: section.getDescriptionTemplates()) {
boolean isDescriptionTemplateAlreadyInPlan = false;
if (!this.conventionService.isListNullOrEmpty(newPlanDescriptionTemplateEntities)) {
PlanDescriptionTemplateEntity existingBlueprintDescriptionTemplateEntity = newPlanDescriptionTemplateEntities.stream().filter(x -> x.getSectionId().equals(section.getId()) && x.getDescriptionTemplateGroupId().equals(blueprintDescriptionTemplate.getDescriptionTemplateGroupId())).findFirst().orElse(null);
if (!this.conventionService.isListNullOrEmpty(newPlanDescriptionTemplateEntitiesEntities)) {
PlanDescriptionTemplateEntity existingBlueprintDescriptionTemplateEntity = newPlanDescriptionTemplateEntitiesEntities.stream().filter(x -> x.getSectionId().equals(section.getId()) && x.getDescriptionTemplateGroupId().equals(blueprintDescriptionTemplate.getDescriptionTemplateGroupId())).findFirst().orElse(null);
isDescriptionTemplateAlreadyInPlan = existingBlueprintDescriptionTemplateEntity != null;
}
@ -542,27 +572,13 @@ public class PlanServiceImpl implements PlanService {
newTemplate.setIsActive(IsActive.Active);
this.entityManager.persist(newTemplate);
this.entityManager.flush();
newPlanDescriptionTemplateEntitiesEntities.add(newTemplate);
}
}
}
}
}
}
else {
for (PlanDescriptionTemplateEntity oldPlanDescriptionTemplate : planDescriptionTemplates) {
if (newPlanDescriptionTemplateEntities.stream().filter(x -> x.getSectionId().equals(oldPlanDescriptionTemplate.getSectionId()) && x.getDescriptionTemplateGroupId().equals(oldPlanDescriptionTemplate.getDescriptionTemplateGroupId())).findFirst().orElse(null) == null){
PlanDescriptionTemplateEntity newTemplate = new PlanDescriptionTemplateEntity();
newTemplate.setId(UUID.randomUUID());
newTemplate.setPlanId(newPlan.getId());
newTemplate.setDescriptionTemplateGroupId(oldPlanDescriptionTemplate.getDescriptionTemplateGroupId());
newTemplate.setSectionId(oldPlanDescriptionTemplate.getSectionId());
newTemplate.setCreatedAt(Instant.now());
newTemplate.setUpdatedAt(Instant.now());
newTemplate.setIsActive(IsActive.Active);
this.entityManager.persist(newTemplate);
}
}
}
this.entityManager.flush();