From b894342f45ae13ad005b08e21e127f101c50df78 Mon Sep 17 00:00:00 2001 From: "CITE\\amentis" Date: Fri, 30 Aug 2024 12:02:20 +0300 Subject: [PATCH] add is active filters for queries with codes --- .../description/DescriptionServiceImpl.java | 2 +- .../DescriptionTemplateServiceImpl.java | 8 ++++++-- .../service/plan/PlanServiceImpl.java | 20 +++++++++---------- .../PlanBlueprintServiceImpl.java | 2 +- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/backend/core/src/main/java/org/opencdmp/service/description/DescriptionServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/description/DescriptionServiceImpl.java index cd6e15f6e..81a216a51 100644 --- a/backend/core/src/main/java/org/opencdmp/service/description/DescriptionServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/description/DescriptionServiceImpl.java @@ -1405,7 +1405,7 @@ public class DescriptionServiceImpl implements DescriptionService { if (descriptionTemplateEntity != null){ descriptionTemplateId = descriptionTemplateEntity.getId(); } else { - descriptionTemplateEntity = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().codes(descriptionXml.getDescriptionTemplate().getCode()).first(); + descriptionTemplateEntity = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().codes(descriptionXml.getDescriptionTemplate().getCode()).versionStatuses(DescriptionTemplateVersionStatus.Current).isActive(IsActive.Active).statuses(DescriptionTemplateStatus.Finalized).first(); if (descriptionTemplateEntity == null) { throw new MyValidationException(this.errors.getDescriptionTemplateImportNotFound().getCode(), descriptionXml.getDescriptionTemplate().getCode()); } else { diff --git a/backend/core/src/main/java/org/opencdmp/service/descriptiontemplate/DescriptionTemplateServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/descriptiontemplate/DescriptionTemplateServiceImpl.java index d6e88467e..f5401a798 100644 --- a/backend/core/src/main/java/org/opencdmp/service/descriptiontemplate/DescriptionTemplateServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/descriptiontemplate/DescriptionTemplateServiceImpl.java @@ -227,7 +227,11 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic .count(); if (activeDescriptionTemplatesForTheGroup > 0) throw new MyApplicationException("Description template group id is in use please use new version endpoint"); - Long descriptionTemplateCodes = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().codes(model.getCode()).count(); + Long descriptionTemplateCodes = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking() + .codes(model.getCode()) + .excludedIds(data.getId()) + .isActive(IsActive.Active) + .count(); if (descriptionTemplateCodes > 0) throw new MyValidationException(this.errors.getDescriptionTemplateCodeExists().getCode(), this.errors.getDescriptionTemplateCodeExists().getMessage()); } @@ -839,7 +843,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic } else { if (!this.conventionService.isNullOrEmpty(importXml.getCode())){ // search by code - entity = this.queryFactory.query(DescriptionTemplateTypeQuery.class).codes(importXml.getCode()).firstAs(new BaseFieldSet().ensure(DescriptionTemplateType._id).ensure(DescriptionTemplateType._code).ensure(DescriptionTemplateType._status)); + entity = this.queryFactory.query(DescriptionTemplateTypeQuery.class).codes(importXml.getCode()).isActive(IsActive.Active).firstAs(new BaseFieldSet().ensure(DescriptionTemplateType._id).ensure(DescriptionTemplateType._code).ensure(DescriptionTemplateType._status)); if (entity != null) { if (!entity.getStatus().equals(DescriptionTemplateTypeStatus.Finalized)) throw new MyValidationException(this.errors.getDescriptionTemplateTypeImportDraft().getCode(), entity.getCode()); return entity.getId(); diff --git a/backend/core/src/main/java/org/opencdmp/service/plan/PlanServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/plan/PlanServiceImpl.java index 1aa26e97f..769066c20 100644 --- a/backend/core/src/main/java/org/opencdmp/service/plan/PlanServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/plan/PlanServiceImpl.java @@ -1073,7 +1073,7 @@ public class PlanServiceImpl implements PlanService { if (blueprintEntityByTenant == null){ blueprintEntityByTenant = this.queryFactory.query(PlanBlueprintQuery.class).disableTracking().groupIds(existingBlueprintEntity.getGroupId()).versionStatuses(PlanBlueprintVersionStatus.Current).isActive(IsActive.Active).statuses(PlanBlueprintStatus.Finalized).first(); if (blueprintEntityByTenant == null){ - blueprintEntityByTenant = this.queryFactory.query(PlanBlueprintQuery.class).disableTracking().codes(existingBlueprintEntity.getCode()).first(); + blueprintEntityByTenant = this.queryFactory.query(PlanBlueprintQuery.class).disableTracking().codes(existingBlueprintEntity.getCode()).versionStatuses(PlanBlueprintVersionStatus.Current).isActive(IsActive.Active).first(); if (blueprintEntityByTenant == null) { throw new MyValidationException(this.errors.getPlanBlueprintImportNotFound().getCode(), existingBlueprintEntity.getCode()); } @@ -1157,14 +1157,14 @@ public class PlanServiceImpl implements PlanService { DescriptionTemplateTypeEntity existingDescriptionTemplateType = descriptionTemplateTypes.stream().filter(x -> x.getId().equals(existingDescriptionTemplate.getTypeId())).findFirst().orElse(null); if (existingDescriptionTemplateType != null) { DescriptionTemplateTypeEntity existingTenantTemplateType = this.queryFactory.query(DescriptionTemplateTypeQuery.class).ids(existingDescriptionTemplateType.getId()).first(); - if (existingTenantTemplateType == null) existingTenantTemplateType = this.queryFactory.query(DescriptionTemplateTypeQuery.class).codes(existingDescriptionTemplateType.getCode()).first(); + if (existingTenantTemplateType == null) existingTenantTemplateType = this.queryFactory.query(DescriptionTemplateTypeQuery.class).codes(existingDescriptionTemplateType.getCode()).isActive(IsActive.Active).first(); if (existingTenantTemplateType == null) throw new MyValidationException(this.errors.getDescriptionTemplateTypeImportNotFound().getCode(), existingTenantTemplateType.getCode()); if (!existingTenantTemplateType.getStatus().equals(DescriptionTemplateTypeStatus.Finalized)) throw new MyValidationException(this.errors.getDescriptionTemplateTypeImportDraft().getCode(), existingTenantTemplateType.getCode()); } org.opencdmp.data.DescriptionTemplateEntity existingTenantTemplate = this.queryFactory.query(DescriptionTemplateQuery.class).ids(existingDescriptionTemplate.getId()).first(); if (existingTenantTemplate == null) existingTenantTemplate = this.queryFactory.query(DescriptionTemplateQuery.class).groupIds(existingDescriptionTemplate.getId()).first(); - if (existingTenantTemplate == null) existingTenantTemplate = this.queryFactory.query(DescriptionTemplateQuery.class).codes(existingDescriptionTemplate.getCode()).first(); + if (existingTenantTemplate == null) existingTenantTemplate = this.queryFactory.query(DescriptionTemplateQuery.class).codes(existingDescriptionTemplate.getCode()).versionStatuses(DescriptionTemplateVersionStatus.Current).isActive(IsActive.Active).first(); if (existingTenantTemplate == null) throw new MyValidationException(this.errors.getDescriptionTemplateImportNotFound().getCode(), existingTenantTemplate.getCode()); if (!existingTenantTemplate.getStatus().equals(DescriptionTemplateStatus.Finalized)) throw new MyValidationException(this.errors.getPlanDescriptionTemplateImportDraft().getCode(), existingTenantTemplate.getCode()); @@ -2297,8 +2297,8 @@ public class PlanServiceImpl implements PlanService { persist.setLanguage(planXml.getLanguage()); persist.setUsers(this.xmlToPlanUsersPersist(planXml)); //TODO ignore users not exists. by id betters solution persist.setProperties(this.xmlToPlanPropertiesPersist(planXml)); - persist.setDescriptionTemplates(this.xmlPlanDescriptionTemplatesToPersist(planXml)); //TODO maybe we should create templates if not exists persist.setBlueprint(this.xmlPlanBlueprintToPersist(planXml)); + persist.setDescriptionTemplates(this.xmlPlanDescriptionTemplatesToPersist(planXml, persist.getBlueprint())); //TODO maybe we should create templates if not exists org.opencdmp.commons.types.planblueprint.DefinitionEntity definition = null; if (persist.getBlueprint() != null) { @@ -2335,7 +2335,7 @@ public class PlanServiceImpl implements PlanService { if (!planBlueprintEntity.getStatus().equals(PlanBlueprintStatus.Finalized)) throw new MyValidationException(this.errors.getPlanBlueprintImportDraft().getCode(), planBlueprintEntity.getCode()); return planBlueprintEntity.getId(); } else { - planBlueprintEntity = !this.conventionService.isNullOrEmpty(planXml.getBlueprint().getCode()) ? this.queryFactory.query(PlanBlueprintQuery.class).disableTracking().codes(planXml.getBlueprint().getCode()).first() : null; + planBlueprintEntity = !this.conventionService.isNullOrEmpty(planXml.getBlueprint().getCode()) ? this.queryFactory.query(PlanBlueprintQuery.class).disableTracking().codes(planXml.getBlueprint().getCode()).versionStatuses(PlanBlueprintVersionStatus.Current).isActive(IsActive.Active).first() : null; if (planBlueprintEntity == null) { throw new MyValidationException(this.errors.getPlanBlueprintImportNotFound().getCode(), planXml.getBlueprint().getCode()); } else { @@ -2475,15 +2475,15 @@ public class PlanServiceImpl implements PlanService { return persist; } - private List xmlPlanDescriptionTemplatesToPersist(PlanImportExport planXml) throws InvalidApplicationException { + private List xmlPlanDescriptionTemplatesToPersist(PlanImportExport planXml, UUID blueprintId) throws InvalidApplicationException { if (!this.conventionService.isListNullOrEmpty(planXml.getDescriptionTemplates())) { List 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 (blueprintId != null) { + PlanBlueprintEntity blueprintEntity = this.entityManager.find(PlanBlueprintEntity.class, blueprintId, 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 sections = definition.getSections().stream().filter(SectionEntity::getHasTemplates).collect(Collectors.toList()); @@ -2512,13 +2512,13 @@ public class PlanServiceImpl implements PlanService { PlanDescriptionTemplatePersist persist = new PlanDescriptionTemplatePersist(); - org.opencdmp.data.DescriptionTemplateEntity data = importXml.getDescriptionTemplateGroupId() != null ? this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().groupIds(importXml.getDescriptionTemplateGroupId()).disableTracking().firstAs(new BaseFieldSet().ensure(DescriptionTemplate._groupId).ensure(DescriptionTemplate._status).ensure(DescriptionTemplate._code)) : null; + org.opencdmp.data.DescriptionTemplateEntity data = importXml.getDescriptionTemplateGroupId() != null ? this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().groupIds(importXml.getDescriptionTemplateGroupId()).isActive(IsActive.Active).disableTracking().firstAs(new BaseFieldSet().ensure(DescriptionTemplate._groupId).ensure(DescriptionTemplate._status).ensure(DescriptionTemplate._code)) : null; if (data != null ) { if (!data.getStatus().equals(DescriptionTemplateStatus.Finalized)) throw new MyValidationException(this.errors.getPlanDescriptionTemplateImportDraft().getCode(), data.getCode()); persist.setDescriptionTemplateGroupId(importXml.getDescriptionTemplateGroupId()); } else { if (!this.conventionService.isNullOrEmpty(importXml.getDescriptionTemplateCode())) { - data = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().codes(importXml.getDescriptionTemplateCode()).disableTracking().firstAs(new BaseFieldSet().ensure(DescriptionTemplate._code).ensure(DescriptionTemplate._groupId).ensure(DescriptionTemplate._status)); + data = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().codes(importXml.getDescriptionTemplateCode()).isActive(IsActive.Active).disableTracking().firstAs(new BaseFieldSet().ensure(DescriptionTemplate._code).ensure(DescriptionTemplate._groupId).ensure(DescriptionTemplate._status)); if (data != null) { if (!data.getStatus().equals(DescriptionTemplateStatus.Finalized)) throw new MyValidationException(this.errors.getPlanDescriptionTemplateImportDraft().getCode(), data.getCode()); persist.setDescriptionTemplateGroupId(data.getGroupId()); diff --git a/backend/core/src/main/java/org/opencdmp/service/planblueprint/PlanBlueprintServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/planblueprint/PlanBlueprintServiceImpl.java index 8951f6bdf..90b7e5bc5 100644 --- a/backend/core/src/main/java/org/opencdmp/service/planblueprint/PlanBlueprintServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/planblueprint/PlanBlueprintServiceImpl.java @@ -823,7 +823,7 @@ public class PlanBlueprintServiceImpl implements PlanBlueprintService { persist.setDescriptionTemplateGroupId(importXml.getDescriptionTemplateGroupId()); } else { if (!this.conventionService.isNullOrEmpty(importXml.getDescriptionTemplateCode())) { - data = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().codes(importXml.getDescriptionTemplateCode()).disableTracking().firstAs(new BaseFieldSet().ensure(DescriptionTemplate._code).ensure(DescriptionTemplate._groupId).ensure(DescriptionTemplate._status)); + data = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().codes(importXml.getDescriptionTemplateCode()).isActive(IsActive.Active).disableTracking().firstAs(new BaseFieldSet().ensure(DescriptionTemplate._code).ensure(DescriptionTemplate._groupId).ensure(DescriptionTemplate._status)); if (data != null) { if (!data.getStatus().equals(DescriptionTemplateStatus.Finalized)) throw new MyValidationException(this.errors.getBlueprintDescriptionTemplateImportDraft().getCode(), data.getCode()); persist.setDescriptionTemplateGroupId(data.getGroupId());