diff --git a/mifosng-data/src/main/java/org/mifosng/data/command/LoanProductCommand.java b/mifosng-data/src/main/java/org/mifosng/data/command/LoanProductCommand.java index 1c307bb00..5a18f4e78 100644 --- a/mifosng-data/src/main/java/org/mifosng/data/command/LoanProductCommand.java +++ b/mifosng-data/src/main/java/org/mifosng/data/command/LoanProductCommand.java @@ -12,6 +12,7 @@ public class LoanProductCommand { private String description; private String externalId; + private String locale; private String currencyCode; private Integer digitsAfterDecimal; private BigDecimal principal; @@ -188,4 +189,12 @@ public class LoanProductCommand { String inArrearsToleranceAmountFormatted) { this.inArrearsToleranceAmountFormatted = inArrearsToleranceAmountFormatted; } + + public String getLocale() { + return locale; + } + + public void setLocale(String locale) { + this.locale = locale; + } } \ No newline at end of file diff --git a/mifosng-data/src/main/java/org/mifosng/data/command/SignupCommand.java b/mifosng-data/src/main/java/org/mifosng/data/command/SignupCommand.java deleted file mode 100644 index 981422745..000000000 --- a/mifosng-data/src/main/java/org/mifosng/data/command/SignupCommand.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.mifosng.data.command; - -import javax.xml.bind.annotation.XmlRootElement; - -import org.joda.time.LocalDate; - -@XmlRootElement -public class SignupCommand { - - private String organisationName; - private String contactEmail; - private String contactName; - - // @DateTimeFormat(pattern = "yyyy-MM-dd") - private LocalDate openingDate = new LocalDate(); - - protected SignupCommand() { - // - } - - public SignupCommand(final String organisationName, - final String contactEmail, final String contactName, - final LocalDate openingDate) { - this.organisationName = organisationName; - this.contactEmail = contactEmail; - this.contactName = contactName; - this.openingDate = openingDate; - } - - public String getContactEmail() { - return this.contactEmail; - } - - public void setContactEmail(final String contactEmail) { - this.contactEmail = contactEmail; - } - - public String getContactName() { - return this.contactName; - } - - public void setContactName(final String contactName) { - this.contactName = contactName; - } - - public String getOrganisationName() { - return this.organisationName; - } - - public void setOrganisationName(final String organisationName) { - this.organisationName = organisationName; - } - - public LocalDate getOpeningDate() { - return this.openingDate; - } - - public void setOpeningDate(final LocalDate openingDate) { - this.openingDate = openingDate; - } -} \ No newline at end of file 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 f7dae0f46..c5d94942c 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 @@ -1,6 +1,7 @@ package org.mifosng.ui; import org.mifosng.ui.infrastructure.BasicAuthUserDetails; +import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.security.access.AccessDeniedException; import org.springframework.security.core.Authentication; import org.springframework.stereotype.Controller; @@ -63,6 +64,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/orghome"; } 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 f409dbbb8..3daf0eab1 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 @@ -24,6 +24,7 @@
+ diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/LoanProductApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/LoanProductApiResource.java index 76c0d1d5d..b5e8e3a20 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/LoanProductApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/LoanProductApiResource.java @@ -49,7 +49,7 @@ public class LoanProductApiResource { private ApiJSONFormattingService jsonFormattingService; @POST - @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({ MediaType.APPLICATION_JSON }) public Response createLoanProduct(LoanProductCommand command) { @@ -60,7 +60,7 @@ public class LoanProductApiResource { } @GET - @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({ MediaType.APPLICATION_JSON }) public String retrieveAllLoanProducts(@Context UriInfo uriInfo) { @@ -79,7 +79,7 @@ public class LoanProductApiResource { */ @GET @Path("template") - @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({ MediaType.APPLICATION_JSON }) public String retrieveNewLoanProductDetails(@Context UriInfo uriInfo) { @@ -94,7 +94,7 @@ public class LoanProductApiResource { @GET @Path("{productId}") - @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({ MediaType.APPLICATION_JSON }) public String retrieveLoanProductDetails( @PathParam("productId") final Long productId, @@ -111,32 +111,22 @@ public class LoanProductApiResource { @PUT @Path("{productId}") - @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({ MediaType.APPLICATION_JSON }) - public Response updateLoanProduct( - @PathParam("productId") final Long productId, - final LoanProductCommand command) { + public Response updateLoanProduct(@PathParam("productId") final Long productId, final LoanProductCommand command) { - // FIXME - pass in locale through query string or in 'request body' - Locale clientApplicationLocale = Locale.UK; - BigDecimal principal = this.apiDataConversionService.convertFrom( - command.getPrincipalFormatted(), "principalFormatted", - clientApplicationLocale); - BigDecimal interestRatePerPeriod = this.apiDataConversionService - .convertFrom(command.getInterestRatePerPeriodFormatted(), - "interestRatePerPeriodFormatted", - clientApplicationLocale); - BigDecimal inArrearsToleranceAmount = this.apiDataConversionService - .convertFrom(command.getInArrearsToleranceAmountFormatted(), - "inArrearsToleranceAmountFormatted", - clientApplicationLocale); + Locale clientApplicationLocale = this.apiDataConversionService.localeFromString(command.getLocale()); + + BigDecimal principal = this.apiDataConversionService.convertFrom(command.getPrincipalFormatted(), "principalFormatted", clientApplicationLocale); + BigDecimal interestRatePerPeriod = this.apiDataConversionService.convertFrom(command.getInterestRatePerPeriodFormatted(),"interestRatePerPeriodFormatted", clientApplicationLocale); + BigDecimal inArrearsToleranceAmount = this.apiDataConversionService.convertFrom(command.getInArrearsToleranceAmountFormatted(), "inArrearsToleranceAmountFormatted", clientApplicationLocale); + command.setPrincipal(principal); command.setInterestRatePerPeriod(interestRatePerPeriod); command.setInArrearsToleranceAmount(inArrearsToleranceAmount); command.setId(productId); - EntityIdentifier entityIdentifier = this.loanProductWritePlatformService - .updateLoanProduct(command); + EntityIdentifier entityIdentifier = this.loanProductWritePlatformService.updateLoanProduct(command); return Response.ok().entity(entityIdentifier).build(); } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiDataConversionService.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiDataConversionService.java index cdd4508bc..ec632b6b2 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiDataConversionService.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiDataConversionService.java @@ -13,4 +13,6 @@ public interface ApiDataConversionService { BigDecimal convertFrom(String principalFormatted, String parameterName, Locale clientApplicationLocale); + Locale localeFromString(String locale); + } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiDataConversionServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiDataConversionServiceImpl.java index 5bf0fd87f..7126588bd 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiDataConversionServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiDataConversionServiceImpl.java @@ -84,4 +84,33 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService { } } + @Override + public Locale localeFromString(final String localeAsString) { + + Locale locale = Locale.getDefault(); + + String[] localeParts = localeAsString.split("_"); + String language = "en"; + String country = "GB"; + String variant = ""; + if (localeParts != null && localeParts.length == 1) { + language = localeParts[0]; + locale = new Locale(language); + } + + if (localeParts != null && localeParts.length == 2) { + language = localeParts[0]; + country = localeParts[1]; + locale = new Locale(language, country); + } + + if (localeParts != null && localeParts.length == 3) { + language = localeParts[0]; + country = localeParts[1]; + variant = localeParts[2]; + locale = new Locale(language, country, variant); + } + + return locale; + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/infrastructure/SignupController.java b/mifosng-provider/src/main/java/org/mifosng/platform/infrastructure/SignupController.java deleted file mode 100644 index fb7656ec5..000000000 --- a/mifosng-provider/src/main/java/org/mifosng/platform/infrastructure/SignupController.java +++ /dev/null @@ -1,130 +0,0 @@ -package org.mifosng.platform.infrastructure; - -import org.apache.commons.lang.StringUtils; -import org.mifosng.data.command.SignupCommand; -import org.mifosng.platform.WritePlatformService; -import org.mifosng.platform.exceptions.InvalidSignupException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.validation.BindingResult; -import org.springframework.validation.ObjectError; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.support.SessionStatus; -import org.springframework.web.servlet.ModelAndView; - -/** - * FIXMED - REMOVE DEPRECATED CONTROLLER and related code artifacts - * @deprecated - remove signup functionality for now. - */ -@Deprecated -//@Controller -//@SessionAttributes("signupFormBean") -public class SignupController { - - private final WritePlatformService signupPlatformService; - - @Autowired - public SignupController(WritePlatformService signupPlatformService) { - this.signupPlatformService = signupPlatformService; - } - - @RequestMapping(value = "/signup", method = RequestMethod.GET) - public ModelAndView loadSignupForm() { - - SignupFormBean bean = new SignupFormBean(); - return new ModelAndView("/tenant/signup", "signupFormBean", bean); - } - - @RequestMapping(value = "/signup", method = RequestMethod.POST) - public ModelAndView handleSignup( - @ModelAttribute("signupFormBean") final SignupFormBean signupFormBean, - final BindingResult result, final SessionStatus status) { - - final String signupFormView = "/tenant/signup"; - - if (result.hasErrors()) { - return new ModelAndView(signupFormView, "signupFormBean", - signupFormBean); - } - - if (StringUtils.isBlank(signupFormBean.getOrganisationName())) { - ObjectError error = new ObjectError("signupFormBean", - new String[] { "organisationName.blank" }, new Object[] {}, - "Organisation name cannot be empty."); - - result.addError(error); - } - - if (signupFormBean.getOpeningDate() == null) { - ObjectError error = new ObjectError("signupFormBean", - new String[] { "openingDate.blank" }, new Object[] {}, - "Organisation Founded date cannot be empty."); - - result.addError(error); - } - - if (StringUtils.isBlank(signupFormBean.getContactEmail())) { - - ObjectError error = new ObjectError("signupFormBean", - new String[] { "contactEmail.blank" }, new Object[] {}, - "Contact email cannot be empty."); - - result.addError(error); - } - - if (StringUtils.isBlank(signupFormBean.getContactName())) { - ObjectError error = new ObjectError("signupFormBean", - new String[] { "contactName.blank" }, new Object[] {}, - "Contact name cannot be empty."); - - result.addError(error); - } - - if (result.hasErrors()) { - return new ModelAndView(signupFormView, "signupFormBean", - signupFormBean); - } - - SignupCommand command = new SignupCommand( - signupFormBean.getOrganisationName(), - signupFormBean.getContactEmail(), - signupFormBean.getContactName(), - signupFormBean.getOpeningDate()); - - ModelAndView mav = null; - try { - // REMOVED -// signupPlatformService.signup(command); - - status.setComplete(); - mav = new ModelAndView("/tenant/signupsuccess", "signupFormBean", - signupFormBean); - } catch (InvalidSignupException e) { - // FIXME - InvalidSignupException is really - // TenantAlreadyExistsException as a tenant already exists with - // given organisationName - - Object[] errorArgs = new Object[] { signupFormBean.getOrganisationName() }; - ObjectError error = new ObjectError("signupFormBean", - new String[] { "organisation.name.already.exists" }, errorArgs, - "An organisation with name {0} already exists."); - result.addError(error); - } catch (PlatformEmailSendException e) { - Object[] errorArgs = new Object[] { signupFormBean.getContactEmail() }; - ObjectError error = new ObjectError( - "signupFormBean", - new String[] { "email.failed.to.send"}, - errorArgs, - "The provided email address [{0}] is not valid or our email service is presently not working, if you believe your email to be correct, please try again in a few minutes."); - result.addError(error); - } - - if (result.hasErrors()) { - mav = new ModelAndView(signupFormView, "signupFormBean", - signupFormBean); - } - - return mav; - } -} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/infrastructure/SignupFormBean.java b/mifosng-provider/src/main/java/org/mifosng/platform/infrastructure/SignupFormBean.java deleted file mode 100644 index a70d505ff..000000000 --- a/mifosng-provider/src/main/java/org/mifosng/platform/infrastructure/SignupFormBean.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.mifosng.platform.infrastructure; - -import org.joda.time.LocalDate; -import org.springframework.format.annotation.DateTimeFormat; - -public class SignupFormBean { - private String contactEmail; - private String contactName; - private String organisationName; - - @DateTimeFormat(pattern = "yyyy-MM-dd") - private LocalDate openingDate = new LocalDate(); - - protected SignupFormBean() { - // no arg constructor - } - - public String getContactEmail() { - return this.contactEmail; - } - - public void setContactEmail(final String contactEmail) { - this.contactEmail = contactEmail; - } - - public String getContactName() { - return this.contactName; - } - - public void setContactName(final String contactName) { - this.contactName = contactName; - } - - public String getOrganisationName() { - return this.organisationName; - } - - public void setOrganisationName(final String organisationName) { - this.organisationName = organisationName; - } - - public LocalDate getOpeningDate() { - return this.openingDate; - } - - public void setOpeningDate(final LocalDate openingDate) { - this.openingDate = openingDate; - } -} \ No newline at end of file