AdminBean adminBean = getAdminBean(request);
JSONEscapeObject jsonResult = new JSONEscapeObject();
jsonResult.put("status", Constants.WEBSERVICE_STATUS_SUCCESS);
Long trProductId = Format.getLong(form.getTaxRegionProductId());
Long custClassId = Format.getLong(form.getCustClassId());
TaxRegionProduct taxRegionProduct = (TaxRegionProduct) em.find(TaxRegionProduct.class, trProductId);
CustomerClass customerClass = (CustomerClass) em.find(CustomerClass.class, custClassId);
Iterator<?> iterator = taxRegionProduct.getCustomerClasses().iterator();
while (iterator.hasNext()) {
TaxRegionProductCust c = (TaxRegionProductCust) iterator.next();
if (c.getCustomerClass().getCustClassId().equals(customerClass.getCustClassId())) {
jsonResult.put("status", Constants.WEBSERVICE_STATUS_FAILED);
jsonResult.put("message", "Customer class already exist");
streamWebService(response, jsonResult.toHtmlString());
return null;
}
}
TaxRegionProductCust trProductCust = new TaxRegionProductCust();
trProductCust.setTaxRegionProduct(taxRegionProduct);
trProductCust.setCustomerClass(customerClass);
trProductCust.setRecUpdateBy(adminBean.getUser().getUserId());
trProductCust.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
trProductCust.setRecCreateBy(adminBean.getUser().getUserId());
trProductCust.setRecCreateDatetime(new Date(System.currentTimeMillis()));
taxRegionProduct.getCustomerClasses().add(trProductCust);
em.persist(trProductCust);
String result = getJSONProduct(request, taxRegionProduct);
streamWebService(response, result);