added check for blank feilds

This commit is contained in:
Pramod Nuthakki
2013-11-25 11:28:33 +05:30
parent a7632d4fae
commit f8da9b4072
@@ -227,22 +227,28 @@ public class LoanProduct extends AbstractPersistable<Long> {
BigDecimal maxValue = null; BigDecimal maxValue = null;
Integer cycleNumber = null; Integer cycleNumber = null;
Integer valueUsageCondition = null; Integer valueUsageCondition = null;
if (jsonObject.has(LoanProductConstants.defaultValueParameterName) && jsonObject.get(LoanProductConstants.defaultValueParameterName).isJsonPrimitive()) { if (jsonObject.has(LoanProductConstants.defaultValueParameterName)
&& jsonObject.get(LoanProductConstants.defaultValueParameterName).isJsonPrimitive()) {
defaultValue = jsonObject.getAsJsonPrimitive(LoanProductConstants.defaultValueParameterName).getAsBigDecimal(); defaultValue = jsonObject.getAsJsonPrimitive(LoanProductConstants.defaultValueParameterName).getAsBigDecimal();
} }
if (jsonObject.has(LoanProductConstants.minValueParameterName) && jsonObject.get(LoanProductConstants.minValueParameterName).isJsonPrimitive()) { if (jsonObject.has(LoanProductConstants.minValueParameterName)
&& jsonObject.get(LoanProductConstants.minValueParameterName).isJsonPrimitive()) {
minValue = jsonObject.getAsJsonPrimitive(LoanProductConstants.minValueParameterName).getAsBigDecimal(); minValue = jsonObject.getAsJsonPrimitive(LoanProductConstants.minValueParameterName).getAsBigDecimal();
} }
if (jsonObject.has(LoanProductConstants.maxValueParameterName) && jsonObject.get(LoanProductConstants.maxValueParameterName).isJsonPrimitive()) { if (jsonObject.has(LoanProductConstants.maxValueParameterName)
&& jsonObject.get(LoanProductConstants.maxValueParameterName).isJsonPrimitive()) {
maxValue = jsonObject.getAsJsonPrimitive(LoanProductConstants.maxValueParameterName).getAsBigDecimal(); maxValue = jsonObject.getAsJsonPrimitive(LoanProductConstants.maxValueParameterName).getAsBigDecimal();
} }
if (jsonObject.has(LoanProductConstants.borrowerCycleNumberParamName) && jsonObject.get(LoanProductConstants.borrowerCycleNumberParamName).isJsonPrimitive()) { if (jsonObject.has(LoanProductConstants.borrowerCycleNumberParamName)
&& jsonObject.get(LoanProductConstants.borrowerCycleNumberParamName).isJsonPrimitive()) {
cycleNumber = jsonObject.getAsJsonPrimitive(LoanProductConstants.borrowerCycleNumberParamName).getAsInt(); cycleNumber = jsonObject.getAsJsonPrimitive(LoanProductConstants.borrowerCycleNumberParamName).getAsInt();
} }
if (jsonObject.has(LoanProductConstants.valueConditionTypeParamName) && jsonObject.get(LoanProductConstants.valueConditionTypeParamName).isJsonPrimitive()) { if (jsonObject.has(LoanProductConstants.valueConditionTypeParamName)
&& jsonObject.get(LoanProductConstants.valueConditionTypeParamName).isJsonPrimitive()) {
valueUsageCondition = jsonObject.getAsJsonPrimitive(LoanProductConstants.valueConditionTypeParamName).getAsInt(); valueUsageCondition = jsonObject.getAsJsonPrimitive(LoanProductConstants.valueConditionTypeParamName).getAsInt();
} }
LoanProductBorrowerCycleVariations borrowerCycleVariations= new LoanProductBorrowerCycleVariations(cycleNumber, paramType, valueUsageCondition, minValue, maxValue, defaultValue); LoanProductBorrowerCycleVariations borrowerCycleVariations = new LoanProductBorrowerCycleVariations(cycleNumber,
paramType, valueUsageCondition, minValue, maxValue, defaultValue);
loanProductBorrowerCycleVariations.add(borrowerCycleVariations); loanProductBorrowerCycleVariations.add(borrowerCycleVariations);
i++; i++;
} while (i < variationArray.size()); } while (i < variationArray.size());
@@ -253,14 +259,18 @@ public class LoanProduct extends AbstractPersistable<Long> {
private Map<String, Object> updateBorrowerCycleVariations(final JsonCommand command) { private Map<String, Object> updateBorrowerCycleVariations(final JsonCommand command) {
final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(20); final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(20);
List<Long> variationIds = fetchAllVariationIds(); List<Long> variationIds = fetchAllVariationIds();
updateBorrowerCycleVaritions(command, LoanProductParamType.PRINCIPAL.getValue(), LoanProductConstants.principalVariationsForBorrowerCycleParameterName, actualChanges, variationIds); updateBorrowerCycleVaritions(command, LoanProductParamType.PRINCIPAL.getValue(),
updateBorrowerCycleVaritions(command, LoanProductParamType.INTERESTRATE.getValue(), LoanProductConstants.interestRateVariationsForBorrowerCycleParameterName, actualChanges, variationIds); LoanProductConstants.principalVariationsForBorrowerCycleParameterName, actualChanges, variationIds);
updateBorrowerCycleVaritions(command, LoanProductParamType.REPAYMENT.getValue(), LoanProductConstants.numberOfRepaymentVariationsForBorrowerCycleParameterName, actualChanges, variationIds); updateBorrowerCycleVaritions(command, LoanProductParamType.INTERESTRATE.getValue(),
LoanProductConstants.interestRateVariationsForBorrowerCycleParameterName, actualChanges, variationIds);
updateBorrowerCycleVaritions(command, LoanProductParamType.REPAYMENT.getValue(),
LoanProductConstants.numberOfRepaymentVariationsForBorrowerCycleParameterName, actualChanges, variationIds);
for (Long id : variationIds) { for (Long id : variationIds) {
this.borrowerCycleVariations.remove(fetchLoanProductBorrowerCycleVariationById(id)); this.borrowerCycleVariations.remove(fetchLoanProductBorrowerCycleVariationById(id));
} }
return actualChanges; return actualChanges;
} }
private List<Long> fetchAllVariationIds() { private List<Long> fetchAllVariationIds() {
List<Long> list = new ArrayList<Long>(); List<Long> list = new ArrayList<Long>();
for (LoanProductBorrowerCycleVariations cycleVariation : this.borrowerCycleVariations) { for (LoanProductBorrowerCycleVariations cycleVariation : this.borrowerCycleVariations) {
@@ -269,8 +279,8 @@ public class LoanProduct extends AbstractPersistable<Long> {
return list; return list;
} }
private void updateBorrowerCycleVaritions(final JsonCommand command,Integer paramType, private void updateBorrowerCycleVaritions(final JsonCommand command, Integer paramType, String variationParameterName,
String variationParameterName,final Map<String, Object> actualChanges, List<Long> variationIds){ final Map<String, Object> actualChanges, List<Long> variationIds) {
if (command.parameterExists(variationParameterName)) { if (command.parameterExists(variationParameterName)) {
final JsonArray variationArray = command.arrayOfParameterNamed(variationParameterName); final JsonArray variationArray = command.arrayOfParameterNamed(variationParameterName);
if (variationArray != null && variationArray.size() > 0) { if (variationArray != null && variationArray.size() > 0) {
@@ -283,25 +293,35 @@ public class LoanProduct extends AbstractPersistable<Long> {
Integer cycleNumber = null; Integer cycleNumber = null;
Integer valueUsageCondition = null; Integer valueUsageCondition = null;
Long id = null; Long id = null;
if (jsonObject.has(LoanProductConstants.defaultValueParameterName) && jsonObject.get(LoanProductConstants.defaultValueParameterName).isJsonPrimitive()) { if (jsonObject.has(LoanProductConstants.defaultValueParameterName)
&& jsonObject.get(LoanProductConstants.defaultValueParameterName).isJsonPrimitive()) {
defaultValue = jsonObject.getAsJsonPrimitive(LoanProductConstants.defaultValueParameterName).getAsBigDecimal(); defaultValue = jsonObject.getAsJsonPrimitive(LoanProductConstants.defaultValueParameterName).getAsBigDecimal();
} }
if (jsonObject.has(LoanProductConstants.minValueParameterName) && jsonObject.get(LoanProductConstants.minValueParameterName).isJsonPrimitive()) { if (jsonObject.has(LoanProductConstants.minValueParameterName)
&& jsonObject.get(LoanProductConstants.minValueParameterName).isJsonPrimitive()
&& StringUtils.isNotBlank((jsonObject.get(LoanProductConstants.minValueParameterName).getAsString()))) {
minValue = jsonObject.getAsJsonPrimitive(LoanProductConstants.minValueParameterName).getAsBigDecimal(); minValue = jsonObject.getAsJsonPrimitive(LoanProductConstants.minValueParameterName).getAsBigDecimal();
} }
if (jsonObject.has(LoanProductConstants.maxValueParameterName) && jsonObject.get(LoanProductConstants.maxValueParameterName).isJsonPrimitive()) { if (jsonObject.has(LoanProductConstants.maxValueParameterName)
&& jsonObject.get(LoanProductConstants.maxValueParameterName).isJsonPrimitive()
&& StringUtils.isNotBlank((jsonObject.get(LoanProductConstants.maxValueParameterName).getAsString()))) {
maxValue = jsonObject.getAsJsonPrimitive(LoanProductConstants.maxValueParameterName).getAsBigDecimal(); maxValue = jsonObject.getAsJsonPrimitive(LoanProductConstants.maxValueParameterName).getAsBigDecimal();
} }
if (jsonObject.has(LoanProductConstants.borrowerCycleNumberParamName) && jsonObject.get(LoanProductConstants.borrowerCycleNumberParamName).isJsonPrimitive()) { if (jsonObject.has(LoanProductConstants.borrowerCycleNumberParamName)
&& jsonObject.get(LoanProductConstants.borrowerCycleNumberParamName).isJsonPrimitive()) {
cycleNumber = jsonObject.getAsJsonPrimitive(LoanProductConstants.borrowerCycleNumberParamName).getAsInt(); cycleNumber = jsonObject.getAsJsonPrimitive(LoanProductConstants.borrowerCycleNumberParamName).getAsInt();
} }
if (jsonObject.has(LoanProductConstants.valueConditionTypeParamName) && jsonObject.get(LoanProductConstants.valueConditionTypeParamName).isJsonPrimitive()) { if (jsonObject.has(LoanProductConstants.valueConditionTypeParamName)
&& jsonObject.get(LoanProductConstants.valueConditionTypeParamName).isJsonPrimitive()) {
valueUsageCondition = jsonObject.getAsJsonPrimitive(LoanProductConstants.valueConditionTypeParamName).getAsInt(); valueUsageCondition = jsonObject.getAsJsonPrimitive(LoanProductConstants.valueConditionTypeParamName).getAsInt();
} }
if (jsonObject.has(LoanProductConstants.borrowerCycleIdParameterName) && jsonObject.get(LoanProductConstants.borrowerCycleIdParameterName).isJsonPrimitive()) { if (jsonObject.has(LoanProductConstants.borrowerCycleIdParameterName)
&& jsonObject.get(LoanProductConstants.borrowerCycleIdParameterName).isJsonPrimitive()
&& StringUtils.isNotBlank((jsonObject.get(LoanProductConstants.borrowerCycleIdParameterName).getAsString()))) {
id = jsonObject.getAsJsonPrimitive(LoanProductConstants.borrowerCycleIdParameterName).getAsLong(); id = jsonObject.getAsJsonPrimitive(LoanProductConstants.borrowerCycleIdParameterName).getAsLong();
} }
LoanProductBorrowerCycleVariations borrowerCycleVariations= new LoanProductBorrowerCycleVariations(cycleNumber, paramType, valueUsageCondition, minValue, maxValue, defaultValue); LoanProductBorrowerCycleVariations borrowerCycleVariations = new LoanProductBorrowerCycleVariations(cycleNumber,
paramType, valueUsageCondition, minValue, maxValue, defaultValue);
if (id == null) { if (id == null) {
borrowerCycleVariations.updateLoanProduct(this); borrowerCycleVariations.updateLoanProduct(this);
this.borrowerCycleVariations.add(borrowerCycleVariations); this.borrowerCycleVariations.add(borrowerCycleVariations);
@@ -320,7 +340,6 @@ public class LoanProduct extends AbstractPersistable<Long> {
} }
} }
private void clearVariations(LoanProductParamType paramType, boolean clearAll) { private void clearVariations(LoanProductParamType paramType, boolean clearAll) {
if (clearAll) { if (clearAll) {
this.borrowerCycleVariations.clear(); this.borrowerCycleVariations.clear();