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