This commit is contained in:
parent
7492fbe823
commit
0aa623836f
1 changed files with 37 additions and 43 deletions
|
|
@ -100,9 +100,13 @@ public enum GatewayEksClientCodeValidationRule implements IValidationRule<ImdgVa
|
|||
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.equals("accountId", accountSymbols.getAccountId())
|
||||
predicateBuilder.and(
|
||||
predicateBuilder.equals("accountId", accountSymbols.getAccountId()),
|
||||
predicateBuilder.equals("companyId", company.getId())
|
||||
)
|
||||
);
|
||||
if (depoAccount == null) {
|
||||
context.storeObject(ClientCodeStoreObjects.DEPO_ACCOUNT, Optional.empty());
|
||||
|
|
@ -122,12 +126,14 @@ public enum GatewayEksClientCodeValidationRule implements IValidationRule<ImdgVa
|
|||
.toList();
|
||||
Imdg<Account> accountImdg = context.obtainMap(IMDGDistributedNames.Map_Account, Account.class);
|
||||
List<Account> validClrnAccs = new ArrayList<>();
|
||||
Company company = context.getStoredObject(ClientCodeStoreObjects.COMPANY);
|
||||
for (MoneyAccountMsgRequest moneyAccount : moneyAccounts) {
|
||||
ImdgPredicateBuilder predicateBuilder = accountImdg.predicateBuilder();
|
||||
Account clrnAcc = accountImdg.getFirstObjectByPredicate(
|
||||
predicateBuilder.and(
|
||||
predicateBuilder.equals("account", moneyAccount.getAccount()),
|
||||
predicateBuilder.equals("accountType", AccountType.Clrn.getKey())
|
||||
predicateBuilder.equals("accountType", AccountType.Clrn.getKey()),
|
||||
predicateBuilder.equals("companyId", company.getId())
|
||||
));
|
||||
if (clrnAcc == null) {
|
||||
return of(AccountError.AccountNotFound, moneyAccount.getAccount());
|
||||
|
|
@ -164,56 +170,44 @@ public enum GatewayEksClientCodeValidationRule implements IValidationRule<ImdgVa
|
|||
|
||||
TcrIsNotPresent() {
|
||||
@Override
|
||||
public Optional<EnumMessage> validate (ImdgValidationContext < TkrAccount > context) {
|
||||
public Optional<EnumMessage> validate(ImdgValidationContext<TkrAccount> context) {
|
||||
Optional<DepoAccount> depoAccountOpt = context.getStoredObject(ClientCodeStoreObjects.DEPO_ACCOUNT);
|
||||
List<Account> clrnAccs = context.getStoredObject(ClientCodeStoreObjects.CLRN_ACCS);
|
||||
Optional<Account> ruClrnAcc = clrnAccs.stream()
|
||||
.filter(ruAcc -> CurrencyCode.RUB.equalsByKey(ruAcc.getCurrency()))
|
||||
.findFirst();
|
||||
|
||||
if (ruClrnAcc.isEmpty() && depoAccountOpt.isEmpty()) {
|
||||
return empty();
|
||||
}
|
||||
Imdg<TradingClearingRegistry> imdg = context.obtainMap(IMDGDistributedNames.Map_TradingClearingRegistry,
|
||||
TradingClearingRegistry.class);
|
||||
Imdg<Account> accountImdg = context.obtainMap(IMDGDistributedNames.Map_Account,
|
||||
Account.class);
|
||||
|
||||
ImdgPredicateBuilder pb = imdg.predicateBuilder();
|
||||
ImdgPredicate query = null;
|
||||
if (ruClrnAcc.isPresent()) {
|
||||
query = pb.equals("moneyAccountId", ruClrnAcc.get().getId());
|
||||
}
|
||||
if (depoAccountOpt.isPresent()) {
|
||||
ImdgPredicate depoCondition = pb.equals("depoAccountId", depoAccountOpt.get().getAccountId());
|
||||
query = query == null ? depoCondition : pb.or(query, depoCondition);
|
||||
}
|
||||
Collection<TradingClearingRegistry> tcr = imdg.getCollectionObjectsByPredicate(query);
|
||||
|
||||
if (tcr.isEmpty()) {
|
||||
return empty();
|
||||
} else {
|
||||
Account dubAcc = null;
|
||||
for (TradingClearingRegistry duplicate : tcr) {
|
||||
if (ruClrnAcc.isPresent() &&
|
||||
Objects.equals(duplicate.getMoneyAccountId(), ruClrnAcc.get().getId())) {
|
||||
dubAcc = ruClrnAcc.get();
|
||||
}
|
||||
if (depoAccountOpt.isPresent() &&
|
||||
depoAccountOpt.get().getAccountId().equals(duplicate.getDepoAccountId())) {
|
||||
dubAcc = accountImdg.getSingleObjectByID(depoAccountOpt.get().getAccountId());
|
||||
}
|
||||
if (dubAcc != null) {
|
||||
break;
|
||||
}
|
||||
for (Account clrnAcc : clrnAccs) {
|
||||
ImdgPredicate query = pb.equals("moneyAccountId", clrnAcc.getId());
|
||||
if (depoAccountOpt.isPresent()) {
|
||||
ImdgPredicate depoCondition = pb.equals("depoAccountId", depoAccountOpt.get().getAccountId());
|
||||
query = pb.or(query, depoCondition);
|
||||
}
|
||||
return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed,
|
||||
dubAcc != null ? dubAcc.getAccount() : "null");
|
||||
}
|
||||
}
|
||||
}
|
||||
Collection<TradingClearingRegistry> tcr = imdg.getCollectionObjectsByPredicate(query);
|
||||
|
||||
;
|
||||
if (!tcr.isEmpty()) {
|
||||
Account dubAcc = null;
|
||||
for (TradingClearingRegistry duplicate : tcr) {
|
||||
if (Objects.equals(duplicate.getMoneyAccountId(), clrnAcc.getId())) {
|
||||
dubAcc = clrnAcc;
|
||||
}
|
||||
if (depoAccountOpt.isPresent() &&
|
||||
depoAccountOpt.get().getAccountId().equals(duplicate.getDepoAccountId())) {
|
||||
dubAcc = accountImdg.getSingleObjectByID(depoAccountOpt.get().getAccountId());
|
||||
}
|
||||
if (dubAcc != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed,
|
||||
dubAcc != null ? dubAcc.getAccount() : "null");
|
||||
}
|
||||
}
|
||||
return empty();
|
||||
}
|
||||
};
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(GatewayEksClientCodeValidationRule.class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue