From a172defde8284fa587afc5a7c9814e73ae78f5cf Mon Sep 17 00:00:00 2001 From: "CITE\\dtziotzios" Date: Mon, 15 Jul 2024 10:34:23 +0300 Subject: [PATCH] uasage limit changes --- .../service/usagelimit/UsageLimitService.java | 2 +- .../service/usagelimit/UsageLimitServiceImpl.java | 12 +++--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/backend/core/src/main/java/org/opencdmp/service/usagelimit/UsageLimitService.java b/backend/core/src/main/java/org/opencdmp/service/usagelimit/UsageLimitService.java index 4de0d621e..cedcad0df 100644 --- a/backend/core/src/main/java/org/opencdmp/service/usagelimit/UsageLimitService.java +++ b/backend/core/src/main/java/org/opencdmp/service/usagelimit/UsageLimitService.java @@ -18,6 +18,6 @@ public interface UsageLimitService { void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException; - void checkIncrease(UsageLimitTargetMetric metric); + void checkIncrease(UsageLimitTargetMetric metric) throws InvalidApplicationException; } 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 552f427cc..58d68dede 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 @@ -130,7 +130,7 @@ public class UsageLimitServiceImpl implements UsageLimitService { this.deleterFactory.deleter(UsageLimitDeleter.class).deleteAndSaveByIds(List.of(id)); } - public void checkIncrease(UsageLimitTargetMetric metric) { + public void checkIncrease(UsageLimitTargetMetric metric) throws InvalidApplicationException { if (usageLimitProperties.getEnabled() == null || !usageLimitProperties.getEnabled()) return; @@ -141,20 +141,14 @@ public class UsageLimitServiceImpl implements UsageLimitService { try { this.tenantEntityManager.loadExplicitTenantFilters(); UsageLimitEntity usageLimitEntity = this.queryFactory.query(UsageLimitQuery.class).disableTracking().usageLimitTargetMetrics(metric).isActive(IsActive.Active).firstAs(new BaseFieldSet().ensure(UsageLimit._targetMetric).ensure(UsageLimit._value)); - if (usageLimitEntity != null && currentValue > usageLimitEntity.getValue()) throw new MyValidationException(this.errors.getUsageLimitException().getCode(), this.errors.getUsageLimitException().getMessage()); + if (usageLimitEntity != null && currentValue >= usageLimitEntity.getValue()) throw new MyValidationException(this.errors.getUsageLimitException().getCode(), this.errors.getUsageLimitException().getMessage()); } catch (InvalidApplicationException e) { log.error(e.getMessage(), e); throw new MyApplicationException(e.getMessage()); } finally { - try { - this.tenantEntityManager.reloadTenantFilters(); - } catch (InvalidApplicationException e) { - log.error(e.getMessage(), e); - throw new MyApplicationException(e.getMessage()); - } + this.tenantEntityManager.reloadTenantFilters(); } } - }