fix up some old validation issues on loans.

This commit is contained in:
Keith Woodlock
2012-09-05 15:46:53 +01:00
parent 99d50b248a
commit b331a29bf8
5 changed files with 20 additions and 17 deletions
@@ -26,11 +26,9 @@ public class Charge extends AbstractAuditableCustom<AppUser, Long> {
@Column(name = "charge_applies_to_enum", nullable = false)
private Integer chargeAppliesTo;
@SuppressWarnings("unused")
@Column(name = "charge_time_enum", nullable = false)
private Integer chargeTime;
@SuppressWarnings("unused")
@Column(name = "charge_calculation_enum")
private Integer chargeCalculation;
@@ -129,7 +129,6 @@ public class Loan extends AbstractAuditableCustom<AppUser, Long> {
@Column(name = "maturedon_date")
private Date maturedOnDate;
@SuppressWarnings("unused")
@LazyCollection(LazyCollectionOption.FALSE)
@OneToMany(cascade = CascadeType.ALL, mappedBy = "loan", orphanRemoval = true)
private Set<LoanCharge> charges;
@@ -162,11 +161,11 @@ public class Loan extends AbstractAuditableCustom<AppUser, Long> {
return new Loan(client, fund, transactionProcessingStrategy, loanProduct, loanRepaymentScheduleDetail, null);
}
public Loan() {
protected Loan() {
this.client = null;
this.loanProduct = null;
this.loanRepaymentScheduleDetail = null;
this.charges = charges;
this.charges = null;
}
public Loan(final Client client, Fund fund, LoanTransactionProcessingStrategy transactionProcessingStrategy, final LoanProduct loanProduct,
@@ -7,17 +7,21 @@ import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
@Entity @IdClass(LoanCharge.LoanChargePK.class)
@Entity
@IdClass(LoanCharge.LoanChargePK.class)
@Table(name = "m_loan_charge")
public class LoanCharge {
@Id
@SuppressWarnings("unused")
@Id
private Loan loan;
@Id
@SuppressWarnings("unused")
@Id
private Charge charge;
@Column(name = "amount", scale = 6, precision = 19, nullable = false)
@SuppressWarnings("unused")
@Column(name = "amount", scale = 6, precision = 19, nullable = false)
private BigDecimal amount;
@SuppressWarnings("unused")
@@ -28,7 +32,8 @@ public class LoanCharge {
@Column(name = "charge_calculation_enum")
private Integer chargeCalculation;
public LoanCharge() {
protected LoanCharge() {
//
}
public LoanCharge(Loan loan, Charge charge, LoanChargeCommand command) {
@@ -54,11 +59,11 @@ public class LoanCharge {
}
}
public LoanCharge(Loan loan, Charge charge) {
public LoanCharge(final Loan loan, final Charge charge) {
this(loan, charge, charge.getAmount(), charge.getChargeTime(), charge.getChargeCalculation());
}
public LoanCharge(Loan loan, Charge charge, BigDecimal amount, Integer chargeTime, Integer chargeCalculation) {
public LoanCharge(final Loan loan, final Charge charge, final BigDecimal amount, final Integer chargeTime, final Integer chargeCalculation) {
this.loan = loan;
this.charge = charge;
this.amount = amount;
@@ -66,13 +71,15 @@ public class LoanCharge {
this.chargeCalculation = chargeCalculation;
}
public static class LoanChargePK implements Serializable{
@Id
public static class LoanChargePK implements Serializable {
@SuppressWarnings("unused")
@Id
@ManyToOne(optional = false)
@JoinColumn(name = "loan_id", referencedColumnName = "id", nullable=false)
private Loan loan;
@Id
@SuppressWarnings("unused")
@Id
@ManyToOne(optional = false)
@JoinColumn(name = "charge_id", referencedColumnName = "id", nullable=false)
private Charge charge;
@@ -47,7 +47,6 @@ public class LoanProduct extends AbstractAuditableCustom<AppUser, Long> {
@Column(name = "description")
private String description;
@SuppressWarnings("unused")
@ManyToMany
@JoinTable(name = "m_product_loan_charge",
joinColumns = @JoinColumn(name = "product_loan_id"),
@@ -33,7 +33,7 @@ public class CalculateLoanScheduleCommandValidator {
// FIXME - this constraint doesnt really need to be here. should be possible to express loan term as say 12 months whilst also saying
// - that the repayment structure is 6 repayments every bi-monthly.
if (!command.getLoanTermFrequencyType().equals(command.getRepaymentFrequencyType())) {
if (command.getLoanTermFrequencyType() != null && !command.getLoanTermFrequencyType().equals(command.getRepaymentFrequencyType())) {
ApiParameterError error = ApiParameterError.parameterError("validation.msg.loan.loanTermFrequencyType.not.the.same.as.repaymentFrequencyType",
"The parameters loanTermFrequencyType and repaymentFrequencyType must be the same.", "loanTermFrequencyType",
command.getLoanTermFrequencyType(), command.getRepaymentFrequencyType());