List of usage examples for org.json JSONObject JSONObject
public JSONObject()
From source file:com.graphhopper.http.GraphHopperServlet.java
Object createPoints(PointList points, boolean pointsEncoded, boolean includeElevation) throws JSONException { if (pointsEncoded) return WebHelper.encodePolyline(points, includeElevation); JSONObject jsonPoints = new JSONObject(); jsonPoints.put("type", "LineString"); jsonPoints.put("coordinates", points.toGeoJson(includeElevation)); return jsonPoints; }
From source file:com.example.cuisoap.agrimac.machineRegister.containerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_machineregister); send_data = new JSONObject(); filelist = new HashMap<>(); InitViewPager();/* w w w. j a v a 2 s.c o m*/ }
From source file:com.jvoid.quote.controller.JVoidQuoteController.java
@RequestMapping(value = "quote/add", method = RequestMethod.GET) public @ResponseBody String addCart(@RequestParam(required = false, value = "callback") String callback, @RequestParam(required = false, value = "params") JSONObject jsonParams, HttpServletResponse response) { // String jstr = "{\"cartId\":-1, \"productId\":2, \"attributeId\":1, \"quantity\":2}"; // String jstr = "{\"cartId\":1, \"productId\":3, \"attributeId\":1, \"quantity\":2}"; int cartId = -1; int productId = -1; int attributeId = -1; int quantity = -1; try {/*from w ww .ja va 2 s .com*/ cartId = jsonParams.getInt("cartId"); productId = jsonParams.getInt("productId"); attributeId = jsonParams.getInt("attributeId"); quantity = jsonParams.getInt("quantity"); } catch (JSONException e) { e.printStackTrace(); } // cartId = 1; // productId = 2; // attributeId = 1; // quantity = 2; CheckoutAddToCart checkoutAddToCart = new CheckoutAddToCart(); checkoutAddToCart.setCartId(cartId); checkoutAddToCart.setProductId(productId); checkoutAddToCart.setAttributeId(attributeId); checkoutAddToCart.setQuantity(quantity); //Making entry to CheckoutQuote CheckoutQuote checkoutQuote = new CheckoutQuote(); checkoutQuote.setId(checkoutAddToCart.getCartId()); int insertedCartId = -1; if (checkoutQuote.getId() == -1) { System.out.println("Setting create id"); checkoutQuote.setId(0); checkoutQuote.setCreatedAt(Utilities.getCurrentDateTime()); checkoutQuote.setBaseGrandTotal(0); checkoutQuote.setBaseSubtotal(0); checkoutQuote.setGrandTotal(0); checkoutQuote.setSubtotal(0); checkoutQuote.setUpdatedAt(Utilities.getCurrentDateTime()); this.checkoutQuoteService.addCheckoutQuote(checkoutQuote); } else { checkoutQuote = this.checkoutQuoteService.getCheckoutQuoteById(cartId); // checkoutQuote.setCreatedAt(this.checkoutQuoteService.getCheckoutQuoteById(checkoutQuote.getId()).getCreatedAt()); } insertedCartId = checkoutQuote.getId(); System.out.println("CheckoutQuote ID: insertedCartId : " + insertedCartId); //Making entry to CheckoutQuoteItem ProductsMaster productItem = getJVoidProduct(checkoutAddToCart.getProductId()); CheckoutQuoteItem checkoutQuoteItem = this.checkoutQuoteItemService.getCheckoutQuoteItem(cartId, productId); int addingNew = 0; if (checkoutQuoteItem == null) { addingNew = 1; checkoutQuoteItem = new CheckoutQuoteItem(); checkoutQuote.setItemsCount(checkoutQuote.getItemsCount() + 1); checkoutQuoteItem.setCreatedAt(Utilities.getCurrentDateTime()); } checkoutQuoteItem.setWeight(productItem.getWeight()); checkoutQuoteItem.setQuantity(checkoutQuoteItem.getQuantity() + checkoutAddToCart.getQuantity()); checkoutQuoteItem.setSku(productItem.getSku()); checkoutQuoteItem.setPrice(productItem.getPrice()); checkoutQuoteItem.setBasePrice(productItem.getPrice()); checkoutQuoteItem.setDescription(productItem.getDescription()); checkoutQuoteItem.setName(productItem.getName()); checkoutQuoteItem.setProductId(productItem.getId()); checkoutQuoteItem.setQuoteId(insertedCartId); // if (checkoutAddToCart.getCartId() == -1) { checkoutQuote.setItemsQuantity(checkoutQuote.getItemsQuantity() + checkoutAddToCart.getQuantity()); // } // else { // checkoutQuoteItem.setCreatedAt(this.checkoutQuoteItemService.getCheckoutQuoteItemById(checkoutQuoteItem.getId()).getCreatedAt()); // } checkoutQuoteItem.setRowTotal(checkoutQuoteItem.getPrice() * checkoutQuoteItem.getQuantity()); checkoutQuoteItem.setBaseRowTotal(checkoutQuoteItem.getBasePrice() * checkoutQuoteItem.getQuantity()); checkoutQuoteItem.setRowWeight(checkoutQuoteItem.getWeight() * checkoutQuoteItem.getQuantity()); checkoutQuoteItem.setUpdatedAt(Utilities.getCurrentDateTime()); this.checkoutQuoteItemService.addCheckoutQuoteItem(checkoutQuoteItem); int insertedProductId = checkoutQuoteItem.getId(); System.out.println("CheckoutItem ID: insertedProductId : " + insertedProductId); System.out.println("Abhi checkoutquote b4 = " + checkoutQuote.toString()); if (addingNew == 0) { checkoutQuote.setBaseSubtotal(checkoutQuote.getBaseSubtotal() + checkoutQuoteItem.getBasePrice() * checkoutAddToCart.getQuantity()); checkoutQuote.setSubtotal( checkoutQuote.getSubtotal() + checkoutQuoteItem.getPrice() * checkoutAddToCart.getQuantity()); } else { checkoutQuote.setBaseSubtotal(checkoutQuote.getBaseSubtotal() + checkoutQuoteItem.getBaseRowTotal()); checkoutQuote.setSubtotal(checkoutQuote.getSubtotal() + checkoutQuoteItem.getRowTotal()); } checkoutQuote.setBaseGrandTotal(checkoutQuote.getBaseSubtotal() + 50); checkoutQuote.setGrandTotal(checkoutQuote.getSubtotal() + 50); checkoutQuote.setUpdatedAt(Utilities.getCurrentDateTime()); this.checkoutQuoteService.addCheckoutQuote(checkoutQuote); System.out.println("Abhi checkoutquote after = " + checkoutQuote.toString()); // } JSONObject jsonObj = new JSONObject(); try { jsonObj.put("cartId", insertedCartId); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return jsonObj.toString(); }
From source file:com.jvoid.quote.controller.JVoidQuoteController.java
public ProductsMaster getJVoidProduct(int productId) { RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); JSONObject jsonObj = new JSONObject(); try {/*from w w w. jav a 2 s .com*/ jsonObj.put("id", productId); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("param jsonObj=>" + jsonObj.toString()); UriComponentsBuilder builder = UriComponentsBuilder .fromHttpUrl(PRODUCT_SERVER_URI + URIConstants.GET_PRODUCT).queryParam("params", jsonObj); HttpEntity<?> entity = new HttpEntity<>(headers); HttpEntity<String> returnString = restTemplate.exchange(builder.build().toUri(), HttpMethod.GET, entity, String.class); System.out.println("returnString=>" + returnString); JSONObject returnJsonObj = null; try { returnJsonObj = new JSONObject(returnString.getBody()); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } JSONArray productsArr = null; ProductsMaster productsMaster = null; try { productsArr = returnJsonObj.getJSONArray("products"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } productsMaster = new ProductsMaster(); try { ObjectMapper mapper = new ObjectMapper(); try { productsMaster = mapper.readValue(productsArr.getJSONObject(0).toString(), ProductsMaster.class); } catch (JsonParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JsonMappingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return productsMaster; }
From source file:com.jvoid.quote.controller.JVoidQuoteController.java
@RequestMapping(value = "quote/cart", method = RequestMethod.GET) public @ResponseBody String getCart(@RequestParam(required = false, value = "callback") String callback, @RequestParam(required = false, value = "params") JSONObject jsonParams, HttpServletResponse response) { //System.out.println("TOTAL RECS1:"+this.productsMasterService.getAllProducts().size()); int cartId = -1; try {//from w w w. j a v a 2 s . c o m cartId = jsonParams.getInt("cartId"); } catch (JSONException e) { e.printStackTrace(); } JSONObject cartObject = new JSONObject(); JSONArray quoteItems = new JSONArray(); List<CheckoutQuoteItem> quoteItemsList = null; quoteItemsList = this.checkoutQuoteItemService.listCheckoutQuoteItems(cartId); System.out.println("ABHI Quote Item List Count= " + quoteItemsList.size()); ObjectMapper mapper = new ObjectMapper(); for (int i = 0; i < quoteItemsList.size(); i++) { try { String strQuoteItemObj = mapper.writeValueAsString(quoteItemsList.get(i)); JSONObject jsonObj = new JSONObject(strQuoteItemObj); quoteItems.put(jsonObj); } catch (JsonGenerationException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } } CheckoutQuote currentQuote = this.checkoutQuoteService.getCheckoutQuoteById(cartId); try { cartObject.put("items", quoteItems); cartObject.put("total", currentQuote.getGrandTotal()); } catch (JSONException e1) { e1.printStackTrace(); } return cartObject.toString(); }
From source file:com.jvoid.quote.controller.JVoidQuoteController.java
@RequestMapping(value = "quote/delete", method = RequestMethod.GET) public @ResponseBody String deleteCart(@RequestParam(required = false, value = "callback") String callback, @RequestParam(required = false, value = "params") JSONObject jsonParams, HttpServletResponse response) { // String jstr = "{\"cartId\":-1, \"productId\":2, \"attributeId\":1, \"quantity\":2}"; // String jstr = "{\"cartId\":1, \"productId\":3, \"attributeId\":1, \"quantity\":2}"; System.out.println("Inside delete"); int cartId = -1; int productId = -1; try {/*from ww w. j a v a 2s . c o m*/ cartId = jsonParams.getInt("cartId"); productId = jsonParams.getInt("productId"); } catch (JSONException e) { e.printStackTrace(); } // cartId = 1; // productId = -1; CheckoutQuoteItem quoteItemToDelete = null; CheckoutQuote checkoutQuote = new CheckoutQuote(); List<CheckoutQuoteItem> quoteItemsList = null; if (productId != -1) { quoteItemToDelete = this.checkoutQuoteItemService.getCheckoutQuoteItem(cartId, productId); quoteItemsList = new ArrayList<CheckoutQuoteItem>(); quoteItemsList.add(quoteItemToDelete); } else { quoteItemsList = this.checkoutQuoteItemService.listCheckoutQuoteItems(cartId); System.out.println("ABHI Quote Item List Count= " + quoteItemsList.size()); } checkoutQuote = this.checkoutQuoteService.getCheckoutQuoteById(cartId); for (int i = 0; i < quoteItemsList.size(); i++) { CheckoutQuoteItem currentQuoteItemToDelete = quoteItemsList.get(i); checkoutQuote.setItemsCount(checkoutQuote.getItemsCount() - 1); checkoutQuote .setItemsQuantity(checkoutQuote.getItemsQuantity() - currentQuoteItemToDelete.getQuantity()); checkoutQuote .setBaseSubtotal(checkoutQuote.getBaseSubtotal() - currentQuoteItemToDelete.getBaseRowTotal()); checkoutQuote.setSubtotal(checkoutQuote.getSubtotal() - currentQuoteItemToDelete.getRowTotal()); this.checkoutQuoteItemService.removeCheckoutQuoteItem(currentQuoteItemToDelete.getId()); } checkoutQuote.setBaseGrandTotal(checkoutQuote.getBaseSubtotal() + 50); checkoutQuote.setGrandTotal(checkoutQuote.getSubtotal() + 50); checkoutQuote.setUpdatedAt(Utilities.getCurrentDateTime()); System.out.println("Abhi checkoutquote after = " + checkoutQuote.toString()); int returnCartId = cartId; if (productId == -1) { this.checkoutQuoteService.removeCheckoutQuote(checkoutQuote.getId()); returnCartId = -1; } else { this.checkoutQuoteService.addCheckoutQuote(checkoutQuote); } JSONObject jsonObj = new JSONObject(); try { jsonObj.put("cartId", returnCartId); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return jsonObj.toString(); }
From source file:com.jvoid.quote.controller.JVoidQuoteController.java
@RequestMapping(value = "quote/addaddress", method = RequestMethod.GET) public @ResponseBody String addAddress(@RequestParam(required = false, value = "callback") String callback, @RequestParam(required = false, value = "params") JSONObject jsonParams, HttpServletResponse response) { int cartId = -1; JSONObject user = null;//from w ww .ja v a 2 s . c o m JSONObject billing = null; JSONObject shipping = null; String checkoutMethod = null; try { cartId = jsonParams.getInt("cartId"); user = jsonParams.getJSONObject("user"); billing = jsonParams.getJSONObject("billing"); shipping = jsonParams.getJSONObject("shipping"); checkoutMethod = jsonParams.getString("checkoutMethod"); } catch (JSONException e) { e.printStackTrace(); } CheckoutQuote checkoutQuote = this.checkoutQuoteService.getCheckoutQuoteById(cartId); checkoutQuote.setCheckoutMethod(checkoutMethod); checkoutQuote.setUpdatedAt(Utilities.getCurrentDateTime()); this.checkoutQuoteService.updateCheckoutQuote(checkoutQuote); try { CheckoutQuoteAddress checkoutQuoteAddress = new CheckoutQuoteAddress(); checkoutQuoteAddress.setQuoteId(cartId); checkoutQuoteAddress.setFirstname(user.getString("firstName")); checkoutQuoteAddress.setLastname(user.getString("lastName")); checkoutQuoteAddress.setCompany(user.getString("company")); checkoutQuoteAddress.setEmail(user.getString("emailAddress")); checkoutQuoteAddress.setAddressType("billing"); checkoutQuoteAddress .setStreet(billing.getString("address") + "," + billing.getString("streetAddress2")); checkoutQuoteAddress.setCity(billing.getString("city") + "," + billing.getString("state")); checkoutQuoteAddress.setCountryId(billing.getString("country")); checkoutQuoteAddress.setPostcode(billing.getString("zip")); checkoutQuoteAddress.setTelephone(billing.getString("telephone")); checkoutQuoteAddress.setFax(billing.getString("fax")); checkoutQuoteAddress.setCreatedAt(Utilities.getCurrentDateTime()); checkoutQuoteAddress.setUpdatedAt(Utilities.getCurrentDateTime()); this.checkoutQuoteAddressService.addCheckoutQuoteAddress(checkoutQuoteAddress); checkoutQuoteAddress = null; checkoutQuoteAddress = new CheckoutQuoteAddress(); checkoutQuoteAddress.setQuoteId(cartId); checkoutQuoteAddress.setFirstname(user.getString("firstName")); checkoutQuoteAddress.setLastname(user.getString("lastName")); checkoutQuoteAddress.setCompany(user.getString("company")); checkoutQuoteAddress.setEmail(user.getString("emailAddress")); checkoutQuoteAddress.setAddressType("shipping"); checkoutQuoteAddress .setStreet(shipping.getString("address") + "," + shipping.getString("streetAddress2")); checkoutQuoteAddress.setCity(shipping.getString("city") + "," + shipping.getString("state")); checkoutQuoteAddress.setCountryId(shipping.getString("country")); checkoutQuoteAddress.setPostcode(shipping.getString("zip")); checkoutQuoteAddress.setTelephone(shipping.getString("telephone")); checkoutQuoteAddress.setFax(shipping.getString("fax")); checkoutQuoteAddress.setCreatedAt(Utilities.getCurrentDateTime()); checkoutQuoteAddress.setUpdatedAt(Utilities.getCurrentDateTime()); this.checkoutQuoteAddressService.addCheckoutQuoteAddress(checkoutQuoteAddress); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } JSONObject jsonObj = new JSONObject(); try { jsonObj.put("cartId", cartId); jsonObj.put("result", "Success"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return jsonObj.toString(); }
From source file:org.b3log.latke.servlet.converter.Converters.java
@Override public Object convert(final Class<?> parameterType, final String paramterName, final HTTPRequestContext context, final MatchResult result, final int sequence) throws Exception { final JSONObject ret = new JSONObject(); final HttpServletRequest request = context.getRequest(); for (Object o : request.getParameterMap().keySet()) { ret.put(String.valueOf(o), request.getParameterMap().get(o)); }/* w w w. j a va 2 s . co m*/ // mapValue will cover for (String key : result.getMapValues().keySet()) { ret.put(key, result.getMapValues().get(key)); } return ret; }
From source file:com.intel.iotkitlib.LibModules.AccountManagement.java
private String createBodyForAddingUserToAccount(String accountId, String inviteeUserId, Boolean isAdmin) throws JSONException { JSONObject addUserJson = new JSONObject(); addUserJson.put("id", inviteeUserId); JSONObject accountsJson = new JSONObject(); if (isAdmin) { accountsJson.put(accountId, "admin"); } else {// w ww. j av a 2 s . c o m accountsJson.put(accountId, "user"); } addUserJson.put("accounts", accountsJson); return addUserJson.toString(); }
From source file:com.example.appengine.mailjet.MailjetServlet.java
@Override public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { String recipient = req.getParameter("to"); String sender = req.getParameter("from"); MailjetRequest email = new MailjetRequest(Email.resource).property(Email.FROMEMAIL, sender) .property(Email.FROMNAME, "pandora").property(Email.SUBJECT, "Your email flight plan!") .property(Email.TEXTPART, "Dear passenger, welcome to Mailjet! May the delivery force be with you!") .property(Email.HTMLPART,/*from w ww . ja v a 2 s . co m*/ "<h3>Dear passenger, welcome to Mailjet!</h3><br/>May the delivery force be with you!") .property(Email.RECIPIENTS, new JSONArray().put(new JSONObject().put("Email", recipient))); try { // trigger the API call MailjetResponse response = client.post(email); // Read the response data and status resp.getWriter().print(response.getStatus()); resp.getWriter().print(response.getData()); } catch (MailjetException e) { throw new ServletException("Mailjet Exception", e); } catch (MailjetSocketTimeoutException e) { throw new ServletException("Mailjet socket timed out", e); } }