From 3d8a654dbd6998a9a7132d2cfb2bea449688c499 Mon Sep 17 00:00:00 2001 From: amentis Date: Wed, 17 Jul 2024 11:04:17 +0300 Subject: [PATCH] fixes --- .../opencdmp/service/usagelimit/UsageLimitServiceImpl.java | 7 +++++-- backend/web/src/main/resources/config/queue.yml | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/core/src/main/java/org/opencdmp/service/usagelimit/UsageLimitServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/usagelimit/UsageLimitServiceImpl.java index ab439ee6c..381abf5ef 100644 --- a/backend/core/src/main/java/org/opencdmp/service/usagelimit/UsageLimitServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/usagelimit/UsageLimitServiceImpl.java @@ -95,10 +95,10 @@ public class UsageLimitServiceImpl implements UsageLimitService { this.authorizationService.authorizeForce(Permission.EditUsageLimit); + List existingUsageLimits; try { this.tenantEntityManager.loadExplicitTenantFilters(); - UsageLimitQuery query = this.queryFactory.query(UsageLimitQuery.class).disableTracking().usageLimitTargetMetrics(model.getTargetMetric()).isActive(IsActive.Active); - if (query != null && query.count() > 0) throw new MyValidationException(this.errors.getUsageLimitMetricAlreadyExists().getCode(), this.errors.getUsageLimitMetricAlreadyExists().getMessage()); + existingUsageLimits = this.queryFactory.query(UsageLimitQuery.class).disableTracking().isActive(IsActive.Active).collectAs((new BaseFieldSet().ensure(UsageLimit._label).ensure(UsageLimit._targetMetric).ensure(UsageLimit._value))); } catch (InvalidApplicationException e) { log.error(e.getMessage(), e); @@ -113,8 +113,11 @@ public class UsageLimitServiceImpl implements UsageLimitService { if (isUpdate) { data = this.entityManager.find(UsageLimitEntity.class, model.getId()); if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), UsageLimit.class.getSimpleName()}, LocaleContextHolder.getLocale())); + if (!data.getTargetMetric().equals(model.getTargetMetric()) && existingUsageLimits != null && !existingUsageLimits.isEmpty() && existingUsageLimits.stream().filter(x -> x.getTargetMetric().equals(model.getTargetMetric())).findFirst().orElse(null) != null) throw new MyValidationException(this.errors.getUsageLimitMetricAlreadyExists().getCode(), this.errors.getUsageLimitMetricAlreadyExists().getMessage()); if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage()); } else { + if (existingUsageLimits != null && !existingUsageLimits.isEmpty() && existingUsageLimits.stream().filter(x -> x.getTargetMetric().equals(model.getTargetMetric())).findFirst().orElse(null) != null) throw new MyValidationException(this.errors.getUsageLimitMetricAlreadyExists().getCode(), this.errors.getUsageLimitMetricAlreadyExists().getMessage()); + data = new UsageLimitEntity(); data.setId(UUID.randomUUID()); data.setIsActive(IsActive.Active); diff --git a/backend/web/src/main/resources/config/queue.yml b/backend/web/src/main/resources/config/queue.yml index 8a44f3126..8eee6adcd 100644 --- a/backend/web/src/main/resources/config/queue.yml +++ b/backend/web/src/main/resources/config/queue.yml @@ -42,7 +42,7 @@ queue: annotation-entities-touch-topic: annotation.entities.touch annotation-entities-removal-topic: annotation.entities.remove what-you-know-about-me-completed-topic: whatyouknowaboutme.completed - accounting-entry-created-topic: accountingentry.created + accounting-entry-created-topic: accountingentry.create generate-file-topic: generate.file rabbitmq: enable: true