From 9d597e2add615ff098ad2083a56c8074de0012a7 Mon Sep 17 00:00:00 2001 From: Keith Woodlock Date: Thu, 31 May 2012 13:39:30 +0100 Subject: [PATCH] tidy up new loan data returned for submit loan flow and ensure locale is posted for forms with numbers and monetary values in them. --- .../ui/ApplicationPagesRoutesController.java | 13 ++ .../views/client/viewClientAccount.jsp | 4 +- .../WEB-INF/views/newloanapplication.jsp | 4 +- .../webapp/WEB-INF/views/view-templates.jsp | 5 +- .../platform/api/data/NewLoanData.java | 130 ++---------------- .../service/LoanReadPlatformServiceImpl.java | 45 ++---- 6 files changed, 46 insertions(+), 155 deletions(-) diff --git a/mifosng-individual-lending-app/src/main/java/org/mifosng/ui/ApplicationPagesRoutesController.java b/mifosng-individual-lending-app/src/main/java/org/mifosng/ui/ApplicationPagesRoutesController.java index c5d94942c..7b489975a 100644 --- a/mifosng-individual-lending-app/src/main/java/org/mifosng/ui/ApplicationPagesRoutesController.java +++ b/mifosng-individual-lending-app/src/main/java/org/mifosng/ui/ApplicationPagesRoutesController.java @@ -30,6 +30,7 @@ public class ApplicationPagesRoutesController { BasicAuthUserDetails userDetails = (BasicAuthUserDetails) authentication.getPrincipal(); model.addAttribute("basicAuthKey", userDetails.getBasicAuthenticationKey()); model.addAttribute("baseApiUrl", userDetails.getFullApiUrl()); + model.addAttribute("currentLocale", LocaleContextHolder.getLocale().toString()); return "redirect:/home"; } @@ -40,6 +41,7 @@ public class ApplicationPagesRoutesController { BasicAuthUserDetails userDetails = (BasicAuthUserDetails) authentication.getPrincipal(); model.addAttribute("basicAuthKey", userDetails.getBasicAuthenticationKey()); model.addAttribute("baseApiUrl", userDetails.getFullApiUrl()); + model.addAttribute("currentLocale", LocaleContextHolder.getLocale().toString()); return new ModelAndView("/home"); } @@ -56,6 +58,7 @@ public class ApplicationPagesRoutesController { model.addAttribute("basicAuthKey", userDetails.getBasicAuthenticationKey()); model.addAttribute("baseApiUrl", userDetails.getFullApiUrl()); model.addAttribute("clientId", clientId); + model.addAttribute("currentLocale", LocaleContextHolder.getLocale().toString()); return "client/viewClientAccount"; } @@ -75,6 +78,9 @@ public class ApplicationPagesRoutesController { BasicAuthUserDetails userDetails = (BasicAuthUserDetails) authentication.getPrincipal(); model.addAttribute("basicAuthKey", userDetails.getBasicAuthenticationKey()); model.addAttribute("baseApiUrl", userDetails.getFullApiUrl()); + + model.addAttribute("currentLocale", LocaleContextHolder.getLocale().toString()); + return "admin/userhome"; } @@ -84,6 +90,9 @@ public class ApplicationPagesRoutesController { model.addAttribute("basicAuthKey", userDetails.getBasicAuthenticationKey()); model.addAttribute("baseApiUrl", userDetails.getFullApiUrl()); model.addAttribute("userId", userDetails.getUserId()); + + model.addAttribute("currentLocale", LocaleContextHolder.getLocale().toString()); + return "admin/accountsettings"; } @@ -95,6 +104,8 @@ public class ApplicationPagesRoutesController { model.addAttribute("baseApiUrl", userDetails.getFullApiUrl()); model.addAttribute("clientId", clientId); + model.addAttribute("currentLocale", LocaleContextHolder.getLocale().toString()); + return "newloanapplication"; } @@ -105,6 +116,8 @@ public class ApplicationPagesRoutesController { model.addAttribute("basicAuthKey", userDetails.getBasicAuthenticationKey()); model.addAttribute("baseApiUrl", userDetails.getFullApiUrl()); + model.addAttribute("currentLocale", LocaleContextHolder.getLocale().toString()); + return "reports/flexireport"; } } \ No newline at end of file diff --git a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/client/viewClientAccount.jsp b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/client/viewClientAccount.jsp index 7fc4f1828..2bb2a6d45 100644 --- a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/client/viewClientAccount.jsp +++ b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/client/viewClientAccount.jsp @@ -27,7 +27,9 @@ $(document).ready(function() { // these helpers are registered for the jsViews and jsRender functionality to fix bug with display zero! $.views.registerHelpers({ - + currentLocale: function() { + return "${currentLocale}"; + }, money: function(monetaryObj) { Globalize.culture().numberFormat.currency.symbol = monetaryObj.displaySymbol; diff --git a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/newloanapplication.jsp b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/newloanapplication.jsp index 69a4584c8..4e4ce0274 100644 --- a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/newloanapplication.jsp +++ b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/newloanapplication.jsp @@ -57,7 +57,7 @@ $(document).ready(function() { }, globalDate: function(dateParts) { try { - + if (dateParts === 'undefined' || dateParts === undefined) return ""; if (dateParts === null || dateParts === '') return ""; var year = dateParts[0]; @@ -69,7 +69,7 @@ $(document).ready(function() { return Globalize.format(d,"dd MMMM yyyy"); } catch(e) { - return "??"; + return dateParts + " ??"; } }, globalDateAsISOString: function(localDateAsISOString) { diff --git a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/view-templates.jsp b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/view-templates.jsp index 36c3590d8..22e6537f9 100644 --- a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/view-templates.jsp +++ b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/view-templates.jsp @@ -57,6 +57,8 @@ + +
@@ -83,7 +85,6 @@   - @@ -826,6 +827,8 @@
+ + diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/NewLoanData.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/NewLoanData.java index f8a1ee13b..0b2f09d69 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/NewLoanData.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/NewLoanData.java @@ -4,63 +4,30 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.List; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; import org.codehaus.jackson.map.annotate.JsonFilter; import org.joda.time.LocalDate; import org.mifosng.data.LoanSchedule; -@JsonIgnoreProperties({ "organisationId", "organisationName" }) @JsonFilter("myFilter") public class NewLoanData implements Serializable { - private Long organisationId; - private String organisationName; private Long clientId; private String clientName; private Long productId; private String productName; - private List allowedProducts = new ArrayList(); - - // extra - private String dateFormat; - private String submittedOnDateFormatted; - private LocalDate submittedOnDate; - private String submittedOnNote = ""; - - private String expectedDisbursementDateFormatted; - private LocalDate expectedDisbursementDate = new LocalDate(); - - private String repaymentsStartingFromDateFormatted; - private LocalDate repaymentsStartingFromDate; - - private String interestCalculatedFromDateFormatted; - private LocalDate interestCalculatedFromDate; + private LoanProductData selectedProduct; + + private LocalDate expectedDisbursementDate; private LoanSchedule repaymentSchedule; - - private LoanProductData selectedProduct; - + + private List allowedProducts = new ArrayList(); + public NewLoanData() { // } - public Long getOrganisationId() { - return organisationId; - } - - public void setOrganisationId(Long organisationId) { - this.organisationId = organisationId; - } - - public String getOrganisationName() { - return organisationName; - } - - public void setOrganisationName(String organisationName) { - this.organisationName = organisationName; - } - public Long getClientId() { return clientId; } @@ -101,22 +68,6 @@ public class NewLoanData implements Serializable { this.allowedProducts = allowedProducts; } - public LocalDate getSubmittedOnDate() { - return submittedOnDate; - } - - public void setSubmittedOnDate(LocalDate submittedOnDate) { - this.submittedOnDate = submittedOnDate; - } - - public String getSubmittedOnNote() { - return submittedOnNote; - } - - public void setSubmittedOnNote(String submittedOnNote) { - this.submittedOnNote = submittedOnNote; - } - public LoanProductData getSelectedProduct() { return selectedProduct; } @@ -125,32 +76,6 @@ public class NewLoanData implements Serializable { this.selectedProduct = selectedProduct; } - public LocalDate getExpectedDisbursementDate() { - return expectedDisbursementDate; - } - - public void setExpectedDisbursementDate(LocalDate expectedDisbursementDate) { - this.expectedDisbursementDate = expectedDisbursementDate; - } - - public LocalDate getRepaymentsStartingFromDate() { - return repaymentsStartingFromDate; - } - - public void setRepaymentsStartingFromDate( - LocalDate repaymentsStartingFromDate) { - this.repaymentsStartingFromDate = repaymentsStartingFromDate; - } - - public LocalDate getInterestCalculatedFromDate() { - return interestCalculatedFromDate; - } - - public void setInterestCalculatedFromDate( - LocalDate interestCalculatedFromDate) { - this.interestCalculatedFromDate = interestCalculatedFromDate; - } - public LoanSchedule getRepaymentSchedule() { return repaymentSchedule; } @@ -159,46 +84,11 @@ public class NewLoanData implements Serializable { this.repaymentSchedule = repaymentSchedule; } - public String getDateFormat() { - return dateFormat; + public LocalDate getExpectedDisbursementDate() { + return expectedDisbursementDate; } - public void setDateFormat(String dateFormat) { - this.dateFormat = dateFormat; - } - - public String getSubmittedOnDateFormatted() { - return submittedOnDateFormatted; - } - - public void setSubmittedOnDateFormatted(String submittedOnDateFormatted) { - this.submittedOnDateFormatted = submittedOnDateFormatted; - } - - public String getExpectedDisbursementDateFormatted() { - return expectedDisbursementDateFormatted; - } - - public void setExpectedDisbursementDateFormatted( - String expectedDisbursementDateFormatted) { - this.expectedDisbursementDateFormatted = expectedDisbursementDateFormatted; - } - - public String getRepaymentsStartingFromDateFormatted() { - return repaymentsStartingFromDateFormatted; - } - - public void setRepaymentsStartingFromDateFormatted( - String repaymentsStartingFromDateFormatted) { - this.repaymentsStartingFromDateFormatted = repaymentsStartingFromDateFormatted; - } - - public String getInterestCalculatedFromDateFormatted() { - return interestCalculatedFromDateFormatted; - } - - public void setInterestCalculatedFromDateFormatted( - String interestCalculatedFromDateFormatted) { - this.interestCalculatedFromDateFormatted = interestCalculatedFromDateFormatted; + public void setExpectedDisbursementDate(LocalDate expectedDisbursementDate) { + this.expectedDisbursementDate = expectedDisbursementDate; } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanReadPlatformServiceImpl.java index fdbc69803..cb8dbed30 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanReadPlatformServiceImpl.java @@ -22,7 +22,6 @@ import org.mifosng.platform.currency.domain.ApplicationCurrencyRepository; import org.mifosng.platform.currency.domain.Money; import org.mifosng.platform.exceptions.CurrencyNotFoundException; import org.mifosng.platform.exceptions.LoanNotFoundException; -import org.mifosng.platform.exceptions.LoanProductNotFoundException; import org.mifosng.platform.exceptions.LoanTransactionNotFoundException; import org.mifosng.platform.loan.domain.Loan; import org.mifosng.platform.loan.domain.LoanRepository; @@ -176,60 +175,44 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { } @Override - public NewLoanData retrieveClientAndProductDetails(final Long clientId, - final Long productId) { + public NewLoanData retrieveClientAndProductDetails(final Long clientId, final Long productId) { - AppUser currentUser = context.authenticatedUser(); + context.authenticatedUser(); NewLoanData workflowData = new NewLoanData(); - workflowData.setOrganisationId(currentUser.getOrganisation().getId()); - workflowData.setOrganisationName(currentUser.getOrganisation() - .getName()); - Collection loanProducts = this.loanProductReadPlatformService - .retrieveAllLoanProductsForLookup(); - workflowData.setAllowedProducts(new ArrayList( - loanProducts)); + Collection loanProducts = this.loanProductReadPlatformService.retrieveAllLoanProductsForLookup(); + workflowData.setAllowedProducts(new ArrayList(loanProducts)); if (loanProducts.size() == 1) { - Long allowedProductId = workflowData.getAllowedProducts().get(0) - .getId(); - LoanProductData selectedProduct = this.loanProductReadPlatformService - .retrieveLoanProduct(allowedProductId); - if (selectedProduct == null) { - throw new LoanProductNotFoundException(allowedProductId); - } + Long allowedProductId = workflowData.getAllowedProducts().get(0).getId(); + LoanProductData selectedProduct = this.loanProductReadPlatformService.retrieveLoanProduct(allowedProductId); workflowData.setProductId(selectedProduct.getId()); workflowData.setProductName(selectedProduct.getName()); workflowData.setSelectedProduct(selectedProduct); } else { - LoanProductData selectedProduct = findLoanProductById(loanProducts, - productId); - if (selectedProduct == null) { - throw new LoanProductNotFoundException(productId); - } + LoanProductData selectedProduct = findLoanProductById(loanProducts, productId); + workflowData.setProductId(selectedProduct.getId()); workflowData.setProductName(selectedProduct.getName()); workflowData.setSelectedProduct(selectedProduct); } - ClientData clientAccount = this.clientReadPlatformService - .retrieveIndividualClient(clientId); + ClientData clientAccount = this.clientReadPlatformService.retrieveIndividualClient(clientId); workflowData.setClientId(clientAccount.getId()); workflowData.setClientName(clientAccount.getDisplayName()); + + workflowData.setExpectedDisbursementDate(new LocalDate()); return workflowData; } - private LoanProductData findLoanProductById( - Collection loanProducts, Long productId) { - LoanProductData match = this.loanProductReadPlatformService - .retrieveNewLoanProductDetails(); + private LoanProductData findLoanProductById(Collection loanProducts, Long productId) { + LoanProductData match = this.loanProductReadPlatformService.retrieveNewLoanProductDetails(); for (LoanProductLookup loanProductLookup : loanProducts) { if (loanProductLookup.getId().equals(productId)) { - match = this.loanProductReadPlatformService - .retrieveLoanProduct(loanProductLookup.getId()); + match = this.loanProductReadPlatformService.retrieveLoanProduct(loanProductLookup.getId()); break; } }