Beispiel #1
0
  /**
   * Given the _id of a JSFile, return the file.
   *
   * @param id _id of the file to find
   * @return The file, if found, otherwise null
   */
  JSFile getJSFile(String id) {

    if (id == null) return null;

    DBCollection f = getDB().getCollection("_files");
    return (JSFile) (f.find(new ObjectId(id)));
  }
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    String deleteProductValue = "false";

    try {

      // Get the form data
      int productID = Integer.parseInt(request.getParameter("productID"));
      PrintWriter out = response.getWriter();
      DB db = mongo.getDB("FashionFactoryProd");
      DBCollection myProducts = db.getCollection("productInfo");
      DBCollection myTrending = db.getCollection("myTrending");
      BasicDBObject searchQuery = new BasicDBObject();
      searchQuery.put("productID", productID);
      DBCursor cursor = myProducts.find(searchQuery);

      if (cursor.count() == 0) {
        deleteProductValue = "false";
        request.setAttribute("deleteProductValue", deleteProductValue);
        RequestDispatcher rd = request.getRequestDispatcher("deleteProduct.jsp");
        rd.forward(request, response);
      } else {
        int product = 0;
        while (cursor.hasNext()) {

          BasicDBObject obj = (BasicDBObject) cursor.next();
          product = obj.getInt("productID");
          if (product == productID) {
            myProducts.remove(obj);
            myTrending.remove(searchQuery);
            deleteProductValue = "true";

            request.setAttribute("deleteProductValue", deleteProductValue);

            RequestDispatcher rd = request.getRequestDispatcher("deleteProduct.jsp");
            rd.forward(request, response);
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }