HttpServletResponse response)
throws Throwable {
createEmptySecureTemplateInfo(request);
ShoppingCartNewUserActionForm form = (ShoppingCartNewUserActionForm) actionForm;
ShoppingCart shoppingCart = ShoppingCart.getSessionInstance(request, true);
ActionMessages messages = validate(form);
if (messages.size() > 0) {
saveMessages(request, messages);
ActionForward actionForward = actionMapping.findForward("error");
return actionForward;
}
ContentBean contentBean = getContentBean(request);
Long defaultSiteDomainId = contentBean.getSiteDomain().getSite().getSiteDomainDefault().getSiteDomainId();
Site site = contentBean.getContentSessionBean().getSiteDomain().getSite();
char singleCheckout = contentBean.getSiteDomain().getSite().getSingleCheckout();
EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
String siteId = site.getSiteId();
String sql = "from Customer customer " +
"where customer.siteDomain.siteDomainId = :siteDomainId " +
"and custEmail = :custEmail";
Query query = em.createQuery(sql);
if (singleCheckout == Constants.VALUE_YES) {
query.setParameter("siteDomainId", defaultSiteDomainId);
}
else {
query.setParameter("siteDomainId", contentBean.getSiteDomain().getSiteDomainId());
}
query.setParameter("custEmail", form.getCustEmail());
List<?> list = query.getResultList();
if (list.size() != 0) {
messages.add("emailDuplicate", new ActionMessage("content.error.email.duplicate"));
}
sql = "from Customer customer " +
"where customer.siteDomain.siteDomainId = :siteDomainId " +
"and custPublicName = :custPublicName";
query = em.createQuery(sql);
if (singleCheckout == Constants.VALUE_YES) {
query.setParameter("siteDomainId", defaultSiteDomainId);
}
else {
query.setParameter("siteDomainId", contentBean.getSiteDomain().getSiteDomainId());
}
query.setParameter("custPublicName", form.getCustPublicName());
list = query.getResultList();
if (list.size() != 0) {
messages.add("custPublicName", new ActionMessage("content.error.publicName.duplicate"));
}
if (messages.size() > 0) {
saveMessages(request, messages);
ActionForward actionForward = actionMapping.findForward("error");
return actionForward;
}
sql = "from CustomerClass customerClass " +
"where customerClass.site.siteId = :siteId " +
"and customerClass.systemRecord = 'Y'";
query = em.createQuery(sql);
query.setParameter("siteId", siteId);
CustomerClass customerClass = (CustomerClass) query.getSingleResult();
Customer customer = new Customer();
customer.setSite(site);
if (singleCheckout == Constants.VALUE_YES) {
SiteDomain siteDomain = (SiteDomain) em.find(SiteDomain.class, defaultSiteDomainId);
customer.setSiteDomain(siteDomain);
}
else {
customer.setSiteDomain(contentBean.getSiteDomain());
}
customer.setCustEmail(form.getCustEmail());
customer.setCustPassword(AESEncoder.getInstance().encode(form.getCustPassword()));
customer.setCustPublicName(form.getCustPublicName());
customer.setCustSource(Constants.CUSTOMER_SOURCE_REGISTER);
customer.setCustSourceRef("");
customer.setActive(Constants.ACTIVE_YES);
customer.setRecUpdateBy(Constants.USERNAME_CUSTOMER);
customer.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
customer.setRecCreateBy(Constants.USERNAME_CUSTOMER);
customer.setRecCreateDatetime(new Date(System.currentTimeMillis()));
customer.setCustomerClass(customerClass);
CustomerAddress customerAddress = shoppingCart.getEstimateAddress();
if (customerAddress == null) {
customerAddress = new CustomerAddress();
}
customer.setCustAddress(customerAddress);
customer.getCustAddresses().add(customerAddress);
customerAddress.setCustUseAddress(Constants.CUST_ADDRESS_USE_OWN);
customerAddress.setCustAddressType(Constants.CUSTOMER_ADDRESS_CUST);
customerAddress.setRecUpdateBy(Constants.USERNAME_CUSTOMER);
customerAddress.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
customerAddress.setRecCreateBy(Constants.USERNAME_CUSTOMER);
customerAddress.setRecCreateDatetime(new Date(System.currentTimeMillis()));
em.persist(customerAddress);
em.persist(customer);
em.flush();
ContentLookupDispatchAction.setCustId(request, customer.getCustId());
shoppingCart.setCustomer(new CustomerDAO(customer));
shoppingCart.setCustAddress(customerAddress);
ActionForward actionForward = actionMapping.findForward("createSuccess");
return actionForward;
}