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