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:
Keith Woodlock
2012-10-03 17:00:04 +01:00
parent fd20f72814
commit 976ea6be21
2 changed files with 19 additions and 16 deletions
@@ -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();
}
}
@@ -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));
}
}
}