Exemplo n.º 1
0
 /**
  * Put or replace an object value in the JSONArray. If the index is greater than the length of the
  * JSONArray, then null elements will be added as necessary to pad it out.
  *
  * @param index The subscript.
  * @param value The value to put into the array. The value should be a Boolean, Double, Integer,
  *     JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object.
  * @return this.
  * @throws JSONException If the index is negative or if the the value is an invalid number.
  */
 public JSONArray put(int index, Object value) throws JSONException {
   JSONObject.testValidity(value);
   if (index < 0) {
     throw new JSONException("JSONArray[" + index + "] not found.");
   }
   if (index < length()) {
     this.myArrayList.set(index, value);
   } else {
     while (index != length()) {
       put(JSONObject.NULL);
     }
     put(value);
   }
   return this;
 }
Exemplo n.º 2
0
  /** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    final DataTableRequestParam param = DataTablesParamUtility.getParam(request);

    String sEcho = param.sEcho;
    int iTotalRecords = 0; // total number of records (unfiltered)
    int iTotalDisplayRecords = 0; // value will be set when code filters companies by keyword
    // DBConnection dbconn = new DBConnection();
    ErateProducts erateProducts = new ErateProducts();
    HttpSession session = request.getSession();
    Connection conn = null;
    DBConn dbconn = new DBConn();
    if (conn == null) {
      conn = dbconn.open();
    }
    JSONArray data = new JSONArray(); // data that will be shown in the table
    try {
      iTotalRecords = erateProducts.getProductCount(conn);
    } catch (Exception e2) {
      // TODO Auto-generated catch block
      e2.printStackTrace();
    }
    // iTotalRecords = DataRepository.GetCompanies().size();
    // List<ProductDataDao> companies = new LinkedList<ProductDataDao>();
    List<ProductDataDao> companies = new LinkedList(Collections.nCopies(iTotalRecords, null));
    ProductDataDao dao = new ProductDataDao();
    System.out.println("company size" + DataRepository.GetCompanies().size());
    // for (int i=0;i<iTotalRecords;i++){
    // List arr ;

    boolean flag = false;
    String searchValue = param.sSearchKeyword.toLowerCase();
    //	System.out.println("testing search.."+param.sSearchKeyword.toLowerCase());
    USFEnv.getLog().writeDebug("testing search.." + param.sSearchKeyword.toLowerCase(), this, null);
    if (!searchValue.equals("")) {
      flag = true;

    } else {

    }
    String var = "NotInSearch";
    session.setAttribute("companySize", var);

    if (param.bSearchable[1] && flag) {
      try {
        dao = erateProducts.searchCRISProduct(param.sSearchKeyword.toLowerCase(), conn);

        if (dao.getProductCode() == null) {
          companies.clear();
        } else {
          session.removeAttribute("companySize");
          companies.clear();
          companies.add(dao);
          if (companies.size() > 0) {
            var = "inFilteredRecord";
            session.setAttribute("companySize", var);
          } else {
            var = "outSideFilteredRecord";
            session.setAttribute("companySize", var);
          }
          // session.setAttribute("companySize",companies.size());
        }
        //	iTotalDisplayRecords1 =companies.size();
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      if (dao.getProductCode() != null) {
        // boolean flag= true;
        // companies.add(dao);
      }
    }

    //	boolean flag = false;

    /*	if(	param.bSearchable[1])  {
    	try {
    		dao = dbconn.searchProduct(param.sSearchKeyword.toLowerCase());
    	} catch (Exception e) {
    		// TODO Auto-generated catch block
    		e.printStackTrace();
    	}
    	if(dao.getProductCode()!=null ){
    	boolean flag= true;
    	companies.add(dao);
    	}
    }*/
    //	param.sSearchKeyword.toLowerCase()
    // if(	param.bSearchable[1] &&
    //	c.getName().toLowerCase().contains(param.sSearchKeyword.toLowerCase())
    //	|| param.bSearchable[2] &&
    // c.getAddress().toLowerCase().contains(param.sSearchKeyword.toLowerCase())
    //	|| param.bSearchable[3] &&
    // c.getTown().toLowerCase().contains(param.sSearchKeyword.toLowerCase()))

    // }

    /*for(ProductDataDao c : iTotalRecords){
    	//Cannot search by column 0 (id)
    	if(	param.bSearchable[1] &&
    		c.getName().toLowerCase().contains(param.sSearchKeyword.toLowerCase())
    		||
    		param.bSearchable[2] &&
    		c.getAddress().toLowerCase().contains(param.sSearchKeyword.toLowerCase())
    		||
    		param.bSearchable[3] &&
    		c.getTown().toLowerCase().contains(param.sSearchKeyword.toLowerCase()))
    	{
    	//	companies.add(c); // Add a company that matches search criterion
    	}
    }*/

    try {
      iTotalDisplayRecords = erateProducts.getProductCount(conn);
      USFEnv.getLog().writeDebug("iTotalDisplayRecords" + iTotalDisplayRecords, this, null);
      //	System.out.println("iTotalDisplayRecords"+iTotalDisplayRecords);
    } catch (Exception e2) {
      // TODO Auto-generated catch block
      e2.printStackTrace();
    }
    // iTotalDisplayRecords = companies.size();//Number of companies that matches search criterion
    // should be returned
    USFEnv.getLog()
        .writeDebug(
            " before param.iDisplayStart"
                + param.iDisplayStart
                + "companies.size()"
                + companies.size(),
            this,
            null);

    //	System.out.println(" before
    // param.iDisplayStart"+param.iDisplayStart+"companies.size()"+companies.size());
    if (companies.size() < param.iDisplayStart + param.iDisplayLength) {

      companies = companies.subList(param.iDisplayStart, companies.size());
    } else {
      try {
        // System.out.println(" after
        // param.iDisplayStart"+param.iDisplayStart+"param.iDisplayLength"+param.iDisplayLength);
        companies =
            erateProducts.getProductInfo(
                param.iDisplayStart, param.iDisplayStart + param.iDisplayLength, conn);
        System.out.println("after");
        try {
          if (conn != null) {
            conn.close();
          }
        } catch (Exception e) {
          // TODO: handle exception
        }

      } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
    }
    // System.out.println(" after
    // param.iDisplayStart"+param.iDisplayStart+"param.iDisplayLength"+param.iDisplayLength);

    USFEnv.getLog()
        .writeDebug(
            " after param.iDisplayStart"
                + param.iDisplayStart
                + "param.iDisplayLength"
                + param.iDisplayLength,
            this,
            null);

    session.putValue("param.iDisplayStart", param.iDisplayStart);
    session.putValue("param.length", param.iDisplayStart + param.iDisplayLength);

    try {
      JSONObject jsonResponse = new JSONObject();

      jsonResponse.put("sEcho", sEcho);
      jsonResponse.put("iTotalRecords", iTotalRecords);
      jsonResponse.put("iTotalDisplayRecords", iTotalDisplayRecords);

      for (ProductDataDao c : companies) {
        JSONArray row = new JSONArray();
        row.put(c.getSeq_id())
            .put(c.getProductCode())
            .put(c.getDescription())
            .put(c.getModifiedBy())
            .put((new SimpleDateFormat("MM/dd/yyyy")).format((java.util.Date) c.getModifiedDate()));
        data.put(row);
      }
      jsonResponse.put("aaData", data);

      response.setContentType("application/json");
      response.getWriter().print(jsonResponse.toString());
    } catch (JSONException e) {
      e.printStackTrace();
      response.setContentType("text/html");
      response.getWriter().print(e.getMessage());
    } finally {
      try {
        conn.close();
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }
Exemplo n.º 3
0
 /**
  * Put a value in the JSONArray, where the value will be a JSONObject which is produced from a
  * Map.
  *
  * @param index The subscript.
  * @param value The Map value.
  * @return this.
  * @throws JSONException If the index is negative or if the the value is an invalid number.
  */
 public JSONArray put(int index, Map value) throws JSONException {
   put(index, new JSONObject(value));
   return this;
 }
Exemplo n.º 4
0
 /**
  * Put or replace an int value. If the index is greater than the length of the JSONArray, then
  * null elements will be added as necessary to pad it out.
  *
  * @param index The subscript.
  * @param value An int value.
  * @return this.
  * @throws JSONException If the index is negative.
  */
 public JSONArray put(int index, int value) throws JSONException {
   put(index, new Integer(value));
   return this;
 }
Exemplo n.º 5
0
 /**
  * Put or replace a long value. If the index is greater than the length of the JSONArray, then
  * null elements will be added as necessary to pad it out.
  *
  * @param index The subscript.
  * @param value A long value.
  * @return this.
  * @throws JSONException If the index is negative.
  */
 public JSONArray put(int index, long value) throws JSONException {
   put(index, new Long(value));
   return this;
 }
Exemplo n.º 6
0
 /**
  * Put a value in the JSONArray, where the value will be a JSONArray which is produced from a
  * Collection.
  *
  * @param index The subscript.
  * @param value A Collection value.
  * @return this.
  * @throws JSONException If the index is negative or if the value is not finite.
  */
 public JSONArray put(int index, Collection value) throws JSONException {
   put(index, new JSONArray(value));
   return this;
 }
Exemplo n.º 7
0
 /**
  * Put or replace a double value. If the index is greater than the length of the JSONArray, then
  * null elements will be added as necessary to pad it out.
  *
  * @param index The subscript.
  * @param value A double value.
  * @return this.
  * @throws JSONException If the index is negative or if the value is not finite.
  */
 public JSONArray put(int index, double value) throws JSONException {
   put(index, new Double(value));
   return this;
 }
Exemplo n.º 8
0
 /**
  * Put a value in the JSONArray, where the value will be a JSONObject which is produced from a
  * Map.
  *
  * @param value A Map value.
  * @return this.
  */
 public JSONArray put(Map value) {
   put(new JSONObject(value));
   return this;
 }
Exemplo n.º 9
0
 /**
  * Put or replace a boolean value in the JSONArray. If the index is greater than the length of the
  * JSONArray, then null elements will be added as necessary to pad it out.
  *
  * @param index The subscript.
  * @param value A boolean value.
  * @return this.
  * @throws JSONException If the index is negative.
  */
 public JSONArray put(int index, boolean value) throws JSONException {
   put(index, value ? Boolean.TRUE : Boolean.FALSE);
   return this;
 }
Exemplo n.º 10
0
 /**
  * Append an long value. This increases the array's length by one.
  *
  * @param value A long value.
  * @return this.
  */
 public JSONArray put(long value) {
   put(new Long(value));
   return this;
 }
Exemplo n.º 11
0
 /**
  * Append an int value. This increases the array's length by one.
  *
  * @param value An int value.
  * @return this.
  */
 public JSONArray put(int value) {
   put(new Integer(value));
   return this;
 }
Exemplo n.º 12
0
 /**
  * Append a double value. This increases the array's length by one.
  *
  * @param value A double value.
  * @throws JSONException if the value is not finite.
  * @return this.
  */
 public JSONArray put(double value) throws JSONException {
   Double d = new Double(value);
   JSONObject.testValidity(d);
   put(d);
   return this;
 }
Exemplo n.º 13
0
 /**
  * Put a value in the JSONArray, where the value will be a JSONArray which is produced from a
  * Collection.
  *
  * @param value A Collection value.
  * @return this.
  */
 public JSONArray put(Collection value) {
   put(new JSONArray(value));
   return this;
 }
Exemplo n.º 14
0
 /**
  * Append a boolean value. This increases the array's length by one.
  *
  * @param value A boolean value.
  * @return this.
  */
 public JSONArray put(boolean value) {
   put(value ? Boolean.TRUE : Boolean.FALSE);
   return this;
 }