data conversion work per locale.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
+4
@@ -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";
|
||||
}
|
||||
|
||||
|
||||
+1
@@ -24,6 +24,7 @@
|
||||
<form id="entityform">
|
||||
<div id="formerrors"></div>
|
||||
<fieldset>
|
||||
<input type="hidden" id="locale" name="locale" value="${currentLocale}" />
|
||||
<legend><spring:message code="form.legend.loan.product.information"/></legend>
|
||||
|
||||
<label for="name"><spring:message code="form.label.loan.product.name"/></label>
|
||||
|
||||
+13
-23
@@ -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();
|
||||
}
|
||||
|
||||
+2
@@ -13,4 +13,6 @@ public interface ApiDataConversionService {
|
||||
BigDecimal convertFrom(String principalFormatted, String parameterName,
|
||||
Locale clientApplicationLocale);
|
||||
|
||||
Locale localeFromString(String locale);
|
||||
|
||||
}
|
||||
|
||||
+29
@@ -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;
|
||||
}
|
||||
}
|
||||
-130
@@ -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;
|
||||
}
|
||||
}
|
||||
-49
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user