MIFOSX-1717,MIFOSX-1662 Test case for account number preferences and Code Refactoring for Client status.

This commit is contained in:
Chandrika
2014-12-15 18:29:30 -05:00
parent a9850c50da
commit d24839267f
12 changed files with 880 additions and 653 deletions
@@ -16,8 +16,8 @@ public class ClientApiConstants {
public static final String CLIENT_RESOURCE_NAME = "client";
public static final String CLIENT_CLOSURE_REASON = "ClientClosureReason";
public static final String CLIENT_ACTION_REASON = "ClientActionReason";
public static final String CLIENT_REJECT_REASON = "ClientRejectReason";
public static final String CLIENT_WITHDRAW_REASON = "ClientWithdrawReason";
public static final String CLIENT_REJECT_REASON = "ClientRejectionReason";
public static final String CLIENT_WITHDRAW_REASON = "ClientWithdrawalReason";
public static final String GENDER = "Gender";
@@ -46,10 +46,10 @@ public class ClientApiConstants {
public static final String closureDateParamName = "closureDate";
public static final String closureReasonIdParamName = "closureReasonId";
public static final String rejectDateParamName = "rejectionDate";
public static final String rejectReasonIdParamName ="rejectionReasonId";
public static final String withdrawDateParamName = "withdrawalDate";
public static final String withdrawReasonIdParamName ="withdrawalReasonId";
public static final String rejectionDateParamName = "rejectionDate";
public static final String rejectionReasonIdParamName ="rejectionReasonId";
public static final String withdrawalDateParamName = "withdrawalDate";
public static final String withdrawalReasonIdParamName ="withdrawalReasonId";
public static final String submittedOnDateParamName = "submittedOnDate";
public static final String savingsProductIdParamName = "savingsProductId";
@@ -115,8 +115,8 @@ public class ClientApiConstants {
public static final Set<String> CLIENT_CLOSE_REQUEST_DATA_PARAMETERS = new HashSet<>(Arrays.asList(localeParamName,
dateFormatParamName, closureDateParamName, closureReasonIdParamName));
public static final Set<String> CLIENT_REJECT_DATA_PARAMETERS = new HashSet<>(Arrays.asList(localeParamName,dateFormatParamName,rejectDateParamName,rejectReasonIdParamName));
public static final Set<String> CLIENT_REJECT_DATA_PARAMETERS = new HashSet<>(Arrays.asList(localeParamName,dateFormatParamName,rejectionDateParamName,rejectionReasonIdParamName));
public static final Set<String> CLIENT_WITHDRAW_DATA_PARAMETERS = new HashSet<>(Arrays.asList(localeParamName,dateFormatParamName,withdrawDateParamName,withdrawReasonIdParamName));
public static final Set<String> CLIENT_WITHDRAW_DATA_PARAMETERS = new HashSet<>(Arrays.asList(localeParamName,dateFormatParamName,withdrawalDateParamName,withdrawalReasonIdParamName));
}
@@ -527,11 +527,11 @@ public final class ClientDataValidator {
final JsonElement element = command.parsedJson();
final LocalDate rejectDate = this.fromApiJsonHelper.extractLocalDateNamed(ClientApiConstants.rejectDateParamName, element);
baseDataValidator.reset().parameter(ClientApiConstants.rejectDateParamName).value(rejectDate).notNull();
final LocalDate rejectionDate = this.fromApiJsonHelper.extractLocalDateNamed(ClientApiConstants.rejectionDateParamName, element);
baseDataValidator.reset().parameter(ClientApiConstants.rejectionDateParamName).value(rejectionDate).notNull();
final Long rejectReasonId = this.fromApiJsonHelper.extractLongNamed(ClientApiConstants.rejectReasonIdParamName, element);
baseDataValidator.reset().parameter(ClientApiConstants.rejectReasonIdParamName).value(rejectReasonId).notNull()
final Long rejectionReasonId = this.fromApiJsonHelper.extractLongNamed(ClientApiConstants.rejectionReasonIdParamName, element);
baseDataValidator.reset().parameter(ClientApiConstants.rejectionReasonIdParamName).value(rejectionReasonId).notNull()
.longGreaterThanZero();
throwExceptionIfValidationWarningsExist(dataValidationErrors);
@@ -553,11 +553,11 @@ public final class ClientDataValidator {
final JsonElement element = command.parsedJson();
final LocalDate withdrawDate = this.fromApiJsonHelper.extractLocalDateNamed(ClientApiConstants.withdrawDateParamName, element);
baseDataValidator.reset().parameter(ClientApiConstants.withdrawDateParamName).value(withdrawDate).notNull();
final LocalDate withdrawalDate = this.fromApiJsonHelper.extractLocalDateNamed(ClientApiConstants.withdrawalDateParamName, element);
baseDataValidator.reset().parameter(ClientApiConstants.withdrawalDateParamName).value(withdrawalDate).notNull();
final Long withdrawReasonId = this.fromApiJsonHelper.extractLongNamed(ClientApiConstants.withdrawReasonIdParamName, element);
baseDataValidator.reset().parameter(ClientApiConstants.withdrawReasonIdParamName).value(withdrawReasonId).notNull()
final Long withdrawalReasonId = this.fromApiJsonHelper.extractLongNamed(ClientApiConstants.withdrawalReasonIdParamName, element);
baseDataValidator.reset().parameter(ClientApiConstants.withdrawalReasonIdParamName).value(withdrawalReasonId).notNull()
.longGreaterThanZero();
throwExceptionIfValidationWarningsExist(dataValidationErrors);
@@ -139,11 +139,11 @@ public final class Client extends AbstractPersistable<Long> {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "reject_reason_cv_id", nullable = true)
private CodeValue rejectReason;
private CodeValue rejectionReason;
@Column(name = "rejectedon_date", nullable = true)
@Temporal(TemporalType.DATE)
private Date rejectDate;
private Date rejectionDate;
@ManyToOne(optional = true)
@JoinColumn(name = "rejectedon_userid", nullable = true)
@@ -151,11 +151,11 @@ public final class Client extends AbstractPersistable<Long> {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "withdraw_reason_cv_id", nullable = true)
private CodeValue withdrawReason;
private CodeValue withdrawalReason;
@Column(name = "withdrawn_on_date", nullable = true)
@Temporal(TemporalType.DATE)
private Date withdrawDate;
private Date withdrawalDate;
@ManyToOne(optional = true)
@JoinColumn(name = "withdraw_on_userid", nullable = true)
@@ -866,22 +866,22 @@ public final class Client extends AbstractPersistable<Long> {
return dateOfBirth;
}
public void reject(AppUser currentUser, CodeValue rejectReason, Date rejectDate) {
this.rejectReason = rejectReason;
this.rejectDate = rejectDate;
public void reject(AppUser currentUser, CodeValue rejectionReason, Date rejectionDate) {
this.rejectionReason = rejectionReason;
this.rejectionDate = rejectionDate;
this.rejectedBy = currentUser;
this.updatedBy = currentUser;
this.updatedOnDate = rejectDate;
this.updatedOnDate = rejectionDate;
this.status = ClientStatus.REJECTED.getValue();
}
public void withdraw(AppUser currentUser, CodeValue withdrawReason, Date withdrawDate) {
this.withdrawReason = withdrawReason;
this.withdrawDate = withdrawDate;
public void withdraw(AppUser currentUser, CodeValue withdrawalReason, Date withdrawalDate) {
this.withdrawalReason = withdrawalReason;
this.withdrawalDate = withdrawalDate;
this.withdrawnBy = currentUser;
this.updatedBy = currentUser;
this.updatedOnDate = withdrawDate;
this.updatedOnDate = withdrawalDate;
this.status = ClientStatus.WITHDRAWN.getValue();
}
@@ -604,22 +604,22 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
this.fromApiJsonDeserializer.validateRejection(command);
final Client client = this.clientRepository.findOneWithNotFoundDetection(entityId);
final LocalDate rejectDate = command.localDateValueOfParameterNamed(ClientApiConstants.rejectDateParamName);
final Long rejectReasonId = command.longValueOfParameterNamed(ClientApiConstants.rejectReasonIdParamName);
final LocalDate rejectionDate = command.localDateValueOfParameterNamed(ClientApiConstants.rejectionDateParamName);
final Long rejectionReasonId = command.longValueOfParameterNamed(ClientApiConstants.rejectionReasonIdParamName);
final CodeValue rejectReason = this.codeValueRepository.findOneByCodeNameAndIdWithNotFoundDetection(
ClientApiConstants.CLIENT_REJECT_REASON, rejectReasonId);
final CodeValue rejectionReason = this.codeValueRepository.findOneByCodeNameAndIdWithNotFoundDetection(
ClientApiConstants.CLIENT_REJECT_REASON, rejectionReasonId);
if (client.isNotPending()) {
final String errorMessage = "Only clients pending activation may be withdrawn.";
throw new InvalidClientStateTransitionException("rejection", "on.account.not.in.pending.activation.status", errorMessage,
rejectDate, client.getSubmittedOnDate());
} else if (client.getSubmittedOnDate().isAfter(rejectDate)) {
rejectionDate, client.getSubmittedOnDate());
} else if (client.getSubmittedOnDate().isAfter(rejectionDate)) {
final String errorMessage = "The client rejection date cannot be before the client submitted date.";
throw new InvalidClientStateTransitionException("rejection", "date.cannot.before.client.submitted.date", errorMessage,
rejectDate, client.getSubmittedOnDate());
rejectionDate, client.getSubmittedOnDate());
}
client.reject(currentUser, rejectReason, rejectDate.toDate());
client.reject(currentUser, rejectionReason, rejectionDate.toDate());
this.clientRepository.saveAndFlush(client);
return new CommandProcessingResultBuilder() //
@@ -635,22 +635,22 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
this.fromApiJsonDeserializer.validateWithdrawn(command);
final Client client = this.clientRepository.findOneWithNotFoundDetection(entityId);
final LocalDate withdrawDate = command.localDateValueOfParameterNamed(ClientApiConstants.withdrawDateParamName);
final Long withdrawReasonId = command.longValueOfParameterNamed(ClientApiConstants.withdrawReasonIdParamName);
final LocalDate withdrawalDate = command.localDateValueOfParameterNamed(ClientApiConstants.withdrawalDateParamName);
final Long withdrawalReasonId = command.longValueOfParameterNamed(ClientApiConstants.withdrawalReasonIdParamName);
final CodeValue withdrawReason = this.codeValueRepository.findOneByCodeNameAndIdWithNotFoundDetection(
ClientApiConstants.CLIENT_WITHDRAW_REASON, withdrawReasonId);
final CodeValue withdrawalReason = this.codeValueRepository.findOneByCodeNameAndIdWithNotFoundDetection(
ClientApiConstants.CLIENT_WITHDRAW_REASON, withdrawalReasonId);
if (client.isNotPending()) {
final String errorMessage = "Only clients pending activation may be withdrawn.";
throw new InvalidClientStateTransitionException("withdrawal", "on.account.not.in.pending.activation.status", errorMessage,
withdrawDate, client.getSubmittedOnDate());
} else if (client.getSubmittedOnDate().isAfter(withdrawDate)) {
withdrawalDate, client.getSubmittedOnDate());
} else if (client.getSubmittedOnDate().isAfter(withdrawalDate)) {
final String errorMessage = "The client withdrawal date cannot be before the client submitted date.";
throw new InvalidClientStateTransitionException("withdrawal", "date.cannot.before.client.submitted.date", errorMessage,
withdrawDate, client.getSubmittedOnDate());
withdrawalDate, client.getSubmittedOnDate());
}
client.withdraw(currentUser, withdrawReason, withdrawDate.toDate());
client.withdraw(currentUser, withdrawalReason, withdrawalDate.toDate());
this.clientRepository.saveAndFlush(client);
return new CommandProcessingResultBuilder() //