diff --git a/backend/core/src/main/java/org/opencdmp/commons/enums/UsageLimitTargetMetric.java b/backend/core/src/main/java/org/opencdmp/commons/enums/UsageLimitTargetMetric.java index 0a615ddbe..5e4aaddd1 100644 --- a/backend/core/src/main/java/org/opencdmp/commons/enums/UsageLimitTargetMetric.java +++ b/backend/core/src/main/java/org/opencdmp/commons/enums/UsageLimitTargetMetric.java @@ -13,7 +13,15 @@ public enum UsageLimitTargetMetric implements DatabaseEnum { DESCRIPTION_TEMPLATE_COUNT(TargetMetrics.DescriptionTemplateCount), DESCRIPTION_TEMPLATE_TYPE_COUNT(TargetMetrics.DescriptionTemplateTypeCount), PREFILLING_SOURCES_COUNT(TargetMetrics.PrefillingSourcesCount), - REFERENCE_TYPE_COUNT(TargetMetrics.ReferenceTypeCount); + REFERENCE_TYPE_COUNT(TargetMetrics.ReferenceTypeCount), + DEPOSIT_EXECUTION_COUNT(TargetMetrics.DepositExecutionCount), + DEPOSIT_EXECUTION_COUNT_FOR(TargetMetrics.DepositExecutionCountFor_), + FILE_TRANSFORMER_EXPORT_PLAN_EXECUTION_COUNT(TargetMetrics.FileTransformerExportPlanExecutionCount), + FILE_TRANSFORMER_EXPORT_PLAN_EXECUTION_COUNT_FOR(TargetMetrics.FileTransformerExportPlanExecutionCountFor_), + FILE_TRANSFORMER_EXPORT_DESCRIPTIONS_EXECUTION_COUNT(TargetMetrics.FileTransformerExportDescriptionExecutionCount), + FILE_TRANSFORMER_EXPORT_DESCRIPTIONS_EXECUTION_COUNT_FOR(TargetMetrics.FileTransformerExportDescriptionExecutionCountFor_), + FILE_TRANSFORMER_IMPORT_PLAN_EXECUTION_COUNT(TargetMetrics.FileTransformerImportPlanExecutionCount), + FILE_TRANSFORMER_IMPORT_PLAN_EXECUTION_COUNT_FOR(TargetMetrics.FileTransformerImportPlanExecutionCountFor_); private final String value; public static class TargetMetrics { @@ -25,6 +33,14 @@ public enum UsageLimitTargetMetric implements DatabaseEnum { public static final String DescriptionTemplateTypeCount = "description_template_type_count"; public static final String PrefillingSourcesCount = "prefilling_sources_count"; public static final String ReferenceTypeCount = "reference_type_count"; + public static final String DepositExecutionCount = "deposit_execution_count"; + public static final String DepositExecutionCountFor_ = "deposit_execution_count_for_"; + public static final String FileTransformerExportPlanExecutionCount = "file_transformer_export_plan_execution_count"; + public static final String FileTransformerExportPlanExecutionCountFor_ = "file_transformer_export_plan_execution_count_for_"; + public static final String FileTransformerExportDescriptionExecutionCount = "file_transformer_export_description_execution_count"; + public static final String FileTransformerExportDescriptionExecutionCountFor_ = "file_transformer_export_description_execution_count_for_"; + public static final String FileTransformerImportPlanExecutionCount = "file_transformer_import_plan_execution_count"; + public static final String FileTransformerImportPlanExecutionCountFor_ = "file_transformer_import_plan_execution_count_for_"; } UsageLimitTargetMetric(String value) { diff --git a/backend/core/src/main/java/org/opencdmp/model/deleter/DescriptionDeleter.java b/backend/core/src/main/java/org/opencdmp/model/deleter/DescriptionDeleter.java index 726258a48..de96b3d42 100644 --- a/backend/core/src/main/java/org/opencdmp/model/deleter/DescriptionDeleter.java +++ b/backend/core/src/main/java/org/opencdmp/model/deleter/DescriptionDeleter.java @@ -1,6 +1,7 @@ package org.opencdmp.model.deleter; import org.opencdmp.commons.enums.IsActive; +import org.opencdmp.commons.enums.UsageLimitTargetMetric; import org.opencdmp.data.DescriptionEntity; import org.opencdmp.data.DescriptionReferenceEntity; import org.opencdmp.data.DescriptionTagEntity; @@ -8,6 +9,7 @@ import org.opencdmp.data.TenantEntityManager; import org.opencdmp.query.DescriptionQuery; import org.opencdmp.query.DescriptionReferenceQuery; import org.opencdmp.query.DescriptionTagQuery; +import org.opencdmp.service.accounting.AccountingService; import org.opencdmp.service.elastic.ElasticService; import gr.cite.tools.data.deleter.Deleter; import gr.cite.tools.data.deleter.DeleterFactory; @@ -40,17 +42,20 @@ public class DescriptionDeleter implements Deleter { protected final DeleterFactory deleterFactory; protected final ElasticService elasticService; + protected final AccountingService accountingService; @Autowired public DescriptionDeleter( TenantEntityManager entityManager, QueryFactory queryFactory, DeleterFactory deleterFactory, - ElasticService elasticService) { + ElasticService elasticService, + AccountingService accountingService) { this.entityManager = entityManager; this.queryFactory = queryFactory; this.deleterFactory = deleterFactory; this.elasticService = elasticService; + this.accountingService = accountingService; } public void deleteAndSaveByIds(List ids, boolean disableElastic) throws InvalidApplicationException, IOException { @@ -98,6 +103,7 @@ public class DescriptionDeleter implements Deleter { logger.trace("updated item"); if (!disableElastic) this.elasticService.deleteDescription(item); + this.accountingService.decrease(UsageLimitTargetMetric.DESCRIPTION_COUNT.getValue()); } } diff --git a/backend/core/src/main/java/org/opencdmp/model/deleter/DescriptionTemplateDeleter.java b/backend/core/src/main/java/org/opencdmp/model/deleter/DescriptionTemplateDeleter.java index 50a568403..77be6fed3 100644 --- a/backend/core/src/main/java/org/opencdmp/model/deleter/DescriptionTemplateDeleter.java +++ b/backend/core/src/main/java/org/opencdmp/model/deleter/DescriptionTemplateDeleter.java @@ -1,6 +1,7 @@ package org.opencdmp.model.deleter; import org.opencdmp.commons.enums.IsActive; +import org.opencdmp.commons.enums.UsageLimitTargetMetric; import org.opencdmp.data.DescriptionTemplateEntity; import org.opencdmp.data.TenantEntityManager; import org.opencdmp.data.UserDescriptionTemplateEntity; @@ -11,6 +12,7 @@ import gr.cite.tools.data.deleter.DeleterFactory; import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.MapLogEntry; +import org.opencdmp.service.accounting.AccountingService; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.ConfigurableBeanFactory; @@ -36,15 +38,18 @@ public class DescriptionTemplateDeleter implements Deleter { protected final DeleterFactory deleterFactory; + protected final AccountingService accountingService; + @Autowired public DescriptionTemplateDeleter( TenantEntityManager entityManager, QueryFactory queryFactory, - DeleterFactory deleterFactory - ) { + DeleterFactory deleterFactory, + AccountingService accountingService) { this.entityManager = entityManager; this.queryFactory = queryFactory; this.deleterFactory = deleterFactory; + this.accountingService = accountingService; } public void deleteAndSaveByIds(List ids) throws InvalidApplicationException { @@ -87,6 +92,7 @@ public class DescriptionTemplateDeleter implements Deleter { logger.trace("updating item"); this.entityManager.merge(item); logger.trace("updated item"); + this.accountingService.decrease(UsageLimitTargetMetric.DESCRIPTION_TEMPLATE_COUNT.getValue()); } } diff --git a/backend/core/src/main/java/org/opencdmp/model/deleter/DescriptionTemplateTypeDeleter.java b/backend/core/src/main/java/org/opencdmp/model/deleter/DescriptionTemplateTypeDeleter.java index d627470d2..e8bf34d3e 100644 --- a/backend/core/src/main/java/org/opencdmp/model/deleter/DescriptionTemplateTypeDeleter.java +++ b/backend/core/src/main/java/org/opencdmp/model/deleter/DescriptionTemplateTypeDeleter.java @@ -1,6 +1,7 @@ package org.opencdmp.model.deleter; import org.opencdmp.commons.enums.IsActive; +import org.opencdmp.commons.enums.UsageLimitTargetMetric; import org.opencdmp.data.DescriptionTemplateEntity; import org.opencdmp.data.DescriptionTemplateTypeEntity; import org.opencdmp.data.TenantEntityManager; @@ -11,6 +12,7 @@ import gr.cite.tools.data.deleter.DeleterFactory; import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.MapLogEntry; +import org.opencdmp.service.accounting.AccountingService; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.ConfigurableBeanFactory; @@ -36,15 +38,18 @@ public class DescriptionTemplateTypeDeleter implements Deleter { protected final DeleterFactory deleterFactory; + protected final AccountingService accountingService; + @Autowired public DescriptionTemplateTypeDeleter( TenantEntityManager entityManager, QueryFactory queryFactory, - DeleterFactory deleterFactory - ) { + DeleterFactory deleterFactory, + AccountingService accountingService) { this.entityManager = entityManager; this.queryFactory = queryFactory; this.deleterFactory = deleterFactory; + this.accountingService = accountingService; } public void deleteAndSaveByIds(List ids) throws InvalidApplicationException { @@ -84,6 +89,7 @@ public class DescriptionTemplateTypeDeleter implements Deleter { logger.trace("updating item"); this.entityManager.merge(item); logger.trace("updated item"); + this.accountingService.decrease(UsageLimitTargetMetric.DESCRIPTION_TEMPLATE_TYPE_COUNT.getValue()); } } diff --git a/backend/core/src/main/java/org/opencdmp/model/deleter/PlanBlueprintDeleter.java b/backend/core/src/main/java/org/opencdmp/model/deleter/PlanBlueprintDeleter.java index 3f3f2938b..ed8a938b3 100644 --- a/backend/core/src/main/java/org/opencdmp/model/deleter/PlanBlueprintDeleter.java +++ b/backend/core/src/main/java/org/opencdmp/model/deleter/PlanBlueprintDeleter.java @@ -1,6 +1,7 @@ package org.opencdmp.model.deleter; import org.opencdmp.commons.enums.IsActive; +import org.opencdmp.commons.enums.UsageLimitTargetMetric; import org.opencdmp.data.PlanBlueprintEntity; import org.opencdmp.data.TenantEntityManager; import org.opencdmp.query.PlanBlueprintQuery; @@ -9,6 +10,7 @@ import gr.cite.tools.data.deleter.DeleterFactory; import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.MapLogEntry; +import org.opencdmp.service.accounting.AccountingService; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.ConfigurableBeanFactory; @@ -33,15 +35,18 @@ public class PlanBlueprintDeleter implements Deleter { protected final DeleterFactory deleterFactory; + protected final AccountingService accountingService; + @Autowired public PlanBlueprintDeleter( TenantEntityManager entityManager, QueryFactory queryFactory, - DeleterFactory deleterFactory - ) { + DeleterFactory deleterFactory, + AccountingService accountingService) { this.entityManager = entityManager; this.queryFactory = queryFactory; this.deleterFactory = deleterFactory; + this.accountingService = accountingService; } public void deleteAndSaveByIds(List ids) throws InvalidApplicationException { @@ -73,6 +78,7 @@ public class PlanBlueprintDeleter implements Deleter { logger.trace("updating item"); this.entityManager.merge(item); logger.trace("updated item"); + this.accountingService.decrease(UsageLimitTargetMetric.BLUEPRINT_COUNT.getValue()); } } diff --git a/backend/core/src/main/java/org/opencdmp/model/deleter/PlanDeleter.java b/backend/core/src/main/java/org/opencdmp/model/deleter/PlanDeleter.java index 027eee2be..20663d2c2 100644 --- a/backend/core/src/main/java/org/opencdmp/model/deleter/PlanDeleter.java +++ b/backend/core/src/main/java/org/opencdmp/model/deleter/PlanDeleter.java @@ -9,11 +9,13 @@ import gr.cite.tools.logging.MapLogEntry; import org.opencdmp.commons.enums.EntityType; import org.opencdmp.commons.enums.IsActive; import org.opencdmp.commons.enums.PlanVersionStatus; +import org.opencdmp.commons.enums.UsageLimitTargetMetric; import org.opencdmp.data.*; import org.opencdmp.model.PlanDescriptionTemplate; import org.opencdmp.model.description.Description; import org.opencdmp.model.planreference.PlanReference; import org.opencdmp.query.*; +import org.opencdmp.service.accounting.AccountingService; import org.opencdmp.service.elastic.ElasticService; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -40,17 +42,20 @@ public class PlanDeleter implements Deleter { protected final DeleterFactory deleterFactory; protected final ElasticService elasticService; + protected final AccountingService accountingService; @Autowired public PlanDeleter( TenantEntityManager entityManager, QueryFactory queryFactory, DeleterFactory deleterFactory, - ElasticService elasticService) { + ElasticService elasticService, + AccountingService accountingService) { this.entityManager = entityManager; this.queryFactory = queryFactory; this.deleterFactory = deleterFactory; this.elasticService = elasticService; + this.accountingService = accountingService; } public void deleteAndSaveByIds(List ids, boolean disableElastic) throws InvalidApplicationException, IOException { @@ -113,6 +118,7 @@ public class PlanDeleter implements Deleter { logger.trace("updated item"); if (!disableElastic) this.elasticService.deletePlan(item); + this.accountingService.decrease(UsageLimitTargetMetric.PLAN_COUNT.getValue()); } } diff --git a/backend/core/src/main/java/org/opencdmp/model/deleter/PrefillingSourceDeleter.java b/backend/core/src/main/java/org/opencdmp/model/deleter/PrefillingSourceDeleter.java index 03b112408..0566a0cc2 100644 --- a/backend/core/src/main/java/org/opencdmp/model/deleter/PrefillingSourceDeleter.java +++ b/backend/core/src/main/java/org/opencdmp/model/deleter/PrefillingSourceDeleter.java @@ -1,6 +1,7 @@ package org.opencdmp.model.deleter; import org.opencdmp.commons.enums.IsActive; +import org.opencdmp.commons.enums.UsageLimitTargetMetric; import org.opencdmp.data.PrefillingSourceEntity; import org.opencdmp.data.TenantEntityManager; import org.opencdmp.query.PrefillingSourceQuery; @@ -9,6 +10,7 @@ import gr.cite.tools.data.deleter.DeleterFactory; import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.MapLogEntry; +import org.opencdmp.service.accounting.AccountingService; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.ConfigurableBeanFactory; @@ -31,16 +33,18 @@ public class PrefillingSourceDeleter implements Deleter { protected final QueryFactory queryFactory; protected final DeleterFactory deleterFactory; + protected final AccountingService accountingService; @Autowired public PrefillingSourceDeleter( TenantEntityManager entityManager, QueryFactory queryFactory, - DeleterFactory deleterFactory - ) { + DeleterFactory deleterFactory, + AccountingService accountingService) { this.entityManager = entityManager; this.queryFactory = queryFactory; this.deleterFactory = deleterFactory; + this.accountingService = accountingService; } public void deleteAndSaveByIds(List ids) throws InvalidApplicationException { @@ -72,6 +76,7 @@ public class PrefillingSourceDeleter implements Deleter { logger.trace("updating item"); this.entityManager.merge(item); logger.trace("updated item"); + this.accountingService.decrease(UsageLimitTargetMetric.PREFILLING_SOURCES_COUNT.getValue()); } } diff --git a/backend/core/src/main/java/org/opencdmp/model/deleter/ReferenceTypeDeleter.java b/backend/core/src/main/java/org/opencdmp/model/deleter/ReferenceTypeDeleter.java index 75a94f8a1..a22bb35eb 100644 --- a/backend/core/src/main/java/org/opencdmp/model/deleter/ReferenceTypeDeleter.java +++ b/backend/core/src/main/java/org/opencdmp/model/deleter/ReferenceTypeDeleter.java @@ -1,6 +1,7 @@ package org.opencdmp.model.deleter; import org.opencdmp.commons.enums.IsActive; +import org.opencdmp.commons.enums.UsageLimitTargetMetric; import org.opencdmp.data.ReferenceTypeEntity; import org.opencdmp.data.TenantEntityManager; import org.opencdmp.query.ReferenceTypeQuery; @@ -9,6 +10,7 @@ import gr.cite.tools.data.deleter.DeleterFactory; import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.MapLogEntry; +import org.opencdmp.service.accounting.AccountingService; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.ConfigurableBeanFactory; @@ -32,15 +34,18 @@ public class ReferenceTypeDeleter implements Deleter { protected final DeleterFactory deleterFactory; + protected final AccountingService accountingService; + @Autowired public ReferenceTypeDeleter( TenantEntityManager entityManager, QueryFactory queryFactory, - DeleterFactory deleterFactory - ) { + DeleterFactory deleterFactory, + AccountingService accountingService) { this.entityManager = entityManager; this.queryFactory = queryFactory; this.deleterFactory = deleterFactory; + this.accountingService = accountingService; } public void deleteAndSaveByIds(List ids) throws InvalidApplicationException { @@ -72,6 +77,7 @@ public class ReferenceTypeDeleter implements Deleter { logger.trace("updating item"); this.entityManager.merge(item); logger.trace("updated item"); + this.accountingService.decrease(UsageLimitTargetMetric.REFERENCE_TYPE_COUNT.getValue()); } } diff --git a/backend/core/src/main/java/org/opencdmp/service/accounting/AccountingService.java b/backend/core/src/main/java/org/opencdmp/service/accounting/AccountingService.java index 802b56c05..1a7c16a4a 100644 --- a/backend/core/src/main/java/org/opencdmp/service/accounting/AccountingService.java +++ b/backend/core/src/main/java/org/opencdmp/service/accounting/AccountingService.java @@ -6,9 +6,9 @@ public interface AccountingService { Integer getCurrentMetricValue(UsageLimitTargetMetric metric); - void set(UsageLimitTargetMetric metric); + void set(String metric); - void increase(UsageLimitTargetMetric metric); + void increase(String metric); - void decrease(UsageLimitTargetMetric metric); + void decrease(String metric); } diff --git a/backend/core/src/main/java/org/opencdmp/service/accounting/AccountingServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/accounting/AccountingServiceImpl.java index 262a74dc3..4b9be5d15 100644 --- a/backend/core/src/main/java/org/opencdmp/service/accounting/AccountingServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/accounting/AccountingServiceImpl.java @@ -39,15 +39,15 @@ public class AccountingServiceImpl implements AccountingService { return 10; } - public void set(UsageLimitTargetMetric metric) { + public void set(String metric) { //TODO } - public void increase(UsageLimitTargetMetric metric) { + public void increase(String metric) { //TODO } - public void decrease(UsageLimitTargetMetric metric) { + public void decrease(String metric) { //TODO } } diff --git a/backend/core/src/main/java/org/opencdmp/service/deposit/DepositServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/deposit/DepositServiceImpl.java index d645110a1..9594eec11 100644 --- a/backend/core/src/main/java/org/opencdmp/service/deposit/DepositServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/deposit/DepositServiceImpl.java @@ -22,6 +22,7 @@ import org.opencdmp.commons.JsonHandlingService; import org.opencdmp.commons.enums.IsActive; import org.opencdmp.commons.enums.StorageType; import org.opencdmp.commons.enums.TenantConfigurationType; +import org.opencdmp.commons.enums.UsageLimitTargetMetric; import org.opencdmp.commons.notification.NotificationProperties; import org.opencdmp.commons.scope.tenant.TenantScope; import org.opencdmp.commons.scope.user.UserScope; @@ -53,6 +54,7 @@ import org.opencdmp.query.PlanQuery; import org.opencdmp.query.PlanUserQuery; import org.opencdmp.query.TenantConfigurationQuery; import org.opencdmp.query.UserQuery; +import org.opencdmp.service.accounting.AccountingService; import org.opencdmp.service.encryption.EncryptionService; import org.opencdmp.service.entitydoi.EntityDoiService; import org.opencdmp.service.filetransformer.FileTransformerService; @@ -112,6 +114,7 @@ public class DepositServiceImpl implements DepositService { private final EncryptionService encryptionService; private final TenantProperties tenantProperties; private final DepositSourcesCacheService depositSourcesCacheService; + private final AccountingService accountingService; @Autowired public DepositServiceImpl(DepositProperties depositProperties, @@ -120,7 +123,7 @@ public class DepositServiceImpl implements DepositService { EntityDoiService doiService, QueryFactory queryFactory, MessageSource messageSource, - BuilderFactory builderFactory, DepositConfigurationCacheService depositConfigurationCacheService, FileTransformerService fileTransformerService, StorageFileService storageFileService, UserScope userScope, ValidatorFactory validatorFactory, StorageFileProperties storageFileProperties, AuthorizationContentResolver authorizationContentResolver, ConventionService conventionService, JsonHandlingService jsonHandlingService, NotificationProperties notificationProperties, NotifyIntegrationEventHandler eventHandler, TenantScope tenantScope, EncryptionService encryptionService, TenantProperties tenantProperties, DepositSourcesCacheService depositSourcesCacheService) { + BuilderFactory builderFactory, DepositConfigurationCacheService depositConfigurationCacheService, FileTransformerService fileTransformerService, StorageFileService storageFileService, UserScope userScope, ValidatorFactory validatorFactory, StorageFileProperties storageFileProperties, AuthorizationContentResolver authorizationContentResolver, ConventionService conventionService, JsonHandlingService jsonHandlingService, NotificationProperties notificationProperties, NotifyIntegrationEventHandler eventHandler, TenantScope tenantScope, EncryptionService encryptionService, TenantProperties tenantProperties, DepositSourcesCacheService depositSourcesCacheService, AccountingService accountingService) { this.depositProperties = depositProperties; this.tokenExchangeCacheService = tokenExchangeCacheService; this.authorizationService = authorizationService; @@ -143,7 +146,8 @@ public class DepositServiceImpl implements DepositService { this.encryptionService = encryptionService; this.tenantProperties = tenantProperties; this.depositSourcesCacheService = depositSourcesCacheService; - this.clients = new HashMap<>(); + this.accountingService = accountingService; + this.clients = new HashMap<>(); } private DepositClient getDepositClient(String repositoryId) throws InvalidApplicationException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { @@ -325,6 +329,10 @@ public class DepositServiceImpl implements DepositService { doiPersist.setDoi(doi); doiPersist.setEntityId(planEntity.getId()); this.sendNotification(planEntity); + + this.accountingService.increase(UsageLimitTargetMetric.DEPOSIT_EXECUTION_COUNT.getValue()); + this.increaseTargetMetricWithRepositoryId(UsageLimitTargetMetric.DEPOSIT_EXECUTION_COUNT_FOR, planDepositModel.getRepositoryId()); + return this.doiService.persist(doiPersist, true, planDepositModel.getProject()); } @@ -377,6 +385,10 @@ public class DepositServiceImpl implements DepositService { return persisted.getFileRef(); } + private void increaseTargetMetricWithRepositoryId(UsageLimitTargetMetric metric, String repositoryId){ + this.accountingService.increase(metric.getValue() + repositoryId); + } + @Override public String getLogo(String repositoryId) throws InvalidApplicationException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { this.authorizationService.authorizeForce(Permission.BrowseDeposit, Permission.DeferredAffiliation); diff --git a/backend/core/src/main/java/org/opencdmp/service/description/DescriptionServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/description/DescriptionServiceImpl.java index c62f50880..7fffedc50 100644 --- a/backend/core/src/main/java/org/opencdmp/service/description/DescriptionServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/description/DescriptionServiceImpl.java @@ -266,7 +266,7 @@ public class DescriptionServiceImpl implements DescriptionService { if (isUpdate) this.entityManager.merge(data); else { this.entityManager.persist(data); - this.accountingService.increase(UsageLimitTargetMetric.DESCRIPTION_COUNT); + this.accountingService.increase(UsageLimitTargetMetric.DESCRIPTION_COUNT.getValue()); } this.entityManager.flush(); @@ -901,7 +901,6 @@ public class DescriptionServiceImpl implements DescriptionService { this.deleterFactory.deleter(DescriptionDeleter.class).deleteAndSaveByIds(List.of(id), false); this.annotationEntityRemovalIntegrationEventHandler.handleDescription(id); - this.accountingService.decrease(UsageLimitTargetMetric.DESCRIPTION_COUNT); } //endregion diff --git a/backend/core/src/main/java/org/opencdmp/service/descriptiontemplate/DescriptionTemplateServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/descriptiontemplate/DescriptionTemplateServiceImpl.java index 1b5f22fac..7a57c6977 100644 --- a/backend/core/src/main/java/org/opencdmp/service/descriptiontemplate/DescriptionTemplateServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/descriptiontemplate/DescriptionTemplateServiceImpl.java @@ -216,7 +216,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic this.entityManager.merge(data); else { this.entityManager.persist(data); - this.accountingService.increase(UsageLimitTargetMetric.DESCRIPTION_TEMPLATE_COUNT); + this.accountingService.increase(UsageLimitTargetMetric.DESCRIPTION_TEMPLATE_COUNT.getValue()); } this.persistUsers(data.getId(), model.getUsers()); @@ -529,7 +529,6 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic } this.deleterFactory.deleter(DescriptionTemplateDeleter.class).deleteAndSaveByIds(List.of(id)); - this.accountingService.decrease(UsageLimitTargetMetric.DESCRIPTION_TEMPLATE_COUNT); } //endregion @@ -623,6 +622,8 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic this.authorizationService.authorizeForce(Permission.CreateNewVersionDescriptionTemplate); + this.usageLimitService.checkIncrease(UsageLimitTargetMetric.DESCRIPTION_TEMPLATE_COUNT); + DescriptionTemplateEntity oldDescriptionTemplateEntity = this.entityManager.find(DescriptionTemplateEntity.class, model.getId(), true); if (oldDescriptionTemplateEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale())); @@ -676,6 +677,8 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic this.entityManager.flush(); + this.accountingService.increase(UsageLimitTargetMetric.DESCRIPTION_TEMPLATE_COUNT.getValue()); + return this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(AuthorizationFlags.AllExceptPublic).build(BaseFieldSet.build(fields, DescriptionTemplate._id), data); } diff --git a/backend/core/src/main/java/org/opencdmp/service/descriptiontemplatetype/DescriptionTemplateTypeServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/descriptiontemplatetype/DescriptionTemplateTypeServiceImpl.java index 738172b00..5500fc51c 100644 --- a/backend/core/src/main/java/org/opencdmp/service/descriptiontemplatetype/DescriptionTemplateTypeServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/descriptiontemplatetype/DescriptionTemplateTypeServiceImpl.java @@ -112,7 +112,7 @@ public class DescriptionTemplateTypeServiceImpl implements DescriptionTemplateTy this.entityManager.merge(data); else{ this.entityManager.persist(data); - this.accountingService.increase(UsageLimitTargetMetric.DESCRIPTION_TEMPLATE_TYPE_COUNT); + this.accountingService.increase(UsageLimitTargetMetric.DESCRIPTION_TEMPLATE_TYPE_COUNT.getValue()); } this.entityManager.flush(); @@ -127,7 +127,6 @@ public class DescriptionTemplateTypeServiceImpl implements DescriptionTemplateTy this.authorizationService.authorizeForce(Permission.DeleteDescriptionTemplateType); this.deleterFactory.deleter(DescriptionTemplateTypeDeleter.class).deleteAndSaveByIds(List.of(id)); - this.accountingService.decrease(UsageLimitTargetMetric.DESCRIPTION_TEMPLATE_TYPE_COUNT); } } diff --git a/backend/core/src/main/java/org/opencdmp/service/filetransformer/FileTransformerServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/filetransformer/FileTransformerServiceImpl.java index f53ffff3a..ad30402b4 100644 --- a/backend/core/src/main/java/org/opencdmp/service/filetransformer/FileTransformerServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/filetransformer/FileTransformerServiceImpl.java @@ -25,6 +25,7 @@ import org.opencdmp.commons.JsonHandlingService; import org.opencdmp.commons.enums.IsActive; import org.opencdmp.commons.enums.StorageType; import org.opencdmp.commons.enums.TenantConfigurationType; +import org.opencdmp.commons.enums.UsageLimitTargetMetric; import org.opencdmp.commons.scope.tenant.TenantScope; import org.opencdmp.commons.scope.user.UserScope; import org.opencdmp.commons.types.filetransformer.FileTransformerSourceEntity; @@ -52,6 +53,7 @@ import org.opencdmp.model.plan.Plan; import org.opencdmp.model.planblueprint.PlanBlueprint; import org.opencdmp.model.tenantconfiguration.TenantConfiguration; import org.opencdmp.query.*; +import org.opencdmp.service.accounting.AccountingService; import org.opencdmp.service.encryption.EncryptionService; import org.opencdmp.service.storage.StorageFileService; import org.opencdmp.service.tenant.TenantProperties; @@ -99,10 +101,11 @@ public class FileTransformerServiceImpl implements FileTransformerService { private final JsonHandlingService jsonHandlingService; private final FileTransformerSourcesCacheService fileTransformerSourcesCacheService; private final UserScope userScope; + private final AccountingService accountingService; @Autowired public FileTransformerServiceImpl(FileTransformerProperties fileTransformerProperties, TokenExchangeCacheService tokenExchangeCacheService, FileTransformerConfigurationCacheService fileTransformerConfigurationCacheService, AuthorizationService authorizationService, - QueryFactory queryFactory, BuilderFactory builderFactory, StorageFileService storageFileService, MessageSource messageSource, ConventionService conventionService, TenantScope tenantScope, EncryptionService encryptionService, TenantProperties tenantProperties, JsonHandlingService jsonHandlingService, FileTransformerSourcesCacheService fileTransformerSourcesCacheService, UserScope userScope) { + QueryFactory queryFactory, BuilderFactory builderFactory, StorageFileService storageFileService, MessageSource messageSource, ConventionService conventionService, TenantScope tenantScope, EncryptionService encryptionService, TenantProperties tenantProperties, JsonHandlingService jsonHandlingService, FileTransformerSourcesCacheService fileTransformerSourcesCacheService, UserScope userScope, AccountingService accountingService) { this.fileTransformerProperties = fileTransformerProperties; this.tokenExchangeCacheService = tokenExchangeCacheService; this.fileTransformerConfigurationCacheService = fileTransformerConfigurationCacheService; @@ -118,6 +121,7 @@ public class FileTransformerServiceImpl implements FileTransformerService { this.jsonHandlingService = jsonHandlingService; this.fileTransformerSourcesCacheService = fileTransformerSourcesCacheService; this.userScope = userScope; + this.accountingService = accountingService; this.clients = new HashMap<>(); } @@ -268,6 +272,10 @@ public class FileTransformerServiceImpl implements FileTransformerService { byte[] data = repository.getConfiguration().isUseSharedStorage() ? this.storageFileService.readByFileRefAsBytesSafe(fileEnvelope.getFileRef(), StorageType.Transformer) : fileEnvelope.getFile(); result.setFile(data); result.setFilename(fileEnvelope.getFilename()); + + this.accountingService.increase(UsageLimitTargetMetric.FILE_TRANSFORMER_EXPORT_PLAN_EXECUTION_COUNT.getValue()); + this.increaseTargetMetricWithRepositoryId(UsageLimitTargetMetric.FILE_TRANSFORMER_EXPORT_PLAN_EXECUTION_COUNT_FOR, repositoryId); + return result; } @@ -288,6 +296,10 @@ public class FileTransformerServiceImpl implements FileTransformerService { byte[] data = repository.getConfiguration().isUseSharedStorage() ? this.storageFileService.readByFileRefAsBytesSafe(fileEnvelope.getFileRef(), StorageType.Transformer) : fileEnvelope.getFile(); //TODO: shared storage should be per repository result.setFile(data); result.setFilename(fileEnvelope.getFilename()); + + this.accountingService.increase(UsageLimitTargetMetric.FILE_TRANSFORMER_EXPORT_DESCRIPTIONS_EXECUTION_COUNT.getValue()); + this.increaseTargetMetricWithRepositoryId(UsageLimitTargetMetric.FILE_TRANSFORMER_EXPORT_DESCRIPTIONS_EXECUTION_COUNT_FOR, repositoryId); + return result; } @@ -376,6 +388,9 @@ public class FileTransformerServiceImpl implements FileTransformerService { planImportModel.setFile(fileEnvelope); + this.accountingService.increase(UsageLimitTargetMetric.FILE_TRANSFORMER_IMPORT_PLAN_EXECUTION_COUNT.getValue()); + this.increaseTargetMetricWithRepositoryId(UsageLimitTargetMetric.FILE_TRANSFORMER_IMPORT_PLAN_EXECUTION_COUNT_FOR, planCommonModelConfig.getRepositoryId()); + return repository.importPlan(planImportModel); } @@ -414,4 +429,8 @@ public class FileTransformerServiceImpl implements FileTransformerService { return repository.preprocessingPlan(fileEnvelope); } + private void increaseTargetMetricWithRepositoryId(UsageLimitTargetMetric metric, String repositoryId){ + this.accountingService.increase(metric.getValue() + repositoryId); + } + } diff --git a/backend/core/src/main/java/org/opencdmp/service/plan/PlanServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/plan/PlanServiceImpl.java index 1b81f6cf9..a749f92cd 100644 --- a/backend/core/src/main/java/org/opencdmp/service/plan/PlanServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/plan/PlanServiceImpl.java @@ -389,7 +389,6 @@ public class PlanServiceImpl implements PlanService { if (previousPlan != null) this.elasticService.persistPlan(previousPlan); this.annotationEntityRemovalIntegrationEventHandler.handlePlan(data.getId()); - this.accountingService.decrease(UsageLimitTargetMetric.PLAN_COUNT); } @Override @@ -397,6 +396,7 @@ public class PlanServiceImpl implements PlanService { logger.debug(new MapLogEntry("persisting data bew version").And("model", model).And("fields", fields)); this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.planAffiliation( model.getId())), Permission.CreateNewVersionPlan); + this.usageLimitService.checkIncrease(UsageLimitTargetMetric.PLAN_COUNT); PlanEntity oldPlanEntity = this.entityManager.find(PlanEntity.class, model.getId(), true); if (oldPlanEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Plan.class.getSimpleName()}, LocaleContextHolder.getLocale())); if (!this.conventionService.hashValue(oldPlanEntity.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage()); @@ -572,12 +572,15 @@ public class PlanServiceImpl implements PlanService { this.annotationEntityTouchedIntegrationEventHandler.handlePlan(newPlan.getId()); this.annotationEntityTouchedIntegrationEventHandler.handlePlan(oldPlanEntity.getId()); + this.accountingService.increase(UsageLimitTargetMetric.PLAN_COUNT.getValue()); + return this.builderFactory.builder(PlanBuilder.class).build(BaseFieldSet.build(fields, Plan._id), newPlan); } public void cloneDescription(UUID planId, Map planDescriptionTemplateRemap, UUID descriptionId, UUID newPlanDescriptionTemplateId) throws InvalidApplicationException, IOException { logger.debug("cloning description: {} with description: {}", descriptionId, planId); + this.usageLimitService.checkIncrease(UsageLimitTargetMetric.DESCRIPTION_COUNT); PlanEntity descriptionPlan = this.queryFactory.query(PlanQuery.class).disableTracking().ids(planId).isActive(IsActive.Active).first(); if (!descriptionPlan.getAccessType().equals(PlanAccessType.Public)) this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.descriptionAffiliation(descriptionId)), Permission.CloneDescription); @@ -642,6 +645,8 @@ public class PlanServiceImpl implements PlanService { this.annotationEntityTouchedIntegrationEventHandler.handleDescription(newDescription.getId()); this.annotationEntityTouchedIntegrationEventHandler.handleDescription(existing.getId()); + + this.accountingService.increase(UsageLimitTargetMetric.DESCRIPTION_COUNT.getValue()); } @@ -686,6 +691,8 @@ public class PlanServiceImpl implements PlanService { @Override public Plan buildClone(ClonePlanPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, IOException, InvalidApplicationException { + this.usageLimitService.checkIncrease(UsageLimitTargetMetric.PLAN_COUNT); + PlanEntity existingPlanEntity = this.queryFactory.query(PlanQuery.class).disableTracking().ids(model.getId()).firstAs(fields); if (!this.conventionService.isValidGuid(model.getId()) || existingPlanEntity == null) @@ -787,6 +794,8 @@ public class PlanServiceImpl implements PlanService { this.annotationEntityTouchedIntegrationEventHandler.handlePlan(newPlan.getId()); + this.accountingService.increase(UsageLimitTargetMetric.PLAN_COUNT.getValue()); + PlanEntity resultingPlanEntity = this.queryFactory.query(PlanQuery.class).disableTracking().ids(newPlan.getId()).firstAs(fields); if (!this.conventionService.isListNullOrEmpty(model.getDescriptions())){ for (UUID description: model.getDescriptions()) { @@ -937,7 +946,7 @@ public class PlanServiceImpl implements PlanService { this.entityManager.merge(data); else { this.entityManager.persist(data); - this.accountingService.increase(UsageLimitTargetMetric.PLAN_COUNT); + this.accountingService.increase(UsageLimitTargetMetric.PLAN_COUNT.getValue()); } this.entityManager.flush(); diff --git a/backend/core/src/main/java/org/opencdmp/service/planblueprint/PlanBlueprintServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/planblueprint/PlanBlueprintServiceImpl.java index 9b61c80ad..fd7dbac23 100644 --- a/backend/core/src/main/java/org/opencdmp/service/planblueprint/PlanBlueprintServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/planblueprint/PlanBlueprintServiceImpl.java @@ -174,7 +174,7 @@ public class PlanBlueprintServiceImpl implements PlanBlueprintService { this.entityManager.merge(data); else{ this.entityManager.persist(data); - this.accountingService.increase(UsageLimitTargetMetric.BLUEPRINT_COUNT); + this.accountingService.increase(UsageLimitTargetMetric.BLUEPRINT_COUNT.getValue()); } this.entityManager.flush(); @@ -318,7 +318,6 @@ public class PlanBlueprintServiceImpl implements PlanBlueprintService { this.authorizationService.authorizeForce(Permission.DeletePlanBlueprint); this.deleterFactory.deleter(PlanBlueprintDeleter.class).deleteAndSaveByIds(List.of(id)); - this.accountingService.decrease(UsageLimitTargetMetric.BLUEPRINT_COUNT); } //endregion @@ -414,6 +413,7 @@ public class PlanBlueprintServiceImpl implements PlanBlueprintService { logger.debug(new MapLogEntry("persisting data planBlueprint").And("model", model).And("fields", fields)); this.authorizationService.authorizeForce(Permission.CreateNewVersionPlanBlueprint); + this.usageLimitService.checkIncrease(UsageLimitTargetMetric.BLUEPRINT_COUNT); PlanBlueprintEntity oldPlanBlueprintEntity = this.entityManager.find(PlanBlueprintEntity.class, model.getId(), true); if (oldPlanBlueprintEntity == null) @@ -461,6 +461,8 @@ public class PlanBlueprintServiceImpl implements PlanBlueprintService { this.entityManager.flush(); + this.accountingService.increase(UsageLimitTargetMetric.BLUEPRINT_COUNT.getValue()); + return this.builderFactory.builder(PlanBlueprintBuilder.class).authorize(AuthorizationFlags.AllExceptPublic).build(BaseFieldSet.build(fields, PlanBlueprint._id), data); } diff --git a/backend/core/src/main/java/org/opencdmp/service/prefillingsource/PrefillingSourceServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/prefillingsource/PrefillingSourceServiceImpl.java index b803fbe8f..e4b6acba6 100644 --- a/backend/core/src/main/java/org/opencdmp/service/prefillingsource/PrefillingSourceServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/prefillingsource/PrefillingSourceServiceImpl.java @@ -158,7 +158,7 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { if (isUpdate) this.entityManager.merge(data); else { this.entityManager.persist(data); - this.accountingService.increase(UsageLimitTargetMetric.PREFILLING_SOURCES_COUNT); + this.accountingService.increase(UsageLimitTargetMetric.PREFILLING_SOURCES_COUNT.getValue()); } this.entityManager.flush(); @@ -329,7 +329,6 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { this.authorizationService.authorizeForce(Permission.DeletePrefillingSource); this.deleterFactory.deleter(PrefillingSourceDeleter.class).deleteAndSaveByIds(List.of(id)); - this.accountingService.decrease(UsageLimitTargetMetric.PREFILLING_SOURCES_COUNT); } public List searchPrefillings(PrefillingSearchRequest model) { diff --git a/backend/core/src/main/java/org/opencdmp/service/referencetype/ReferenceTypeServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/referencetype/ReferenceTypeServiceImpl.java index d74266fd4..ce6bad57d 100644 --- a/backend/core/src/main/java/org/opencdmp/service/referencetype/ReferenceTypeServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/referencetype/ReferenceTypeServiceImpl.java @@ -113,7 +113,7 @@ public class ReferenceTypeServiceImpl implements ReferenceTypeService { if (isUpdate) this.entityManager.merge(data); else { this.entityManager.persist(data); - this.accountingService.increase(UsageLimitTargetMetric.REFERENCE_TYPE_COUNT); + this.accountingService.increase(UsageLimitTargetMetric.REFERENCE_TYPE_COUNT.getValue()); } this.entityManager.flush(); @@ -306,6 +306,5 @@ public class ReferenceTypeServiceImpl implements ReferenceTypeService { this.authorizationService.authorizeForce(Permission.DeleteReferenceType); this.deleterFactory.deleter(ReferenceTypeDeleter.class).deleteAndSaveByIds(List.of(id)); - this.accountingService.decrease(UsageLimitTargetMetric.REFERENCE_TYPE_COUNT); } } 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 58d68dede..93141f6d0 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 @@ -140,8 +140,8 @@ 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()); + UsageLimitEntity usageLimitEntity = this.queryFactory.query(UsageLimitQuery.class).disableTracking().usageLimitTargetMetrics(metric).isActive(IsActive.Active).firstAs(new BaseFieldSet().ensure(UsageLimit._label).ensure(UsageLimit._targetMetric).ensure(UsageLimit._value)); + if (usageLimitEntity != null && currentValue >= usageLimitEntity.getValue()) throw new MyValidationException(this.errors.getUsageLimitException().getCode(), usageLimitEntity.getLabel()); } catch (InvalidApplicationException e) { log.error(e.getMessage(), e); diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index 6df99ec8c..b8684b288 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -80,7 +80,7 @@ const cookieConfig: NgcCookieConsentConfig = { type: 'info' }; -export function InstallationConfigurationFactory(appConfig: ConfigurationService, keycloak: KeycloakService, authService: AuthService, languageService: LanguageService, tenantHandlingService: TenantHandlingService) { +export function InstallationConfigurationFactory(appConfig: ConfigurationService, keycloak: KeycloakService, authService: AuthService, languageService: LanguageService, tenantHandlingService: TenantHandlingService, router: Router) { return () => appConfig.loadConfiguration().then(() => { return languageService.loadAvailableLanguages().toPromise(); }).then(x => keycloak.init({ @@ -112,7 +112,7 @@ export function InstallationConfigurationFactory(appConfig: ConfigurationService const token = keycloak.getToken(); return authService.prepareAuthRequest(from(token), tenantCode, { params }).toPromise().catch(error => { authService.onAuthenticateError(error); - window.location.pathname = "/"; + router.navigate(['/']); }); })); } diff --git a/frontend/src/app/ui/admin/plan-blueprint/editor/plan-blueprint-editor.component.ts b/frontend/src/app/ui/admin/plan-blueprint/editor/plan-blueprint-editor.component.ts index c627108ce..dda9a4abe 100644 --- a/frontend/src/app/ui/admin/plan-blueprint/editor/plan-blueprint-editor.component.ts +++ b/frontend/src/app/ui/admin/plan-blueprint/editor/plan-blueprint-editor.component.ts @@ -226,7 +226,10 @@ export class PlanBlueprintEditorComponent extends BaseEditor onSuccess ? onSuccess(complete) : this.onCallbackSuccess(complete), - error => this.onCallbackError(error) + error => { + this.formGroup.get('status').setValue(PlanBlueprintStatus.Draft); + this.onCallbackError(error); + } ); } else if (this.isNewVersion == true && this.isNew == false && this.isClone == false) { const formData = this.formService.getValue(this.formGroup.value) as NewVersionPlanBlueprintPersist; diff --git a/frontend/src/assets/i18n/baq.json b/frontend/src/assets/i18n/baq.json index 08a588d5e..77fc50c10 100644 --- a/frontend/src/assets/i18n/baq.json +++ b/frontend/src/assets/i18n/baq.json @@ -80,7 +80,7 @@ "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": "You have reached the available number of items for this entity " + "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator." }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Kontuz!", diff --git a/frontend/src/assets/i18n/de.json b/frontend/src/assets/i18n/de.json index b6490687f..bfbc5f023 100644 --- a/frontend/src/assets/i18n/de.json +++ b/frontend/src/assets/i18n/de.json @@ -80,7 +80,7 @@ "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": "You have reached the available number of items for this entity " + "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator." }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Warnung!", diff --git a/frontend/src/assets/i18n/en.json b/frontend/src/assets/i18n/en.json index cd08fa92b..7ee851695 100644 --- a/frontend/src/assets/i18n/en.json +++ b/frontend/src/assets/i18n/en.json @@ -80,7 +80,7 @@ "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": "You have reached the available number of items for this entity " + "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator." }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Warning!", diff --git a/frontend/src/assets/i18n/es.json b/frontend/src/assets/i18n/es.json index fda087fee..3747171cb 100644 --- a/frontend/src/assets/i18n/es.json +++ b/frontend/src/assets/i18n/es.json @@ -80,7 +80,7 @@ "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": "You have reached the available number of items for this entity " + "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator." }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Atención!", diff --git a/frontend/src/assets/i18n/gr.json b/frontend/src/assets/i18n/gr.json index 1aefd37bc..f331e85cf 100644 --- a/frontend/src/assets/i18n/gr.json +++ b/frontend/src/assets/i18n/gr.json @@ -80,7 +80,7 @@ "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": "You have reached the available number of items for this entity " + "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator." }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Προσοχή!", diff --git a/frontend/src/assets/i18n/hr.json b/frontend/src/assets/i18n/hr.json index 2b7653a8f..64153cafd 100644 --- a/frontend/src/assets/i18n/hr.json +++ b/frontend/src/assets/i18n/hr.json @@ -80,7 +80,7 @@ "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": "You have reached the available number of items for this entity " + "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator." }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Oprez!", diff --git a/frontend/src/assets/i18n/pl.json b/frontend/src/assets/i18n/pl.json index cb33e8a91..96acdb17a 100644 --- a/frontend/src/assets/i18n/pl.json +++ b/frontend/src/assets/i18n/pl.json @@ -80,7 +80,7 @@ "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": "You have reached the available number of items for this entity " + "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator." }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Ostrzeżenie!", diff --git a/frontend/src/assets/i18n/pt.json b/frontend/src/assets/i18n/pt.json index 7b6c3fc1e..4e0805046 100644 --- a/frontend/src/assets/i18n/pt.json +++ b/frontend/src/assets/i18n/pt.json @@ -80,7 +80,7 @@ "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": "You have reached the available number of items for this entity " + "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator." }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Atenção!", diff --git a/frontend/src/assets/i18n/sk.json b/frontend/src/assets/i18n/sk.json index 0fe7a88f3..2ece162cc 100644 --- a/frontend/src/assets/i18n/sk.json +++ b/frontend/src/assets/i18n/sk.json @@ -80,7 +80,7 @@ "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": "You have reached the available number of items for this entity " + "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator." }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Upozornenie!", diff --git a/frontend/src/assets/i18n/sr.json b/frontend/src/assets/i18n/sr.json index ad8760502..c8928c032 100644 --- a/frontend/src/assets/i18n/sr.json +++ b/frontend/src/assets/i18n/sr.json @@ -80,7 +80,7 @@ "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": "You have reached the available number of items for this entity " + "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator." }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Oprez!", diff --git a/frontend/src/assets/i18n/tr.json b/frontend/src/assets/i18n/tr.json index a49e934e2..eebe50cef 100644 --- a/frontend/src/assets/i18n/tr.json +++ b/frontend/src/assets/i18n/tr.json @@ -80,7 +80,7 @@ "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": "You have reached the available number of items for this entity " + "USAGE-LIMIT-EXCEPTION": "Υou have exceeded the {{usageLimitLabel}} usage limit. Please contact your administrator." }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Uyarı!", diff --git a/frontend/src/common/modules/errors/error-handling/http-error-handling.service.ts b/frontend/src/common/modules/errors/error-handling/http-error-handling.service.ts index e555d819a..d0803e9ed 100644 --- a/frontend/src/common/modules/errors/error-handling/http-error-handling.service.ts +++ b/frontend/src/common/modules/errors/error-handling/http-error-handling.service.ts @@ -1,6 +1,6 @@ import { HttpErrorResponse } from '@angular/common/http'; import { Injectable } from '@angular/core'; -import { ResponseErrorCodeHelper } from '@app/core/common/enum/respone-error-code'; +import { ResponseErrorCode, ResponseErrorCodeHelper } from '@app/core/common/enum/respone-error-code'; import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service'; import { TranslateService } from '@ngx-translate/core'; @@ -17,7 +17,11 @@ export class HttpErrorHandlingService { let errorMessage = messageOvverrides?.has(error.statusCode) ? messageOvverrides?.get(error.statusCode) : null; if(errorResponse.error && ResponseErrorCodeHelper.isBackendError(errorResponse.error?.code)){ - this.uiNotificationService.snackBarNotification(ResponseErrorCodeHelper.getErrorMessageByBackendStatusCode(errorResponse.error.code, this.language), SnackBarNotificationLevel.Error); + if (errorResponse.error.code === ResponseErrorCode.UsageLimitException && errorResponse.error.error){ + this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.BACKEND-ERRORS.USAGE-LIMIT-EXCEPTION', { 'usageLimitLabel': errorResponse.error.error }), SnackBarNotificationLevel.Error); + } else { + this.uiNotificationService.snackBarNotification(ResponseErrorCodeHelper.getErrorMessageByBackendStatusCode(errorResponse.error.code, this.language), SnackBarNotificationLevel.Error); + } } else if (error.statusCode === 302) { errorMessage ??= this.language.instant('GENERAL.SNACK-BAR.REDIRECT');