From e1781164349df43ee596adb17fb493435671ecb5 Mon Sep 17 00:00:00 2001 From: amentis Date: Mon, 15 Jul 2024 17:26:56 +0300 Subject: [PATCH] add validation for duplicate usage limit metric in one tenant --- .../opencdmp/errorcode/ErrorThesaurusProperties.java | 10 ++++++++++ .../service/usagelimit/UsageLimitServiceImpl.java | 12 ++++++++++++ backend/web/src/main/resources/config/errors.yml | 5 ++++- .../src/app/core/common/enum/respone-error-code.ts | 3 +++ frontend/src/assets/i18n/baq.json | 3 ++- frontend/src/assets/i18n/de.json | 3 ++- frontend/src/assets/i18n/en.json | 3 ++- frontend/src/assets/i18n/es.json | 3 ++- frontend/src/assets/i18n/gr.json | 3 ++- frontend/src/assets/i18n/hr.json | 3 ++- frontend/src/assets/i18n/pl.json | 3 ++- frontend/src/assets/i18n/pt.json | 3 ++- frontend/src/assets/i18n/sk.json | 3 ++- frontend/src/assets/i18n/sr.json | 3 ++- frontend/src/assets/i18n/tr.json | 3 ++- 15 files changed, 51 insertions(+), 12 deletions(-) diff --git a/backend/core/src/main/java/org/opencdmp/errorcode/ErrorThesaurusProperties.java b/backend/core/src/main/java/org/opencdmp/errorcode/ErrorThesaurusProperties.java index 8baa57b70..e5a308716 100644 --- a/backend/core/src/main/java/org/opencdmp/errorcode/ErrorThesaurusProperties.java +++ b/backend/core/src/main/java/org/opencdmp/errorcode/ErrorThesaurusProperties.java @@ -398,4 +398,14 @@ public class ErrorThesaurusProperties { public void setUsageLimitException(ErrorDescription usageLimitException) { this.usageLimitException = usageLimitException; } + + private ErrorDescription usageLimitMetricAlreadyExists; + + public ErrorDescription getUsageLimitMetricAlreadyExists() { + return usageLimitMetricAlreadyExists; + } + + public void setUsageLimitMetricAlreadyExists(ErrorDescription usageLimitMetricAlreadyExists) { + this.usageLimitMetricAlreadyExists = usageLimitMetricAlreadyExists; + } } 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 93141f6d0..ab439ee6c 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,6 +95,18 @@ public class UsageLimitServiceImpl implements UsageLimitService { this.authorizationService.authorizeForce(Permission.EditUsageLimit); + 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()); + + } catch (InvalidApplicationException e) { + log.error(e.getMessage(), e); + throw new MyApplicationException(e.getMessage()); + } finally { + this.tenantEntityManager.reloadTenantFilters(); + } + Boolean isUpdate = this.conventionService.isValidGuid(model.getId()); UsageLimitEntity data; diff --git a/backend/web/src/main/resources/config/errors.yml b/backend/web/src/main/resources/config/errors.yml index 8f9f9b836..944caa928 100644 --- a/backend/web/src/main/resources/config/errors.yml +++ b/backend/web/src/main/resources/config/errors.yml @@ -124,4 +124,7 @@ error-thesaurus: message: Max descriptions exceeded for this plan usageLimitException: code: 145 - message: Usage limit exception for this target metric \ No newline at end of file + message: Usage limit exception for this target metric + usageLimitMetricAlreadyExists: + code: 146 + message: Usage limit metric is already selected as target \ No newline at end of file diff --git a/frontend/src/app/core/common/enum/respone-error-code.ts b/frontend/src/app/core/common/enum/respone-error-code.ts index c882b2da4..b00192641 100644 --- a/frontend/src/app/core/common/enum/respone-error-code.ts +++ b/frontend/src/app/core/common/enum/respone-error-code.ts @@ -41,6 +41,7 @@ export enum ResponseErrorCode { RequestHasExpired = 143, MaxDescriptionsExceeded = 144, UsageLimitException = 145, + UsageLimitMetricAlreadyExists = 146, // Notification & Annotation Errors InvalidApiKey = 200, @@ -157,6 +158,8 @@ export class ResponseErrorCodeHelper { return language.instant("GENERAL.BACKEND-ERRORS.MAX-DESCRIPTION-EXCEEDED"); case ResponseErrorCode.UsageLimitException: return language.instant("GENERAL.BACKEND-ERRORS.USAGE-LIMIT-EXCEPTION"); + case ResponseErrorCode.UsageLimitMetricAlreadyExists: + return language.instant("GENERAL.BACKEND-ERRORS.USAGE-LIMIT-METRIC-ALLREADY-EXISTS"); default: return language.instant("GENERAL.SNACK-BAR.NOT-FOUND"); } diff --git a/frontend/src/assets/i18n/baq.json b/frontend/src/assets/i18n/baq.json index 226185830..5efb749a0 100644 --- a/frontend/src/assets/i18n/baq.json +++ b/frontend/src/assets/i18n/baq.json @@ -80,7 +80,8 @@ "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", "REQUEST-HAS-EXPIRED": "Request has expired", "MAX-DESCRIPTION-EXCEEDED": "This plan has reached the maximun descriptions for this description template", - "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator." + "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator.", + "USAGE-LIMIT-METRIC-ALLREADY-EXISTS": "This usage limit metric is already defined in this tenant. Change metric or select other tenant." }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Kontuz!", diff --git a/frontend/src/assets/i18n/de.json b/frontend/src/assets/i18n/de.json index 958ff9442..ed9fba26d 100644 --- a/frontend/src/assets/i18n/de.json +++ b/frontend/src/assets/i18n/de.json @@ -80,7 +80,8 @@ "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", "REQUEST-HAS-EXPIRED": "Request has expired", "MAX-DESCRIPTION-EXCEEDED": "This plan has reached the maximun descriptions for this description template", - "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator." + "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator.", + "USAGE-LIMIT-METRIC-ALLREADY-EXISTS": "This usage limit metric is already defined in this tenant. Change metric or select other tenant." }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Warnung!", diff --git a/frontend/src/assets/i18n/en.json b/frontend/src/assets/i18n/en.json index 1c8624d96..970e61411 100644 --- a/frontend/src/assets/i18n/en.json +++ b/frontend/src/assets/i18n/en.json @@ -80,7 +80,8 @@ "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", "REQUEST-HAS-EXPIRED": "Request has expired", "MAX-DESCRIPTION-EXCEEDED": "This plan has reached the maximun descriptions for this description template", - "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator." + "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator.", + "USAGE-LIMIT-METRIC-ALLREADY-EXISTS": "This usage limit metric is already defined in this tenant. Change metric or select other tenant." }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Warning!", diff --git a/frontend/src/assets/i18n/es.json b/frontend/src/assets/i18n/es.json index f38dad6f7..dbb70abc0 100644 --- a/frontend/src/assets/i18n/es.json +++ b/frontend/src/assets/i18n/es.json @@ -80,7 +80,8 @@ "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", "REQUEST-HAS-EXPIRED": "Request has expired", "MAX-DESCRIPTION-EXCEEDED": "This plan has reached the maximun descriptions for this description template", - "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator." + "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator.", + "USAGE-LIMIT-METRIC-ALLREADY-EXISTS": "This usage limit metric is already defined in this tenant. Change metric or select other tenant." }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Atención!", diff --git a/frontend/src/assets/i18n/gr.json b/frontend/src/assets/i18n/gr.json index 0da64d929..9281664ff 100644 --- a/frontend/src/assets/i18n/gr.json +++ b/frontend/src/assets/i18n/gr.json @@ -80,7 +80,8 @@ "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", "REQUEST-HAS-EXPIRED": "Request has expired", "MAX-DESCRIPTION-EXCEEDED": "This plan has reached the maximun descriptions for this description template", - "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator." + "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator.", + "USAGE-LIMIT-METRIC-ALLREADY-EXISTS": "This usage limit metric is already defined in this tenant. Change metric or select other tenant." }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Προσοχή!", diff --git a/frontend/src/assets/i18n/hr.json b/frontend/src/assets/i18n/hr.json index a8f19394b..a0cb992fe 100644 --- a/frontend/src/assets/i18n/hr.json +++ b/frontend/src/assets/i18n/hr.json @@ -80,7 +80,8 @@ "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", "REQUEST-HAS-EXPIRED": "Request has expired", "MAX-DESCRIPTION-EXCEEDED": "This plan has reached the maximun descriptions for this description template", - "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator." + "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator.", + "USAGE-LIMIT-METRIC-ALLREADY-EXISTS": "This usage limit metric is already defined in this tenant. Change metric or select other tenant." }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Oprez!", diff --git a/frontend/src/assets/i18n/pl.json b/frontend/src/assets/i18n/pl.json index 03050ecde..341b3d0cb 100644 --- a/frontend/src/assets/i18n/pl.json +++ b/frontend/src/assets/i18n/pl.json @@ -80,7 +80,8 @@ "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", "REQUEST-HAS-EXPIRED": "Request has expired", "MAX-DESCRIPTION-EXCEEDED": "This plan has reached the maximun descriptions for this description template", - "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator." + "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator.", + "USAGE-LIMIT-METRIC-ALLREADY-EXISTS": "This usage limit metric is already defined in this tenant. Change metric or select other tenant." }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Ostrzeżenie!", diff --git a/frontend/src/assets/i18n/pt.json b/frontend/src/assets/i18n/pt.json index 756d8dd00..af3e24bf9 100644 --- a/frontend/src/assets/i18n/pt.json +++ b/frontend/src/assets/i18n/pt.json @@ -80,7 +80,8 @@ "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", "REQUEST-HAS-EXPIRED": "Request has expired", "MAX-DESCRIPTION-EXCEEDED": "This plan has reached the maximun descriptions for this description template", - "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator." + "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator.", + "USAGE-LIMIT-METRIC-ALLREADY-EXISTS": "This usage limit metric is already defined in this tenant. Change metric or select other tenant." }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Atenção!", diff --git a/frontend/src/assets/i18n/sk.json b/frontend/src/assets/i18n/sk.json index c3eec8bb8..1365594c9 100644 --- a/frontend/src/assets/i18n/sk.json +++ b/frontend/src/assets/i18n/sk.json @@ -80,7 +80,8 @@ "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", "REQUEST-HAS-EXPIRED": "Request has expired", "MAX-DESCRIPTION-EXCEEDED": "This plan has reached the maximun descriptions for this description template", - "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator." + "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator.", + "USAGE-LIMIT-METRIC-ALLREADY-EXISTS": "This usage limit metric is already defined in this tenant. Change metric or select other tenant." }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Upozornenie!", diff --git a/frontend/src/assets/i18n/sr.json b/frontend/src/assets/i18n/sr.json index ce1767f9d..0d26fd9c9 100644 --- a/frontend/src/assets/i18n/sr.json +++ b/frontend/src/assets/i18n/sr.json @@ -80,7 +80,8 @@ "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", "REQUEST-HAS-EXPIRED": "Request has expired", "MAX-DESCRIPTION-EXCEEDED": "This plan has reached the maximun descriptions for this description template", - "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator." + "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator.", + "USAGE-LIMIT-METRIC-ALLREADY-EXISTS": "This usage limit metric is already defined in this tenant. Change metric or select other tenant." }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Oprez!", diff --git a/frontend/src/assets/i18n/tr.json b/frontend/src/assets/i18n/tr.json index f3776dc23..66b2d3fd0 100644 --- a/frontend/src/assets/i18n/tr.json +++ b/frontend/src/assets/i18n/tr.json @@ -80,7 +80,8 @@ "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", "REQUEST-HAS-EXPIRED": "Request has expired", "MAX-DESCRIPTION-EXCEEDED": "This plan has reached the maximun descriptions for this description template", - "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator." + "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator.", + "USAGE-LIMIT-METRIC-ALLREADY-EXISTS": "This usage limit metric is already defined in this tenant. Change metric or select other tenant." }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Uyarı!",