customAttribute.setCustomAttribTypeCode(form.getCustomAttribTypeCode().charAt(0));
SiteCurrencyClass siteCurrencyClass = (SiteCurrencyClass) em.find(SiteCurrencyClass.class, form.getSiteCurrencyClassId());
for (int i = 0; i < form.getCustomAttribOptions().length; i++) {
CustomAttributeOptionDisplayForm optionForm = form.getCustomAttribOptions()[i];
CustomAttributeOption customAttributeOption = null;
boolean exist = false;
if (Format.isNullOrEmpty(optionForm.getCustomAttribOptionId())) {
customAttributeOption = new CustomAttributeOption();
customAttributeOption.setCustomAttribute(customAttribute);
customAttributeOption.setRecCreateBy(adminBean.getUser().getUserId());
customAttributeOption.setRecCreateDatetime(new Date(System.currentTimeMillis()));
}
else {
Long customAttribOptionId = Format.getLong(optionForm.getCustomAttribOptionId());
customAttributeOption = CustomAttributeOptionDAO.load(adminBean.getSite().getSiteId(), customAttribOptionId);
exist = true;
}
customAttributeOption.setCustomAttribSkuCode(optionForm.getCustomAttribSkuCode());
customAttributeOption.setRecUpdateBy(adminBean.getUser().getUserId());
customAttributeOption.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
if (!exist) {
em.persist(customAttributeOption);
}
if (customAttribute.getCustomAttribDataTypeCode() == Constants.CUSTOM_ATTRIBUTE_DATA_TYPE_CURRENCY) {
exist = true;
CustomAttributeOptionCurrency customAttribOptionCurrency = customAttributeOption.getCustomAttributeOptionCurrency();
if (customAttribOptionCurrency == null) {
customAttribOptionCurrency = new CustomAttributeOptionCurrency();
exist = false;
customAttribOptionCurrency.setSiteCurrencyClass(siteCurrencyClass);
customAttribOptionCurrency.setCustomAttributeOption(customAttributeOption);
customAttribOptionCurrency.setRecCreateBy(adminBean.getUser().getUserId());
customAttribOptionCurrency.setRecCreateDatetime(new Date(System.currentTimeMillis()));
customAttributeOption.setCustomAttributeOptionCurrency(customAttribOptionCurrency);
customAttributeOption.getCustomAttributeOptionCurrencies().add(customAttribOptionCurrency);
}
customAttribOptionCurrency.setCustomAttribValue(optionForm.getCustomAttribValue());
customAttribOptionCurrency.setRecUpdateBy(adminBean.getUser().getUserId());
customAttribOptionCurrency.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
if (!exist) {
em.persist(customAttribOptionCurrency);
}
}
else {
exist = true;
CustomAttributeOptionLanguage customAttribOptionLanguage = customAttributeOption.getCustomAttributeOptionLanguage();
if (customAttribOptionLanguage == null) {
SiteProfileClass siteProfileClass = SiteProfileClassDAO.load(form.getSiteProfileClassId());
customAttribOptionLanguage = new CustomAttributeOptionLanguage();
exist = false;
customAttribOptionLanguage.setCustomAttributeOption(customAttributeOption);
customAttribOptionLanguage.setSiteProfileClass(siteProfileClass);
customAttribOptionLanguage.setRecCreateBy(adminBean.getUser().getUserId());
customAttribOptionLanguage.setRecCreateDatetime(new Date(System.currentTimeMillis()));
customAttributeOption.setCustomAttributeOptionLanguage(customAttribOptionLanguage);
customAttributeOption.getCustomAttributeOptionLanguages().add(customAttribOptionLanguage);
}
customAttribOptionLanguage.setCustomAttribValue(optionForm.getCustomAttribValue());
customAttribOptionLanguage.setRecUpdateBy(adminBean.getUser().getUserId());
customAttribOptionLanguage.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
if (!exist) {
em.persist(customAttribOptionLanguage);
}
}
optionForm.setCustomAttribOptionId(customAttributeOption.getCustomAttribOptionId().toString());
}
}