add validation for duplicate usage limit metric in one tenant

This commit is contained in:
amentis 2024-07-15 17:26:56 +03:00
parent 79acc134f9
commit e178116434
15 changed files with 51 additions and 12 deletions

View File

@ -398,4 +398,14 @@ public class ErrorThesaurusProperties {
public void setUsageLimitException(ErrorDescription usageLimitException) { public void setUsageLimitException(ErrorDescription usageLimitException) {
this.usageLimitException = usageLimitException; this.usageLimitException = usageLimitException;
} }
private ErrorDescription usageLimitMetricAlreadyExists;
public ErrorDescription getUsageLimitMetricAlreadyExists() {
return usageLimitMetricAlreadyExists;
}
public void setUsageLimitMetricAlreadyExists(ErrorDescription usageLimitMetricAlreadyExists) {
this.usageLimitMetricAlreadyExists = usageLimitMetricAlreadyExists;
}
} }

View File

@ -95,6 +95,18 @@ public class UsageLimitServiceImpl implements UsageLimitService {
this.authorizationService.authorizeForce(Permission.EditUsageLimit); 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()); Boolean isUpdate = this.conventionService.isValidGuid(model.getId());
UsageLimitEntity data; UsageLimitEntity data;

View File

@ -124,4 +124,7 @@ error-thesaurus:
message: Max descriptions exceeded for this plan message: Max descriptions exceeded for this plan
usageLimitException: usageLimitException:
code: 145 code: 145
message: Usage limit exception for this target metric message: Usage limit exception for this target metric
usageLimitMetricAlreadyExists:
code: 146
message: Usage limit metric is already selected as target

View File

@ -41,6 +41,7 @@ export enum ResponseErrorCode {
RequestHasExpired = 143, RequestHasExpired = 143,
MaxDescriptionsExceeded = 144, MaxDescriptionsExceeded = 144,
UsageLimitException = 145, UsageLimitException = 145,
UsageLimitMetricAlreadyExists = 146,
// Notification & Annotation Errors // Notification & Annotation Errors
InvalidApiKey = 200, InvalidApiKey = 200,
@ -157,6 +158,8 @@ export class ResponseErrorCodeHelper {
return language.instant("GENERAL.BACKEND-ERRORS.MAX-DESCRIPTION-EXCEEDED"); return language.instant("GENERAL.BACKEND-ERRORS.MAX-DESCRIPTION-EXCEEDED");
case ResponseErrorCode.UsageLimitException: case ResponseErrorCode.UsageLimitException:
return language.instant("GENERAL.BACKEND-ERRORS.USAGE-LIMIT-EXCEPTION"); return language.instant("GENERAL.BACKEND-ERRORS.USAGE-LIMIT-EXCEPTION");
case ResponseErrorCode.UsageLimitMetricAlreadyExists:
return language.instant("GENERAL.BACKEND-ERRORS.USAGE-LIMIT-METRIC-ALLREADY-EXISTS");
default: default:
return language.instant("GENERAL.SNACK-BAR.NOT-FOUND"); return language.instant("GENERAL.SNACK-BAR.NOT-FOUND");
} }

View File

@ -80,7 +80,8 @@
"INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed",
"REQUEST-HAS-EXPIRED": "Request has expired", "REQUEST-HAS-EXPIRED": "Request has expired",
"MAX-DESCRIPTION-EXCEEDED": "This plan has reached the maximun descriptions for this description template", "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": { "FORM-VALIDATION-DISPLAY-DIALOG": {
"WARNING": "Kontuz!", "WARNING": "Kontuz!",

View File

@ -80,7 +80,8 @@
"INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed",
"REQUEST-HAS-EXPIRED": "Request has expired", "REQUEST-HAS-EXPIRED": "Request has expired",
"MAX-DESCRIPTION-EXCEEDED": "This plan has reached the maximun descriptions for this description template", "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": { "FORM-VALIDATION-DISPLAY-DIALOG": {
"WARNING": "Warnung!", "WARNING": "Warnung!",

View File

@ -80,7 +80,8 @@
"INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed",
"REQUEST-HAS-EXPIRED": "Request has expired", "REQUEST-HAS-EXPIRED": "Request has expired",
"MAX-DESCRIPTION-EXCEEDED": "This plan has reached the maximun descriptions for this description template", "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": { "FORM-VALIDATION-DISPLAY-DIALOG": {
"WARNING": "Warning!", "WARNING": "Warning!",

View File

@ -80,7 +80,8 @@
"INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed",
"REQUEST-HAS-EXPIRED": "Request has expired", "REQUEST-HAS-EXPIRED": "Request has expired",
"MAX-DESCRIPTION-EXCEEDED": "This plan has reached the maximun descriptions for this description template", "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": { "FORM-VALIDATION-DISPLAY-DIALOG": {
"WARNING": "Atención!", "WARNING": "Atención!",

View File

@ -80,7 +80,8 @@
"INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed",
"REQUEST-HAS-EXPIRED": "Request has expired", "REQUEST-HAS-EXPIRED": "Request has expired",
"MAX-DESCRIPTION-EXCEEDED": "This plan has reached the maximun descriptions for this description template", "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": { "FORM-VALIDATION-DISPLAY-DIALOG": {
"WARNING": "Προσοχή!", "WARNING": "Προσοχή!",

View File

@ -80,7 +80,8 @@
"INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed",
"REQUEST-HAS-EXPIRED": "Request has expired", "REQUEST-HAS-EXPIRED": "Request has expired",
"MAX-DESCRIPTION-EXCEEDED": "This plan has reached the maximun descriptions for this description template", "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": { "FORM-VALIDATION-DISPLAY-DIALOG": {
"WARNING": "Oprez!", "WARNING": "Oprez!",

View File

@ -80,7 +80,8 @@
"INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed",
"REQUEST-HAS-EXPIRED": "Request has expired", "REQUEST-HAS-EXPIRED": "Request has expired",
"MAX-DESCRIPTION-EXCEEDED": "This plan has reached the maximun descriptions for this description template", "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": { "FORM-VALIDATION-DISPLAY-DIALOG": {
"WARNING": "Ostrzeżenie!", "WARNING": "Ostrzeżenie!",

View File

@ -80,7 +80,8 @@
"INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed",
"REQUEST-HAS-EXPIRED": "Request has expired", "REQUEST-HAS-EXPIRED": "Request has expired",
"MAX-DESCRIPTION-EXCEEDED": "This plan has reached the maximun descriptions for this description template", "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": { "FORM-VALIDATION-DISPLAY-DIALOG": {
"WARNING": "Atenção!", "WARNING": "Atenção!",

View File

@ -80,7 +80,8 @@
"INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed",
"REQUEST-HAS-EXPIRED": "Request has expired", "REQUEST-HAS-EXPIRED": "Request has expired",
"MAX-DESCRIPTION-EXCEEDED": "This plan has reached the maximun descriptions for this description template", "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": { "FORM-VALIDATION-DISPLAY-DIALOG": {
"WARNING": "Upozornenie!", "WARNING": "Upozornenie!",

View File

@ -80,7 +80,8 @@
"INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed",
"REQUEST-HAS-EXPIRED": "Request has expired", "REQUEST-HAS-EXPIRED": "Request has expired",
"MAX-DESCRIPTION-EXCEEDED": "This plan has reached the maximun descriptions for this description template", "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": { "FORM-VALIDATION-DISPLAY-DIALOG": {
"WARNING": "Oprez!", "WARNING": "Oprez!",

View File

@ -80,7 +80,8 @@
"INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed",
"REQUEST-HAS-EXPIRED": "Request has expired", "REQUEST-HAS-EXPIRED": "Request has expired",
"MAX-DESCRIPTION-EXCEEDED": "This plan has reached the maximun descriptions for this description template", "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": { "FORM-VALIDATION-DISPLAY-DIALOG": {
"WARNING": "Uyarı!", "WARNING": "Uyarı!",