}
form.setItemShortDesc(form.getItemShortDesc());
form.setItemShortDescLang(form.getItemShortDescLang());
AdminBean adminBean = getAdminBean(request);
Site site = adminBean.getSite();
initSiteProfiles(form, site);
Item item = new Item();
if (!insertMode) {
item = ItemDAO.load(site.getSiteId(), Format.getLong(form.getItemId()));
}
ActionMessages errors = validate(request, form, site.getSiteId(), insertMode, item);
if (errors.size() != 0) {
saveMessages(request, errors);
createAdditionalInfo(adminBean, form, item);
return mapping.findForward("error");
}
if (insertMode) {
item.setSite(site);
item.setItemTypeCd(form.getItemTypeCd());
item.setItemHitCounter(new Integer(0));
item.setItemRating(new Float(0));
item.setItemRatingCount(new Integer(0));
item.setItemQty(new Integer(0));
item.setItemBookedQty(new Integer(0));
item.setRecCreateBy(adminBean.getUser().getUserId());
item.setRecCreateDatetime(new Date(System.currentTimeMillis()));
if (!Format.isNullOrEmpty(form.getCustomAttribGroupId())) {
Long customAttribGroupId = Format.getLong(form.getCustomAttribGroupId());
CustomAttributeGroup customAttributeGroup = CustomAttributeGroupDAO.load(site.getSiteId(), customAttribGroupId);
item.setCustomAttributeGroup(customAttributeGroup);
form.setCustomAttribGroupName(customAttributeGroup.getCustomAttribGroupName());
String sql = "select customAttributeDetail " +
"from CustomAttributeGroup customAttributeGroup " +
"join customAttributeGroup.customAttributeDetails customAttributeDetail " +
"where customAttributeGroup.customAttribGroupId = :customAttribGroupId " +
"order by customAttributeDetail.seqNum ";
Query query = em.createQuery(sql);
query.setParameter("customAttribGroupId", Format.getLong(form.getCustomAttribGroupId()));
Iterator<?> iterator = query.getResultList().iterator();
Vector<ItemAttributeDetailDisplayForm> itemAttributeDetails = new Vector<ItemAttributeDetailDisplayForm>();
boolean itemAttributeLangFlag = false;
while (iterator.hasNext()) {
CustomAttributeDetail customAttributeDetail = (CustomAttributeDetail) iterator.next();
/*
ItemAttributeDetail itemAttributeDetail = new ItemAttributeDetail();
itemAttributeDetail.setItem(item);
itemAttributeDetail.setCustomAttributeDetail(customAttributeDetail);
itemAttributeDetail.setRecUpdateBy(adminBean.getUser().getUserId());
itemAttributeDetail.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
itemAttributeDetail.setRecCreateBy(adminBean.getUser().getUserId());
itemAttributeDetail.setRecCreateDatetime(new Date(System.currentTimeMillis()));
ItemAttributeDetailLanguage itemAttributeDetailLanguage = new ItemAttributeDetailLanguage();
itemAttributeDetailLanguage.setItemAttribDetailValue("");
itemAttributeDetailLanguage.setRecUpdateBy(adminBean.getUser().getUserId());
itemAttributeDetailLanguage.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
itemAttributeDetailLanguage.setRecCreateBy(adminBean.getUser().getUserId());
itemAttributeDetailLanguage.setRecCreateDatetime(new Date(System.currentTimeMillis()));
SiteProfileClass siteProfileClass = SiteProfileClassDAO.load(form.getSiteProfileClassDefaultId());
itemAttributeDetailLanguage.setSiteProfileClass(siteProfileClass);
if (customAttributeDetail.getCustomAttribute().getCustomAttribTypeCode() == Constants.CUSTOM_ATTRIBUTE_TYPE_USER_SELECT_DROPDOWN) {
CustomAttributeOption customAttributeOption = null;
for (CustomAttributeOption option : customAttributeDetail.getCustomAttribute().getCustomAttributeOptions()) {
customAttributeOption = option;
break;
}
itemAttributeDetail.setCustomAttributeOption(customAttributeOption);
}
em.persist(itemAttributeDetailLanguage);
itemAttributeDetail.setItemAttributeDetailLanguage(itemAttributeDetailLanguage);
em.persist(itemAttributeDetail);
*/
ItemAttributeDetailDisplayForm displayForm = new ItemAttributeDetailDisplayForm();
displayForm.setCustomAttribId(customAttributeDetail.getCustomAttribute().getCustomAttribId().toString());
displayForm.setCustomAttribTypeCode(String.valueOf(customAttributeDetail.getCustomAttribute().getCustomAttribTypeCode()));
displayForm.setCustomAttribDetailId(customAttributeDetail.getCustomAttribDetailId().toString());
displayForm.setCustomAttribName(customAttributeDetail.getCustomAttribute().getCustomAttribName());
displayForm.setCustomAttribTypeCode(String.valueOf(customAttributeDetail.getCustomAttribute().getCustomAttribTypeCode()));
displayForm.setItemAttribDetailValue("");
itemAttributeDetails.add(displayForm);
}
form.setItemAttribDetailValueLangFlag(itemAttributeLangFlag);
ItemAttributeDetailDisplayForm[] itemAttributeDetailDisplayForms = new ItemAttributeDetailDisplayForm[itemAttributeDetails.size()];
itemAttributeDetails.copyInto(itemAttributeDetailDisplayForms);
form.setItemAttributeDetails(itemAttributeDetailDisplayForms);
}
form.setItemTypeDesc(resources.getMessage("item.typeCode." + form.getItemTypeCd()));
}
if (form.isSiteProfileClassDefault() && form.isSiteCurrencyClassDefault()) {
saveDefault(item, form, adminBean, insertMode);
form.setRecUpdateBy(item.getRecUpdateBy());
form.setRecUpdateDatetime(Format.getFullDatetime(item.getRecUpdateDatetime()));
User user = adminBean.getUser();
item.setUser(user);
if (insertMode) {
em.persist(item);
form.setItemId(Format.getLong(item.getItemId()));
}
else {
// em.update(item);
}
}
else {
if (!form.isSiteProfileClassDefault()) {
saveLanguage(item, form, adminBean);
}
if (!form.isSiteCurrencyClassDefault()) {
saveCurrency(item, form, adminBean);
}
}
if (!Format.isNullOrEmpty(form.getShippingTypeId())) {
ShippingType shippingType = (ShippingType) em.find(ShippingType.class, Format.getLong(form.getShippingTypeId()));
if (shippingType != null) {
item.setShippingType(shippingType);
}
}
else {
item.setShippingType(null);
}
if (!Format.isNullOrEmpty(form.getProductClassId())) {
ProductClass productClass = (ProductClass) em.find(ProductClass.class, Format.getLong(form.getProductClassId()));
if (productClass != null) {
item.setProductClass(productClass);
}
}
else {
item.setShippingType(null);
}
CategorySearchUtil.itemPriceSearchUpdate(item, site, adminBean);
CategorySearchUtil.itemDescSearchUpdate(item, site, adminBean);
if (insertMode) {
em.persist(item);
form.setItemId(Format.getLong(item.getItemId()));
}
else {
// em.update(item);
}
Iterator<?> iterator = item.getMenus().iterator();
while (iterator.hasNext()) {
Menu menu = (Menu) iterator.next();
CacheDAO.removeByKeyPrefix(site.getSiteId(), Constants.CACHE_MENU + "." + menu.getMenuSetName());
}
Indexer.getInstance(site.getSiteId()).updateItem(item);
createAdditionalInfo(adminBean, form, item);
form.setMode("U");
FormUtils.setFormDisplayMode(request, form, FormUtils.EDIT_MODE);