add is active filters for queries with codes

This commit is contained in:
CITE\amentis 2024-08-30 12:02:20 +03:00
parent 514f9990b9
commit b894342f45
4 changed files with 18 additions and 14 deletions

View File

@ -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 {

View File

@ -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();

View File

@ -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<PlanDescriptionTemplatePersist> xmlPlanDescriptionTemplatesToPersist(PlanImportExport planXml) throws InvalidApplicationException {
private List<PlanDescriptionTemplatePersist> xmlPlanDescriptionTemplatesToPersist(PlanImportExport planXml, UUID blueprintId) 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 (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<SectionEntity> 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());

View File

@ -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());