tidy up validation of savings accounts.

This commit is contained in:
Keith Woodlock
2013-07-17 14:11:52 +01:00
parent 28f0c80b84
commit 12abc17a88
7 changed files with 95 additions and 15 deletions
@@ -46,7 +46,9 @@ public enum SavingsCompoundingInterestPeriodType {
public static Object[] integerValues() {
List<Integer> values = new ArrayList<Integer>();
for (SavingsCompoundingInterestPeriodType enumType : values()) {
values.add(enumType.getValue());
if (enumType.getValue() > 0) {
values.add(enumType.getValue());
}
}
return values.toArray();
@@ -5,6 +5,9 @@
*/
package org.mifosplatform.portfolio.savings;
import java.util.ArrayList;
import java.util.List;
/**
* <ul>
* People typically use either of the following settings when calculating there
@@ -35,6 +38,17 @@ public enum SavingsInterestCalculationDaysInYearType {
return code;
}
public static Object[] integerValues() {
List<Integer> values = new ArrayList<Integer>();
for (SavingsInterestCalculationDaysInYearType enumType : values()) {
if (enumType.getValue() > 0) {
values.add(enumType.getValue());
}
}
return values.toArray();
}
public static SavingsInterestCalculationDaysInYearType fromInt(final Integer type) {
SavingsInterestCalculationDaysInYearType repaymentFrequencyType = SavingsInterestCalculationDaysInYearType.INVALID;
if (type != null) {
@@ -5,6 +5,9 @@
*/
package org.mifosplatform.portfolio.savings;
import java.util.ArrayList;
import java.util.List;
/**
* <ul>
* There are two methods to calculate the interest on a savings account:
@@ -49,6 +52,17 @@ public enum SavingsInterestCalculationType {
return code;
}
public static Object[] integerValues() {
List<Integer> values = new ArrayList<Integer>();
for (SavingsInterestCalculationType enumType : values()) {
if (enumType.getValue() > 0) {
values.add(enumType.getValue());
}
}
return values.toArray();
}
public static SavingsInterestCalculationType fromInt(final Integer type) {
SavingsInterestCalculationType repaymentFrequencyType = SavingsInterestCalculationType.INVALID;
if (type != null) {
@@ -5,6 +5,9 @@
*/
package org.mifosplatform.portfolio.savings;
import java.util.ArrayList;
import java.util.List;
/**
* The interest posting period is the span of time at the end of which savings
* earned but not yet credited/posted in a client's account is credited/posted.
@@ -32,6 +35,17 @@ public enum SavingsPostingInterestPeriodType {
return code;
}
public static Object[] integerValues() {
List<Integer> values = new ArrayList<Integer>();
for (SavingsPostingInterestPeriodType enumType : values()) {
if (enumType.getValue() > 0) {
values.add(enumType.getValue());
}
}
return values.toArray();
}
public static SavingsPostingInterestPeriodType fromInt(final Integer type) {
SavingsPostingInterestPeriodType repaymentFrequencyType = SavingsPostingInterestPeriodType.INVALID;
if (type != null) {
@@ -5,6 +5,9 @@
*/
package org.mifosplatform.portfolio.savings;
import java.util.ArrayList;
import java.util.List;
public enum SavingsWithdrawalFeesType {
INVALID(0, "savingsWithdrawalFeesType.invalid"), //
@@ -27,6 +30,17 @@ public enum SavingsWithdrawalFeesType {
return code;
}
public static Object[] integerValues() {
List<Integer> values = new ArrayList<Integer>();
for (SavingsWithdrawalFeesType enumType : values()) {
if (enumType.getValue() > 0) {
values.add(enumType.getValue());
}
}
return values.toArray();
}
public static SavingsWithdrawalFeesType fromInt(final Integer type) {
SavingsWithdrawalFeesType withdrawalFeeType = SavingsWithdrawalFeesType.INVALID;
@@ -10,6 +10,7 @@ import static org.mifosplatform.portfolio.savings.SavingsApiConstants.annualFeeA
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.annualFeeOnMonthDayParamName;
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.clientIdParamName;
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.externalIdParamName;
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.fieldOfficerIdParamName;
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.groupIdParamName;
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.interestCalculationDaysInYearTypeParamName;
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.interestCalculationTypeParamName;
@@ -39,6 +40,11 @@ import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
import org.mifosplatform.portfolio.savings.SavingsApiConstants;
import org.mifosplatform.portfolio.savings.SavingsCompoundingInterestPeriodType;
import org.mifosplatform.portfolio.savings.SavingsInterestCalculationDaysInYearType;
import org.mifosplatform.portfolio.savings.SavingsInterestCalculationType;
import org.mifosplatform.portfolio.savings.SavingsPostingInterestPeriodType;
import org.mifosplatform.portfolio.savings.SavingsWithdrawalFeesType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -84,6 +90,11 @@ public class SavingsAccountDataValidator {
final Long productId = fromApiJsonHelper.extractLongNamed(productIdParamName, element);
baseDataValidator.reset().parameter(productIdParamName).value(productId).notNull().integerGreaterThanZero();
if (fromApiJsonHelper.parameterExists(fieldOfficerIdParamName, element)) {
final Long fieldOfficerId = fromApiJsonHelper.extractLongNamed(fieldOfficerIdParamName, element);
baseDataValidator.reset().parameter(fieldOfficerIdParamName).value(fieldOfficerId).notNull().integerGreaterThanZero();
}
final LocalDate submittedOnDate = fromApiJsonHelper.extractLocalDateNamed(submittedOnDateParamName, element);
baseDataValidator.reset().parameter(submittedOnDateParamName).value(submittedOnDate).notNull();
@@ -106,28 +117,28 @@ public class SavingsAccountDataValidator {
final Integer interestCompoundingPeriodType = fromApiJsonHelper.extractIntegerSansLocaleNamed(
interestCompoundingPeriodTypeParamName, element);
baseDataValidator.reset().parameter(interestCompoundingPeriodTypeParamName).value(interestCompoundingPeriodType).notNull()
.isOneOfTheseValues(new Object[] { 1, 2, 3, 4, 5, 6, 7, 8 });
.isOneOfTheseValues(SavingsCompoundingInterestPeriodType.integerValues());
}
if (fromApiJsonHelper.parameterExists(interestPostingPeriodTypeParamName, element)) {
final Integer interestPostingPeriodType = fromApiJsonHelper.extractIntegerSansLocaleNamed(interestPostingPeriodTypeParamName,
element);
baseDataValidator.reset().parameter(interestPostingPeriodTypeParamName).value(interestPostingPeriodType).notNull()
.isOneOfTheseValues(new Object[] { 4, 5, 6, 7 });
.isOneOfTheseValues(SavingsPostingInterestPeriodType.integerValues());
}
if (fromApiJsonHelper.parameterExists(interestCalculationTypeParamName, element)) {
final Integer interestCalculationType = fromApiJsonHelper.extractIntegerSansLocaleNamed(interestCalculationTypeParamName,
element);
baseDataValidator.reset().parameter(interestCalculationTypeParamName).value(interestCalculationType).notNull()
.isOneOfTheseValues(new Object[] { 1, 2 });
.isOneOfTheseValues(SavingsInterestCalculationType.integerValues());
}
if (fromApiJsonHelper.parameterExists(interestCalculationDaysInYearTypeParamName, element)) {
final Integer interestCalculationDaysInYearType = fromApiJsonHelper.extractIntegerSansLocaleNamed(
interestCalculationDaysInYearTypeParamName, element);
baseDataValidator.reset().parameter(interestCalculationDaysInYearTypeParamName).value(interestCalculationDaysInYearType)
.notNull().isOneOfTheseValues(360, 365);
.notNull().isOneOfTheseValues(SavingsInterestCalculationDaysInYearType.integerValues());
}
if (this.fromApiJsonHelper.parameterExists(minRequiredOpeningBalanceParamName, element)) {
@@ -170,7 +181,8 @@ public class SavingsAccountDataValidator {
if (withdrawalFeeAmount != null) {
final Integer withdrawalFeeType = fromApiJsonHelper.extractIntegerSansLocaleNamed(withdrawalFeeTypeParamName, element);
baseDataValidator.reset().parameter(withdrawalFeeTypeParamName).value(withdrawalFeeType).isOneOfTheseValues(1, 2);
baseDataValidator.reset().parameter(withdrawalFeeTypeParamName).value(withdrawalFeeType)
.isOneOfTheseValues(SavingsWithdrawalFeesType.integerValues());
}
}
@@ -262,6 +274,11 @@ public class SavingsAccountDataValidator {
baseDataValidator.reset().parameter(productIdParamName).value(productId).notNull().integerGreaterThanZero();
}
if (fromApiJsonHelper.parameterExists(fieldOfficerIdParamName, element)) {
final Long fieldOfficerId = fromApiJsonHelper.extractLongNamed(fieldOfficerIdParamName, element);
baseDataValidator.reset().parameter(fieldOfficerIdParamName).value(fieldOfficerId).notNull().integerGreaterThanZero();
}
if (fromApiJsonHelper.parameterExists(submittedOnDateParamName, element)) {
final LocalDate submittedOnDate = fromApiJsonHelper.extractLocalDateNamed(submittedOnDateParamName, element);
baseDataValidator.reset().parameter(submittedOnDateParamName).value(submittedOnDate).notNull();
@@ -286,28 +303,28 @@ public class SavingsAccountDataValidator {
final Integer interestCompoundingPeriodType = fromApiJsonHelper.extractIntegerSansLocaleNamed(
interestCompoundingPeriodTypeParamName, element);
baseDataValidator.reset().parameter(interestCompoundingPeriodTypeParamName).value(interestCompoundingPeriodType).notNull()
.isOneOfTheseValues(new Object[] { 1, 2, 3, 4, 5, 6, 7, 8 });
.isOneOfTheseValues(SavingsCompoundingInterestPeriodType.integerValues());
}
if (this.fromApiJsonHelper.parameterExists(interestPostingPeriodTypeParamName, element)) {
final Integer interestPostingPeriodType = fromApiJsonHelper.extractIntegerSansLocaleNamed(interestPostingPeriodTypeParamName,
element);
baseDataValidator.reset().parameter(interestPostingPeriodTypeParamName).value(interestPostingPeriodType).notNull()
.isOneOfTheseValues(new Object[] { 4, 5, 6, 7 });
.isOneOfTheseValues(SavingsPostingInterestPeriodType.integerValues());
}
if (this.fromApiJsonHelper.parameterExists(interestCalculationTypeParamName, element)) {
final Integer interestCalculationType = fromApiJsonHelper.extractIntegerSansLocaleNamed(interestCalculationTypeParamName,
element);
baseDataValidator.reset().parameter(interestCalculationTypeParamName).value(interestCalculationType).notNull()
.isOneOfTheseValues(new Object[] { 1, 2 });
.isOneOfTheseValues(SavingsInterestCalculationType.integerValues());
}
if (this.fromApiJsonHelper.parameterExists(interestCalculationDaysInYearTypeParamName, element)) {
final Integer interestCalculationDaysInYearType = fromApiJsonHelper.extractIntegerSansLocaleNamed(
interestCalculationDaysInYearTypeParamName, element);
baseDataValidator.reset().parameter(interestCalculationDaysInYearTypeParamName).value(interestCalculationDaysInYearType)
.notNull().isOneOfTheseValues(360, 365);
.notNull().isOneOfTheseValues(SavingsInterestCalculationDaysInYearType.integerValues());
}
if (this.fromApiJsonHelper.parameterExists(minRequiredOpeningBalanceParamName, element)) {
@@ -339,7 +356,7 @@ public class SavingsAccountDataValidator {
if (this.fromApiJsonHelper.parameterExists(withdrawalFeeTypeParamName, element)) {
final Integer withdrawalFeeType = fromApiJsonHelper.extractIntegerSansLocaleNamed(withdrawalFeeTypeParamName, element);
baseDataValidator.reset().parameter(withdrawalFeeTypeParamName).value(withdrawalFeeType).ignoreIfNull()
.isOneOfTheseValues(1, 2);
.isOneOfTheseValues(SavingsWithdrawalFeesType.integerValues());
}
if (this.fromApiJsonHelper.parameterExists(annualFeeAmountParamName, element)) {
@@ -41,6 +41,10 @@ import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
import org.mifosplatform.portfolio.savings.SavingsCompoundingInterestPeriodType;
import org.mifosplatform.portfolio.savings.SavingsInterestCalculationDaysInYearType;
import org.mifosplatform.portfolio.savings.SavingsInterestCalculationType;
import org.mifosplatform.portfolio.savings.SavingsPostingInterestPeriodType;
import org.mifosplatform.portfolio.savings.SavingsWithdrawalFeesType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -96,16 +100,16 @@ public class SavingsProductDataValidator {
final Integer interestPostingPeriodType = fromApiJsonHelper.extractIntegerSansLocaleNamed(interestPostingPeriodTypeParamName,
element);
baseDataValidator.reset().parameter(interestPostingPeriodTypeParamName).value(interestPostingPeriodType).notNull()
.isOneOfTheseValues(new Object[] { 4, 5, 6, 7 });
.isOneOfTheseValues(SavingsPostingInterestPeriodType.integerValues());
final Integer interestCalculationType = fromApiJsonHelper.extractIntegerSansLocaleNamed(interestCalculationTypeParamName, element);
baseDataValidator.reset().parameter(interestCalculationTypeParamName).value(interestCalculationType).notNull()
.isOneOfTheseValues(new Object[] { 1, 2 });
.isOneOfTheseValues(SavingsInterestCalculationType.integerValues());
final Integer interestCalculationDaysInYearType = fromApiJsonHelper.extractIntegerSansLocaleNamed(
interestCalculationDaysInYearTypeParamName, element);
baseDataValidator.reset().parameter(interestCalculationDaysInYearTypeParamName).value(interestCalculationDaysInYearType).notNull()
.isOneOfTheseValues(360, 365);
.isOneOfTheseValues(SavingsInterestCalculationDaysInYearType.integerValues());
if (this.fromApiJsonHelper.parameterExists(minRequiredOpeningBalanceParamName, element)) {
final BigDecimal minOpeningBalance = fromApiJsonHelper.extractBigDecimalWithLocaleNamed(minRequiredOpeningBalanceParamName,
@@ -147,7 +151,8 @@ public class SavingsProductDataValidator {
if (withdrawalFeeAmount != null) {
final Integer withdrawalFeeType = fromApiJsonHelper.extractIntegerSansLocaleNamed(withdrawalFeeTypeParamName, element);
baseDataValidator.reset().parameter(withdrawalFeeTypeParamName).value(withdrawalFeeType).isOneOfTheseValues(1, 2);
baseDataValidator.reset().parameter(withdrawalFeeTypeParamName).value(withdrawalFeeType)
.isOneOfTheseValues(SavingsWithdrawalFeesType.integerValues());
}
}