remove unused accounting action env

This commit is contained in:
amentis 2024-07-23 15:21:28 +03:00
parent 8bb909f513
commit 117bc22515
4 changed files with 12 additions and 23 deletions

View File

@ -10,8 +10,6 @@ public class AccountingProperties {
private Boolean enabled;
private String serviceId;
private String action;
private String subjectId;
private List<String> projectFields;
@ -34,14 +32,6 @@ public class AccountingProperties {
this.serviceId = serviceId;
}
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
public String getSubjectId() {
return subjectId;
}

View File

@ -6,7 +6,7 @@ import javax.management.InvalidApplicationException;
public interface AccountingService {
Integer getCurrentMetricValue(UsageLimitTargetMetric metric);
Integer getCurrentMetricValue(UsageLimitTargetMetric metric) throws InvalidApplicationException;
void set(String metric);

View File

@ -130,7 +130,7 @@ public class AccountingServiceImpl implements AccountingService {
});
}
public Integer getCurrentMetricValue(UsageLimitTargetMetric metric) {
public Integer getCurrentMetricValue(UsageLimitTargetMetric metric) throws InvalidApplicationException {
if (this.isEnabled) {
AccountingClient accountingClient = null;
try {
@ -160,6 +160,7 @@ public class AccountingServiceImpl implements AccountingService {
lookup.setServiceCodes(List.of(this.accountingProperties.getServiceId()));
lookup.setAggregateTypes(List.of(AccountingAggregateType.Sum));
lookup.setActionCodes(List.of(metric.getValue()));
lookup.setUserCodes(List.of(this.getSubjectId()));
try {
lookup.setResourceCodes(List.of(this.tenantScope.getTenantCode() != null ? this.tenantScope.getTenantCode() : this.tenantScope.getDefaultTenantCode()));
} catch (InvalidApplicationException e) {
@ -196,11 +197,7 @@ public class AccountingServiceImpl implements AccountingService {
public void increase(String metric) throws InvalidApplicationException {
if (this.isEnabled) {
String subjectId;
UserCredentialEntity userCredential = this.queryFactory.query(UserCredentialQuery.class).disableTracking().userIds(this.userScope.getUserId()).first();
if (userCredential != null) subjectId = userCredential.getExternalId();
else subjectId = this.userScope.getUserId().toString();
String subjectId = this.getSubjectId();
this.accountingEntryCreatedIntegrationEventHandler.handleAccountingEntry(metric, AccountingValueType.Plus, subjectId, this.tenantScope.getTenant(), this.tenantScope.getTenantCode() != null ? this.tenantScope.getTenantCode() : this.tenantScope.getDefaultTenantCode());
}
@ -208,14 +205,17 @@ public class AccountingServiceImpl implements AccountingService {
public void decrease(String metric) throws InvalidApplicationException {
if (this.isEnabled) {
String subjectId;
UserCredentialEntity userCredential = this.queryFactory.query(UserCredentialQuery.class).disableTracking().userIds(this.userScope.getUserId()).first();
if (userCredential != null) subjectId = userCredential.getExternalId();
else subjectId = this.userScope.getUserId().toString();
String subjectId = this.getSubjectId();
this.accountingEntryCreatedIntegrationEventHandler.handleAccountingEntry(metric, AccountingValueType.Minus, subjectId, this.tenantScope.getTenant(), this.tenantScope.getTenantCode() != null ? this.tenantScope.getTenantCode() : this.tenantScope.getDefaultTenantCode());
}
}
private String getSubjectId() throws InvalidApplicationException {
UserCredentialEntity userCredential = this.queryFactory.query(UserCredentialQuery.class).disableTracking().userIds(this.userScope.getUserId()).first();
if (userCredential != null) return userCredential.getExternalId();
return this.userScope.getUserId().toString();
}
}

View File

@ -1,7 +1,6 @@
accounting:
enabled: ${ACCOUNTING_ENABLED}
serviceId: ${SERVICE_ID}
action: ${ACCOUNTING_ACTION}
subjectId: unknown
projectFields:
- sum