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) {
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);
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;

View File

@ -125,3 +125,6 @@ error-thesaurus:
usageLimitException:
code: 145
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,
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");
}

View File

@ -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!",

View File

@ -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!",

View File

@ -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!",

View File

@ -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!",

View File

@ -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": "Προσοχή!",

View File

@ -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!",

View File

@ -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!",

View File

@ -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!",

View File

@ -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!",

View File

@ -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!",

View File

@ -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ı!",