etreschenkov 2024-06-06 11:32:19 +03:00
parent 7ce2445fc9
commit cc87b6ec1e

View file

@ -61,6 +61,7 @@ public class TradingClearingRegistryListValidationConfig {
new ExistAllAccountId<>("accountId", new ExistAllAccountId<>("accountId",
TradingClearingRegistryListNewRequest::getCurrencyAccountList, TradingClearingRegistryListNewRequest::getCurrencyAccountList,
TradingClearingRegistryListNewRequest::getAccountId, TradingClearingRegistryListNewRequest::getAccountId,
TradingClearingRegistryListNewRequest::getTradingClearingRegistryId,
false, false,
null), null),
DictionaryPresentRule.instance("stauts", DictionaryPresentRule.instance("stauts",
@ -158,16 +159,19 @@ public class TradingClearingRegistryListValidationConfig {
String fieldName; String fieldName;
Function<R, List<Long>> accountIdListGetter; Function<R, List<Long>> accountIdListGetter;
Function<R, Long> accountIdGetter; Function<R, Long> accountIdGetter;
Function<R, Long> tkrIdGetter;
boolean required; boolean required;
Function<R, Long> idGetter; Function<R, Long> idGetter;
public ExistAllAccountId(String fieldName, public ExistAllAccountId(String fieldName,
Function<R, List<Long>> accountIdListGetter, Function<R, List<Long>> accountIdListGetter,
Function<R, Long> accountIdGetter, Function<R, Long> accountIdGetter,
Function<R, Long> tkrIdGetter,
boolean required, Function<R, Long> idGetter) { boolean required, Function<R, Long> idGetter) {
this.fieldName = fieldName; this.fieldName = fieldName;
this.accountIdListGetter = accountIdListGetter; this.accountIdListGetter = accountIdListGetter;
this.accountIdGetter = accountIdGetter; this.accountIdGetter = accountIdGetter;
this.tkrIdGetter = tkrIdGetter;
this.required = required; this.required = required;
this.idGetter = idGetter; this.idGetter = idGetter;
} }
@ -176,7 +180,7 @@ public class TradingClearingRegistryListValidationConfig {
public Optional<EnumMessage> validate(ImdgValidationContext<R> context) { public Optional<EnumMessage> validate(ImdgValidationContext<R> context) {
R validatedObject = context.getValidatedObject(); R validatedObject = context.getValidatedObject();
List<Long> accounts = accountIdListGetter.apply(validatedObject); List<Long> accounts = accountIdListGetter.apply(validatedObject);
if (accounts.isEmpty()){ if (accounts == null) {
accounts = new ArrayList<>(); accounts = new ArrayList<>();
} }
Long singleAccountId = accountIdGetter.apply(validatedObject); Long singleAccountId = accountIdGetter.apply(validatedObject);
@ -206,9 +210,12 @@ public class TradingClearingRegistryListValidationConfig {
// Проверка отсутствия других TradingClearingRegistryList с этими счетами // Проверка отсутствия других TradingClearingRegistryList с этими счетами
Imdg<TradingClearingRegistryList> tradingClearingRegistryListImdg = context.obtainMap(IMDGDistributedNames.Map_TradingClearingRegistryList, TradingClearingRegistryList.class); Imdg<TradingClearingRegistryList> tradingClearingRegistryListImdg = context.obtainMap(IMDGDistributedNames.Map_TradingClearingRegistryList, TradingClearingRegistryList.class);
Long tkrId = tkrIdGetter.apply(validatedObject);
ImdgPredicateBuilder pb = tradingClearingRegistryListImdg.predicateBuilder(); ImdgPredicateBuilder pb = tradingClearingRegistryListImdg.predicateBuilder();
ImdgPredicate query = pb.and(pb.equals("status", WorkflowStatus.Active.getKey()), ImdgPredicate query = pb.and(
pb.equals("currency", byIdObject.getCurrency())); pb.equals("status", WorkflowStatus.Active.getKey()),
pb.equals("currency", byIdObject.getCurrency()),
pb.equals("tradingClearingRegistryId", tkrId));
if (idGetter != null) { if (idGetter != null) {
Long id = idGetter.apply(validatedObject); Long id = idGetter.apply(validatedObject);
if (id == null) // never if (id == null) // never
@ -217,9 +224,9 @@ public class TradingClearingRegistryListValidationConfig {
} }
Collection<TradingClearingRegistryList> inOtherLists = tradingClearingRegistryListImdg.getCollectionObjectsByPredicate(query); Collection<TradingClearingRegistryList> inOtherLists = tradingClearingRegistryListImdg.getCollectionObjectsByPredicate(query);
if (!inOtherLists.isEmpty()) { if (!inOtherLists.isEmpty()) {
Collection<Long> duplicateAccounts = inOtherLists.stream() Collection<String> duplicateAccounts = inOtherLists.stream()
.map(TradingClearingRegistryList::getAccountId) .map(tradingClearingRegistryList ->
.filter(accountId::equals) accountImdg.getSingleObjectByID(tradingClearingRegistryList.getAccountId()).getAccount())
.collect(Collectors.toSet()); .collect(Collectors.toSet());
return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, duplicateAccounts, fieldName); // (5023) «Счет %s уже используется» return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, duplicateAccounts, fieldName); // (5023) «Счет %s уже используется»
} }