insertMode = true;
}
AdminBean adminBean = getAdminBean(request);
Site site = new Site();
if (!insertMode) {
site = SiteDAO.load(form.getSiteId());
}
SiteParamBean siteParamBean = new SiteParamBean();
if (!Format.isNullOrEmpty(site.getSiteParam())) {
siteParamBean = (SiteParamBean) Utility.joxUnMarshall(SiteParamBean.class, site.getSiteParam());
}
form.setMailSmtpPort(form.getMailSmtpPort().trim());
ActionMessages errors = validate(form, siteParamBean);
if (errors.size() != 0) {
form.setMailSmtpPassword("");
form.setCaptchaPrivateKey("");
form.setCaptchaPublicKey("");
initListInfo(form);
saveMessages(request, errors);
return mapping.findForward("error");
}
site.setSiteDesc(form.getSiteDesc());
if (!insertMode) {
site.setShareInventory(form.isShareInventory() ? Constants.VALUE_YES : Constants.VALUE_NO);
site.setManageInventory(form.isManageInventory() ? Constants.VALUE_YES : Constants.VALUE_NO);
site.setSingleCheckout(form.isSingleCheckout() ? Constants.VALUE_YES : Constants.VALUE_NO);
site.setListingPageSize(Format.getInt(form.getListingPageSize()));
site.setMailSmtpHost(form.getMailSmtpHost());
site.setMailSmtpPort(form.getMailSmtpPort());
site.setMailSmtpAccount(form.getMailSmtpAccount());
if (!Format.isNullOrEmpty(form.getMailSmtpPassword())) {
site.setMailSmtpPassword(AESEncoder.getInstance().encode(form.getMailSmtpPassword()));
}
if (form.getMailSmtpPassword().equals(" ")) {
site.setMailSmtpPassword(AESEncoder.getInstance().encode(""));
}
}
site.setActive(form.isActive() ? Constants.VALUE_YES : Constants.VALUE_NO);
siteParamBean.setEnableCaptcha(form.isEnableCaptcha() ? String.valueOf(Constants.VALUE_YES) : String.valueOf(Constants.VALUE_NO));
if (!Format.isNullOrEmpty(form.getCaptchaPrivateKey())) {
siteParamBean.setCaptchaPrivateKey(AESEncoder.getInstance().encode(form.getCaptchaPrivateKey()));
}
if (!Format.isNullOrEmpty(form.getCaptchaPublicKey())) {
siteParamBean.setCaptchaPublicKey(AESEncoder.getInstance().encode(form.getCaptchaPublicKey()));
}
if (!form.isEnableCaptcha()) {
siteParamBean.setCaptchaPrivateKey("");
siteParamBean.setCaptchaPublicKey("");
}
site.setSiteParam(Utility.joxMarshall("SiteParamBean", siteParamBean));
site.setRecUpdateBy(adminBean.getUser().getUserId());
site.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
if (insertMode) {
boolean checked = false;
String siteDomainPrefix = "localhost";
int count = 0;
while (!checked) {
String sql = "from Site";
Query query = em.createQuery(sql);
Iterator<?> iterator = query.getResultList().iterator();
boolean found = false;
if (count > 0) {
siteDomainPrefix = "localhost" + count;
}
while (iterator.hasNext()) {
Site otherSite = (Site) iterator.next();
for (SiteDomain otherSiteDomain : otherSite.getSiteDomains()) {
if (otherSiteDomain.getSiteDomainPrefix().equals(siteDomainPrefix)) {
found = true;
break;
}
}