CouponMaintActionForm form = (CouponMaintActionForm) actionForm;
AdminBean adminBean = getAdminBean(request);
String siteId = adminBean.getSite().getSiteId();
MessageResources resources = this.getResources(request);
Coupon coupon = CouponDAO.load(siteId, Format.getLong(form.getCouponId()));
boolean found = false;
java.util.Iterator<Item> iterator = coupon.getItems().iterator();
while (iterator.hasNext()) {
Item item = (Item) iterator.next();
if (item.getItemId().equals(Format.getLong(form.getItemId()))) {
found = true;
break;
}
}
if (found) {
JSONEscapeObject jsonResult = new JSONEscapeObject();
jsonResult.put("status", Constants.WEBSERVICE_STATUS_FAILED);
jsonResult.put("message", resources.getMessage("error.item.exist"));
streamWebService(response, jsonResult.toHtmlString());
}
Item item = ItemDAO.load(siteId, Format.getLong(form.getItemId()));
if (item == null) {
JSONEscapeObject jsonResult = new JSONEscapeObject();
jsonResult.put("status", Constants.WEBSERVICE_STATUS_FAILED);
jsonResult.put("message", resources.getMessage("error.item.notexist"));
streamWebService(response, jsonResult.toHtmlString());
}
coupon.getItems().add(item);
em.persist(coupon);
String result = getJSONItemList(coupon, form);
streamWebService(response, result);
return null;
}