http://jira.mfd.msk:8088/browse/CLS-290 fix valadators
This commit is contained in:
parent
fac24548fa
commit
37335728cf
2 changed files with 37 additions and 53 deletions
|
|
@ -134,10 +134,8 @@ public class ValidationConfig {
|
||||||
addImdg.accept(IMDGDistributedNames.Map_Account);
|
addImdg.accept(IMDGDistributedNames.Map_Account);
|
||||||
addImdg.accept(IMDGDistributedNames.Map_Company);
|
addImdg.accept(IMDGDistributedNames.Map_Company);
|
||||||
return new ValidatorImpl<>(context,
|
return new ValidatorImpl<>(context,
|
||||||
Sdf57ValidationRule.CompanyDebPresent,
|
Sdf57ValidationRule.CompanyDebOrCredPresent,
|
||||||
Sdf57ValidationRule.CompanyCredPresent,
|
Sdf57ValidationRule.AccountDebOrCredPresent,
|
||||||
Sdf57ValidationRule.AccountDebPresent,
|
|
||||||
Sdf57ValidationRule.AccountCredPresent,
|
|
||||||
Sdf57ValidationRule.CurrencyCode
|
Sdf57ValidationRule.CurrencyCode
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -14,65 +14,51 @@ import ru.spcex.platform.utils.validation.IValidationRule;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public enum Sdf57ValidationRule implements IValidationRule<ImdgValidationContext<SDf57>> {
|
public enum Sdf57ValidationRule implements IValidationRule<ImdgValidationContext<SDf57>> {
|
||||||
CompanyDebPresent() {
|
CompanyDebOrCredPresent() {
|
||||||
@Override
|
@Override
|
||||||
public Optional<EnumMessage> validate(ImdgValidationContext<SDf57> context) {
|
public Optional<EnumMessage> validate(ImdgValidationContext<SDf57> context) {
|
||||||
SDf57 sdf57 = context.getValidatedObject();
|
SDf57 sdf57 = context.getValidatedObject();
|
||||||
if (TextUtil.isEmpty(sdf57.getDeal_deb())) {
|
|
||||||
return of(ClearingError.CompanyNotFound, sdf57.getDeal_deb());
|
|
||||||
}
|
|
||||||
Imdg<Company> companyImdg = context.obtainMap(IMDGDistributedNames.Map_Company, Company.class);
|
Imdg<Company> companyImdg = context.obtainMap(IMDGDistributedNames.Map_Company, Company.class);
|
||||||
Company found = companyImdg.getSingleObjectBySQL("tradingCode = '" + sdf57.getDeal_deb() + "'");
|
|
||||||
if (found == null) {
|
|
||||||
return of(ClearingError.CompanyNotFound, sdf57.getDeal_deb());
|
|
||||||
}
|
|
||||||
context.storeObject(ValidationStored.Sdf57CompanyDeb, found);
|
|
||||||
return empty();
|
|
||||||
}
|
|
||||||
}, CompanyCredPresent() {
|
|
||||||
@Override
|
|
||||||
public Optional<EnumMessage> validate(ImdgValidationContext<SDf57> context) {
|
|
||||||
SDf57 sdf57 = context.getValidatedObject();
|
|
||||||
if (TextUtil.isEmpty(sdf57.getDeal_cred())) {
|
|
||||||
return of(ClearingError.CompanyNotFound, sdf57.getDeal_cred());
|
|
||||||
}
|
|
||||||
Imdg<Company> companyImdg = context.obtainMap(IMDGDistributedNames.Map_Company, Company.class);
|
|
||||||
Company found = companyImdg.getSingleObjectBySQL("tradingCode = '" + sdf57.getDeal_cred() + "'");
|
|
||||||
if (found == null) {
|
|
||||||
return of(ClearingError.CompanyNotFound, sdf57.getDeal_cred());
|
|
||||||
}
|
|
||||||
context.storeObject(ValidationStored.Sdf57CompanyCred, found);
|
|
||||||
return empty();
|
|
||||||
}
|
|
||||||
}, AccountDebPresent() {
|
|
||||||
@Override
|
|
||||||
public Optional<EnumMessage> validate(ImdgValidationContext<SDf57> context) {
|
|
||||||
SDf57 sdf57 = context.getValidatedObject();
|
|
||||||
if (TextUtil.isEmpty(sdf57.getC_acc_deb())) {
|
|
||||||
return of(ClearingError.AccountNotPresent, sdf57.getC_acc_deb());
|
|
||||||
}
|
|
||||||
Imdg<Account> accountImdg = context.obtainMap(IMDGDistributedNames.Map_Account, Account.class);
|
|
||||||
Account found = accountImdg.getSingleObjectBySQL("account = '" + sdf57.getC_acc_deb() + "'");
|
|
||||||
if (found == null) {
|
|
||||||
return of(ClearingError.AccountNotPresent, sdf57.getC_acc_deb());
|
|
||||||
}
|
|
||||||
context.storeObject(ValidationStored.Sdf57AccountDeb, found);
|
|
||||||
return empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
}, AccountCredPresent() {
|
Optional<Company> companyDebFound = Optional.empty();
|
||||||
|
Optional<Company> companyCredFound = Optional.empty();
|
||||||
|
|
||||||
|
if (!TextUtil.isEmpty(sdf57.getDeal_deb())) {
|
||||||
|
companyDebFound = Optional.ofNullable(companyImdg.getSingleObjectBySQL("tradingCode = '" + sdf57.getDeal_deb() + "'"));
|
||||||
|
companyDebFound.ifPresent(companyDeb -> context.storeObject(ValidationStored.Sdf57CompanyDeb, companyDeb));
|
||||||
|
}
|
||||||
|
if (!TextUtil.isEmpty(sdf57.getDeal_cred())) {
|
||||||
|
companyCredFound = Optional.ofNullable(companyImdg.getSingleObjectBySQL("tradingCode = '" + sdf57.getDeal_cred() + "'"));
|
||||||
|
companyCredFound.ifPresent(companyCred -> context.storeObject(ValidationStored.Sdf57CompanyCred, companyCred));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (companyDebFound.isEmpty() && companyCredFound.isEmpty()) {
|
||||||
|
return of(ClearingError.CompanyNotFound, String.format("dealDeb = '%s'/ deal_cred = '%s'",
|
||||||
|
sdf57.getDeal_deb(), sdf57.getDeal_cred()));
|
||||||
|
}
|
||||||
|
return empty();
|
||||||
|
}
|
||||||
|
}, AccountDebOrCredPresent() {
|
||||||
@Override
|
@Override
|
||||||
public Optional<EnumMessage> validate(ImdgValidationContext<SDf57> context) {
|
public Optional<EnumMessage> validate(ImdgValidationContext<SDf57> context) {
|
||||||
SDf57 sdf57 = context.getValidatedObject();
|
SDf57 sdf57 = context.getValidatedObject();
|
||||||
if (TextUtil.isEmpty(sdf57.getC_acc_cred())) {
|
|
||||||
return of(ClearingError.AccountNotPresent, sdf57.getC_acc_cred());
|
|
||||||
}
|
|
||||||
Imdg<Account> accountImdg = context.obtainMap(IMDGDistributedNames.Map_Account, Account.class);
|
Imdg<Account> accountImdg = context.obtainMap(IMDGDistributedNames.Map_Account, Account.class);
|
||||||
Account found = accountImdg.getSingleObjectBySQL("account = '" + sdf57.getC_acc_cred() + "'");
|
|
||||||
if (found == null) {
|
Optional<Account> accountDebFound = Optional.empty();
|
||||||
return of(ClearingError.AccountNotPresent, sdf57.getC_acc_cred());
|
Optional<Account> accountCredFound = Optional.empty();
|
||||||
|
if (!TextUtil.isEmpty(sdf57.getC_acc_deb())) {
|
||||||
|
accountDebFound = Optional.ofNullable(accountImdg.getSingleObjectBySQL("account = '" + sdf57.getC_acc_deb() + "'"));
|
||||||
|
accountDebFound.ifPresent(accountDeb -> context.storeObject(ValidationStored.Sdf57AccountDeb, accountDeb));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TextUtil.isEmpty(sdf57.getC_acc_cred())) {
|
||||||
|
accountCredFound = Optional.ofNullable(accountImdg.getSingleObjectBySQL("account = '" + sdf57.getC_acc_cred() + "'"));
|
||||||
|
accountCredFound.ifPresent(accountCred -> context.storeObject(ValidationStored.Sdf57AccountCred, accountCred));
|
||||||
|
}
|
||||||
|
if (accountDebFound.isEmpty() && accountCredFound.isEmpty()) {
|
||||||
|
return of(ClearingError.AccountNotPresent, String.format("accDeb = '%s'/ accDred = '%s'",
|
||||||
|
sdf57.getC_acc_deb(), sdf57.getC_acc_cred()));
|
||||||
}
|
}
|
||||||
context.storeObject(ValidationStored.Sdf57AccountCred, found);
|
|
||||||
return empty();
|
return empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue