call checkIncrease for all entities
This commit is contained in:
parent
df7a6586ce
commit
c5fb1de856
|
@ -70,6 +70,7 @@ import org.opencdmp.model.planblueprint.PlanBlueprint;
|
||||||
import org.opencdmp.model.reference.Reference;
|
import org.opencdmp.model.reference.Reference;
|
||||||
import org.opencdmp.model.referencetype.ReferenceType;
|
import org.opencdmp.model.referencetype.ReferenceType;
|
||||||
import org.opencdmp.query.*;
|
import org.opencdmp.query.*;
|
||||||
|
import org.opencdmp.service.accounting.AccountingService;
|
||||||
import org.opencdmp.service.descriptiontemplate.DescriptionTemplateService;
|
import org.opencdmp.service.descriptiontemplate.DescriptionTemplateService;
|
||||||
import org.opencdmp.service.elastic.ElasticService;
|
import org.opencdmp.service.elastic.ElasticService;
|
||||||
import org.opencdmp.service.filetransformer.FileTransformerService;
|
import org.opencdmp.service.filetransformer.FileTransformerService;
|
||||||
|
@ -77,6 +78,7 @@ import org.opencdmp.service.responseutils.ResponseUtilsService;
|
||||||
import org.opencdmp.service.storage.StorageFileProperties;
|
import org.opencdmp.service.storage.StorageFileProperties;
|
||||||
import org.opencdmp.service.storage.StorageFileService;
|
import org.opencdmp.service.storage.StorageFileService;
|
||||||
import org.opencdmp.service.tag.TagService;
|
import org.opencdmp.service.tag.TagService;
|
||||||
|
import org.opencdmp.service.usagelimit.UsageLimitService;
|
||||||
import org.opencdmp.service.visibility.VisibilityService;
|
import org.opencdmp.service.visibility.VisibilityService;
|
||||||
import org.opencdmp.service.visibility.VisibilityServiceImpl;
|
import org.opencdmp.service.visibility.VisibilityServiceImpl;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -138,6 +140,8 @@ public class DescriptionServiceImpl implements DescriptionService {
|
||||||
private final ResponseUtilsService responseUtilsService;
|
private final ResponseUtilsService responseUtilsService;
|
||||||
private final DescriptionTemplateService descriptionTemplateService;
|
private final DescriptionTemplateService descriptionTemplateService;
|
||||||
private final TagService tagService;
|
private final TagService tagService;
|
||||||
|
private final UsageLimitService usageLimitService;
|
||||||
|
private final AccountingService accountingService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DescriptionServiceImpl(
|
public DescriptionServiceImpl(
|
||||||
|
@ -152,7 +156,7 @@ public class DescriptionServiceImpl implements DescriptionService {
|
||||||
QueryFactory queryFactory,
|
QueryFactory queryFactory,
|
||||||
JsonHandlingService jsonHandlingService,
|
JsonHandlingService jsonHandlingService,
|
||||||
UserScope userScope,
|
UserScope userScope,
|
||||||
XmlHandlingService xmlHandlingService, NotifyIntegrationEventHandler eventHandler, NotificationProperties notificationProperties, FileTransformerService fileTransformerService, ElasticService elasticService, ValidatorFactory validatorFactory, StorageFileProperties storageFileConfig, StorageFileService storageFileService, AuthorizationContentResolver authorizationContentResolver, AnnotationEntityTouchedIntegrationEventHandler annotationEntityTouchedIntegrationEventHandler, AnnotationEntityRemovalIntegrationEventHandler annotationEntityRemovalIntegrationEventHandler, TenantScope tenantScope, ResponseUtilsService responseUtilsService, DescriptionTemplateService descriptionTemplateService, TagService tagService) {
|
XmlHandlingService xmlHandlingService, NotifyIntegrationEventHandler eventHandler, NotificationProperties notificationProperties, FileTransformerService fileTransformerService, ElasticService elasticService, ValidatorFactory validatorFactory, StorageFileProperties storageFileConfig, StorageFileService storageFileService, AuthorizationContentResolver authorizationContentResolver, AnnotationEntityTouchedIntegrationEventHandler annotationEntityTouchedIntegrationEventHandler, AnnotationEntityRemovalIntegrationEventHandler annotationEntityRemovalIntegrationEventHandler, TenantScope tenantScope, ResponseUtilsService responseUtilsService, DescriptionTemplateService descriptionTemplateService, TagService tagService, UsageLimitService usageLimitService, AccountingService accountingService) {
|
||||||
this.entityManager = entityManager;
|
this.entityManager = entityManager;
|
||||||
this.authorizationService = authorizationService;
|
this.authorizationService = authorizationService;
|
||||||
this.deleterFactory = deleterFactory;
|
this.deleterFactory = deleterFactory;
|
||||||
|
@ -179,6 +183,8 @@ public class DescriptionServiceImpl implements DescriptionService {
|
||||||
this.responseUtilsService = responseUtilsService;
|
this.responseUtilsService = responseUtilsService;
|
||||||
this.descriptionTemplateService = descriptionTemplateService;
|
this.descriptionTemplateService = descriptionTemplateService;
|
||||||
this.tagService = tagService;
|
this.tagService = tagService;
|
||||||
|
this.usageLimitService = usageLimitService;
|
||||||
|
this.accountingService = accountingService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -222,7 +228,7 @@ public class DescriptionServiceImpl implements DescriptionService {
|
||||||
if (!data.getPlanId().equals(model.getPlanId())) throw new MyValidationException(this.errors.getPlanCanNotChange().getCode(), this.errors.getPlanCanNotChange().getMessage());
|
if (!data.getPlanId().equals(model.getPlanId())) throw new MyValidationException(this.errors.getPlanCanNotChange().getCode(), this.errors.getPlanCanNotChange().getMessage());
|
||||||
if (!data.getPlanDescriptionTemplateId().equals(model.getPlanDescriptionTemplateId())) throw new MyValidationException(this.errors.getPlanDescriptionTemplateCanNotChange().getCode(), this.errors.getPlanDescriptionTemplateCanNotChange().getMessage());
|
if (!data.getPlanDescriptionTemplateId().equals(model.getPlanDescriptionTemplateId())) throw new MyValidationException(this.errors.getPlanDescriptionTemplateCanNotChange().getCode(), this.errors.getPlanDescriptionTemplateCanNotChange().getMessage());
|
||||||
} else {
|
} else {
|
||||||
//this.usageLimitService.checkIncrease("description_count");
|
this.usageLimitService.checkIncrease(UsageLimitTargetMetric.DESCRIPTION_COUNT);
|
||||||
|
|
||||||
PlanEntity planEntity = this.entityManager.find(PlanEntity.class, model.getPlanId(), true);
|
PlanEntity planEntity = this.entityManager.find(PlanEntity.class, model.getPlanId(), true);
|
||||||
if (planEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getPlanId(), Plan.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
if (planEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getPlanId(), Plan.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||||
|
@ -258,7 +264,10 @@ public class DescriptionServiceImpl implements DescriptionService {
|
||||||
data.setDescriptionTemplateId(model.getDescriptionTemplateId());
|
data.setDescriptionTemplateId(model.getDescriptionTemplateId());
|
||||||
data.setUpdatedAt(Instant.now());
|
data.setUpdatedAt(Instant.now());
|
||||||
if (isUpdate) this.entityManager.merge(data);
|
if (isUpdate) this.entityManager.merge(data);
|
||||||
else this.entityManager.persist(data);
|
else {
|
||||||
|
this.entityManager.persist(data);
|
||||||
|
this.accountingService.increase(UsageLimitTargetMetric.DESCRIPTION_COUNT);
|
||||||
|
}
|
||||||
|
|
||||||
this.entityManager.flush();
|
this.entityManager.flush();
|
||||||
|
|
||||||
|
@ -892,6 +901,7 @@ 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
|
||||||
|
|
|
@ -58,10 +58,12 @@ import org.opencdmp.model.user.User;
|
||||||
import org.opencdmp.query.DescriptionTemplateQuery;
|
import org.opencdmp.query.DescriptionTemplateQuery;
|
||||||
import org.opencdmp.query.DescriptionTemplateTypeQuery;
|
import org.opencdmp.query.DescriptionTemplateTypeQuery;
|
||||||
import org.opencdmp.query.UserDescriptionTemplateQuery;
|
import org.opencdmp.query.UserDescriptionTemplateQuery;
|
||||||
|
import org.opencdmp.service.accounting.AccountingService;
|
||||||
import org.opencdmp.service.descriptiontemplatetype.DescriptionTemplateTypeService;
|
import org.opencdmp.service.descriptiontemplatetype.DescriptionTemplateTypeService;
|
||||||
import org.opencdmp.service.fielddatahelper.FieldDataHelperService;
|
import org.opencdmp.service.fielddatahelper.FieldDataHelperService;
|
||||||
import org.opencdmp.service.fielddatahelper.FieldDataHelperServiceProvider;
|
import org.opencdmp.service.fielddatahelper.FieldDataHelperServiceProvider;
|
||||||
import org.opencdmp.service.responseutils.ResponseUtilsService;
|
import org.opencdmp.service.responseutils.ResponseUtilsService;
|
||||||
|
import org.opencdmp.service.usagelimit.UsageLimitService;
|
||||||
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.context.MessageSource;
|
import org.springframework.context.MessageSource;
|
||||||
|
@ -120,6 +122,8 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
|
||||||
private final ValidatorFactory validatorFactory;
|
private final ValidatorFactory validatorFactory;
|
||||||
private final DescriptionTemplateTypeService descriptionTemplateTypeService;
|
private final DescriptionTemplateTypeService descriptionTemplateTypeService;
|
||||||
private final AuthorizationContentResolver authorizationContentResolver;
|
private final AuthorizationContentResolver authorizationContentResolver;
|
||||||
|
private final UsageLimitService usageLimitService;
|
||||||
|
private final AccountingService accountingService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DescriptionTemplateServiceImpl(
|
public DescriptionTemplateServiceImpl(
|
||||||
|
@ -137,7 +141,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
|
||||||
JsonHandlingService jsonHandlingService,
|
JsonHandlingService jsonHandlingService,
|
||||||
NotifyIntegrationEventHandler eventHandler,
|
NotifyIntegrationEventHandler eventHandler,
|
||||||
NotificationProperties notificationProperties,
|
NotificationProperties notificationProperties,
|
||||||
ValidatorFactory validatorFactory, DescriptionTemplateTypeService descriptionTemplateTypeService, AuthorizationContentResolver authorizationContentResolver) {
|
ValidatorFactory validatorFactory, DescriptionTemplateTypeService descriptionTemplateTypeService, AuthorizationContentResolver authorizationContentResolver, UsageLimitService usageLimitService, AccountingService accountingService) {
|
||||||
this.entityManager = entityManager;
|
this.entityManager = entityManager;
|
||||||
this.userScope = userScope;
|
this.userScope = userScope;
|
||||||
this.authorizationService = authorizationService;
|
this.authorizationService = authorizationService;
|
||||||
|
@ -157,6 +161,8 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
|
||||||
this.validatorFactory = validatorFactory;
|
this.validatorFactory = validatorFactory;
|
||||||
this.descriptionTemplateTypeService = descriptionTemplateTypeService;
|
this.descriptionTemplateTypeService = descriptionTemplateTypeService;
|
||||||
this.authorizationContentResolver = authorizationContentResolver;
|
this.authorizationContentResolver = authorizationContentResolver;
|
||||||
|
this.usageLimitService = usageLimitService;
|
||||||
|
this.accountingService = accountingService;
|
||||||
}
|
}
|
||||||
|
|
||||||
//region Persist
|
//region Persist
|
||||||
|
@ -178,6 +184,8 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
|
||||||
if (data.getStatus().equals(DescriptionTemplateStatus.Finalized))
|
if (data.getStatus().equals(DescriptionTemplateStatus.Finalized))
|
||||||
throw new MyForbiddenException("Can not update finalized template");
|
throw new MyForbiddenException("Can not update finalized template");
|
||||||
} else {
|
} else {
|
||||||
|
this.usageLimitService.checkIncrease(UsageLimitTargetMetric.DESCRIPTION_TEMPLATE_COUNT);
|
||||||
|
|
||||||
data = new DescriptionTemplateEntity();
|
data = new DescriptionTemplateEntity();
|
||||||
data.setId(UUID.randomUUID());
|
data.setId(UUID.randomUUID());
|
||||||
data.setStatus(DescriptionTemplateStatus.Draft);
|
data.setStatus(DescriptionTemplateStatus.Draft);
|
||||||
|
@ -206,8 +214,10 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
|
||||||
data.setDefinition(this.xmlHandlingService.toXml(this.buildDefinitionEntity(model.getDefinition())));
|
data.setDefinition(this.xmlHandlingService.toXml(this.buildDefinitionEntity(model.getDefinition())));
|
||||||
if (isUpdate)
|
if (isUpdate)
|
||||||
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.persistUsers(data.getId(), model.getUsers());
|
this.persistUsers(data.getId(), model.getUsers());
|
||||||
|
|
||||||
|
@ -519,6 +529,7 @@ 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
|
||||||
|
|
|
@ -71,7 +71,6 @@ import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEvent;
|
||||||
import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEventHandler;
|
import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEventHandler;
|
||||||
import org.opencdmp.model.PlanUser;
|
import org.opencdmp.model.PlanUser;
|
||||||
import org.opencdmp.model.PlanValidationResult;
|
import org.opencdmp.model.PlanValidationResult;
|
||||||
import org.opencdmp.model.PublicPlan;
|
|
||||||
import org.opencdmp.model.builder.PlanUserBuilder;
|
import org.opencdmp.model.builder.PlanUserBuilder;
|
||||||
import org.opencdmp.model.builder.description.DescriptionBuilder;
|
import org.opencdmp.model.builder.description.DescriptionBuilder;
|
||||||
import org.opencdmp.model.builder.plan.PlanBuilder;
|
import org.opencdmp.model.builder.plan.PlanBuilder;
|
||||||
|
@ -92,8 +91,8 @@ import org.opencdmp.model.planblueprint.PlanBlueprint;
|
||||||
import org.opencdmp.model.planreference.PlanReferenceData;
|
import org.opencdmp.model.planreference.PlanReferenceData;
|
||||||
import org.opencdmp.model.reference.Reference;
|
import org.opencdmp.model.reference.Reference;
|
||||||
import org.opencdmp.model.referencetype.ReferenceType;
|
import org.opencdmp.model.referencetype.ReferenceType;
|
||||||
import org.opencdmp.model.result.QueryResult;
|
|
||||||
import org.opencdmp.query.*;
|
import org.opencdmp.query.*;
|
||||||
|
import org.opencdmp.service.accounting.AccountingService;
|
||||||
import org.opencdmp.service.actionconfirmation.ActionConfirmationService;
|
import org.opencdmp.service.actionconfirmation.ActionConfirmationService;
|
||||||
import org.opencdmp.service.description.DescriptionService;
|
import org.opencdmp.service.description.DescriptionService;
|
||||||
import org.opencdmp.service.descriptiontemplate.DescriptionTemplateService;
|
import org.opencdmp.service.descriptiontemplate.DescriptionTemplateService;
|
||||||
|
@ -101,6 +100,7 @@ import org.opencdmp.service.elastic.ElasticService;
|
||||||
import org.opencdmp.service.filetransformer.FileTransformerService;
|
import org.opencdmp.service.filetransformer.FileTransformerService;
|
||||||
import org.opencdmp.service.planblueprint.PlanBlueprintService;
|
import org.opencdmp.service.planblueprint.PlanBlueprintService;
|
||||||
import org.opencdmp.service.responseutils.ResponseUtilsService;
|
import org.opencdmp.service.responseutils.ResponseUtilsService;
|
||||||
|
import org.opencdmp.service.usagelimit.UsageLimitService;
|
||||||
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.context.MessageSource;
|
import org.springframework.context.MessageSource;
|
||||||
|
@ -127,8 +127,6 @@ import java.time.Instant;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.opencdmp.authorization.AuthorizationFlags.Public;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class PlanServiceImpl implements PlanService {
|
public class PlanServiceImpl implements PlanService {
|
||||||
|
|
||||||
|
@ -179,6 +177,8 @@ public class PlanServiceImpl implements PlanService {
|
||||||
private final TenantScope tenantScope;
|
private final TenantScope tenantScope;
|
||||||
private final ResponseUtilsService responseUtilsService;
|
private final ResponseUtilsService responseUtilsService;
|
||||||
private final PlanBlueprintService planBlueprintService;
|
private final PlanBlueprintService planBlueprintService;
|
||||||
|
private final UsageLimitService usageLimitService;
|
||||||
|
private final AccountingService accountingService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public PlanServiceImpl(
|
public PlanServiceImpl(
|
||||||
|
@ -201,7 +201,7 @@ public class PlanServiceImpl implements PlanService {
|
||||||
FileTransformerService fileTransformerService,
|
FileTransformerService fileTransformerService,
|
||||||
ValidatorFactory validatorFactory,
|
ValidatorFactory validatorFactory,
|
||||||
ElasticService elasticService, DescriptionTemplateService descriptionTemplateService,
|
ElasticService elasticService, DescriptionTemplateService descriptionTemplateService,
|
||||||
AnnotationEntityTouchedIntegrationEventHandler annotationEntityTouchedIntegrationEventHandler, AnnotationEntityRemovalIntegrationEventHandler annotationEntityRemovalIntegrationEventHandler, AuthorizationContentResolver authorizationContentResolver, TenantScope tenantScope, ResponseUtilsService responseUtilsService, PlanBlueprintService planBlueprintService) {
|
AnnotationEntityTouchedIntegrationEventHandler annotationEntityTouchedIntegrationEventHandler, AnnotationEntityRemovalIntegrationEventHandler annotationEntityRemovalIntegrationEventHandler, AuthorizationContentResolver authorizationContentResolver, TenantScope tenantScope, ResponseUtilsService responseUtilsService, PlanBlueprintService planBlueprintService, UsageLimitService usageLimitService, AccountingService accountingService) {
|
||||||
this.entityManager = entityManager;
|
this.entityManager = entityManager;
|
||||||
this.authorizationService = authorizationService;
|
this.authorizationService = authorizationService;
|
||||||
this.deleterFactory = deleterFactory;
|
this.deleterFactory = deleterFactory;
|
||||||
|
@ -228,13 +228,18 @@ public class PlanServiceImpl implements PlanService {
|
||||||
this.tenantScope = tenantScope;
|
this.tenantScope = tenantScope;
|
||||||
this.responseUtilsService = responseUtilsService;
|
this.responseUtilsService = responseUtilsService;
|
||||||
this.planBlueprintService = planBlueprintService;
|
this.planBlueprintService = planBlueprintService;
|
||||||
|
this.usageLimitService = usageLimitService;
|
||||||
|
this.accountingService = accountingService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Plan persist(PlanPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, IOException {
|
public Plan persist(PlanPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, IOException {
|
||||||
|
|
||||||
Boolean isUpdate = this.conventionService.isValidGuid(model.getId());
|
Boolean isUpdate = this.conventionService.isValidGuid(model.getId());
|
||||||
if (isUpdate) this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.planAffiliation(model.getId())), Permission.EditPlan);
|
if (isUpdate) this.authorizationService.authorizeAtLeastOneForce(List.of(this.authorizationContentResolver.planAffiliation(model.getId())), Permission.EditPlan);
|
||||||
else this.authorizationService.authorizeForce(Permission.NewPlan);
|
else {
|
||||||
|
this.authorizationService.authorizeForce(Permission.NewPlan);
|
||||||
|
this.usageLimitService.checkIncrease(UsageLimitTargetMetric.PLAN_COUNT);
|
||||||
|
}
|
||||||
|
|
||||||
PlanEntity data = this.patchAndSave(model);
|
PlanEntity data = this.patchAndSave(model);
|
||||||
|
|
||||||
|
@ -384,6 +389,7 @@ 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
|
||||||
|
@ -931,6 +937,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.entityManager.flush();
|
this.entityManager.flush();
|
||||||
|
|
|
@ -46,7 +46,9 @@ import org.opencdmp.query.DescriptionTemplateQuery;
|
||||||
import org.opencdmp.query.PlanBlueprintQuery;
|
import org.opencdmp.query.PlanBlueprintQuery;
|
||||||
import org.opencdmp.query.PrefillingSourceQuery;
|
import org.opencdmp.query.PrefillingSourceQuery;
|
||||||
import org.opencdmp.query.ReferenceTypeQuery;
|
import org.opencdmp.query.ReferenceTypeQuery;
|
||||||
|
import org.opencdmp.service.accounting.AccountingService;
|
||||||
import org.opencdmp.service.responseutils.ResponseUtilsService;
|
import org.opencdmp.service.responseutils.ResponseUtilsService;
|
||||||
|
import org.opencdmp.service.usagelimit.UsageLimitService;
|
||||||
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.context.MessageSource;
|
import org.springframework.context.MessageSource;
|
||||||
|
@ -90,6 +92,9 @@ public class PlanBlueprintServiceImpl implements PlanBlueprintService {
|
||||||
|
|
||||||
private final ValidatorFactory validatorFactory;
|
private final ValidatorFactory validatorFactory;
|
||||||
private final TenantScope tenantScope;
|
private final TenantScope tenantScope;
|
||||||
|
|
||||||
|
private final UsageLimitService usageLimitService;
|
||||||
|
private final AccountingService accountingService;
|
||||||
@Autowired
|
@Autowired
|
||||||
public PlanBlueprintServiceImpl(
|
public PlanBlueprintServiceImpl(
|
||||||
TenantEntityManager entityManager,
|
TenantEntityManager entityManager,
|
||||||
|
@ -101,7 +106,7 @@ public class PlanBlueprintServiceImpl implements PlanBlueprintService {
|
||||||
ResponseUtilsService responseUtilsService,
|
ResponseUtilsService responseUtilsService,
|
||||||
XmlHandlingService xmlHandlingService,
|
XmlHandlingService xmlHandlingService,
|
||||||
ErrorThesaurusProperties errors,
|
ErrorThesaurusProperties errors,
|
||||||
ValidatorFactory validatorFactory, TenantScope tenantScope) {
|
ValidatorFactory validatorFactory, TenantScope tenantScope, UsageLimitService usageLimitService, AccountingService accountingService) {
|
||||||
this.entityManager = entityManager;
|
this.entityManager = entityManager;
|
||||||
this.authorizationService = authorizationService;
|
this.authorizationService = authorizationService;
|
||||||
this.deleterFactory = deleterFactory;
|
this.deleterFactory = deleterFactory;
|
||||||
|
@ -114,6 +119,8 @@ public class PlanBlueprintServiceImpl implements PlanBlueprintService {
|
||||||
this.errors = errors;
|
this.errors = errors;
|
||||||
this.validatorFactory = validatorFactory;
|
this.validatorFactory = validatorFactory;
|
||||||
this.tenantScope = tenantScope;
|
this.tenantScope = tenantScope;
|
||||||
|
this.usageLimitService = usageLimitService;
|
||||||
|
this.accountingService = accountingService;
|
||||||
}
|
}
|
||||||
|
|
||||||
//region Persist
|
//region Persist
|
||||||
|
@ -135,6 +142,7 @@ public class PlanBlueprintServiceImpl implements PlanBlueprintService {
|
||||||
if (data.getStatus().equals(PlanBlueprintStatus.Finalized))
|
if (data.getStatus().equals(PlanBlueprintStatus.Finalized))
|
||||||
throw new MyForbiddenException("Cannot update finalized blueprint");
|
throw new MyForbiddenException("Cannot update finalized blueprint");
|
||||||
} else {
|
} else {
|
||||||
|
this.usageLimitService.checkIncrease(UsageLimitTargetMetric.BLUEPRINT_COUNT);
|
||||||
data = new PlanBlueprintEntity();
|
data = new PlanBlueprintEntity();
|
||||||
data.setId(UUID.randomUUID());
|
data.setId(UUID.randomUUID());
|
||||||
data.setStatus(PlanBlueprintStatus.Draft);
|
data.setStatus(PlanBlueprintStatus.Draft);
|
||||||
|
@ -164,8 +172,10 @@ public class PlanBlueprintServiceImpl implements PlanBlueprintService {
|
||||||
|
|
||||||
if (isUpdate)
|
if (isUpdate)
|
||||||
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.entityManager.flush();
|
this.entityManager.flush();
|
||||||
|
|
||||||
|
@ -308,6 +318,7 @@ 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
|
||||||
|
|
|
@ -20,6 +20,7 @@ import org.opencdmp.authorization.Permission;
|
||||||
import org.opencdmp.commons.JsonHandlingService;
|
import org.opencdmp.commons.JsonHandlingService;
|
||||||
import org.opencdmp.commons.XmlHandlingService;
|
import org.opencdmp.commons.XmlHandlingService;
|
||||||
import org.opencdmp.commons.enums.IsActive;
|
import org.opencdmp.commons.enums.IsActive;
|
||||||
|
import org.opencdmp.commons.enums.UsageLimitTargetMetric;
|
||||||
import org.opencdmp.commons.types.descriptiontemplate.DefinitionEntity;
|
import org.opencdmp.commons.types.descriptiontemplate.DefinitionEntity;
|
||||||
import org.opencdmp.commons.types.descriptiontemplate.FieldEntity;
|
import org.opencdmp.commons.types.descriptiontemplate.FieldEntity;
|
||||||
import org.opencdmp.commons.types.descriptiontemplate.FieldSetEntity;
|
import org.opencdmp.commons.types.descriptiontemplate.FieldSetEntity;
|
||||||
|
@ -60,10 +61,12 @@ import org.opencdmp.model.referencetype.ReferenceType;
|
||||||
import org.opencdmp.query.PrefillingSourceQuery;
|
import org.opencdmp.query.PrefillingSourceQuery;
|
||||||
import org.opencdmp.query.TagQuery;
|
import org.opencdmp.query.TagQuery;
|
||||||
import org.opencdmp.query.lookup.ReferenceSearchLookup;
|
import org.opencdmp.query.lookup.ReferenceSearchLookup;
|
||||||
|
import org.opencdmp.service.accounting.AccountingService;
|
||||||
import org.opencdmp.service.externalfetcher.ExternalFetcherService;
|
import org.opencdmp.service.externalfetcher.ExternalFetcherService;
|
||||||
import org.opencdmp.service.externalfetcher.criteria.ExternalReferenceCriteria;
|
import org.opencdmp.service.externalfetcher.criteria.ExternalReferenceCriteria;
|
||||||
import org.opencdmp.service.externalfetcher.models.ExternalDataResult;
|
import org.opencdmp.service.externalfetcher.models.ExternalDataResult;
|
||||||
import org.opencdmp.service.reference.ReferenceService;
|
import org.opencdmp.service.reference.ReferenceService;
|
||||||
|
import org.opencdmp.service.usagelimit.UsageLimitService;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.context.MessageSource;
|
import org.springframework.context.MessageSource;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
|
@ -99,13 +102,15 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService {
|
||||||
private final ErrorThesaurusProperties errors;
|
private final ErrorThesaurusProperties errors;
|
||||||
private final JsonHandlingService jsonHandlingService;
|
private final JsonHandlingService jsonHandlingService;
|
||||||
private final ReferenceService referenceService;
|
private final ReferenceService referenceService;
|
||||||
|
private final UsageLimitService usageLimitService;
|
||||||
|
private final AccountingService accountingService;
|
||||||
|
|
||||||
private static final String Zenodo = "Zenodo";
|
private static final String Zenodo = "Zenodo";
|
||||||
|
|
||||||
public PrefillingSourceServiceImpl(
|
public PrefillingSourceServiceImpl(
|
||||||
TenantEntityManager entityManager, AuthorizationService authorizationService, DeleterFactory deleterFactory, BuilderFactory builderFactory,
|
TenantEntityManager entityManager, AuthorizationService authorizationService, DeleterFactory deleterFactory, BuilderFactory builderFactory,
|
||||||
QueryFactory queryFactory, ConventionService conventionService, MessageSource messageSource,
|
QueryFactory queryFactory, ConventionService conventionService, MessageSource messageSource,
|
||||||
XmlHandlingService xmlHandlingService, ExternalFetcherService externalFetcherService, ErrorThesaurusProperties errors, JsonHandlingService jsonHandlingService, ReferenceService referenceService) {
|
XmlHandlingService xmlHandlingService, ExternalFetcherService externalFetcherService, ErrorThesaurusProperties errors, JsonHandlingService jsonHandlingService, ReferenceService referenceService, UsageLimitService usageLimitService, AccountingService accountingService) {
|
||||||
this.entityManager = entityManager;
|
this.entityManager = entityManager;
|
||||||
this.authorizationService = authorizationService;
|
this.authorizationService = authorizationService;
|
||||||
this.deleterFactory = deleterFactory;
|
this.deleterFactory = deleterFactory;
|
||||||
|
@ -118,6 +123,8 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService {
|
||||||
this.errors = errors;
|
this.errors = errors;
|
||||||
this.jsonHandlingService = jsonHandlingService;
|
this.jsonHandlingService = jsonHandlingService;
|
||||||
this.referenceService = referenceService;
|
this.referenceService = referenceService;
|
||||||
|
this.usageLimitService = usageLimitService;
|
||||||
|
this.accountingService = accountingService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -135,6 +142,7 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService {
|
||||||
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), PrefillingSource.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), PrefillingSource.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||||
if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
|
if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
|
||||||
} else {
|
} else {
|
||||||
|
this.usageLimitService.checkIncrease(UsageLimitTargetMetric.PREFILLING_SOURCES_COUNT);
|
||||||
|
|
||||||
data = new PrefillingSourceEntity();
|
data = new PrefillingSourceEntity();
|
||||||
data.setId(UUID.randomUUID());
|
data.setId(UUID.randomUUID());
|
||||||
|
@ -148,7 +156,10 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService {
|
||||||
data.setUpdatedAt(Instant.now());
|
data.setUpdatedAt(Instant.now());
|
||||||
|
|
||||||
if (isUpdate) this.entityManager.merge(data);
|
if (isUpdate) this.entityManager.merge(data);
|
||||||
else this.entityManager.persist(data);
|
else {
|
||||||
|
this.entityManager.persist(data);
|
||||||
|
this.accountingService.increase(UsageLimitTargetMetric.PREFILLING_SOURCES_COUNT);
|
||||||
|
}
|
||||||
|
|
||||||
this.entityManager.flush();
|
this.entityManager.flush();
|
||||||
|
|
||||||
|
@ -318,6 +329,7 @@ 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) {
|
||||||
|
|
|
@ -19,6 +19,7 @@ import org.opencdmp.authorization.Permission;
|
||||||
import org.opencdmp.commons.XmlHandlingService;
|
import org.opencdmp.commons.XmlHandlingService;
|
||||||
import org.opencdmp.commons.enums.ExternalFetcherSourceType;
|
import org.opencdmp.commons.enums.ExternalFetcherSourceType;
|
||||||
import org.opencdmp.commons.enums.IsActive;
|
import org.opencdmp.commons.enums.IsActive;
|
||||||
|
import org.opencdmp.commons.enums.UsageLimitTargetMetric;
|
||||||
import org.opencdmp.commons.types.externalfetcher.*;
|
import org.opencdmp.commons.types.externalfetcher.*;
|
||||||
import org.opencdmp.commons.types.referencetype.ReferenceTypeDefinitionEntity;
|
import org.opencdmp.commons.types.referencetype.ReferenceTypeDefinitionEntity;
|
||||||
import org.opencdmp.commons.types.referencetype.ReferenceTypeFieldEntity;
|
import org.opencdmp.commons.types.referencetype.ReferenceTypeFieldEntity;
|
||||||
|
@ -34,6 +35,8 @@ import org.opencdmp.model.persist.referencetypedefinition.ReferenceTypeDefinitio
|
||||||
import org.opencdmp.model.persist.referencetypedefinition.ReferenceTypeFieldPersist;
|
import org.opencdmp.model.persist.referencetypedefinition.ReferenceTypeFieldPersist;
|
||||||
import org.opencdmp.model.referencetype.ReferenceType;
|
import org.opencdmp.model.referencetype.ReferenceType;
|
||||||
import org.opencdmp.query.ReferenceTypeQuery;
|
import org.opencdmp.query.ReferenceTypeQuery;
|
||||||
|
import org.opencdmp.service.accounting.AccountingService;
|
||||||
|
import org.opencdmp.service.usagelimit.UsageLimitService;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.context.MessageSource;
|
import org.springframework.context.MessageSource;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
|
@ -59,11 +62,13 @@ public class ReferenceTypeServiceImpl implements ReferenceTypeService {
|
||||||
private final XmlHandlingService xmlHandlingService;
|
private final XmlHandlingService xmlHandlingService;
|
||||||
private final ErrorThesaurusProperties errors;
|
private final ErrorThesaurusProperties errors;
|
||||||
private final QueryFactory queryFactory;
|
private final QueryFactory queryFactory;
|
||||||
|
private final UsageLimitService usageLimitService;
|
||||||
|
private final AccountingService accountingService;
|
||||||
|
|
||||||
public ReferenceTypeServiceImpl(
|
public ReferenceTypeServiceImpl(
|
||||||
TenantEntityManager entityManager, AuthorizationService authorizationService, DeleterFactory deleterFactory, BuilderFactory builderFactory,
|
TenantEntityManager entityManager, AuthorizationService authorizationService, DeleterFactory deleterFactory, BuilderFactory builderFactory,
|
||||||
ConventionService conventionService, MessageSource messageSource,
|
ConventionService conventionService, MessageSource messageSource,
|
||||||
XmlHandlingService xmlHandlingService, ErrorThesaurusProperties errors, QueryFactory queryFactory) {
|
XmlHandlingService xmlHandlingService, ErrorThesaurusProperties errors, QueryFactory queryFactory, UsageLimitService usageLimitService, AccountingService accountingService) {
|
||||||
this.entityManager = entityManager;
|
this.entityManager = entityManager;
|
||||||
this.authorizationService = authorizationService;
|
this.authorizationService = authorizationService;
|
||||||
this.deleterFactory = deleterFactory;
|
this.deleterFactory = deleterFactory;
|
||||||
|
@ -73,6 +78,8 @@ public class ReferenceTypeServiceImpl implements ReferenceTypeService {
|
||||||
this.xmlHandlingService = xmlHandlingService;
|
this.xmlHandlingService = xmlHandlingService;
|
||||||
this.errors = errors;
|
this.errors = errors;
|
||||||
this.queryFactory = queryFactory;
|
this.queryFactory = queryFactory;
|
||||||
|
this.usageLimitService = usageLimitService;
|
||||||
|
this.accountingService = accountingService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -90,6 +97,7 @@ public class ReferenceTypeServiceImpl implements ReferenceTypeService {
|
||||||
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), ReferenceType.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), ReferenceType.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||||
if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
|
if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
|
||||||
} else {
|
} else {
|
||||||
|
this.usageLimitService.checkIncrease(UsageLimitTargetMetric.REFERENCE_TYPE_COUNT);
|
||||||
|
|
||||||
data = new ReferenceTypeEntity();
|
data = new ReferenceTypeEntity();
|
||||||
data.setId(UUID.randomUUID());
|
data.setId(UUID.randomUUID());
|
||||||
|
@ -103,7 +111,10 @@ public class ReferenceTypeServiceImpl implements ReferenceTypeService {
|
||||||
data.setUpdatedAt(Instant.now());
|
data.setUpdatedAt(Instant.now());
|
||||||
|
|
||||||
if (isUpdate) this.entityManager.merge(data);
|
if (isUpdate) this.entityManager.merge(data);
|
||||||
else this.entityManager.persist(data);
|
else {
|
||||||
|
this.entityManager.persist(data);
|
||||||
|
this.accountingService.increase(UsageLimitTargetMetric.REFERENCE_TYPE_COUNT);
|
||||||
|
}
|
||||||
|
|
||||||
this.entityManager.flush();
|
this.entityManager.flush();
|
||||||
|
|
||||||
|
@ -295,5 +306,6 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package org.opencdmp.service.usagelimit;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableConfigurationProperties(UsageLimitProperties.class)
|
||||||
|
public class UsageLimitConfiguration {
|
||||||
|
private final UsageLimitProperties properties;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public UsageLimitConfiguration(UsageLimitProperties properties) {
|
||||||
|
this.properties = properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UsageLimitProperties getProperties() {
|
||||||
|
return this.properties;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package org.opencdmp.service.usagelimit;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
|
@ConfigurationProperties(prefix = "usage-limits")
|
||||||
|
public class UsageLimitProperties {
|
||||||
|
private Boolean enabled;
|
||||||
|
|
||||||
|
public Boolean getEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(Boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
}
|
|
@ -64,6 +64,8 @@ public class UsageLimitServiceImpl implements UsageLimitService {
|
||||||
|
|
||||||
private final AccountingService accountingService;
|
private final AccountingService accountingService;
|
||||||
|
|
||||||
|
private final UsageLimitProperties usageLimitProperties;
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public UsageLimitServiceImpl(
|
public UsageLimitServiceImpl(
|
||||||
|
@ -74,7 +76,7 @@ public class UsageLimitServiceImpl implements UsageLimitService {
|
||||||
ConventionService conventionService,
|
ConventionService conventionService,
|
||||||
ErrorThesaurusProperties errors,
|
ErrorThesaurusProperties errors,
|
||||||
MessageSource messageSource,
|
MessageSource messageSource,
|
||||||
QueryFactory queryFactory, TenantEntityManager tenantEntityManager, AccountingService accountingService) {
|
QueryFactory queryFactory, TenantEntityManager tenantEntityManager, AccountingService accountingService, UsageLimitProperties usageLimitProperties) {
|
||||||
this.entityManager = entityManager;
|
this.entityManager = entityManager;
|
||||||
this.authorizationService = authorizationService;
|
this.authorizationService = authorizationService;
|
||||||
this.deleterFactory = deleterFactory;
|
this.deleterFactory = deleterFactory;
|
||||||
|
@ -85,6 +87,7 @@ public class UsageLimitServiceImpl implements UsageLimitService {
|
||||||
this.queryFactory = queryFactory;
|
this.queryFactory = queryFactory;
|
||||||
this.tenantEntityManager = tenantEntityManager;
|
this.tenantEntityManager = tenantEntityManager;
|
||||||
this.accountingService = accountingService;
|
this.accountingService = accountingService;
|
||||||
|
this.usageLimitProperties = usageLimitProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UsageLimit persist(UsageLimitPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException {
|
public UsageLimit persist(UsageLimitPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException {
|
||||||
|
@ -128,6 +131,9 @@ public class UsageLimitServiceImpl implements UsageLimitService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkIncrease(UsageLimitTargetMetric metric) {
|
public void checkIncrease(UsageLimitTargetMetric metric) {
|
||||||
|
|
||||||
|
if (usageLimitProperties.getEnabled() == null || !usageLimitProperties.getEnabled()) return;
|
||||||
|
|
||||||
if (metric == null) throw new MyApplicationException("Target Metric not defined");
|
if (metric == null) throw new MyApplicationException("Target Metric not defined");
|
||||||
|
|
||||||
Integer currentValue = this.accountingService.getCurrentMetricValue(metric);
|
Integer currentValue = this.accountingService.getCurrentMetricValue(metric);
|
||||||
|
|
|
@ -32,6 +32,7 @@ spring:
|
||||||
optional:classpath:config/authorization.yml[.yml], optional:classpath:config/authorization-${spring.profiles.active}.yml[.yml], optional:file:../config/authorization-${spring.profiles.active}.yml[.yml],
|
optional:classpath:config/authorization.yml[.yml], optional:classpath:config/authorization-${spring.profiles.active}.yml[.yml], optional:file:../config/authorization-${spring.profiles.active}.yml[.yml],
|
||||||
optional:classpath:config/metrics.yml[.yml], optional:classpath:config/metrics-${spring.profiles.active}.yml[.yml], optional:file:../config/metrics-${spring.profiles.active}.yml[.yml],
|
optional:classpath:config/metrics.yml[.yml], optional:classpath:config/metrics-${spring.profiles.active}.yml[.yml], optional:file:../config/metrics-${spring.profiles.active}.yml[.yml],
|
||||||
optional:classpath:config/field-set-expander.yml[.yml], optional:classpath:config/field-set-expander-${spring.profiles.active}.yml[.yml], optional:file:../config/field-set-expander-${spring.profiles.active}.yml[.yml],
|
optional:classpath:config/field-set-expander.yml[.yml], optional:classpath:config/field-set-expander-${spring.profiles.active}.yml[.yml], optional:file:../config/field-set-expander-${spring.profiles.active}.yml[.yml],
|
||||||
optional:classpath:config/lock.yml[.yml], optional:classpath:config/lock-${spring.profiles.active}.yml[.yml], optional:file:../config/lock-${spring.profiles.active}.yml[.yml]
|
optional:classpath:config/lock.yml[.yml], optional:classpath:config/lock-${spring.profiles.active}.yml[.yml], optional:file:../config/lock-${spring.profiles.active}.yml[.yml],
|
||||||
|
optional:classpath:config/usage-limits.yml[.yml], optional:classpath:config/usage-limits-${spring.profiles.active}.yml[.yml], optional:file:../config/usage-limits-${spring.profiles.active}.yml[.yml]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
usage-limits:
|
||||||
|
enabled: false
|
Loading…
Reference in New Issue