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_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<String> {
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) {

View File

@ -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<UUID> 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());
}
}

View File

@ -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<UUID> 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());
}
}

View File

@ -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<UUID> 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());
}
}

View File

@ -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<UUID> 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());
}
}

View File

@ -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<UUID> 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());
}
}

View File

@ -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<UUID> 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());
}
}

View File

@ -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<UUID> 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());
}
}

View File

@ -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);
}

View File

@ -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
}
}

View File

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

View File

@ -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

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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<UUID, UUID> 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();

View File

@ -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);
}

View File

@ -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<Prefilling> searchPrefillings(PrefillingSearchRequest model) {

View File

@ -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);
}
}

View File

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

View File

@ -226,7 +226,10 @@ export class PlanBlueprintEditorComponent extends BaseEditor<PlanBlueprintEditor
this.planBlueprintService.persist(formData)
.pipe(takeUntil(this._destroyed)).subscribe(
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) {
const formData = this.formService.getValue(this.formGroup.value) as NewVersionPlanBlueprintPersist;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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');