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);