throws Throwable {
EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
MessageResources resources = this.getResources(request);
boolean insertMode = false;
CustomAttributeMaintActionForm form = (CustomAttributeMaintActionForm) actionForm;
if (form.getMode().equals("C")) {
insertMode = true;
}
AdminBean adminBean = getAdminBean(request);
Site site = adminBean.getSite();
initSiteProfiles(form, site);
CustomAttribute customAttribute = new CustomAttribute();
if (!insertMode) {
customAttribute = CustomAttributeDAO.load(site.getSiteId(), Format.getLong(form.getCustomAttribId()));
}
ActionMessages errors = validate(form, request);
if (errors.size() != 0) {
saveMessages(request, errors);
return mapping.findForward("error");
}
if (insertMode) {
customAttribute.setRecCreateBy(adminBean.getUser().getUserId());
customAttribute.setRecCreateDatetime(new Date(System.currentTimeMillis()));
form.setCustomAttribDataTypeCodeDesc(resources.getMessage("customAttrib.dataTypeCode." + form.getCustomAttribDataTypeCode()));
form.setCustomAttribTypeCodeDesc(resources.getMessage("customAttrib.typeCode." + form.getCustomAttribTypeCode()));
CustomAttributeLanguage customAttribLanguage = new CustomAttributeLanguage();
customAttribute.setSystemRecord(Constants.VALUE_NO);
customAttribLanguage.setRecCreateBy(adminBean.getUser().getUserId());
customAttribLanguage.setRecCreateDatetime(new Date(System.currentTimeMillis()));
SiteProfileClass siteProfileClass = (SiteProfileClass) em.find(SiteProfileClass.class, form.getSiteProfileClassDefaultId());
customAttribLanguage.setSiteProfileClass(siteProfileClass);
customAttribLanguage.setCustomAttribute(customAttribute);
customAttribute.setCustomAttributeLanguage(customAttribLanguage);
customAttribute.getCustomAttributeLanguages().add(customAttribLanguage);
}
customAttribute.setSite(site);
customAttribute.setCustomAttribName(form.getCustomAttribName());
customAttribute.setRecUpdateBy(adminBean.getUser().getUserId());
customAttribute.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
if (form.isSiteProfileClassDefault() && form.isSiteCurrencyClassDefault()) {
saveDefault(customAttribute, form, adminBean);
}
else {
if (!form.isSiteProfileClassDefault()) {
saveLanguage(customAttribute, form, adminBean);
}
if (!form.isSiteCurrencyClassDefault()) {
saveCurrency(customAttribute, form, adminBean);
}
}
if (insertMode) {
em.persist(customAttribute);
}
else {
// em.update(customAttribute);
}
form.setMode("U");
form.setCustomAttribId(customAttribute.getCustomAttribId().toString());
FormUtils.setFormDisplayMode(request, form, FormUtils.EDIT_MODE);
return mapping.findForward("success");
}