【发布时间】:2021-04-19 14:45:29
【问题描述】:
我有一种方法可以进行大量验证,并且正在失控。我将不胜感激有关如何最好地清理此方法的任何建议。我正在使用 Java 11,此方法是 Spring Boot 微服务的一部分。
public void validateRequest(DepositRequest depositRequest, String transferId, String userId) {
if (!Arrays.asList("REALTIME_PAYMENT", "ACCOUNT_PAYMENT").contains(depositRequest.creditTransfer()
.getTransferInformation().getValue())) {
logError(depositRequest, participantUserId, etransferId, INVALID_ACCOUNT_NUMBER);
throw new ServerValidationException(INVALID_ACCOUNT_NUMBER, PAYMENT);
}
if (depositRequest.creditTransfer().getGroupHeader().getSettlementInformation().getClearingSystem() == null) {
logSchemaValidationError(depositRequest, etransferId, participantUserId, "proprietary");
throw new ServerValidationException(SCHEMA_VALIDATION_ERROR, PAYMENT);
}
if (depositRequest.creditTransfer().getGroupHeader().getInstructing()
.getInstitutionIdentification().getMemberIdentification() == null) {
logSchemaValidationError(depositRequest, etransferId, participantUserId, "member_identification");
throw new ServerValidationException(SCHEMA_VALIDATION_ERROR, PAYMENT);
}
if (depositRequest.creditTransfer().getGroupHeader().getInstructed()
cialInstitutionIdentification().getMemberIdentification() == null) {
logSchemaValidationError(depositRequest, etransferId, participantUserId, "member_identification");
throw new ServerValidationException(SCHEMA_VALIDATION_ERROR, PAYMENT);
}
if (depositRequest.creditTransfer().getTransferInformation().getCreditor().getName() == null) {
logSchemaValidationError(depositRequest, etransferId, participantUserId, "creditor.name");
throw new ServerValidationException(SCHEMA_VALIDATION_ERROR, PAYMENT);
}
if (depositRequest.creditTransfer().getTransferInformation().getDebtor().getName() == null) {
logSchemaValidationError(depositRequest, etransferId, participantUserId, "debtor.name");
throw new ServerValidationException(SCHEMA_VALIDATION_ERROR, PAYMENT);
}
if (depositRequest.authorization() != null) {
if (depositRequest.authorization().getToken() == null ||
authorization().getToken().length() < 1 ||
authorization().getToken().length() > 35) {
logSchemaValidationError(depositRequest, etransferId, participantUserId, "participant_authorization_token");
throw new ServerValidationException(SCHEMA_VALIDATION_ERROR, PAYMENT);
}
}
if (!isCreditorAccountIdentificationValid(depositRequest.creditTransfer().getTransferInformation().getIdentification())) {
logSchemaValidationError(depositRequest, etransferId, participantUserId, "identification");
throw new ServerValidationException(INVALID_ACCOUNT_INFO, PAYMENT);
}
if (!depositRequest.creditTransfer().getTransferInformation().getSettlementDate().equals(LocalDate.now())) {
logSchemaValidationError(depositRequest, etransferId, participantUserId, "settlement_date");
throw new ServerValidationException(SCHEMA_VALIDATION_ERROR, PAYMENT);
}
}
【问题讨论】:
标签: java refactoring