Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring

This commit is contained in:
Diamantis Tziotzios 2024-07-15 17:05:50 +03:00
commit fbbb449ba0
33 changed files with 157 additions and 52 deletions

View File

@ -13,7 +13,15 @@ public enum UsageLimitTargetMetric implements DatabaseEnum<String> {
DESCRIPTION_TEMPLATE_COUNT(TargetMetrics.DescriptionTemplateCount), DESCRIPTION_TEMPLATE_COUNT(TargetMetrics.DescriptionTemplateCount),
DESCRIPTION_TEMPLATE_TYPE_COUNT(TargetMetrics.DescriptionTemplateTypeCount), DESCRIPTION_TEMPLATE_TYPE_COUNT(TargetMetrics.DescriptionTemplateTypeCount),
PREFILLING_SOURCES_COUNT(TargetMetrics.PrefillingSourcesCount), 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; private final String value;
public static class TargetMetrics { public static class TargetMetrics {
@ -25,6 +33,14 @@ public enum UsageLimitTargetMetric implements DatabaseEnum<String> {
public static final String DescriptionTemplateTypeCount = "description_template_type_count"; public static final String DescriptionTemplateTypeCount = "description_template_type_count";
public static final String PrefillingSourcesCount = "prefilling_sources_count"; public static final String PrefillingSourcesCount = "prefilling_sources_count";
public static final String ReferenceTypeCount = "reference_type_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) { UsageLimitTargetMetric(String value) {

View File

@ -1,6 +1,7 @@
package org.opencdmp.model.deleter; package org.opencdmp.model.deleter;
import org.opencdmp.commons.enums.IsActive; import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.commons.enums.UsageLimitTargetMetric;
import org.opencdmp.data.DescriptionEntity; import org.opencdmp.data.DescriptionEntity;
import org.opencdmp.data.DescriptionReferenceEntity; import org.opencdmp.data.DescriptionReferenceEntity;
import org.opencdmp.data.DescriptionTagEntity; import org.opencdmp.data.DescriptionTagEntity;
@ -8,6 +9,7 @@ import org.opencdmp.data.TenantEntityManager;
import org.opencdmp.query.DescriptionQuery; import org.opencdmp.query.DescriptionQuery;
import org.opencdmp.query.DescriptionReferenceQuery; import org.opencdmp.query.DescriptionReferenceQuery;
import org.opencdmp.query.DescriptionTagQuery; import org.opencdmp.query.DescriptionTagQuery;
import org.opencdmp.service.accounting.AccountingService;
import org.opencdmp.service.elastic.ElasticService; import org.opencdmp.service.elastic.ElasticService;
import gr.cite.tools.data.deleter.Deleter; import gr.cite.tools.data.deleter.Deleter;
import gr.cite.tools.data.deleter.DeleterFactory; import gr.cite.tools.data.deleter.DeleterFactory;
@ -40,17 +42,20 @@ public class DescriptionDeleter implements Deleter {
protected final DeleterFactory deleterFactory; protected final DeleterFactory deleterFactory;
protected final ElasticService elasticService; protected final ElasticService elasticService;
protected final AccountingService accountingService;
@Autowired @Autowired
public DescriptionDeleter( public DescriptionDeleter(
TenantEntityManager entityManager, TenantEntityManager entityManager,
QueryFactory queryFactory, QueryFactory queryFactory,
DeleterFactory deleterFactory, DeleterFactory deleterFactory,
ElasticService elasticService) { ElasticService elasticService,
AccountingService accountingService) {
this.entityManager = entityManager; this.entityManager = entityManager;
this.queryFactory = queryFactory; this.queryFactory = queryFactory;
this.deleterFactory = deleterFactory; this.deleterFactory = deleterFactory;
this.elasticService = elasticService; this.elasticService = elasticService;
this.accountingService = accountingService;
} }
public void deleteAndSaveByIds(List<UUID> ids, boolean disableElastic) throws InvalidApplicationException, IOException { public void deleteAndSaveByIds(List<UUID> ids, boolean disableElastic) throws InvalidApplicationException, IOException {
@ -98,6 +103,7 @@ public class DescriptionDeleter implements Deleter {
logger.trace("updated item"); logger.trace("updated item");
if (!disableElastic) this.elasticService.deleteDescription(item); if (!disableElastic) this.elasticService.deleteDescription(item);
this.accountingService.decrease(UsageLimitTargetMetric.DESCRIPTION_COUNT.getValue());
} }
} }

View File

@ -1,6 +1,7 @@
package org.opencdmp.model.deleter; package org.opencdmp.model.deleter;
import org.opencdmp.commons.enums.IsActive; import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.commons.enums.UsageLimitTargetMetric;
import org.opencdmp.data.DescriptionTemplateEntity; import org.opencdmp.data.DescriptionTemplateEntity;
import org.opencdmp.data.TenantEntityManager; import org.opencdmp.data.TenantEntityManager;
import org.opencdmp.data.UserDescriptionTemplateEntity; 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.data.query.QueryFactory;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry; import gr.cite.tools.logging.MapLogEntry;
import org.opencdmp.service.accounting.AccountingService;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
@ -36,15 +38,18 @@ public class DescriptionTemplateDeleter implements Deleter {
protected final DeleterFactory deleterFactory; protected final DeleterFactory deleterFactory;
protected final AccountingService accountingService;
@Autowired @Autowired
public DescriptionTemplateDeleter( public DescriptionTemplateDeleter(
TenantEntityManager entityManager, TenantEntityManager entityManager,
QueryFactory queryFactory, QueryFactory queryFactory,
DeleterFactory deleterFactory DeleterFactory deleterFactory,
) { AccountingService accountingService) {
this.entityManager = entityManager; this.entityManager = entityManager;
this.queryFactory = queryFactory; this.queryFactory = queryFactory;
this.deleterFactory = deleterFactory; this.deleterFactory = deleterFactory;
this.accountingService = accountingService;
} }
public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException { public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException {
@ -87,6 +92,7 @@ public class DescriptionTemplateDeleter implements Deleter {
logger.trace("updating item"); logger.trace("updating item");
this.entityManager.merge(item); this.entityManager.merge(item);
logger.trace("updated item"); logger.trace("updated item");
this.accountingService.decrease(UsageLimitTargetMetric.DESCRIPTION_TEMPLATE_COUNT.getValue());
} }
} }

View File

@ -1,6 +1,7 @@
package org.opencdmp.model.deleter; package org.opencdmp.model.deleter;
import org.opencdmp.commons.enums.IsActive; import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.commons.enums.UsageLimitTargetMetric;
import org.opencdmp.data.DescriptionTemplateEntity; import org.opencdmp.data.DescriptionTemplateEntity;
import org.opencdmp.data.DescriptionTemplateTypeEntity; import org.opencdmp.data.DescriptionTemplateTypeEntity;
import org.opencdmp.data.TenantEntityManager; 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.data.query.QueryFactory;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry; import gr.cite.tools.logging.MapLogEntry;
import org.opencdmp.service.accounting.AccountingService;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
@ -36,15 +38,18 @@ public class DescriptionTemplateTypeDeleter implements Deleter {
protected final DeleterFactory deleterFactory; protected final DeleterFactory deleterFactory;
protected final AccountingService accountingService;
@Autowired @Autowired
public DescriptionTemplateTypeDeleter( public DescriptionTemplateTypeDeleter(
TenantEntityManager entityManager, TenantEntityManager entityManager,
QueryFactory queryFactory, QueryFactory queryFactory,
DeleterFactory deleterFactory DeleterFactory deleterFactory,
) { AccountingService accountingService) {
this.entityManager = entityManager; this.entityManager = entityManager;
this.queryFactory = queryFactory; this.queryFactory = queryFactory;
this.deleterFactory = deleterFactory; this.deleterFactory = deleterFactory;
this.accountingService = accountingService;
} }
public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException { public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException {
@ -84,6 +89,7 @@ public class DescriptionTemplateTypeDeleter implements Deleter {
logger.trace("updating item"); logger.trace("updating item");
this.entityManager.merge(item); this.entityManager.merge(item);
logger.trace("updated item"); logger.trace("updated item");
this.accountingService.decrease(UsageLimitTargetMetric.DESCRIPTION_TEMPLATE_TYPE_COUNT.getValue());
} }
} }

View File

@ -1,6 +1,7 @@
package org.opencdmp.model.deleter; package org.opencdmp.model.deleter;
import org.opencdmp.commons.enums.IsActive; import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.commons.enums.UsageLimitTargetMetric;
import org.opencdmp.data.PlanBlueprintEntity; import org.opencdmp.data.PlanBlueprintEntity;
import org.opencdmp.data.TenantEntityManager; import org.opencdmp.data.TenantEntityManager;
import org.opencdmp.query.PlanBlueprintQuery; 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.data.query.QueryFactory;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry; import gr.cite.tools.logging.MapLogEntry;
import org.opencdmp.service.accounting.AccountingService;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
@ -33,15 +35,18 @@ public class PlanBlueprintDeleter implements Deleter {
protected final DeleterFactory deleterFactory; protected final DeleterFactory deleterFactory;
protected final AccountingService accountingService;
@Autowired @Autowired
public PlanBlueprintDeleter( public PlanBlueprintDeleter(
TenantEntityManager entityManager, TenantEntityManager entityManager,
QueryFactory queryFactory, QueryFactory queryFactory,
DeleterFactory deleterFactory DeleterFactory deleterFactory,
) { AccountingService accountingService) {
this.entityManager = entityManager; this.entityManager = entityManager;
this.queryFactory = queryFactory; this.queryFactory = queryFactory;
this.deleterFactory = deleterFactory; this.deleterFactory = deleterFactory;
this.accountingService = accountingService;
} }
public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException { public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException {
@ -73,6 +78,7 @@ public class PlanBlueprintDeleter implements Deleter {
logger.trace("updating item"); logger.trace("updating item");
this.entityManager.merge(item); this.entityManager.merge(item);
logger.trace("updated item"); logger.trace("updated item");
this.accountingService.decrease(UsageLimitTargetMetric.BLUEPRINT_COUNT.getValue());
} }
} }

View File

@ -9,11 +9,13 @@ import gr.cite.tools.logging.MapLogEntry;
import org.opencdmp.commons.enums.EntityType; import org.opencdmp.commons.enums.EntityType;
import org.opencdmp.commons.enums.IsActive; import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.commons.enums.PlanVersionStatus; import org.opencdmp.commons.enums.PlanVersionStatus;
import org.opencdmp.commons.enums.UsageLimitTargetMetric;
import org.opencdmp.data.*; import org.opencdmp.data.*;
import org.opencdmp.model.PlanDescriptionTemplate; import org.opencdmp.model.PlanDescriptionTemplate;
import org.opencdmp.model.description.Description; import org.opencdmp.model.description.Description;
import org.opencdmp.model.planreference.PlanReference; import org.opencdmp.model.planreference.PlanReference;
import org.opencdmp.query.*; import org.opencdmp.query.*;
import org.opencdmp.service.accounting.AccountingService;
import org.opencdmp.service.elastic.ElasticService; import org.opencdmp.service.elastic.ElasticService;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -40,17 +42,20 @@ public class PlanDeleter implements Deleter {
protected final DeleterFactory deleterFactory; protected final DeleterFactory deleterFactory;
protected final ElasticService elasticService; protected final ElasticService elasticService;
protected final AccountingService accountingService;
@Autowired @Autowired
public PlanDeleter( public PlanDeleter(
TenantEntityManager entityManager, TenantEntityManager entityManager,
QueryFactory queryFactory, QueryFactory queryFactory,
DeleterFactory deleterFactory, DeleterFactory deleterFactory,
ElasticService elasticService) { ElasticService elasticService,
AccountingService accountingService) {
this.entityManager = entityManager; this.entityManager = entityManager;
this.queryFactory = queryFactory; this.queryFactory = queryFactory;
this.deleterFactory = deleterFactory; this.deleterFactory = deleterFactory;
this.elasticService = elasticService; this.elasticService = elasticService;
this.accountingService = accountingService;
} }
public void deleteAndSaveByIds(List<UUID> ids, boolean disableElastic) throws InvalidApplicationException, IOException { public void deleteAndSaveByIds(List<UUID> ids, boolean disableElastic) throws InvalidApplicationException, IOException {
@ -113,6 +118,7 @@ public class PlanDeleter implements Deleter {
logger.trace("updated item"); logger.trace("updated item");
if (!disableElastic) this.elasticService.deletePlan(item); if (!disableElastic) this.elasticService.deletePlan(item);
this.accountingService.decrease(UsageLimitTargetMetric.PLAN_COUNT.getValue());
} }
} }

View File

@ -1,6 +1,7 @@
package org.opencdmp.model.deleter; package org.opencdmp.model.deleter;
import org.opencdmp.commons.enums.IsActive; import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.commons.enums.UsageLimitTargetMetric;
import org.opencdmp.data.PrefillingSourceEntity; import org.opencdmp.data.PrefillingSourceEntity;
import org.opencdmp.data.TenantEntityManager; import org.opencdmp.data.TenantEntityManager;
import org.opencdmp.query.PrefillingSourceQuery; 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.data.query.QueryFactory;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry; import gr.cite.tools.logging.MapLogEntry;
import org.opencdmp.service.accounting.AccountingService;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
@ -31,16 +33,18 @@ public class PrefillingSourceDeleter implements Deleter {
protected final QueryFactory queryFactory; protected final QueryFactory queryFactory;
protected final DeleterFactory deleterFactory; protected final DeleterFactory deleterFactory;
protected final AccountingService accountingService;
@Autowired @Autowired
public PrefillingSourceDeleter( public PrefillingSourceDeleter(
TenantEntityManager entityManager, TenantEntityManager entityManager,
QueryFactory queryFactory, QueryFactory queryFactory,
DeleterFactory deleterFactory DeleterFactory deleterFactory,
) { AccountingService accountingService) {
this.entityManager = entityManager; this.entityManager = entityManager;
this.queryFactory = queryFactory; this.queryFactory = queryFactory;
this.deleterFactory = deleterFactory; this.deleterFactory = deleterFactory;
this.accountingService = accountingService;
} }
public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException { public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException {
@ -72,6 +76,7 @@ public class PrefillingSourceDeleter implements Deleter {
logger.trace("updating item"); logger.trace("updating item");
this.entityManager.merge(item); this.entityManager.merge(item);
logger.trace("updated item"); logger.trace("updated item");
this.accountingService.decrease(UsageLimitTargetMetric.PREFILLING_SOURCES_COUNT.getValue());
} }
} }

View File

@ -1,6 +1,7 @@
package org.opencdmp.model.deleter; package org.opencdmp.model.deleter;
import org.opencdmp.commons.enums.IsActive; import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.commons.enums.UsageLimitTargetMetric;
import org.opencdmp.data.ReferenceTypeEntity; import org.opencdmp.data.ReferenceTypeEntity;
import org.opencdmp.data.TenantEntityManager; import org.opencdmp.data.TenantEntityManager;
import org.opencdmp.query.ReferenceTypeQuery; 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.data.query.QueryFactory;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry; import gr.cite.tools.logging.MapLogEntry;
import org.opencdmp.service.accounting.AccountingService;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
@ -32,15 +34,18 @@ public class ReferenceTypeDeleter implements Deleter {
protected final DeleterFactory deleterFactory; protected final DeleterFactory deleterFactory;
protected final AccountingService accountingService;
@Autowired @Autowired
public ReferenceTypeDeleter( public ReferenceTypeDeleter(
TenantEntityManager entityManager, TenantEntityManager entityManager,
QueryFactory queryFactory, QueryFactory queryFactory,
DeleterFactory deleterFactory DeleterFactory deleterFactory,
) { AccountingService accountingService) {
this.entityManager = entityManager; this.entityManager = entityManager;
this.queryFactory = queryFactory; this.queryFactory = queryFactory;
this.deleterFactory = deleterFactory; this.deleterFactory = deleterFactory;
this.accountingService = accountingService;
} }
public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException { public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException {
@ -72,6 +77,7 @@ public class ReferenceTypeDeleter implements Deleter {
logger.trace("updating item"); logger.trace("updating item");
this.entityManager.merge(item); this.entityManager.merge(item);
logger.trace("updated item"); logger.trace("updated item");
this.accountingService.decrease(UsageLimitTargetMetric.REFERENCE_TYPE_COUNT.getValue());
} }
} }

View File

@ -6,9 +6,9 @@ public interface AccountingService {
Integer getCurrentMetricValue(UsageLimitTargetMetric metric); 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);
} }

View File

@ -39,15 +39,15 @@ public class AccountingServiceImpl implements AccountingService {
return 10; return 10;
} }
public void set(UsageLimitTargetMetric metric) { public void set(String metric) {
//TODO //TODO
} }
public void increase(UsageLimitTargetMetric metric) { public void increase(String metric) {
//TODO //TODO
} }
public void decrease(UsageLimitTargetMetric metric) { public void decrease(String metric) {
//TODO //TODO
} }
} }

View File

@ -22,6 +22,7 @@ import org.opencdmp.commons.JsonHandlingService;
import org.opencdmp.commons.enums.IsActive; import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.commons.enums.StorageType; import org.opencdmp.commons.enums.StorageType;
import org.opencdmp.commons.enums.TenantConfigurationType; import org.opencdmp.commons.enums.TenantConfigurationType;
import org.opencdmp.commons.enums.UsageLimitTargetMetric;
import org.opencdmp.commons.notification.NotificationProperties; import org.opencdmp.commons.notification.NotificationProperties;
import org.opencdmp.commons.scope.tenant.TenantScope; import org.opencdmp.commons.scope.tenant.TenantScope;
import org.opencdmp.commons.scope.user.UserScope; 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.PlanUserQuery;
import org.opencdmp.query.TenantConfigurationQuery; import org.opencdmp.query.TenantConfigurationQuery;
import org.opencdmp.query.UserQuery; import org.opencdmp.query.UserQuery;
import org.opencdmp.service.accounting.AccountingService;
import org.opencdmp.service.encryption.EncryptionService; import org.opencdmp.service.encryption.EncryptionService;
import org.opencdmp.service.entitydoi.EntityDoiService; import org.opencdmp.service.entitydoi.EntityDoiService;
import org.opencdmp.service.filetransformer.FileTransformerService; import org.opencdmp.service.filetransformer.FileTransformerService;
@ -112,6 +114,7 @@ public class DepositServiceImpl implements DepositService {
private final EncryptionService encryptionService; private final EncryptionService encryptionService;
private final TenantProperties tenantProperties; private final TenantProperties tenantProperties;
private final DepositSourcesCacheService depositSourcesCacheService; private final DepositSourcesCacheService depositSourcesCacheService;
private final AccountingService accountingService;
@Autowired @Autowired
public DepositServiceImpl(DepositProperties depositProperties, public DepositServiceImpl(DepositProperties depositProperties,
@ -120,7 +123,7 @@ public class DepositServiceImpl implements DepositService {
EntityDoiService doiService, EntityDoiService doiService,
QueryFactory queryFactory, QueryFactory queryFactory,
MessageSource messageSource, 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.depositProperties = depositProperties;
this.tokenExchangeCacheService = tokenExchangeCacheService; this.tokenExchangeCacheService = tokenExchangeCacheService;
this.authorizationService = authorizationService; this.authorizationService = authorizationService;
@ -143,7 +146,8 @@ public class DepositServiceImpl implements DepositService {
this.encryptionService = encryptionService; this.encryptionService = encryptionService;
this.tenantProperties = tenantProperties; this.tenantProperties = tenantProperties;
this.depositSourcesCacheService = depositSourcesCacheService; 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 { 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.setDoi(doi);
doiPersist.setEntityId(planEntity.getId()); doiPersist.setEntityId(planEntity.getId());
this.sendNotification(planEntity); 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()); return this.doiService.persist(doiPersist, true, planDepositModel.getProject());
} }
@ -377,6 +385,10 @@ public class DepositServiceImpl implements DepositService {
return persisted.getFileRef(); return persisted.getFileRef();
} }
private void increaseTargetMetricWithRepositoryId(UsageLimitTargetMetric metric, String repositoryId){
this.accountingService.increase(metric.getValue() + repositoryId);
}
@Override @Override
public String getLogo(String repositoryId) throws InvalidApplicationException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { public String getLogo(String repositoryId) throws InvalidApplicationException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
this.authorizationService.authorizeForce(Permission.BrowseDeposit, Permission.DeferredAffiliation); this.authorizationService.authorizeForce(Permission.BrowseDeposit, Permission.DeferredAffiliation);

View File

@ -266,7 +266,7 @@ public class DescriptionServiceImpl implements DescriptionService {
if (isUpdate) this.entityManager.merge(data); if (isUpdate) this.entityManager.merge(data);
else { else {
this.entityManager.persist(data); this.entityManager.persist(data);
this.accountingService.increase(UsageLimitTargetMetric.DESCRIPTION_COUNT); this.accountingService.increase(UsageLimitTargetMetric.DESCRIPTION_COUNT.getValue());
} }
this.entityManager.flush(); this.entityManager.flush();
@ -901,7 +901,6 @@ public class DescriptionServiceImpl implements DescriptionService {
this.deleterFactory.deleter(DescriptionDeleter.class).deleteAndSaveByIds(List.of(id), false); this.deleterFactory.deleter(DescriptionDeleter.class).deleteAndSaveByIds(List.of(id), false);
this.annotationEntityRemovalIntegrationEventHandler.handleDescription(id); this.annotationEntityRemovalIntegrationEventHandler.handleDescription(id);
this.accountingService.decrease(UsageLimitTargetMetric.DESCRIPTION_COUNT);
} }
//endregion //endregion

View File

@ -216,7 +216,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
this.entityManager.merge(data); this.entityManager.merge(data);
else { else {
this.entityManager.persist(data); 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()); 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.deleterFactory.deleter(DescriptionTemplateDeleter.class).deleteAndSaveByIds(List.of(id));
this.accountingService.decrease(UsageLimitTargetMetric.DESCRIPTION_TEMPLATE_COUNT);
} }
//endregion //endregion
@ -623,6 +622,8 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
this.authorizationService.authorizeForce(Permission.CreateNewVersionDescriptionTemplate); this.authorizationService.authorizeForce(Permission.CreateNewVersionDescriptionTemplate);
this.usageLimitService.checkIncrease(UsageLimitTargetMetric.DESCRIPTION_TEMPLATE_COUNT);
DescriptionTemplateEntity oldDescriptionTemplateEntity = this.entityManager.find(DescriptionTemplateEntity.class, model.getId(), true); DescriptionTemplateEntity oldDescriptionTemplateEntity = this.entityManager.find(DescriptionTemplateEntity.class, model.getId(), true);
if (oldDescriptionTemplateEntity == null) if (oldDescriptionTemplateEntity == null)
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale())); 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.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); return this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(AuthorizationFlags.AllExceptPublic).build(BaseFieldSet.build(fields, DescriptionTemplate._id), data);
} }

View File

@ -112,7 +112,7 @@ public class DescriptionTemplateTypeServiceImpl implements DescriptionTemplateTy
this.entityManager.merge(data); this.entityManager.merge(data);
else{ else{
this.entityManager.persist(data); this.entityManager.persist(data);
this.accountingService.increase(UsageLimitTargetMetric.DESCRIPTION_TEMPLATE_TYPE_COUNT); this.accountingService.increase(UsageLimitTargetMetric.DESCRIPTION_TEMPLATE_TYPE_COUNT.getValue());
} }
this.entityManager.flush(); this.entityManager.flush();
@ -127,7 +127,6 @@ public class DescriptionTemplateTypeServiceImpl implements DescriptionTemplateTy
this.authorizationService.authorizeForce(Permission.DeleteDescriptionTemplateType); this.authorizationService.authorizeForce(Permission.DeleteDescriptionTemplateType);
this.deleterFactory.deleter(DescriptionTemplateTypeDeleter.class).deleteAndSaveByIds(List.of(id)); this.deleterFactory.deleter(DescriptionTemplateTypeDeleter.class).deleteAndSaveByIds(List.of(id));
this.accountingService.decrease(UsageLimitTargetMetric.DESCRIPTION_TEMPLATE_TYPE_COUNT);
} }
} }

View File

@ -25,6 +25,7 @@ import org.opencdmp.commons.JsonHandlingService;
import org.opencdmp.commons.enums.IsActive; import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.commons.enums.StorageType; import org.opencdmp.commons.enums.StorageType;
import org.opencdmp.commons.enums.TenantConfigurationType; import org.opencdmp.commons.enums.TenantConfigurationType;
import org.opencdmp.commons.enums.UsageLimitTargetMetric;
import org.opencdmp.commons.scope.tenant.TenantScope; import org.opencdmp.commons.scope.tenant.TenantScope;
import org.opencdmp.commons.scope.user.UserScope; import org.opencdmp.commons.scope.user.UserScope;
import org.opencdmp.commons.types.filetransformer.FileTransformerSourceEntity; 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.planblueprint.PlanBlueprint;
import org.opencdmp.model.tenantconfiguration.TenantConfiguration; import org.opencdmp.model.tenantconfiguration.TenantConfiguration;
import org.opencdmp.query.*; import org.opencdmp.query.*;
import org.opencdmp.service.accounting.AccountingService;
import org.opencdmp.service.encryption.EncryptionService; import org.opencdmp.service.encryption.EncryptionService;
import org.opencdmp.service.storage.StorageFileService; import org.opencdmp.service.storage.StorageFileService;
import org.opencdmp.service.tenant.TenantProperties; import org.opencdmp.service.tenant.TenantProperties;
@ -99,10 +101,11 @@ public class FileTransformerServiceImpl implements FileTransformerService {
private final JsonHandlingService jsonHandlingService; private final JsonHandlingService jsonHandlingService;
private final FileTransformerSourcesCacheService fileTransformerSourcesCacheService; private final FileTransformerSourcesCacheService fileTransformerSourcesCacheService;
private final UserScope userScope; private final UserScope userScope;
private final AccountingService accountingService;
@Autowired @Autowired
public FileTransformerServiceImpl(FileTransformerProperties fileTransformerProperties, TokenExchangeCacheService tokenExchangeCacheService, FileTransformerConfigurationCacheService fileTransformerConfigurationCacheService, AuthorizationService authorizationService, 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.fileTransformerProperties = fileTransformerProperties;
this.tokenExchangeCacheService = tokenExchangeCacheService; this.tokenExchangeCacheService = tokenExchangeCacheService;
this.fileTransformerConfigurationCacheService = fileTransformerConfigurationCacheService; this.fileTransformerConfigurationCacheService = fileTransformerConfigurationCacheService;
@ -118,6 +121,7 @@ public class FileTransformerServiceImpl implements FileTransformerService {
this.jsonHandlingService = jsonHandlingService; this.jsonHandlingService = jsonHandlingService;
this.fileTransformerSourcesCacheService = fileTransformerSourcesCacheService; this.fileTransformerSourcesCacheService = fileTransformerSourcesCacheService;
this.userScope = userScope; this.userScope = userScope;
this.accountingService = accountingService;
this.clients = new HashMap<>(); 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(); byte[] data = repository.getConfiguration().isUseSharedStorage() ? this.storageFileService.readByFileRefAsBytesSafe(fileEnvelope.getFileRef(), StorageType.Transformer) : fileEnvelope.getFile();
result.setFile(data); result.setFile(data);
result.setFilename(fileEnvelope.getFilename()); 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; 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 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.setFile(data);
result.setFilename(fileEnvelope.getFilename()); 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; return result;
} }
@ -376,6 +388,9 @@ public class FileTransformerServiceImpl implements FileTransformerService {
planImportModel.setFile(fileEnvelope); 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); return repository.importPlan(planImportModel);
} }
@ -414,4 +429,8 @@ public class FileTransformerServiceImpl implements FileTransformerService {
return repository.preprocessingPlan(fileEnvelope); return repository.preprocessingPlan(fileEnvelope);
} }
private void increaseTargetMetricWithRepositoryId(UsageLimitTargetMetric metric, String repositoryId){
this.accountingService.increase(metric.getValue() + repositoryId);
}
} }

View File

@ -389,7 +389,6 @@ public class PlanServiceImpl implements PlanService {
if (previousPlan != null) this.elasticService.persistPlan(previousPlan); if (previousPlan != null) this.elasticService.persistPlan(previousPlan);
this.annotationEntityRemovalIntegrationEventHandler.handlePlan(data.getId()); this.annotationEntityRemovalIntegrationEventHandler.handlePlan(data.getId());
this.accountingService.decrease(UsageLimitTargetMetric.PLAN_COUNT);
} }
@Override @Override
@ -397,6 +396,7 @@ public class PlanServiceImpl implements PlanService {
logger.debug(new MapLogEntry("persisting data bew version").And("model", model).And("fields", fields)); 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.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); 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 (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()); 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(newPlan.getId());
this.annotationEntityTouchedIntegrationEventHandler.handlePlan(oldPlanEntity.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); return this.builderFactory.builder(PlanBuilder.class).build(BaseFieldSet.build(fields, Plan._id), newPlan);
} }
public void cloneDescription(UUID planId, Map<UUID, UUID> planDescriptionTemplateRemap, UUID descriptionId, UUID newPlanDescriptionTemplateId) throws InvalidApplicationException, IOException { public void cloneDescription(UUID planId, Map<UUID, UUID> planDescriptionTemplateRemap, UUID descriptionId, UUID newPlanDescriptionTemplateId) throws InvalidApplicationException, IOException {
logger.debug("cloning description: {} with description: {}", descriptionId, planId); 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(); 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); 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(newDescription.getId());
this.annotationEntityTouchedIntegrationEventHandler.handleDescription(existing.getId()); this.annotationEntityTouchedIntegrationEventHandler.handleDescription(existing.getId());
this.accountingService.increase(UsageLimitTargetMetric.DESCRIPTION_COUNT.getValue());
} }
@ -686,6 +691,8 @@ public class PlanServiceImpl implements PlanService {
@Override @Override
public Plan buildClone(ClonePlanPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, IOException, InvalidApplicationException { 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); PlanEntity existingPlanEntity = this.queryFactory.query(PlanQuery.class).disableTracking().ids(model.getId()).firstAs(fields);
if (!this.conventionService.isValidGuid(model.getId()) || existingPlanEntity == null) if (!this.conventionService.isValidGuid(model.getId()) || existingPlanEntity == null)
@ -787,6 +794,8 @@ public class PlanServiceImpl implements PlanService {
this.annotationEntityTouchedIntegrationEventHandler.handlePlan(newPlan.getId()); 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); PlanEntity resultingPlanEntity = this.queryFactory.query(PlanQuery.class).disableTracking().ids(newPlan.getId()).firstAs(fields);
if (!this.conventionService.isListNullOrEmpty(model.getDescriptions())){ if (!this.conventionService.isListNullOrEmpty(model.getDescriptions())){
for (UUID description: model.getDescriptions()) { for (UUID description: model.getDescriptions()) {
@ -937,7 +946,7 @@ public class PlanServiceImpl implements PlanService {
this.entityManager.merge(data); this.entityManager.merge(data);
else { else {
this.entityManager.persist(data); this.entityManager.persist(data);
this.accountingService.increase(UsageLimitTargetMetric.PLAN_COUNT); this.accountingService.increase(UsageLimitTargetMetric.PLAN_COUNT.getValue());
} }
this.entityManager.flush(); this.entityManager.flush();

View File

@ -174,7 +174,7 @@ public class PlanBlueprintServiceImpl implements PlanBlueprintService {
this.entityManager.merge(data); this.entityManager.merge(data);
else{ else{
this.entityManager.persist(data); this.entityManager.persist(data);
this.accountingService.increase(UsageLimitTargetMetric.BLUEPRINT_COUNT); this.accountingService.increase(UsageLimitTargetMetric.BLUEPRINT_COUNT.getValue());
} }
this.entityManager.flush(); this.entityManager.flush();
@ -318,7 +318,6 @@ public class PlanBlueprintServiceImpl implements PlanBlueprintService {
this.authorizationService.authorizeForce(Permission.DeletePlanBlueprint); this.authorizationService.authorizeForce(Permission.DeletePlanBlueprint);
this.deleterFactory.deleter(PlanBlueprintDeleter.class).deleteAndSaveByIds(List.of(id)); this.deleterFactory.deleter(PlanBlueprintDeleter.class).deleteAndSaveByIds(List.of(id));
this.accountingService.decrease(UsageLimitTargetMetric.BLUEPRINT_COUNT);
} }
//endregion //endregion
@ -414,6 +413,7 @@ public class PlanBlueprintServiceImpl implements PlanBlueprintService {
logger.debug(new MapLogEntry("persisting data planBlueprint").And("model", model).And("fields", fields)); logger.debug(new MapLogEntry("persisting data planBlueprint").And("model", model).And("fields", fields));
this.authorizationService.authorizeForce(Permission.CreateNewVersionPlanBlueprint); this.authorizationService.authorizeForce(Permission.CreateNewVersionPlanBlueprint);
this.usageLimitService.checkIncrease(UsageLimitTargetMetric.BLUEPRINT_COUNT);
PlanBlueprintEntity oldPlanBlueprintEntity = this.entityManager.find(PlanBlueprintEntity.class, model.getId(), true); PlanBlueprintEntity oldPlanBlueprintEntity = this.entityManager.find(PlanBlueprintEntity.class, model.getId(), true);
if (oldPlanBlueprintEntity == null) if (oldPlanBlueprintEntity == null)
@ -461,6 +461,8 @@ public class PlanBlueprintServiceImpl implements PlanBlueprintService {
this.entityManager.flush(); 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); return this.builderFactory.builder(PlanBlueprintBuilder.class).authorize(AuthorizationFlags.AllExceptPublic).build(BaseFieldSet.build(fields, PlanBlueprint._id), data);
} }

View File

@ -158,7 +158,7 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService {
if (isUpdate) this.entityManager.merge(data); if (isUpdate) this.entityManager.merge(data);
else { else {
this.entityManager.persist(data); this.entityManager.persist(data);
this.accountingService.increase(UsageLimitTargetMetric.PREFILLING_SOURCES_COUNT); this.accountingService.increase(UsageLimitTargetMetric.PREFILLING_SOURCES_COUNT.getValue());
} }
this.entityManager.flush(); this.entityManager.flush();
@ -329,7 +329,6 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService {
this.authorizationService.authorizeForce(Permission.DeletePrefillingSource); this.authorizationService.authorizeForce(Permission.DeletePrefillingSource);
this.deleterFactory.deleter(PrefillingSourceDeleter.class).deleteAndSaveByIds(List.of(id)); this.deleterFactory.deleter(PrefillingSourceDeleter.class).deleteAndSaveByIds(List.of(id));
this.accountingService.decrease(UsageLimitTargetMetric.PREFILLING_SOURCES_COUNT);
} }
public List<Prefilling> searchPrefillings(PrefillingSearchRequest model) { public List<Prefilling> searchPrefillings(PrefillingSearchRequest model) {

View File

@ -113,7 +113,7 @@ public class ReferenceTypeServiceImpl implements ReferenceTypeService {
if (isUpdate) this.entityManager.merge(data); if (isUpdate) this.entityManager.merge(data);
else { else {
this.entityManager.persist(data); this.entityManager.persist(data);
this.accountingService.increase(UsageLimitTargetMetric.REFERENCE_TYPE_COUNT); this.accountingService.increase(UsageLimitTargetMetric.REFERENCE_TYPE_COUNT.getValue());
} }
this.entityManager.flush(); this.entityManager.flush();
@ -306,6 +306,5 @@ public class ReferenceTypeServiceImpl implements ReferenceTypeService {
this.authorizationService.authorizeForce(Permission.DeleteReferenceType); this.authorizationService.authorizeForce(Permission.DeleteReferenceType);
this.deleterFactory.deleter(ReferenceTypeDeleter.class).deleteAndSaveByIds(List.of(id)); this.deleterFactory.deleter(ReferenceTypeDeleter.class).deleteAndSaveByIds(List.of(id));
this.accountingService.decrease(UsageLimitTargetMetric.REFERENCE_TYPE_COUNT);
} }
} }

View File

@ -140,8 +140,8 @@ public class UsageLimitServiceImpl implements UsageLimitService {
try { try {
this.tenantEntityManager.loadExplicitTenantFilters(); 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)); 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(), this.errors.getUsageLimitException().getMessage()); if (usageLimitEntity != null && currentValue >= usageLimitEntity.getValue()) throw new MyValidationException(this.errors.getUsageLimitException().getCode(), usageLimitEntity.getLabel());
} catch (InvalidApplicationException e) { } catch (InvalidApplicationException e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);

View File

@ -226,7 +226,10 @@ export class PlanBlueprintEditorComponent extends BaseEditor<PlanBlueprintEditor
this.planBlueprintService.persist(formData) this.planBlueprintService.persist(formData)
.pipe(takeUntil(this._destroyed)).subscribe( .pipe(takeUntil(this._destroyed)).subscribe(
complete => onSuccess ? onSuccess(complete) : this.onCallbackSuccess(complete), complete => 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) { } else if (this.isNewVersion == true && this.isNew == false && this.isClone == false) {
const formData = this.formService.getValue(this.formGroup.value) as NewVersionPlanBlueprintPersist; const formData = this.formService.getValue(this.formGroup.value) as NewVersionPlanBlueprintPersist;

View File

@ -80,7 +80,7 @@
"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": "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": { "FORM-VALIDATION-DISPLAY-DIALOG": {
"WARNING": "Kontuz!", "WARNING": "Kontuz!",

View File

@ -80,7 +80,7 @@
"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": "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": { "FORM-VALIDATION-DISPLAY-DIALOG": {
"WARNING": "Warnung!", "WARNING": "Warnung!",

View File

@ -80,7 +80,7 @@
"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": "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": { "FORM-VALIDATION-DISPLAY-DIALOG": {
"WARNING": "Warning!", "WARNING": "Warning!",

View File

@ -80,7 +80,7 @@
"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": "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": { "FORM-VALIDATION-DISPLAY-DIALOG": {
"WARNING": "Atención!", "WARNING": "Atención!",

View File

@ -80,7 +80,7 @@
"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": "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": { "FORM-VALIDATION-DISPLAY-DIALOG": {
"WARNING": "Προσοχή!", "WARNING": "Προσοχή!",

View File

@ -80,7 +80,7 @@
"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": "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": { "FORM-VALIDATION-DISPLAY-DIALOG": {
"WARNING": "Oprez!", "WARNING": "Oprez!",

View File

@ -80,7 +80,7 @@
"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": "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": { "FORM-VALIDATION-DISPLAY-DIALOG": {
"WARNING": "Ostrzeżenie!", "WARNING": "Ostrzeżenie!",

View File

@ -80,7 +80,7 @@
"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": "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": { "FORM-VALIDATION-DISPLAY-DIALOG": {
"WARNING": "Atenção!", "WARNING": "Atenção!",

View File

@ -80,7 +80,7 @@
"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": "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": { "FORM-VALIDATION-DISPLAY-DIALOG": {
"WARNING": "Upozornenie!", "WARNING": "Upozornenie!",

View File

@ -80,7 +80,7 @@
"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": "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": { "FORM-VALIDATION-DISPLAY-DIALOG": {
"WARNING": "Oprez!", "WARNING": "Oprez!",

View File

@ -80,7 +80,7 @@
"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": "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": { "FORM-VALIDATION-DISPLAY-DIALOG": {
"WARNING": "Uyarı!", "WARNING": "Uyarı!",

View File

@ -1,6 +1,6 @@
import { HttpErrorResponse } from '@angular/common/http'; import { HttpErrorResponse } from '@angular/common/http';
import { Injectable } from '@angular/core'; 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 { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
@ -17,7 +17,11 @@ export class HttpErrorHandlingService {
let errorMessage = messageOvverrides?.has(error.statusCode) ? messageOvverrides?.get(error.statusCode) : null; let errorMessage = messageOvverrides?.has(error.statusCode) ? messageOvverrides?.get(error.statusCode) : null;
if(errorResponse.error && ResponseErrorCodeHelper.isBackendError(errorResponse.error?.code)){ 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) { else if (error.statusCode === 302) {
errorMessage ??= this.language.instant('GENERAL.SNACK-BAR.REDIRECT'); errorMessage ??= this.language.instant('GENERAL.SNACK-BAR.REDIRECT');