ClearingAccountUpdateRequest, update clearing account, fix some names
This commit is contained in:
parent
441546dd18
commit
32d95c175f
10 changed files with 119 additions and 39 deletions
|
|
@ -143,13 +143,13 @@ public class BankAccountValidationConfig {
|
|||
};
|
||||
}
|
||||
|
||||
@Bean("bankAccountDeleteRequestValidator")
|
||||
public Function<CommonDeleteRequest, IValidator> bankAccountDeleteRequestValidator(
|
||||
@Bean("bankAccountBlockRequestValidator")
|
||||
public Function<CommonDeleteRequest, IValidator> bankAccountBlockRequestValidator(
|
||||
Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation
|
||||
) {
|
||||
return bankAccountDeleteRequest -> {
|
||||
return bankAccountBlockRequest -> {
|
||||
ImdgValidationContext<CommonDeleteRequest> context = new ImdgValidationContext<>();
|
||||
context.setValidatedObject(bankAccountDeleteRequest);
|
||||
context.setValidatedObject(bankAccountBlockRequest);
|
||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||
addImdg.accept(IMDGDistributedNames.Map_BankAccount);
|
||||
addImdg.accept(IMDGDistributedNames.Map_Account);
|
||||
|
|
|
|||
|
|
@ -84,13 +84,6 @@ public class ClearingAccountValidationConfig {
|
|||
addImdg.accept(IMDGDistributedNames.Map_Company);
|
||||
addImdg.accept(IMDGDistributedNames.Map_ClearingAccount);
|
||||
return new ValidatorImpl<>(context,
|
||||
IdPresentRule.instance("companyId",
|
||||
ClearingAccountUpdateRequest::getCompanyId,
|
||||
IMDGDistributedNames.Map_Company,
|
||||
Company.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.CompanyNotFound,
|
||||
company -> !WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus()) ? AccountError.CompanyNotActive : null),
|
||||
FieldRequiredRule.instance("account",
|
||||
ClearingAccountUpdateRequest::getAccount,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
|
|
@ -108,6 +101,24 @@ public class ClearingAccountValidationConfig {
|
|||
Collection<Account> accounts = accountImdg.getCollectionObjectsByPredicate(finalPredicate);
|
||||
if (accounts.isEmpty()) return AccountError.AccountNotFound;
|
||||
return null;
|
||||
}),
|
||||
FieldRequiredRule.instance("status",
|
||||
ClearingAccountUpdateRequest::getStatus,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
statusValue -> {
|
||||
if (statusValue == 0 || statusValue == 1 || statusValue == 2) return null;
|
||||
return AccountError.WrongFieldValue;
|
||||
}),
|
||||
FieldRequiredRule.instance("deal",
|
||||
ClearingAccountUpdateRequest::getDeal,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
dealValue -> {
|
||||
Imdg<Company> companyImdg = context.obtainMap(
|
||||
IMDGDistributedNames.Map_Company, Company.class
|
||||
);
|
||||
Company company = companyImdg.getSingleObjectByFieldValues(Map.of("tradingCode", dealValue));
|
||||
if (company == null) return AccountError.WrongFieldValue;
|
||||
return null;
|
||||
})
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import ru.spcex.platform.enumeration.AccountType;
|
|||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.api.ImdgTransaction;
|
||||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||
import ru.spcex.platform.utils.validation.IValidator;
|
||||
|
||||
import java.time.Instant;
|
||||
|
|
@ -45,13 +44,12 @@ public class BankAccountService extends QueueConsumer implements InitializingBea
|
|||
|
||||
private final Function<BankAccountNewRequest, IValidator> bankAccountNewRequestValidator;
|
||||
private final Function<BankAccountUpdateRequest, IValidator> bankAccountUpdateRequestValidator;
|
||||
private final Function<CommonDeleteRequest, IValidator> bankAccountDeleteRequestValidator;
|
||||
private final Function<CommonDeleteRequest, IValidator> bankAccountBlockRequestValidator;
|
||||
|
||||
@Autowired
|
||||
public BankAccountService(Consumer<String, Object> kafkaQueue,
|
||||
Producer<String, Object> kafkaProducer,
|
||||
ImdgProvider imdgProvider,
|
||||
IMessageResolver messageResolver,
|
||||
UserRoleVerification userRoleVerification,
|
||||
ValidationHelper validationHelper,
|
||||
AccountService accountService,
|
||||
|
|
@ -59,8 +57,8 @@ public class BankAccountService extends QueueConsumer implements InitializingBea
|
|||
Function<BankAccountNewRequest, IValidator> bankAccountNewRequestValidator,
|
||||
@Qualifier("bankAccountUpdateRequestValidator")
|
||||
Function<BankAccountUpdateRequest, IValidator> bankAccountUpdateRequestValidator,
|
||||
@Qualifier("bankAccountDeleteRequestValidator")
|
||||
Function<CommonDeleteRequest, IValidator> bankAccountDeleteRequestValidator) {
|
||||
@Qualifier("bankAccountBlockRequestValidator")
|
||||
Function<CommonDeleteRequest, IValidator> bankAccountBlockRequestValidator) {
|
||||
super(kafkaQueue, kafkaProducer);
|
||||
this.bankAccountMap = imdgProvider.getImdg(IMDGDistributedNames.Map_BankAccount, BankAccount.class);
|
||||
this.accountMap = imdgProvider.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
|
|
@ -70,7 +68,7 @@ public class BankAccountService extends QueueConsumer implements InitializingBea
|
|||
this.accountService = accountService;
|
||||
this.bankAccountNewRequestValidator = bankAccountNewRequestValidator;
|
||||
this.bankAccountUpdateRequestValidator = bankAccountUpdateRequestValidator;
|
||||
this.bankAccountDeleteRequestValidator = bankAccountDeleteRequestValidator;
|
||||
this.bankAccountBlockRequestValidator = bankAccountBlockRequestValidator;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -82,8 +80,8 @@ public class BankAccountService extends QueueConsumer implements InitializingBea
|
|||
.setFunction(this::bankAccountUpdate)
|
||||
.forDestination(Consts.DESTINATION_BANK_ACCOUNT_UPDATE, callbacks::put);
|
||||
callback(CommonDeleteRequest.class)
|
||||
.setFunction(this::bankAccountDelete)
|
||||
.forDestination(Consts.DESTINATION_BANK_ACCOUNT_DELETE, callbacks::put);
|
||||
.setFunction(this::bankAccountBlock)
|
||||
.forDestination(Consts.DESTINATION_BANK_ACCOUNT_BLOCK, callbacks::put);
|
||||
init();
|
||||
}
|
||||
|
||||
|
|
@ -139,7 +137,7 @@ public class BankAccountService extends QueueConsumer implements InitializingBea
|
|||
log.debug("successfully processed, new bank account id {}, account id {}", bankAccountId, accountId);
|
||||
} else {
|
||||
// todo выяснить, что возвращать из метода в этой ситуации
|
||||
log.debug("failed insert, new bank account id {}, new account id {} (if id = -1, insert is failed)",
|
||||
log.debug("failed insert, new bank account id {}, new account id {} (if id = -1 then insert is failed)",
|
||||
bankAccountId,
|
||||
accountId);
|
||||
imdgTransaction.rollbackTransaction();
|
||||
|
|
@ -173,19 +171,38 @@ public class BankAccountService extends QueueConsumer implements InitializingBea
|
|||
account.setAccount(req.account);
|
||||
account.setUpdated(Instant.now());
|
||||
|
||||
accountMap.update(account);
|
||||
bankAccountMap.update(bankAccount);
|
||||
ImdgTransaction imdgTransaction = imdgProvider.newTransaction();
|
||||
boolean txOk = false;
|
||||
imdgTransaction.beginTransaction();
|
||||
try {
|
||||
accountMap.update(account);
|
||||
bankAccountMap.update(bankAccount);
|
||||
txOk = true;
|
||||
} finally {
|
||||
if (txOk) {
|
||||
imdgTransaction.commitTransaction();
|
||||
log.debug("successfully processed, new bank account id {}, account id {}",
|
||||
bankAccount.getId(),
|
||||
account.getId());
|
||||
} else {
|
||||
// todo выяснить, что возвращать из метода в этой ситуации
|
||||
log.debug("failed update, bank account id {}, new account id {}",
|
||||
bankAccount.getId(),
|
||||
account.getId());
|
||||
imdgTransaction.rollbackTransaction();
|
||||
}
|
||||
}
|
||||
log.debug("successfully update, existing bankAccount with id {}", bankAccount.getId());
|
||||
return null;
|
||||
}
|
||||
|
||||
private RequestInfoUpdate bankAccountDelete(BaseRequest<CommonDeleteRequest> userRequest) {
|
||||
private RequestInfoUpdate bankAccountBlock(BaseRequest<CommonDeleteRequest> userRequest) {
|
||||
CommonDeleteRequest req = userRequest.getRequestPayload();
|
||||
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, bankAccountDeleteRequestValidator);
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, bankAccountBlockRequestValidator);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
log.debug("CommonDeleteRequest received id = {}", req.getId());
|
||||
|
|
@ -194,10 +211,29 @@ public class BankAccountService extends QueueConsumer implements InitializingBea
|
|||
Account account = accountMap.getSingleObjectByID(bankAccount.getAccountId());
|
||||
account.setStatus(AccountStatus.BLOCKED.getKey());
|
||||
account.setUpdated(Instant.now());
|
||||
|
||||
accountMap.update(account);
|
||||
bankAccountMap.delete(bankAccount);
|
||||
log.debug("successfully delete, existing bankAccount with id {}", bankAccount.getId());
|
||||
|
||||
ImdgTransaction imdgTransaction = imdgProvider.newTransaction();
|
||||
boolean txOk = false;
|
||||
imdgTransaction.beginTransaction();
|
||||
try {
|
||||
accountMap.update(account);
|
||||
bankAccountMap.delete(bankAccount);
|
||||
txOk = true;
|
||||
} finally {
|
||||
if (txOk) {
|
||||
imdgTransaction.commitTransaction();
|
||||
log.debug("successfully processed, new bank account id {}, account id {}",
|
||||
bankAccount.getId(),
|
||||
account.getId());
|
||||
} else {
|
||||
// todo выяснить, что возвращать из метода в этой ситуации
|
||||
log.debug("failed block, bank account id {}, new account id {}",
|
||||
bankAccount.getId(),
|
||||
account.getId());
|
||||
imdgTransaction.rollbackTransaction();
|
||||
}
|
||||
}
|
||||
log.debug("successfully block, existing bankAccount with id {}", bankAccount.getId());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
|||
import org.springframework.stereotype.Service;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.account.ClearingAccount;
|
||||
import ru.spcex.clearing.account.errors.AccountError;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||
|
|
@ -17,6 +18,7 @@ import ru.spcex.clearing.platform.messaging.domain.cud.account.ClearingAccountNe
|
|||
import ru.spcex.clearing.platform.messaging.domain.cud.account.ClearingAccountUpdateRequest;
|
||||
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
|
||||
import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate;
|
||||
import ru.spcex.clearing.platform.messaging.service.Status;
|
||||
import ru.spcex.clearing.validation.common.ValidationHelper;
|
||||
import ru.spcex.platform.enumeration.AccountStatus;
|
||||
import ru.spcex.platform.enumeration.AccountType;
|
||||
|
|
@ -25,6 +27,8 @@ import ru.spcex.platform.imdg.api.ImdgProvider;
|
|||
import ru.spcex.platform.imdg.api.ImdgTransaction;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||
import ru.spcex.platform.utils.validation.IValidator;
|
||||
|
||||
import java.time.Instant;
|
||||
|
|
@ -39,6 +43,7 @@ public class ClearingAccountService extends QueueConsumer implements Initializin
|
|||
private final ImdgProvider imdgProvider;
|
||||
private final Imdg<Account> accountImdg;
|
||||
private final Imdg<ClearingAccount> clearingAccountImdg;
|
||||
private final IMessageResolver messageResolver;
|
||||
private final Function<ClearingAccountNewRequest, IValidator> clearingAccountNewRequestValidator;
|
||||
private final Function<ClearingAccountUpdateRequest, IValidator> clearingAccountUpdateRequestValidator;
|
||||
|
||||
|
|
@ -48,6 +53,7 @@ public class ClearingAccountService extends QueueConsumer implements Initializin
|
|||
AccountService accountService,
|
||||
ValidationHelper validationHelper,
|
||||
ImdgProvider imdgProvider,
|
||||
IMessageResolver messageResolver,
|
||||
@Qualifier("clearingAccountNewRequestValidator")
|
||||
Function<ClearingAccountNewRequest, IValidator> clearingAccountNewRequestValidator,
|
||||
@Qualifier("clearingAccountUpdateRequestValidator")
|
||||
|
|
@ -58,6 +64,7 @@ public class ClearingAccountService extends QueueConsumer implements Initializin
|
|||
this.imdgProvider = imdgProvider;
|
||||
this.accountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
this.clearingAccountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_ClearingAccount, ClearingAccount.class);
|
||||
this.messageResolver = messageResolver;
|
||||
this.clearingAccountNewRequestValidator = clearingAccountNewRequestValidator;
|
||||
this.clearingAccountUpdateRequestValidator = clearingAccountUpdateRequestValidator;
|
||||
}
|
||||
|
|
@ -111,7 +118,7 @@ public class ClearingAccountService extends QueueConsumer implements Initializin
|
|||
log.debug("successfully processed, new clearing account id {}, account id {}", clearingAccountId, accountId);
|
||||
} else {
|
||||
// todo выяснить, что возвращать из метода в этой ситуации
|
||||
log.debug("failed insert, new clearing account id {}, new account id {} (if id = -1, insert is failed)",
|
||||
log.debug("failed insert, new clearing account id {}, new account id {} (if id = -1 then insert is failed)",
|
||||
clearingAccountId,
|
||||
accountId);
|
||||
imdgTransaction.rollbackTransaction();
|
||||
|
|
@ -134,10 +141,26 @@ public class ClearingAccountService extends QueueConsumer implements Initializin
|
|||
ImdgPredicate finalPredicate = pb.and(accountValuePredicate,
|
||||
accountStatusPredicate,
|
||||
accountTypePredicate);
|
||||
|
||||
Account account = accountImdg.getCollectionObjectsByPredicate(finalPredicate).iterator().next();
|
||||
Long accountId = account.getId();
|
||||
|
||||
ClearingAccount clearingAccount = clearingAccountImdg.getSingleObjectByFieldValues(Map.of("accountId", accountId));
|
||||
if (clearingAccount == null) {
|
||||
String errMsg = messageResolver.resolve(new EnumMessage(AccountError.AccountNotFound, account.getAccount()));
|
||||
return new RequestInfoUpdate()
|
||||
.setId(userRequest.getId())
|
||||
.setStatus(Status.Error)
|
||||
.setMessage(errMsg);
|
||||
}
|
||||
|
||||
Integer statusValue = req.getStatus();
|
||||
if (statusValue == 0) account.setStatus(AccountStatus.BLOCKED.getKey());
|
||||
else if (statusValue == 1) account.setStatus(AccountStatus.ACTIVE.getKey());
|
||||
else if (statusValue == 2) account.setStatus(AccountStatus.CLOSE.getKey());
|
||||
account.setUpdated(Instant.now());
|
||||
|
||||
accountImdg.update(account);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ public class InformationAccountService extends QueueConsumer implements Initiali
|
|||
accountId);
|
||||
} else {
|
||||
// todo выяснить, что возвращать из метода в этой ситуации
|
||||
log.debug("failed insert, new information account id {}, new account id {} (if id = -1, insert is failed)",
|
||||
log.debug("failed insert, new information account id {}, new account id {} (if id = -1 then insert is failed)",
|
||||
informationAccountId,
|
||||
accountId);
|
||||
imdgTransaction.rollbackTransaction();
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ public class BankAccountServiceTest {
|
|||
private static final int PARTITION = 0;
|
||||
private static final String TOPIC_ACCOUNT_NEW = Consts.DESTINATION_BANK_ACCOUNT_NEW;
|
||||
private static final String TOPIC_ACCOUNT_UPDATE = Consts.DESTINATION_BANK_ACCOUNT_UPDATE;
|
||||
private static final String TOPIC_ACCOUNT_DELETE = Consts.DESTINATION_BANK_ACCOUNT_DELETE;
|
||||
private static final String TOPIC_ACCOUNT_DELETE = Consts.DESTINATION_BANK_ACCOUNT_BLOCK;
|
||||
private static final Long ID = 0L;
|
||||
private static final AtomicInteger countRun = new AtomicInteger(1);
|
||||
private static final Long accountId = 12L;
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ public class BankAccountController extends AbstractQueueController {
|
|||
@PathVariable("id") Long id) throws ExecutionException, InterruptedException {
|
||||
CommonDeleteAction deleteAction = new CommonDeleteAction();
|
||||
deleteAction.setId(id);
|
||||
return processRequest(Consts.DESTINATION_BANK_ACCOUNT_DELETE, deleteAction);
|
||||
return processRequest(Consts.DESTINATION_BANK_ACCOUNT_BLOCK, deleteAction);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get bank account.")
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ class BankAccountControllerTest extends AbstractControllerTest {
|
|||
deleteAction.setId(id);
|
||||
//ACT and ASSERT
|
||||
checkDeletingByRestApi(REST_URL, id);
|
||||
checkSendedMessegeFromKafka(Consts.DESTINATION_BANK_ACCOUNT_DELETE, deleteAction);
|
||||
checkSendedMessegeFromKafka(Consts.DESTINATION_BANK_ACCOUNT_BLOCK, deleteAction);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public interface Consts {
|
|||
String DESTINATION_CORRESPONDENT_ACCOUNT_UPDATE = "correspondent-account-update";
|
||||
String DESTINATION_CORRESPONDENT_ACCOUNT_BLOCK = "correspondent-account-block";
|
||||
|
||||
String DESTINATION_BANK_ACCOUNT_DELETE = "bank-account-delete";
|
||||
String DESTINATION_BANK_ACCOUNT_BLOCK = "bank-account-block";
|
||||
String DESTINATION_BANK_ACCOUNT_UPDATE = "bank-account-update";
|
||||
String DESTINATION_BANK_ACCOUNT_NEW = "bank-account-new";
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,10 @@ public class ClearingAccountUpdateRequest {
|
|||
public String account;
|
||||
|
||||
@JsonProperty
|
||||
public Long companyId;
|
||||
public Integer status;
|
||||
|
||||
@JsonProperty
|
||||
public String deal;
|
||||
|
||||
public String getAccount() {
|
||||
return account;
|
||||
|
|
@ -18,11 +20,19 @@ public class ClearingAccountUpdateRequest {
|
|||
this.account = account;
|
||||
}
|
||||
|
||||
public Long getCompanyId() {
|
||||
return companyId;
|
||||
public Integer getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setCompanyId(Long companyId) {
|
||||
this.companyId = companyId;
|
||||
public void setStatus(Integer status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getDeal() {
|
||||
return deal;
|
||||
}
|
||||
|
||||
public void setDeal(String deal) {
|
||||
this.deal = deal;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue