From 63a1f6cd6359a66a0f76e4681ab3511cfe77b86c Mon Sep 17 00:00:00 2001 From: Keith Woodlock Date: Fri, 25 May 2012 14:04:16 +0100 Subject: [PATCH] tidy up ui for loanproducts and offices after json changes. --- .../command/OrganisationCurrencyCommand.java | 24 +-- .../global-translations/messages.properties | 4 +- .../messages_fr.properties | 2 +- .../webapp/WEB-INF/views/admin/orghome.jsp | 41 ++-- .../views/administration-view-templates.jsp | 12 +- .../platform/DataValidatorBuilder.java | 7 + ...WritePlatformServiceJpaRepositoryImpl.java | 39 ++-- .../service/LoanProductCommandValidator.java | 196 +----------------- 8 files changed, 74 insertions(+), 251 deletions(-) diff --git a/mifosng-data/src/main/java/org/mifosng/data/command/OrganisationCurrencyCommand.java b/mifosng-data/src/main/java/org/mifosng/data/command/OrganisationCurrencyCommand.java index 87823d3c2..a328416b0 100644 --- a/mifosng-data/src/main/java/org/mifosng/data/command/OrganisationCurrencyCommand.java +++ b/mifosng-data/src/main/java/org/mifosng/data/command/OrganisationCurrencyCommand.java @@ -1,8 +1,6 @@ package org.mifosng.data.command; import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collection; import java.util.List; import javax.xml.bind.annotation.XmlRootElement; @@ -10,30 +8,30 @@ import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class OrganisationCurrencyCommand implements Serializable { - private Collection notSelectedItems = new ArrayList(); - private Collection selectedItems = new ArrayList(); + private String[] notSelectedCurrencies; + private String[] currencies; public OrganisationCurrencyCommand() { // } public OrganisationCurrencyCommand(final List selectedCurrencyCodes) { - this.selectedItems = selectedCurrencyCodes; + this.currencies = selectedCurrencyCodes.toArray(new String[selectedCurrencyCodes.size()]); } - public Collection getSelectedItems() { - return selectedItems; + public String[] getNotSelectedCurrencies() { + return notSelectedCurrencies; } - public void setSelectedItems(Collection selectedItems) { - this.selectedItems = selectedItems; + public void setNotSelectedCurrencies(String... notSelectedCurrencies) { + this.notSelectedCurrencies = notSelectedCurrencies; } - public Collection getNotSelectedItems() { - return notSelectedItems; + public String[] getCurrencies() { + return currencies; } - public void setNotSelectedItems(Collection notSelectedItems) { - this.notSelectedItems = notSelectedItems; + public void setCurrencies(String... currencies) { + this.currencies = currencies; } } \ No newline at end of file diff --git a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/global-translations/messages.properties b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/global-translations/messages.properties index 2b163fabf..c75f3f156 100644 --- a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/global-translations/messages.properties +++ b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/global-translations/messages.properties @@ -16,7 +16,7 @@ label.client.search=Choose client: option.client.search.first.choice=--Select Client-- link.add.new.client=Add a new client -page.client.account.title=View Client Account Details +page.client.account.title=View Client Account Detailscon page.admin.home.title=Administration Home page.admin.settings.title=Account Settings @@ -281,7 +281,7 @@ dialog.title.configuration.currencies=Currency Configuration form.label.configuration.available.currencies=Available currencies: form.label.configuration.allowed.currencies=Allowed currencies: -validation.msg.organisation.allowed.currencies.cannot.be.blank=You must select at least one currency that is 'allowed' for your organisation. +validation.msg.configuration.currencies.cannot.be.empty=You must select at least one currency that is 'allowed' for your organisation. # user account settings and admin screens tab.settings=Settings diff --git a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/global-translations/messages_fr.properties b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/global-translations/messages_fr.properties index a158c1fe2..70f3bd6ad 100644 --- a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/global-translations/messages_fr.properties +++ b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/static/global-translations/messages_fr.properties @@ -279,7 +279,7 @@ validation.msg.office.externalId.exceeds.max.length=External id exceeds max leng form.label.configuration.available.currencies=Available currencies:(fr) form.label.configuration.allowed.currencies=Allowed currencies:(fr) -validation.msg.organisation.allowed.currencies.cannot.be.blank=You must select at least one currency that is 'allowed' for your organisation.(fr) +validation.msg.configuration.currencies.cannot.be.empty=You must select at least one currency that is 'allowed' for your organisation.(fr) # user account settings and admin screens tab.settings=Settings(fr) diff --git a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/admin/orghome.jsp b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/admin/orghome.jsp index b2069dd47..47a7c6050 100644 --- a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/admin/orghome.jsp +++ b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/admin/orghome.jsp @@ -58,7 +58,23 @@ return false; } }, - globalDate: function(localDateAsISOString) { + globalDate: function(dateParts) { + try { + + var year = dateParts[0]; + var month = parseInt(dateParts[1]) - 1; // month is zero indexed + var day = dateParts[2]; + + var d = new Date(); + d.setFullYear(year,month,day); + + return Globalize.format(d,"dd MMMM yyyy"); + } catch(e) { + return "??"; + } + }, + globalDateAsISOString: function(localDateAsISOString) { + try { var dateParts = localDateAsISOString.split("-") var year = dateParts[0]; @@ -193,7 +209,7 @@ o[this.name].push(this.value || ''); } else { - if (this.name === 'selectedItems' || this.name === 'notSelectedItems') { + if (this.name === 'currencies' || this.name === 'notSelectedCurrencies') { o[this.name] = new Array(); o[this.name].push(this.value || ''); } else { @@ -228,11 +244,11 @@ var buttonsOpts = {}; buttonsOpts[saveButton] = function() { - $('#notSelectedItems option').each(function(i) { + $('#notSelectedCurrencies option').each(function(i) { $(this).attr("selected", "selected"); }); - $('#selectedItems option').each(function(i) { + $('#currencies option').each(function(i) { $(this).attr("selected", "selected"); }); @@ -272,11 +288,11 @@ open: function (event, ui) { $('#add').click(function() { - return !$('#notSelectedItems option:selected').remove().appendTo('#selectedItems'); + return !$('#notSelectedCurrencies option:selected').remove().appendTo('#currencies'); }); $('#remove').click(function() { - return !$('#selectedItems option:selected').remove().appendTo('#notSelectedItems'); + return !$('#currencies option:selected').remove().appendTo('#notSelectedCurrencies'); }); $('.datepickerfield').datepicker({constrainInput: true, maxDate: 0, dateFormat: 'dd MM yy'}); @@ -322,13 +338,12 @@ dataType: 'json', cache: false, beforeSend: function(xhr) { - console.log("base64: " + base64); xhr.setRequestHeader("Authorization", "Basic " + base64); }, success: function(data, textStatus, jqXHR) { var productlistParent = new Object(); - productlistParent.items = data.products; + productlistParent.products = data; var productListHtml = $("#productListTemplate").render(productlistParent); $("#listplaceholder").html(productListHtml); @@ -336,7 +351,7 @@ $("a.editproduct").click( function(e) { var linkId = this.id; var productId = linkId.replace("editproduct", ""); - var getUrl = baseApiUrl + 'loanproducts/' + productId; + var getUrl = baseApiUrl + 'loanproducts/' + productId + '?template=true'; var putUrl = baseApiUrl + 'loanproducts/' + productId; var templateSelector = "#productFormTemplate"; @@ -423,12 +438,8 @@ }, success: function(data, textStatus, jqXHR) { - $.each(data.offices, function(i, item) { - //alert(item.name); - }); - console.log(data); var officelistParent = new Object(); - officelistParent.items = data.offices; + officelistParent.offices = data; var officeListHtml = $("#officeListTemplate").render(officelistParent); $("#listplaceholder").html(officeListHtml); @@ -436,7 +447,7 @@ $("a.edit").click( function(e) { var linkId = this.id; var entityId = linkId.replace("edit", ""); - var getUrl = baseApiUrl + 'offices/' + entityId; + var getUrl = baseApiUrl + 'offices/' + entityId + '?template=true'; var putUrl = baseApiUrl + 'offices/' + entityId; var templateSelector = "#officeFormTemplate"; diff --git a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/administration-view-templates.jsp b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/administration-view-templates.jsp index 3e9c3f344..f409dbbb8 100644 --- a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/administration-view-templates.jsp +++ b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/administration-view-templates.jsp @@ -170,7 +170,7 @@ -{{#each items}} +{{#each products}} {{=name}} {{=$ctx.globalDateTime(createdOn)}} @@ -201,7 +201,7 @@ -{{#each items}} +{{#each offices}} {{=name}} {{=externalId}} @@ -261,8 +261,8 @@
- - {{#each currencyOptions}} {{#if $ctx.number($parent.parent.data.code)===code}} @@ -275,8 +275,8 @@
- - {{#each selectedCurrencyOptions}} {{#if $ctx.number($parent.parent.data.code)===code}} diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/DataValidatorBuilder.java b/mifosng-provider/src/main/java/org/mifosng/platform/DataValidatorBuilder.java index 81f7981f8..e33fd7953 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/DataValidatorBuilder.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/DataValidatorBuilder.java @@ -160,4 +160,11 @@ public class DataValidatorBuilder { } return this; } + + public void inValidValue(String parameterValueCode, Object invalidValue) { + StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(resource).append(".").append(parameter).append(".invalid.").append(parameterValueCode); + StringBuilder defaultEnglishMessage = new StringBuilder("The parameter ").append(parameter).append(" has an invalid value."); + ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), parameter, invalidValue); + dataValidationErrors.add(error); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/configuration/service/ConfigurationWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/configuration/service/ConfigurationWritePlatformServiceJpaRepositoryImpl.java index 177fa318c..622e86fa4 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/configuration/service/ConfigurationWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/configuration/service/ConfigurationWritePlatformServiceJpaRepositoryImpl.java @@ -7,6 +7,7 @@ import java.util.Set; import org.mifosng.data.ApiParameterError; import org.mifosng.data.command.OrganisationCurrencyCommand; +import org.mifosng.platform.DataValidatorBuilder; import org.mifosng.platform.currency.domain.ApplicationCurrency; import org.mifosng.platform.currency.domain.ApplicationCurrencyRepository; import org.mifosng.platform.exceptions.PlatformApiDataValidationException; @@ -40,33 +41,33 @@ public class ConfigurationWritePlatformServiceJpaRepositoryImpl implements Confi AppUser currentUser = context.authenticatedUser(); - if (command.getSelectedItems().isEmpty()) { - - List dataValidationErrors = new ArrayList(); - ApiParameterError error = ApiParameterError.parameterError("validation.msg.organisation.allowed.currencies.cannot.be.blank", "The parameter selectedItems is invalid.", "selectedItems"); - dataValidationErrors.add(error); - + List dataValidationErrors = new ArrayList(); + DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("configuration"); + + baseDataValidator.reset().parameter("currencies").value(command.getCurrencies()).arrayNotEmpty(); + + if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); } - + Set allowedCurrencies = new HashSet(); - for (String currencyCode : command.getSelectedItems()) { + for (String currencyCode : command.getCurrencies()) { ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(currencyCode); if (currency == null) { - List dataValidationErrors = new ArrayList(); - ApiParameterError error = ApiParameterError.parameterError("validation.msg.currency.code.invalid", "The parameter selectedItems contains an invalid currency code entry.", "selectedItems", currencyCode); - dataValidationErrors.add(error); - - throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); + baseDataValidator.reset().parameter("currencies").value(command.getCurrencies()).inValidValue("currency.code", currencyCode); + } else { + OrganisationCurrency allowedCurrency = new OrganisationCurrency( + currency.getCode(), currency.getName(), + currency.getDecimalPlaces(), currency.getNameCode(), currency.getDisplaySymbol()); + + allowedCurrencies.add(allowedCurrency); } - - OrganisationCurrency allowedCurrency = new OrganisationCurrency( - currency.getCode(), currency.getName(), - currency.getDecimalPlaces(), currency.getNameCode(), currency.getDisplaySymbol()); - - allowedCurrencies.add(allowedCurrency); + } + + if (!dataValidationErrors.isEmpty()) { + throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); } Organisation org = currentUser.getOrganisation(); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductCommandValidator.java b/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductCommandValidator.java index 83b9e7793..11e812bee 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductCommandValidator.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductCommandValidator.java @@ -82,199 +82,5 @@ public class LoanProductCommandValidator { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); } } - -// FIXME - commented out old validation for now. test that new validation is appropriate -// private void validateRemainingAttributes(LoanProductCommand command, List dataValidationErrors) { -// -// if (StringUtils.isBlank(command.getName())) { -// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.name.cannot.be.blank", "The parameter name cannot be blank.", "name"); -// dataValidationErrors.add(error); -// } -// -// if (command.getDescription() != null) { -// if (command.getDescription().length() > 500) { -// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.description.exceeds.max.length", "The parameter description cannot exceed max length of {}.", "description", 500); -// dataValidationErrors.add(error); -// } -// } -// -// if (StringUtils.isBlank(command.getCurrencyCode())) { -// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.currency.cannot.be.empty", "The parameter currencyCode cannot be blank.", "currencyCode"); -// dataValidationErrors.add(error); -// } -// -// if (command.getDigitsAfterDecimal() != null) { -// -// if (command.getDigitsAfterDecimal() < 0 || command.getDigitsAfterDecimal() > 6) { -// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.currency.digitsAfterDecimal.must.be.between.zero.and.six.inclusive", "The parameter digitsAfterDecimal must be between {0} and {1} inclusive.", "selectedDigitsAfterDecimal", 0, 6); -// dataValidationErrors.add(error); -// } -// } else { -// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.currency.digitsAfterDecimal.cannot.be.empty", "The parameter digitsAfterDecimal cannot be blank.", "selectedDigitsAfterDecimal"); -// dataValidationErrors.add(error); -// } -// -// if (command.getPrincipal() != null) { -// if (command.getPrincipal().doubleValue() <= Double.valueOf("0.0")) { -// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.principal.amount.must.be.greater.than.zero", "The parameter amount must be greater than zero.", "amount"); -// dataValidationErrors.add(error); -// } -// } else { -// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.principal.amount.cannot.be.empty", "The parameter amount cannot be blank.", "amount"); -// dataValidationErrors.add(error); -// } -// -// if (command.getRepaymentFrequency() != null) { -// PeriodFrequencyType frequencyType = PeriodFrequencyType.fromInt(command.getRepaymentFrequency()); -// ApiParameterError error = null; -// switch (frequencyType) { -// case DAYS: -// error = validateNumberExistsAndInRange("validation.msg.product.repayment.repaidEvery", "repaidEvery", command.getRepaymentEvery(), 1, 365); -// break; -// case WEEKS: -// error = validateNumberExistsAndInRange("validation.msg.product.repayment.repaidEvery", "repaidEvery", command.getRepaymentEvery(), 1, 52); -// break; -// case MONTHS: -// error = validateNumberExistsAndInRange("validation.msg.product.repayment.repaidEvery", "repaidEvery", command.getRepaymentEvery(), 1, 12); -// break; -// case YEARS: -// error = validateNumberExistsAndInRange("validation.msg.product.repayment.repaidEvery", "repaidEvery", command.getRepaymentEvery(), 1, 2); -// break; -// default: -// error = ApiParameterError.parameterError("validation.msg.product.repayment.frequency.invalid", "The parameter selectedRepaymentFrequencyOption is invalid.", "selectedRepaymentFrequencyOption"); -// break; -// } -// if (error != null) { -// dataValidationErrors.add(error); -// } -// } else { -// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.repayment.frequency.cannot.be.empty", -// "The parameter selectedRepaymentFrequencyOption cannot be blank.", "selectedRepaymentFrequencyOption"); -// dataValidationErrors.add(error); -// } -// -// if (command.getNumberOfRepayments() != null) { -// if (command.getNumberOfRepayments() < 1 || command.getNumberOfRepayments() > 100) { -// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.number.of.repayments.is.out.of.range", -// "The parameter numberOfRepayments must be between {} and {} inclusive.", "numberOfRepayments", 1, 100); -// dataValidationErrors.add(error); -// } -// } else { -// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.number.of.repayments.cannot.be.empty", -// "The parameter numberOfRepayments cannot be empty.", "numberOfRepayments"); -// dataValidationErrors.add(error); -// } -// -// if (command.getAmortizationMethod() != null) { -// AmortizationMethod amortizationMethod = AmortizationMethod.fromInt(command.getAmortizationMethod()); -// ApiParameterError error = null; -// switch (amortizationMethod) { -// case EQUAL_PRINCIPAL: -// break; -// case EQUAL_INSTALLMENTS: -// break; -// default: -// error = ApiParameterError.parameterError("validation.msg.product.amortization.method.invalid", -// "The parameter selectedAmortizationMethodOption cannot be empty.", "selectedAmortizationMethodOption"); -// break; -// } -// if (error != null) { -// dataValidationErrors.add(error); -// } -// } else { -// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.amortization.method.cannot.be.empty", -// "The parameter selectedAmortizationMethodOption cannot be empty.", "selectedAmortizationMethodOption"); -// dataValidationErrors.add(error); -// } -// -// // refactor in validation of monetary value. -// if (command.getInArrearsToleranceAmount() != null) { -// if (command.getInArrearsToleranceAmount().doubleValue() < Double.valueOf("0.0")) { -// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.arrears.tolerance.amount.cannot.be.negative", -// "The parameter inArrearsTolerance cannot be less than zero.", "inArrearsTolerance"); -// dataValidationErrors.add(error); -// } -// } else { -// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.arrears.tolerance.amount.cannot.be.empty", -// "The parameter inArrearsTolerance cannot be empty.", "inArrearsTolerance"); -// dataValidationErrors.add(error); -// } -// -// if (command.getInterestRatePerPeriod()!= null) { -// if (command.getInterestRatePerPeriod().doubleValue() < Double.valueOf("0.0")) { -// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.interest.rate.per.period.amount.cannot.be.negative", -// "The parameter nominalInterestRate cannot be less than zero.", "nominalInterestRate"); -// dataValidationErrors.add(error); -// } -// } else { -// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.interest.rate.per.period.amount.cannot.be.empty", -// "The parameter nominalInterestRate cannot be empty.", "nominalInterestRate"); -// dataValidationErrors.add(error); -// } -// -// // interest rate period type -// if (command.getInterestRateFrequencyMethod() != null) { -// PeriodFrequencyType frequencyType = PeriodFrequencyType.fromInt(command.getInterestRateFrequencyMethod()); -// ApiParameterError error = null; -// switch (frequencyType) { -// case DAYS: -// break; -// case WEEKS: -// break; -// case MONTHS: -// break; -// case YEARS: -// break; -// default: -// error = ApiParameterError.parameterError("validation.msg.product.interest.frequency.invalid", -// "The parameter selectedInterestFrequencyOption is invalid.", "selectedInterestFrequencyOption"); -// break; -// } -// if (error != null) { -// dataValidationErrors.add(error); -// } -// } else { -// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.interest.frequency.cannot.be.empty", -// "The parameter selectedInterestFrequencyOption cannot be empty.", "selectedInterestFrequencyOption"); -// dataValidationErrors.add(error); -// } -// -// if (command.getInterestMethod() != null) { -// InterestMethod interestMethod = InterestMethod.fromInt(command.getInterestMethod()); -// ApiParameterError error = null; -// switch (interestMethod) { -// case DECLINING_BALANCE: -// break; -// case FLAT: -// break; -// default: -// error = ApiParameterError.parameterError("validation.msg.product.interest.method.invalid", -// "The parameter selectedInterestMethodOption is invalid.", "selectedInterestMethodOption"); -// break; -// } -// if (error != null) { -// dataValidationErrors.add(error); -// } -// } else { -// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.interest.method.cannot.be.empty", -// "The parameter selectedInterestMethodOption cannot be empty.", "selectedInterestMethodOption"); -// dataValidationErrors.add(error); -// } -// -// if (!dataValidationErrors.isEmpty()) { -// throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); -// } -// } -// -// private ApiParameterError validateNumberExistsAndInRange(String errorCodePreFix, String fieldName, Integer value, int min, int max) { -// ApiParameterError error = null; -// if (value == null) { -// error = ApiParameterError.parameterError(errorCodePreFix + ".cannot.be.empty", "The parameter " + fieldName + " cannot be blank.", fieldName); -// } else { -// if (value < min || value > max) { -// error = ApiParameterError.parameterError(errorCodePreFix + ".outside.allowed.range", "The parameter " + fieldName + " must be between {0} and {1} inclusive.", fieldName, min, max); -// } -// } -// return error; -// } + } \ No newline at end of file