ItemMaintActionForm form = (ItemMaintActionForm) actionForm;
AdminBean adminBean = getAdminBean(request);
Site site = adminBean.getSite();
initSiteProfiles(form, site);
JSONEscapeObject jsonResult = new JSONEscapeObject();
Item item = ItemDAO.load(site.getSiteId(), Format.getLong(form.getItemId()));
String sql = "from Item " +
"where siteId = :siteId " +
"and itemNum = :itemNum " +
"and itemId != :itemId";
Query query = em.createQuery(sql);
query.setParameter("siteId", site.getSiteId());
query.setParameter("itemNum", form.getItemNum());
query.setParameter("itemId", Format.getLong(form.getItemId()));
Iterator<?> iterator = query.getResultList().iterator();
if (iterator.hasNext()) {
jsonResult.put("status", Constants.WEBSERVICE_STATUS_FAILED);
jsonResult.put("message", resources.getMessage("error.item.itemNum.duplicate"));
streamWebService(response, jsonResult.toHtmlString());
return null;
}
CustomAttributeGroup customAttributeGroup = item.getCustomAttributeGroup();
if (customAttributeGroup != null) {
Vector<AttributeDetailOption[]> attributeVector = new Vector<AttributeDetailOption[]>();
for (CustomAttributeDetail customAttributeDetail : customAttributeGroup.getCustomAttributeDetails()) {
CustomAttribute customAttribute = customAttributeDetail.getCustomAttribute();
if (customAttribute.getCustomAttributeOptions().size() == 0) {
continue;
}
if (customAttribute.getCustomAttribTypeCode() != Constants.CUSTOM_ATTRIBUTE_TYPE_SKU_MAKEUP) {
continue;
}
Vector<AttributeDetailOption> optionVector = new Vector<AttributeDetailOption>();
for (CustomAttributeOption customAttributeOption : customAttribute.getCustomAttributeOptions()) {
AttributeDetailOption attributeDetailOption = new AttributeDetailOption();
attributeDetailOption.setCustomAttributeOption(customAttributeOption);
attributeDetailOption.setCustomAttributeDetail(customAttributeDetail);
optionVector.add(attributeDetailOption);
}
AttributeDetailOption options[] = new AttributeDetailOption[optionVector.size()];
optionVector.copyInto(options);
attributeVector.add(options);
}
AttributeDetailOption[] attributes[] = new AttributeDetailOption[attributeVector.size()][];
attributeVector.copyInto(attributes);
if (attributes.length > 0) {
Vector<Item> items = new Vector<Item>();
generateSkus(items, attributes, item.getItemNum(), 0, new Vector<Object>());
iterator = items.iterator();
while (iterator.hasNext()) {
Item itemSku = (Item) iterator.next();
cloneSku(itemSku, item, adminBean);
}
}
}
jsonResult.put("status", Constants.WEBSERVICE_STATUS_SUCCESS);
jsonResult.put("recUpdateBy", item.getRecUpdateBy());
jsonResult.put("recUpdateDatetime", Format.getFullDatetime(item.getRecUpdateDatetime()));
form.setStream(true);
form.setStreamData(jsonResult.toHtmlString());
return null;
}