AdminBean adminBean = getAdminBean(request);
Site site = adminBean.getSite();
String siteId = site.getSiteId();
TaxRegion taxRegion = new TaxRegion();
if (!insertMode) {
taxRegion = TaxRegionDAO.load(siteId, Format.getLong(form.getTaxRegionId()));
}
ActionMessages errors = validate(form);
if (errors.size() != 0) {
saveMessages(request, errors);
if (insertMode) {
FormUtils.setFormDisplayMode(request, form, FormUtils.CREATE_MODE);
}
else {
FormUtils.setFormDisplayMode(request, form, FormUtils.EDIT_MODE);
}
return mapping.findForward("error");
}
if (insertMode) {
taxRegion.setRecCreateBy(adminBean.getUser().getUserId());
taxRegion.setRecCreateDatetime(new Date(System.currentTimeMillis()));
}
taxRegion.setSite(site);
taxRegion.setTaxRegionDesc(form.getTaxRegionDesc());
if (!Format.isNullOrEmpty(form.getShippingProductClassId())) {
ProductClass productClass = (ProductClass) em.find(ProductClass.class, Format.getLong(form.getShippingProductClassId()));
taxRegion.setShippingProductClass(productClass);
}
else {
taxRegion.setShippingProductClass(null);
}
taxRegion.setPublished(Constants.VALUE_NO);
if (form.isPublished()) {
taxRegion.setPublished(Constants.VALUE_YES);
}
taxRegion.setRecUpdateBy(adminBean.getUser().getUserId());
taxRegion.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
if (insertMode) {
em.persist(taxRegion);
}
else {
// em.update(taxRegion);
}
form.setTaxRegionId(Format.getLong(taxRegion.getTaxRegionId()));
form.setMode("U");
createAdditionalInfo(form, site, taxRegion);
FormUtils.setFormDisplayMode(request, form, FormUtils.EDIT_MODE);
return mapping.findForward("success");
}