Example #1
0
  public static void main(String[] args) {
    // Reads the item file
    Document item = null;
    if (args.length >= 1 && validFilename(args[0])) {
      item = XMLHandler.addDoc(args[0]);
    }
    if (item == null) {
      return;
    }

    // Gets the name of the item from the item file
    Element itemName = item.getRootElement().getChild("itemName", n).clone();

    // Creates a createItem with a shopKey and the itemName from before
    Document createItem = XMLHandler.createItem(itemName);

    // Connects to the cloud
    HttpURLConnection con = handler.connect("/createItem");

    // Sends the createItem to the cloud and gets the itemID
    Document itemID =
        handler.getResponse(con, createItem, XMLHandler.getOutputter(), XMLHandler.getSAXBuilder());

    // Creates a modifyItem with most of the elements from the item + the
    // itemID
    Document modifyItem =
        XMLHandler.modifyItem(itemID.getRootElement().clone(), item.getRootElement().clone());

    // Connects to the cloud
    con = handler.connect("/modifyItem");

    // Sends the modifyItem to the cloud
    handler.getResponse(con, modifyItem, XMLHandler.getOutputter(), XMLHandler.getSAXBuilder());

    // SUCCESS!!!!
    System.out.println("SUCCESS!!!!");
  }
Example #2
0
  @POST
  @Path("update")
  public String updateBasket(@FormParam("itemList") String itemList) {

    // Correct to some condition that checks login!
    if (session.getAttribute("id") == null || ((String) session.getAttribute("id")).equals("")) {

      return "Not logged in!";
    }

    String res = "";

    JSONArray jsonArray = new JSONArray(itemList);

    for (int i = 0; i < jsonArray.length(); i++) {
      JSONObject o = (JSONObject) jsonArray.get(i);

      String itemID = (String) o.get("itemID");
      String amount = (String) o.get("amount");

      String customerID = (String) session.getAttribute("id");

      Document buydoc = XMLHandler.buyItem(itemID, amount, customerID);

      HttpURLConnection con = cloudHandler.connect(true, "/sellItems");
      Document responseDoc =
          cloudHandler.getResponse(
              true, con, buydoc, XMLHandler.getOutputter(), XMLHandler.getSAXBuilder());

      java.util.List<Element> children = responseDoc.getRootElement().getChildren();

      if (children.get(0).getName().equals("ok")) {

        res += "Succæ ve' " + itemID + "\n";

      } else if (children.get(0).getName().equals("itemSoldOut")) {

        res += "Der æ' fler tilbage a' " + itemID + " tilbage \n";

      } else {

        res += "Dar sket' a fej wæ" + itemID + "\n";
      }
    }
    return res;
  }