Tidy up programming style bad smells around GETTING data from objects rather than putting behaviour on object that owns the data and using that behaviour.
This commit is contained in:
+8
-1
@@ -79,7 +79,6 @@ public class DepositAccount extends AbstractAuditableCustom<AppUser, Long> {
|
||||
@Column(name = "matures_on_date")
|
||||
private Date maturesOnDate;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Column(name = "projected_interest_accrued_on_maturity", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal projectedInterestAccruedOnMaturity;
|
||||
|
||||
@@ -638,4 +637,12 @@ public class DepositAccount extends AbstractAuditableCustom<AppUser, Long> {
|
||||
this.renewalAllowed=renewalAllowed;
|
||||
this.isInterestWithdrawable=isInterestWithdrawable;
|
||||
}
|
||||
|
||||
public boolean isSubmittedAndPendingApproval() {
|
||||
return DepositAccountStatus.fromInt(this.depositStatus).isSubmittedAndPendingApproval();
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return DepositAccountStatus.fromInt(this.depositStatus).isActive();
|
||||
}
|
||||
}
|
||||
+11
-15
@@ -55,8 +55,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
|
||||
final DepositAccountRepository depositAccountRepository,
|
||||
final DepositAccountAssembler depositAccountAssembler,
|
||||
final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator,
|
||||
final NoteRepository noteRepository
|
||||
) {
|
||||
final NoteRepository noteRepository) {
|
||||
this.context=context;
|
||||
this.depositAccountRepository = depositAccountRepository;
|
||||
this.depositAccountAssembler = depositAccountAssembler;
|
||||
@@ -369,12 +368,8 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
|
||||
&& (new LocalDate().isAfter(account.maturesOnDate()) || new LocalDate()
|
||||
.isEqual(account.maturesOnDate()))) {
|
||||
|
||||
// FIXME - KW - rather than getting the status from account and then checking,
|
||||
// add isActive behaviour on account so all places that use account dont have to repeat this type of checking.
|
||||
if (account.getDepositStatus().equals(
|
||||
DepositAccountStatus.ACTIVE.getValue())) {
|
||||
final DepositAccount renewedAccount = this.depositAccountAssembler
|
||||
.assembleFrom(account, command);
|
||||
if (account.isActive()) {
|
||||
final DepositAccount renewedAccount = this.depositAccountAssembler.assembleFrom(account, command);
|
||||
this.depositAccountRepository.save(renewedAccount);
|
||||
account.closeDepositAccount(defaultDepositLifecycleStateMachine());
|
||||
this.depositAccountRepository.save(account);
|
||||
@@ -396,14 +391,17 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
|
||||
DepositAccountCommandValidator validator = new DepositAccountCommandValidator(command);
|
||||
validator.validateForUpdate();
|
||||
|
||||
DepositAccount account = this.depositAccountRepository.findOne(command.getId());
|
||||
final DepositAccount account = this.depositAccountRepository.findOne(command.getId());
|
||||
if (account == null || account.isDeleted()) {
|
||||
throw new DepositAccountNotFoundException(command.getId());
|
||||
}
|
||||
if(account.getDepositStatus() == 100)
|
||||
this.depositAccountAssembler.assembleUpdatedDepositAccount(account,command);
|
||||
else if(account.getDepositStatus() == 300)
|
||||
this.depositAccountAssembler.updateApprovedDepositAccount(account,command);
|
||||
|
||||
if (account.isSubmittedAndPendingApproval()) {
|
||||
this.depositAccountAssembler.assembleUpdatedDepositAccount(account, command);
|
||||
} else if (account.isActive()) {
|
||||
this.depositAccountAssembler.updateApprovedDepositAccount(account, command);
|
||||
}
|
||||
|
||||
this.depositAccountRepository.save(account);
|
||||
|
||||
return new EntityIdentifier(account.getId());
|
||||
@@ -411,7 +409,5 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
|
||||
handleDataIntegrityIssues(command, dve);
|
||||
return new EntityIdentifier(Long.valueOf(-1));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user