This commit is contained in:
parent
da33692e03
commit
459fe3db6c
5 changed files with 206 additions and 6 deletions
|
|
@ -170,12 +170,21 @@ public class ClientCodeValidationConfig {
|
|||
ImdgValidationContext<TkrAccount> context = new ImdgValidationContext<>();
|
||||
context.setValidatedObject(tkrGatewayRequest);
|
||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||
addImdg.accept(IMDGDistributedNames.Map_Company);
|
||||
addImdg.accept(IMDGDistributedNames.Map_CompanySymbols);
|
||||
addImdg.accept(IMDGDistributedNames.Map_Account);
|
||||
addImdg.accept(IMDGDistributedNames.Map_TradingClearingRegistry);
|
||||
addImdg.accept(IMDGDistributedNames.Map_TradingClearingRegistryList);
|
||||
addImdg.accept(IMDGDistributedNames.Map_AccountSymbols);
|
||||
addImdg.accept(IMDGDistributedNames.Map_DepoAccount);
|
||||
addImdg.accept(IMDGDistributedNames.Map_ClientCode);
|
||||
return new ValidatorImpl<>(context,
|
||||
GatewayUpdateEksClientCodeValidationRule.CompanyPresent,
|
||||
GatewayUpdateEksClientCodeValidationRule.TkrIsPresent,
|
||||
GatewayUpdateEksClientCodeValidationRule.AccountsNotLinkedToTkr
|
||||
GatewayUpdateEksClientCodeValidationRule.DepoAccountIsValid,
|
||||
GatewayUpdateEksClientCodeValidationRule.NewForRubNotAllowed,
|
||||
GatewayUpdateEksClientCodeValidationRule.ClientCodeIsPresent,
|
||||
GatewayUpdateEksClientCodeValidationRule.ClrnAccountsNotLinkedToTkr,
|
||||
GatewayUpdateEksClientCodeValidationRule.AnltAccountsNotLinkedToTkr
|
||||
);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ public enum AccountError implements IErrorEnumId {
|
|||
CurrencyForTradingClearingRegistryListAlreadyUsed(5031L),
|
||||
BadSymbol(5032L),
|
||||
TradingClearingRegistryNotFound(3022L),
|
||||
ClientCodeNotLinedToTkr(3033L),
|
||||
AccountRubForbiddenForAdd(3033L),
|
||||
CurrencyNotFound(1016L),
|
||||
;
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Stream;
|
||||
import org.apache.kafka.clients.consumer.Consumer;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -221,8 +222,9 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali
|
|||
ValidationResult validationResult = entry.getValue();
|
||||
IValidator validator = validationResult.validator();
|
||||
List<Account> clrnAccs = validator.getStored(ClientCodeStoreObjects.CLRN_ACCS);
|
||||
List<Account> anltAccs = validator.getStored(ClientCodeStoreObjects.ANLT_ACCS);
|
||||
TradingClearingRegistry tradingClearingRegistry = validator.getStored(ClientCodeStoreObjects.TRADING_CLEARING_REGISTRY);
|
||||
List<Long> accIds = clrnAccs.stream()
|
||||
List<Long> accIds = Stream.concat(clrnAccs.stream(), anltAccs.stream())
|
||||
.map(Account::getId)
|
||||
.toList();
|
||||
|
||||
|
|
|
|||
|
|
@ -7,5 +7,6 @@ public enum ClientCodeStoreObjects {
|
|||
CLRN_ACCS,
|
||||
ANLT_ACCS,
|
||||
MAPPED_TO_CURRENCY_ACCOUNTS,
|
||||
TRADING_CLEARING_REGISTRY
|
||||
TRADING_CLEARING_REGISTRY,
|
||||
CLIENT_CODE
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,16 @@ package ru.spcex.clearing.account.validation;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.StringUtils;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.account.AccountSymbols;
|
||||
import ru.clearing.classes.statics.data.account.ClientCode;
|
||||
import ru.clearing.classes.statics.data.account.DepoAccount;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
|
||||
import ru.clearing.classes.statics.data.registry.TradingClearingRegistryList;
|
||||
import ru.spcex.clearing.account.errors.AccountError;
|
||||
|
|
@ -22,18 +28,40 @@ import ru.spcex.platform.utils.enumeration.EnumMessage;
|
|||
import ru.spcex.platform.utils.validation.IValidationRule;
|
||||
|
||||
public enum GatewayUpdateEksClientCodeValidationRule implements IValidationRule<ImdgValidationContext<TkrAccount>> {
|
||||
CompanyPresent() {
|
||||
@Override
|
||||
public Optional<EnumMessage> validate(ImdgValidationContext<TkrAccount> context) {
|
||||
TkrAccount validatedObject = context.getValidatedObject();
|
||||
Long tradingCode = validatedObject.getTradingCode();
|
||||
if (tradingCode == null) {
|
||||
return of(AccountError.RequiredFieldEmpty, "trading_code");
|
||||
}
|
||||
|
||||
Imdg<Company> companyImdg = context.obtainMap(IMDGDistributedNames.Map_Company, Company.class);
|
||||
Company company = companyImdg.getFirstObjectByFieldValues(
|
||||
Map.of("tradingCode", String.valueOf(tradingCode))
|
||||
);
|
||||
if (company == null) {
|
||||
return of(AccountError.COMPANY_NOT_FOUND_GTW, "trading_code");
|
||||
}
|
||||
|
||||
context.storeObject(ClientCodeStoreObjects.COMPANY, company);
|
||||
return Optional.empty();
|
||||
}
|
||||
},
|
||||
|
||||
TkrIsPresent() {
|
||||
@Override
|
||||
public Optional<EnumMessage> validate(ImdgValidationContext<TkrAccount> context) {
|
||||
TkrAccount validatedObject = context.getValidatedObject();
|
||||
Company company = context.getStoredObject(ClientCodeStoreObjects.COMPANY);
|
||||
Imdg<TradingClearingRegistry> tkrImdg = context.obtainMap(IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class);
|
||||
ImdgPredicateBuilder predicate = tkrImdg.predicateBuilder();
|
||||
String trkCode = validatedObject.getTkrCode();
|
||||
TradingClearingRegistry existTkr = tkrImdg.getSingleObjectByPredicate(
|
||||
predicate.and(
|
||||
predicate.equals("code", trkCode),
|
||||
predicate.equals("status", Status.Active.getKey())
|
||||
predicate.equals("companyId", company.getId())
|
||||
)
|
||||
);
|
||||
if (existTkr == null) {
|
||||
|
|
@ -43,7 +71,82 @@ public enum GatewayUpdateEksClientCodeValidationRule implements IValidationRule<
|
|||
return empty();
|
||||
}
|
||||
},
|
||||
AccountsNotLinkedToTkr() {
|
||||
DepoAccountIsValid() {
|
||||
@Override
|
||||
public Optional<EnumMessage> validate(ImdgValidationContext<TkrAccount> context) {
|
||||
TkrAccount validatedObject = context.getValidatedObject();
|
||||
TradingClearingRegistry tkr = context.getStoredObject(ClientCodeStoreObjects.TRADING_CLEARING_REGISTRY);
|
||||
if (StringUtils.hasText(validatedObject.getDepoAccount())) {
|
||||
String depoAccountVal = validatedObject.getDepoAccount();
|
||||
Imdg<AccountSymbols> accountSymbolsImdg = context.obtainMap(IMDGDistributedNames.Map_AccountSymbols, AccountSymbols.class);
|
||||
ImdgPredicateBuilder predicateBuilder = accountSymbolsImdg.predicateBuilder();
|
||||
AccountSymbols accountSymbols = accountSymbolsImdg.getSingleObjectByPredicate(
|
||||
predicateBuilder.equals("accountSymbolValue", depoAccountVal)
|
||||
);
|
||||
|
||||
if (accountSymbols == null) {
|
||||
return of(AccountError.DepoAccountNotFound, "depo_account");
|
||||
}
|
||||
Company company = context.getStoredObject(ClientCodeStoreObjects.COMPANY);
|
||||
Imdg<DepoAccount> imdg = context.obtainMap(IMDGDistributedNames.Map_DepoAccount, DepoAccount.class);
|
||||
DepoAccount depoAccount = imdg.getFirstObjectByPredicate(
|
||||
predicateBuilder.and(
|
||||
predicateBuilder.equals("accountId", accountSymbols.getAccountId()),
|
||||
predicateBuilder.equals("companyId", company.getId())
|
||||
)
|
||||
);
|
||||
if (depoAccount == null) {
|
||||
context.storeObject(ClientCodeStoreObjects.DEPO_ACCOUNT, Optional.empty());
|
||||
return of(AccountError.DepoAccountNotFound, "depo_account");
|
||||
}
|
||||
if (!tkr.getDepoAccountId().equals(depoAccount.getAccountId())) {
|
||||
return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, depoAccount.getAccountId());
|
||||
}
|
||||
}
|
||||
return empty();
|
||||
}
|
||||
},
|
||||
NewForRubNotAllowed(){
|
||||
@Override
|
||||
public Optional<EnumMessage> validate(ImdgValidationContext<TkrAccount> context) {
|
||||
TkrAccount validatedObject = context.getValidatedObject();
|
||||
List<MoneyAccountMsgRequest> accounts = validatedObject.getMoneyAccounts().stream()
|
||||
.filter(moneyAccountMsgRequest ->
|
||||
moneyAccountMsgRequest.getStatus().equals("NEW")
|
||||
&& CurrencyCode.RUB.equalsByKey(moneyAccountMsgRequest.getCurrCode()))
|
||||
.toList();
|
||||
if (!accounts.isEmpty()) {
|
||||
return of(AccountError.AccountRubForbiddenForAdd, accounts.stream().findFirst().get().getAccount());
|
||||
}
|
||||
return empty();
|
||||
}
|
||||
},
|
||||
ClientCodeIsPresent() {
|
||||
@Override
|
||||
public Optional<EnumMessage> validate(ImdgValidationContext<TkrAccount> context) {
|
||||
TkrAccount validatedObject = context.getValidatedObject();
|
||||
if (!StringUtils.hasText(validatedObject.getClientCode())) {
|
||||
return empty();
|
||||
}
|
||||
TradingClearingRegistry tkr = context.getStoredObject(ClientCodeStoreObjects.TRADING_CLEARING_REGISTRY);
|
||||
Imdg<ClientCode> clientCodeImdg = context.obtainMap(IMDGDistributedNames.Map_ClientCode, ClientCode.class);
|
||||
ImdgPredicateBuilder predicate = clientCodeImdg.predicateBuilder();
|
||||
String trkCode = validatedObject.getTkrCode();
|
||||
ClientCode existClientCode = clientCodeImdg.getSingleObjectByPredicate(
|
||||
predicate.and(
|
||||
predicate.equals("code", validatedObject.getClientCode()),
|
||||
predicate.equals("tradingClearingRegistryId", tkr.getId()),
|
||||
predicate.equals("status", Status.Active.getKey())
|
||||
)
|
||||
);
|
||||
if (existClientCode == null) {
|
||||
return of(AccountError.ClientCodeNotLinedToTkr, trkCode);
|
||||
}
|
||||
context.storeObject(ClientCodeStoreObjects.CLIENT_CODE, existClientCode);
|
||||
return empty();
|
||||
}
|
||||
},
|
||||
ClrnAccountsNotLinkedToTkr() {
|
||||
@Override
|
||||
public Optional<EnumMessage> validate(ImdgValidationContext<TkrAccount> context) {
|
||||
TkrAccount validatedObject = context.getValidatedObject();
|
||||
|
|
@ -55,6 +158,11 @@ public enum GatewayUpdateEksClientCodeValidationRule implements IValidationRule<
|
|||
moneyAccountMsgRequest.getStatus().equals("NEW")
|
||||
&& !CurrencyCode.RUB.equalsByKey(moneyAccountMsgRequest.getCurrCode()))
|
||||
.toList();
|
||||
List<MoneyAccountMsgRequest> existAccounts = validatedObject.getMoneyAccounts().stream()
|
||||
.filter(moneyAccountMsgRequest ->
|
||||
moneyAccountMsgRequest.getStatus().equals("NEW")
|
||||
&& !CurrencyCode.RUB.equalsByKey(moneyAccountMsgRequest.getCurrCode()))
|
||||
.toList();
|
||||
List<Account> clrnAccounts = new ArrayList<>();
|
||||
for (MoneyAccountMsgRequest request : accounts) {
|
||||
Account account = accountImdg.getFirstObjectByPredicate(
|
||||
|
|
@ -74,9 +182,87 @@ public enum GatewayUpdateEksClientCodeValidationRule implements IValidationRule<
|
|||
}
|
||||
clrnAccounts.add(account);
|
||||
}
|
||||
|
||||
for (MoneyAccountMsgRequest request : existAccounts) {
|
||||
Account account = accountImdg.getFirstObjectByPredicate(
|
||||
predicateBuilder.and(
|
||||
predicateBuilder.equals("account", request.getAccount()),
|
||||
predicateBuilder.equals("accountType", AccountType.Clrn.getKey())
|
||||
)
|
||||
);
|
||||
if (account == null) {
|
||||
return of(AccountError.AccountNotFound, request.getAccount());
|
||||
}
|
||||
TradingClearingRegistryList tkrListByAccount = tkrList.getSingleObjectByPredicate(
|
||||
predicateBuilder.equals("accountId", account.getId())
|
||||
);
|
||||
if (tkrListByAccount == null) {
|
||||
return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, account.getId());
|
||||
}
|
||||
}
|
||||
context.storeObject(ClientCodeStoreObjects.CLRN_ACCS, clrnAccounts);
|
||||
return empty();
|
||||
}
|
||||
},
|
||||
AnltAccountsNotLinkedToTkr() {
|
||||
@Override
|
||||
public Optional<EnumMessage> validate(ImdgValidationContext<TkrAccount> context) {
|
||||
TkrAccount validatedObject = context.getValidatedObject();
|
||||
Imdg<Account> accountImdg = context.obtainMap(IMDGDistributedNames.Map_Account, Account.class);
|
||||
Imdg<TradingClearingRegistryList> tkrList = context.obtainMap(IMDGDistributedNames.Map_TradingClearingRegistryList, TradingClearingRegistryList.class);
|
||||
ImdgPredicateBuilder predicateBuilder = accountImdg.predicateBuilder();
|
||||
List<MoneyAccountMsgRequest> newAccounts = validatedObject.getMoneyAccounts().stream()
|
||||
.filter(moneyAccountMsgRequest ->
|
||||
StringUtils.hasText(moneyAccountMsgRequest.getEks_account()) && moneyAccountMsgRequest.getStatus().equals("NEW")
|
||||
&& !CurrencyCode.RUB.equalsByKey(moneyAccountMsgRequest.getCurrCode()))
|
||||
.toList();
|
||||
List<Account> anltAccounts = new ArrayList<>();
|
||||
for (MoneyAccountMsgRequest request : newAccounts) {
|
||||
Account account = accountImdg.getFirstObjectByPredicate(
|
||||
predicateBuilder.and(
|
||||
predicateBuilder.equals("accountType", AccountType.Anlt.getKey()),
|
||||
predicateBuilder.equals("currency", request.getCurrCode()),
|
||||
predicateBuilder.equals("account", request.getEks_account())
|
||||
)
|
||||
);
|
||||
if (account == null) {
|
||||
return of(AccountError.AccountNotFound, request.getAccount());
|
||||
}
|
||||
TradingClearingRegistryList tkrListByAccount = tkrList.getSingleObjectByPredicate(
|
||||
predicateBuilder.equals("accountId", account.getId())
|
||||
);
|
||||
if (tkrListByAccount != null) {
|
||||
return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, account.getId());
|
||||
}
|
||||
anltAccounts.add(account);
|
||||
}
|
||||
|
||||
List<MoneyAccountMsgRequest> existAccounts = validatedObject.getMoneyAccounts().stream()
|
||||
.filter(moneyAccountMsgRequest ->
|
||||
StringUtils.hasText(moneyAccountMsgRequest.getEks_account()) && moneyAccountMsgRequest.getStatus().equals("NOW")
|
||||
&& !CurrencyCode.RUB.equalsByKey(moneyAccountMsgRequest.getCurrCode()))
|
||||
.toList();
|
||||
for (MoneyAccountMsgRequest request : existAccounts) {
|
||||
Account account = accountImdg.getFirstObjectByPredicate(
|
||||
predicateBuilder.and(
|
||||
predicateBuilder.equals("accountType", AccountType.Anlt.getKey()),
|
||||
predicateBuilder.equals("currency", request.getCurrCode()),
|
||||
predicateBuilder.equals("account", request.getEks_account())
|
||||
)
|
||||
);
|
||||
if (account == null) {
|
||||
return of(AccountError.AccountNotFound, request.getAccount());
|
||||
}
|
||||
TradingClearingRegistryList tkrListByAccount = tkrList.getSingleObjectByPredicate(
|
||||
predicateBuilder.equals("accountId", account.getId())
|
||||
);
|
||||
if (tkrListByAccount == null) {
|
||||
return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, account.getId());
|
||||
}
|
||||
}
|
||||
context.storeObject(ClientCodeStoreObjects.ANLT_ACCS, anltAccounts);
|
||||
return empty();
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue