String custPassword1 = request.getParameter("custPassword1");
EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
ContentBean contentBean = getContentBean(request);
Long defaultSiteDomainId = contentBean.getSiteDomain().getSite().getSiteDomainDefault().getSiteDomainId();
Language language = contentBean.getContentSessionBean().getSiteProfile().getSiteProfileClass().getLanguage();
JSONEscapeObject jsonResult = new JSONEscapeObject();
if (Format.isNullOrEmpty(custPublicName)) {
jsonResult.put("custPublicNameError", Languages.getLangTranValue(language.getLangId(), "content.error.string.required"));
}
if (Format.isNullOrEmpty(custEmail)) {
jsonResult.put("custEmailError", Languages.getLangTranValue(language.getLangId(), "content.error.string.required"));
}
if (Format.isNullOrEmpty(custPassword)) {
jsonResult.put("custPasswordError", Languages.getLangTranValue(language.getLangId(), "content.error.string.required"));
}
if (Format.isNullOrEmpty(custPassword1)) {
jsonResult.put("custPassword1Error", Languages.getLangTranValue(language.getLangId(), "content.error.string.required"));
}
if (!Format.isNullOrEmpty(custPassword) && !Format.isNullOrEmpty(custPassword1)) {
if (!custPassword.equals(custPassword1)) {
jsonResult.put("custPasswordMatch", Languages.getLangTranValue(language.getLangId(), "content.error.password.nomatch"));
}
}
if (jsonResult.length() > 0) {
jsonResult.put("status", Constants.WEBSERVICE_STATUS_FAILED);
this.streamWebService(response, jsonResult.toHtmlString());
return null;
}
char singleCheckout = contentBean.getSiteDomain().getSite().getSingleCheckout();
String sql = "from Customer customer " +
"where customer.siteDomain.siteDomainId = :siteDomainId " +
"and custPublicName = :custPublicName ";
Query query = em.createQuery(sql);
query.setParameter("custPublicName", custPublicName);
if (singleCheckout == Constants.VALUE_YES) {
query.setParameter("siteDomainId", defaultSiteDomainId);
}
else {
query.setParameter("siteDomainId", contentBean.getSiteDomain().getSiteDomainId());
}
Customer customer = null;
try {
customer = (Customer) query.getSingleResult();
}
catch (javax.persistence.NoResultException e) {}
if (customer != null) {
jsonResult.put("status", Constants.WEBSERVICE_STATUS_FAILED);
jsonResult.put("custPublicNameError", Languages.getLangTranValue(language.getLangId(), "content.error.publicName.duplicate"));
this.streamWebService(response, jsonResult.toHtmlString());
return null;
}
sql = "from CustomerClass customerClass where siteId = :siteId and customerClass.systemRecord = 'Y'";
query = em.createQuery(sql);
query.setParameter("siteId", contentBean.getSiteDomain().getSite().getSiteId());
CustomerClass customerClass = (CustomerClass) query.getSingleResult();
sql = "from Customer customer " +
"where customer.siteDomain.siteDomainId = :siteDomainId " +
"and custEmail = :custEmail ";
query = em.createQuery(sql);
query.setParameter("custEmail", custEmail);
if (singleCheckout == Constants.VALUE_YES) {
query.setParameter("siteDomainId", defaultSiteDomainId);
}
else {
query.setParameter("siteDomainId", contentBean.getSiteDomain().getSiteDomainId());
}
try {
customer = (Customer) query.getSingleResult();
}
catch (javax.persistence.NoResultException e) {}
if (customer != null) {
jsonResult.put("status", Constants.WEBSERVICE_STATUS_FAILED);
jsonResult.put("custEmailError", Languages.getLangTranValue(language.getLangId(), "content.error.email.duplicate"));
this.streamWebService(response, jsonResult.toHtmlString());
return null;
}