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