List of usage examples for org.json JSONObject getInt
public int getInt(String key) throws JSONException
From source file:com.jvoid.products.controller.JVoidProductController.java
@RequestMapping(value = "attribute/delete", method = RequestMethod.GET) public @ResponseBody String deleteAttribute(@RequestParam(required = false, value = "callback") String callback, @RequestParam(required = false, value = "params") JSONObject jsonParams, HttpServletResponse response) { JSONObject jparams = jsonParams; int attributeId = 0; try {//from ww w.java 2 s. c o m attributeId = jparams.getInt("id"); } catch (JSONException e) { e.printStackTrace(); } JSONObject jsonObject = new JSONObject(); if (attributeId > 0) { int status = this.productsMasterService.deleteAttribute(attributeId); if (status == 1) { try { jsonObject.put("status", 1); jsonObject.put("message", "Attribute deleted successfully."); } catch (JSONException e) { e.printStackTrace(); } } else { try { jsonObject.put("status", 0); jsonObject.put("message", "Failed to delete Attribute."); } catch (JSONException e) { e.printStackTrace(); } } } else { try { jsonObject.put("status", 0); jsonObject.put("message", "Failed to delete Attribute."); } catch (JSONException e) { e.printStackTrace(); } } return jsonObject.toString(); }
From source file:com.jvoid.products.controller.JVoidProductController.java
@RequestMapping(value = "attribute/add", method = RequestMethod.GET) public @ResponseBody String addAttribute(@RequestParam(required = false, value = "callback") String callback, @RequestParam(required = false, value = "params") JSONObject jsonParams, HttpServletResponse response) { JSONObject jparams = jsonParams; int attributeGroupId = 0; String attributeName = null;/*from w w w. j a v a2s . c o m*/ try { attributeName = jparams.getString("name"); attributeGroupId = jparams.getInt("id"); } catch (JSONException e) { e.printStackTrace(); } int id = this.productsMasterService.addAttribute(attributeGroupId, attributeName); JSONObject jsonObject = new JSONObject(); if (id > 0) { try { jsonObject.put("status", 1); jsonObject.put("id", id); jsonObject.put("message", "Attribute created successfully."); } catch (JSONException e) { e.printStackTrace(); } } else { try { jsonObject.put("status", 0); jsonObject.put("message", "Failed to create Attribute."); } catch (JSONException e) { e.printStackTrace(); } } return jsonObject.toString(); }
From source file:com.jvoid.products.controller.JVoidProductController.java
@RequestMapping(value = "attributegroup/delete", method = RequestMethod.GET) public @ResponseBody String deleteAttributeGroup( @RequestParam(required = false, value = "callback") String callback, @RequestParam(required = false, value = "params") JSONObject jsonParams, HttpServletResponse response) { JSONObject jparams = jsonParams; int attributeGroupId = 0; try {//from w w w.j a v a 2 s. c o m attributeGroupId = jparams.getInt("id"); } catch (JSONException e) { e.printStackTrace(); } JSONObject jsonObject = new JSONObject(); if (attributeGroupId > 0) { int status = this.productsMasterService.deleteAttributeGroup(attributeGroupId); if (status == 1) { try { jsonObject.put("status", 1); jsonObject.put("message", "AttributeGroup deleted successfully."); } catch (JSONException e) { e.printStackTrace(); } } else { try { jsonObject.put("status", 0); jsonObject.put("message", "Failed to delete AttributeGroup."); } catch (JSONException e) { e.printStackTrace(); } } } else { try { jsonObject.put("status", 0); jsonObject.put("message", "Failed to delete AttributeGroup."); } catch (JSONException e) { e.printStackTrace(); } } return jsonObject.toString(); }
From source file:com.jvoid.products.controller.JVoidProductController.java
@RequestMapping(value = "attributegroup/add", method = RequestMethod.GET) public @ResponseBody String addAttributeGroup( @RequestParam(required = false, value = "callback") String callback, @RequestParam(required = false, value = "params") JSONObject jsonParams, HttpServletResponse response) { JSONObject jparams = jsonParams; String attributeGroupName = null; int attributSetId = 0; try {/*from www. j a v a2 s.co m*/ attributeGroupName = jparams.getString("name"); attributSetId = jparams.getInt("id"); } catch (JSONException e) { e.printStackTrace(); } int id = this.productsMasterService.addAttributeGroup(attributSetId, attributeGroupName); JSONObject jsonObject = new JSONObject(); if (id > 0) { try { jsonObject.put("status", 1); jsonObject.put("id", id); jsonObject.put("message", "AttributeGroup created successfully."); } catch (JSONException e) { e.printStackTrace(); } } else { try { jsonObject.put("status", 0); jsonObject.put("message", "Failed to create AttributeGroup."); } catch (JSONException e) { e.printStackTrace(); } } return jsonObject.toString(); }
From source file:com.jvoid.products.controller.JVoidProductController.java
@RequestMapping(value = "attributeset/delete", method = RequestMethod.GET) public @ResponseBody String deleteAttributeSet( @RequestParam(required = false, value = "callback") String callback, @RequestParam(required = false, value = "params") JSONObject jsonParams, HttpServletResponse response) { JSONObject jparams = jsonParams; int attrSetId = 0; try {//from w w w.ja v a 2s . com attrSetId = jparams.getInt("id"); } catch (JSONException e) { e.printStackTrace(); } JSONObject jsonObject = new JSONObject(); if (attrSetId > 0) { int status = this.productsMasterService.deleteAttributeSet(attrSetId); if (status == 1) { try { jsonObject.put("status", 1); jsonObject.put("message", "AttributeSet deleted successfully."); } catch (JSONException e) { e.printStackTrace(); } } else { try { jsonObject.put("status", 0); jsonObject.put("message", "Failed to delete AttributeSet."); } catch (JSONException e) { e.printStackTrace(); } } } else { try { jsonObject.put("status", 0); jsonObject.put("message", "Failed to delete AttributeSet."); } catch (JSONException e) { e.printStackTrace(); } } return jsonObject.toString(); }
From source file:com.jvoid.products.controller.JVoidProductController.java
@RequestMapping(value = "catalog/category/delete", method = RequestMethod.GET) public @ResponseBody String removeCategory(@RequestParam(required = false, value = "callback") String callback, @RequestParam(required = false, value = "params") JSONObject jsonParams, HttpServletResponse response) { JSONObject test = new JSONObject(); try {// w w w. j av a 2 s. co m test.put("id", 1); } catch (JSONException e2) { e2.printStackTrace(); } JSONObject jparams = jsonParams; int categoryId = 0; try { categoryId = jparams.getInt("id"); } catch (JSONException e) { e.printStackTrace(); } int status = this.categoryProductsMasterService.removeCategory(categoryId); JSONObject jsonObject = new JSONObject(); if (status > 0) { try { jsonObject.put("status", 1); jsonObject.put("message", "Category deleted successfully."); } catch (JSONException e) { e.printStackTrace(); } } else { try { jsonObject.put("status", 0); jsonObject.put("message", "Failed to delete category."); } catch (JSONException e) { e.printStackTrace(); } } return jsonObject.toString(); }
From source file:com.jvoid.products.controller.JVoidProductController.java
@RequestMapping(value = "catalog/category", method = RequestMethod.GET) public @ResponseBody String listCategory(@RequestParam(required = false, value = "callback") String callback, @RequestParam(required = false, value = "params") JSONObject jsonParams, HttpServletResponse response) { JSONObject test = new JSONObject(); try {//from w w w . j a va 2 s . co m test.put("id", -1); } catch (JSONException e2) { e2.printStackTrace(); } JSONObject jparams = jsonParams; int cid = -1; try { cid = jparams.getInt("id"); } catch (JSONException e) { e.printStackTrace(); } List<CategoryMaster> categoryMasterList = null; if (cid > 0) { CategoryMaster categoryMaster = this.categoryProductsMasterService.getCategoryById(cid); List<CategoryMaster> cmList = new ArrayList<>(); cmList.add(categoryMaster); categoryMasterList = cmList; } else if (cid == -1) { categoryMasterList = this.categoryProductsMasterService.getAllCategories(); } JSONObject categoryListObject = new JSONObject(); JSONArray categories = new JSONArray(); ObjectMapper mapper = new ObjectMapper(); for (int i = 0; i < categoryMasterList.size(); i++) { try { String strCategoryMasterObj = mapper.writeValueAsString(categoryMasterList.get(i)); JSONObject jsonObj = new JSONObject(strCategoryMasterObj); categories.put(jsonObj); } catch (JsonGenerationException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } } try { categoryListObject.put("categories", categories); } catch (JSONException e1) { e1.printStackTrace(); } return categoryListObject.toString(); }
From source file:com.jvoid.products.controller.JVoidProductController.java
@RequestMapping(value = "catalog/product/delete", method = RequestMethod.GET) public @ResponseBody String deleteProduct(@RequestParam(required = false, value = "callback") String callback, @RequestParam(required = false, value = "params") JSONObject jsonParams, HttpServletResponse response) { JSONObject test = new JSONObject(); try {// www .ja v a 2 s . c om test.put("id", -1); } catch (JSONException e2) { e2.printStackTrace(); } JSONObject jparams = jsonParams; int pid = -1; try { pid = jparams.getInt("id"); } catch (JSONException e) { e.printStackTrace(); } String json = ""; json = this.productsMasterService.deleteProduct(pid); return json; }
From source file:com.jvoid.products.controller.JVoidProductController.java
@RequestMapping(value = "catalog/product", method = RequestMethod.GET) public @ResponseBody String getProductById(@RequestParam(required = false, value = "callback") String callback, @RequestParam(required = false, value = "params") JSONObject jsonParams, HttpServletResponse response) { JSONObject test = new JSONObject(); try {//ww w.j a va2 s .co m test.put("id", -1); } catch (JSONException e2) { e2.printStackTrace(); } JSONObject jparams = jsonParams; ByteArrayOutputStream out = new ByteArrayOutputStream(); String json = ""; //System.out.println("TOTAL RECS1:"+this.productsMasterService.getAllProducts().size()); int pid = -1; try { pid = jparams.getInt("id"); } catch (JSONException e) { e.printStackTrace(); } List<ProductsMaster> productsList = null; if (pid > 0) { List<ProductsMaster> pmList = new ArrayList<>(); ProductsMaster productsMaster = this.productsMasterService.getProductById(pid); pmList.add(productsMaster); productsList = pmList; } else { productsList = this.productsMasterService.getAllProducts(); } JSONObject productListObject = new JSONObject(); JSONArray products = new JSONArray(); ObjectMapper mapper = new ObjectMapper(); for (int i = 0; i < productsList.size(); i++) { try { String strProductMasterObj = mapper.writeValueAsString(productsList.get(i)); JSONObject jsonObj = new JSONObject(strProductMasterObj); products.put(jsonObj); } catch (JsonGenerationException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } } try { productListObject.put("products", products); } catch (JSONException e1) { e1.printStackTrace(); } //productsList.add(arg0) json = productListObject.toString(); return json; /*try { ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); if (null == callback) { json = ow.writeValueAsString(productListObject); } else { json = callback + "(" + ow.writeValueAsString(productListObject) + ")"; } System.out.println(json); out.write(json.getBytes()); response.setContentType("application/json;charset=UTF-8"); response.setHeader("Connection", "Keep-Alive"); response.setHeader("Keep-Alive", "timeout=5, max=100"); response.setContentLength(out.size()); response.getOutputStream().write(out.toByteArray()); response.getOutputStream().flush(); } catch (IOException e) { e.printStackTrace(); }*/ }
From source file:com.jvoid.products.controller.JVoidProductController.java
@RequestMapping(value = "catalog/categoryproduct", method = RequestMethod.GET) public @ResponseBody String getProductByCategory( @RequestParam(required = false, value = "callback") String callback, @RequestParam(required = false, value = "params") JSONObject jsonParams, HttpServletResponse response) { JSONObject test = new JSONObject(); try {/*from w w w.j a va 2s.com*/ test.put("id", -1); } catch (JSONException e2) { e2.printStackTrace(); } JSONObject jparams = jsonParams; ByteArrayOutputStream out = new ByteArrayOutputStream(); String json = ""; int cid = -1; try { cid = jparams.getInt("id"); } catch (JSONException e) { e.printStackTrace(); } List<ProductsMaster> productsList = null; if (cid > 0) { productsList = this.productsMasterService.getProductByCategory(cid); } else { productsList = this.productsMasterService.getAllProducts(); } JSONObject productListObject = new JSONObject(); JSONArray products = new JSONArray(); ObjectMapper mapper = new ObjectMapper(); for (int i = 0; i < productsList.size(); i++) { try { String strProductMasterObj = mapper.writeValueAsString(productsList.get(i)); JSONObject jsonObj = new JSONObject(strProductMasterObj); products.put(jsonObj); } catch (JsonGenerationException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } try { productListObject.put("products", products); } catch (JSONException e1) { e1.printStackTrace(); } //productsList.add(arg0) json = productListObject.toString(); return json; }