}
if (form.getMode().equals("C")) {
insertMode = true;
}
ShippingMethod shippingMethod = new ShippingMethod();
ShippingMethodLanguage shippingMethodLanguage = new ShippingMethodLanguage();
if (!insertMode) {
shippingMethod = ShippingMethodDAO.load(site.getSiteId(), Format.getLong(form.getShippingMethodId()));
shippingMethodLanguage = shippingMethod.getShippingMethodLanguage();
}
if (insertMode) {
String sql = "select max(seqNum) " +
"from ShippingMethod " +
"where siteId = :siteId ";
int seqNum = 0;
Query query = em.createQuery(sql);
query.setParameter("siteId", site.getSiteId());
Integer i = (Integer) query.getResultList().iterator().next();
if (i != null) {
seqNum = i.intValue() + 1;
}
shippingMethod.setSeqNum(seqNum);
shippingMethod.setSite(site);
shippingMethod.setRecCreateBy(adminBean.getUser().getUserId());
shippingMethod.setRecCreateDatetime(new Date(System.currentTimeMillis()));
shippingMethodLanguage.setRecCreateBy(adminBean.getUser().getUserId());
shippingMethodLanguage.setRecCreateDatetime(new Date(System.currentTimeMillis()));
shippingMethodLanguage.setShippingMethod(shippingMethod);
SiteProfileClass siteProfileClass = SiteProfileClassDAO.load(form.getSiteProfileClassId());
shippingMethodLanguage.setSiteProfileClass(siteProfileClass);
shippingMethod.getShippingMethodLanguages().add(shippingMethodLanguage);
}
for (ShippingMethodRegion shippingMethodRegion : shippingMethod.getShippingMethodRegions()) {
shippingMethodRegion.setPublished(Constants.PUBLISHED_NO);
String shippingRegionId = shippingMethodRegion.getShippingRegion().getShippingRegionId().toString();
if (form.getShippingRegionIds() != null) {
for (int i = 0; i < form.getShippingRegionIds().length; i++) {
if (shippingRegionId.equals(form.getShippingRegionIds()[i])) {
shippingMethodRegion.setPublished(Constants.PUBLISHED_YES);
break;
}
}
}
shippingMethodRegion.setRecUpdateBy(adminBean.getUser().getUserId());
shippingMethodRegion.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
em.persist(shippingMethodRegion);
}
if (form.isSiteProfileClassDefault()) {
saveDefault(shippingMethod, shippingMethodLanguage, form, adminBean);
shippingMethod.setShippingMethodLanguage(shippingMethodLanguage);
if (insertMode) {
em.persist(shippingMethodLanguage);
em.persist(shippingMethod);
}
}
else {
saveLanguage(shippingMethod, form, adminBean);
}
initJsonSmRegions(form, shippingMethod, site.getSiteId(), adminBean.getUser());
form.setMode("U");
form.setShippingMethodId(shippingMethod.getShippingMethodId().toString());
FormUtils.setFormDisplayMode(request, form, FormUtils.EDIT_MODE);
return mapping.findForward("success");
}