List of usage examples for com.google.gson JsonElement getAsInt
public int getAsInt()
From source file:crawlers.Xinh.java
private static boolean saveImageByUrl(String urlGet, String tags) throws IOException { boolean isMore = false; List<AppImageEnt> listAppImageEnt = new ArrayList<AppImageEnt>(); JsonObject jsonObj = readJsonObjectFromUrl(urlGet); if (jsonObj != null) { JsonElement jsonElementErrorCode = jsonObj.get("ErrorCode"); if (jsonElementErrorCode != null && jsonElementErrorCode.getAsInt() == 0) { String jsonElementLoadMore = jsonObj.get("LoadMore").getAsString(); if (jsonElementLoadMore.equalsIgnoreCase("YES")) { isMore = true;// www. j a v a 2 s . c o m } JsonArray jsonElementData = jsonObj.get("DATA").getAsJsonArray(); if (jsonElementData != null && jsonElementData.size() > 0) { for (JsonElement tmpJson : jsonElementData) { JsonObject jsonItem = tmpJson.getAsJsonObject(); listAppImageEnt.add(new AppImageEnt(jsonItem, tags, AppImageEnt.STATUS.ENABLE)); } } DatabaseServiceUtils.InsertAppImageEnt(listAppImageEnt); } } return isMore; }
From source file:dao.ChatDAO.java
public HashMap<Integer, Chat> getChatList(int staffId, String token) throws UnsupportedEncodingException, IOException, ParseException { HashMap<Integer, Chat> chatList = new HashMap<Integer, Chat>(); //Add URL here String url = "http://119.81.43.85/chat/retrive_chat_list_history"; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); // add header post.setHeader("User-Agent", USER_AGENT); //Add parameters here List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("staff_id", staffId + "")); urlParameters.add(new BasicNameValuePair("token", token)); post.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) { result.append(line);//from www. j a v a 2 s. c o m } String str = result.toString(); JsonParser jsonParser = new JsonParser(); JsonElement element = jsonParser.parse(str); JsonObject jobj = element.getAsJsonObject(); JsonObject jobj2 = jobj.getAsJsonObject("payload"); JsonObject jobj3 = jobj2.getAsJsonObject("chat_history_list_result"); JsonArray arr = jobj3.getAsJsonArray("generalList"); int arrSize = arr.size(); for (int i = 0; i < arrSize; i++) { // for (int i = 0; i < arr.size(); i++) { JsonElement qrElement = arr.get(i); JsonObject qrObj = qrElement.getAsJsonObject(); JsonElement attElement = qrObj.get("id"); int id = 0; if (!attElement.isJsonNull()) { id = attElement.getAsInt(); } attElement = qrObj.get("service_id"); int service_id = 0; if (!attElement.isJsonNull()) { service_id = attElement.getAsInt(); } attElement = qrObj.get("user_id"); int user_id = 0; if (!attElement.isJsonNull()) { user_id = attElement.getAsInt(); } attElement = qrObj.get("shop_id"); int shop_id = 0; if (!attElement.isJsonNull()) { shop_id = attElement.getAsInt(); } attElement = qrObj.get("last_message"); String last_message = ""; if (!attElement.isJsonNull()) { last_message = attElement.getAsString(); } attElement = qrObj.get("modified"); Timestamp modified = null; String dateTimeString = "1990-01-01 00:00:00"; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Date parsedDate = dateFormat.parse(dateTimeString); modified = new java.sql.Timestamp(parsedDate.getTime()); if (attElement != null && !attElement.isJsonNull()) { dateTimeString = attElement.getAsString(); dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); parsedDate = dateFormat.parse(dateTimeString); modified = new java.sql.Timestamp(parsedDate.getTime()); } attElement = qrObj.get("created"); Timestamp created = null; dateTimeString = "1990-01-01 00:00:00"; dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); parsedDate = dateFormat.parse(dateTimeString); created = new java.sql.Timestamp(parsedDate.getTime()); if (attElement != null && !attElement.isJsonNull()) { dateTimeString = attElement.getAsString(); dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); parsedDate = dateFormat.parse(dateTimeString); created = new java.sql.Timestamp(parsedDate.getTime()); } attElement = qrObj.get("deleted_at"); Timestamp deleted_at = null; dateTimeString = "1990-01-01 00:00:00"; dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); parsedDate = dateFormat.parse(dateTimeString); deleted_at = new java.sql.Timestamp(parsedDate.getTime()); if (attElement != null && !attElement.isJsonNull()) { dateTimeString = attElement.getAsString(); dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); parsedDate = dateFormat.parse(dateTimeString); deleted_at = new java.sql.Timestamp(parsedDate.getTime()); } attElement = qrObj.get("user_name"); String user_name = ""; if (!attElement.isJsonNull()) { user_name = attElement.getAsString(); } Chat chat = new Chat(id, service_id, user_id, shop_id, last_message, modified, created, deleted_at, user_name); chatList.put(i, chat); } return chatList; }
From source file:dao.CustomerDAO.java
public Customer getCustomer(int givenId) throws UnsupportedEncodingException, IOException { //Add URL here String url = ""; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); // add header post.setHeader("User-Agent", USER_AGENT); //Add parameters here List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("", "")); urlParameters.add(new BasicNameValuePair("", "")); post.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) { result.append(line);/*from www .ja v a 2s.com*/ } String str = result.toString(); JsonParser jsonParser = new JsonParser(); JsonElement element = jsonParser.parse(str); JsonObject jobj = element.getAsJsonObject().getAsJsonObject("payload"); JsonElement attElement = jobj.get("id"); int id = attElement.getAsInt(); attElement = jobj.get("name"); String name = attElement.getAsString(); attElement = jobj.get("email"); String email = attElement.getAsString(); attElement = jobj.get("handphone"); String handphone = attElement.getAsString(); Customer customer = new Customer(id, name, email, handphone); return customer; }
From source file:dao.QuotationRequestDAO.java
public HashMap<Integer, QuotationRequest> retrieveQuotationRequest(int staffId, String token, int givenID) throws SQLException, ParseException, UnsupportedEncodingException, IOException { HashMap<Integer, QuotationRequest> allQuotationRequests = new HashMap<Integer, QuotationRequest>(); String url = "http://119.81.43.85/erp/quotation_request/get_quotation_request_info_by_service_id"; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); // add header post.setHeader("User-Agent", USER_AGENT); List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("staff_id", staffId + "")); urlParameters.add(new BasicNameValuePair("token", token)); urlParameters.add(new BasicNameValuePair("service_id", givenID + "")); post.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) { result.append(line);/*from w w w . j a va 2 s .co m*/ } String str = result.toString(); JsonParser jsonParser = new JsonParser(); JsonElement element = jsonParser.parse(str); JsonObject jobj = element.getAsJsonObject(); JsonArray arr = jobj.getAsJsonObject("payload").getAsJsonArray("quotation_request_info"); int arrSize = arr.size(); if (arrSize > 20) { arrSize = 20; } for (int i = 0; i < arrSize; i++) { // for (int i = 0; i < arr.size(); i++) { JsonElement qrElement = arr.get(i); JsonObject qrObj = qrElement.getAsJsonObject(); JsonElement attElement = qrObj.get("service_id"); int id = 0; if (!attElement.isJsonNull()) { id = attElement.getAsInt(); } attElement = qrObj.get("service_name"); String name = ""; if (!attElement.isJsonNull()) { name = attElement.getAsString(); } attElement = qrObj.get("service_details"); String details = ""; if (!attElement.isJsonNull()) { details = attElement.getAsString(); } attElement = qrObj.get("service_description"); String description = ""; if (!attElement.isJsonNull()) { description = attElement.getAsString(); } attElement = qrObj.get("service_mileage"); String mileage = ""; if (!attElement.isJsonNull()) { mileage = attElement.getAsString(); } attElement = qrObj.get("service_urgency"); String urgency = ""; if (!attElement.isJsonNull()) { urgency = attElement.getAsString(); } attElement = qrObj.get("service_address"); String address = ""; if (!attElement.isJsonNull()) { address = attElement.getAsString(); } attElement = qrObj.get("service_longitude"); double longitude = 0.0; if (!attElement.isJsonNull()) { longitude = attElement.getAsDouble(); } attElement = qrObj.get("service_latitude"); double latitude = 0.0; if (!attElement.isJsonNull()) { latitude = attElement.getAsDouble(); } attElement = qrObj.get("service_amenities"); String amenities = ""; if (!attElement.isJsonNull()) { amenities = attElement.getAsString(); } attElement = qrObj.get("service_photos"); String photos = ""; if (!attElement.isJsonNull()) { photos = attElement.getAsString(); } attElement = qrObj.get("offer_id"); int offerId = 0; if (attElement != null && !attElement.isJsonNull()) { offerId = attElement.getAsInt(); } attElement = qrObj.get("offer_status"); int offerStatus = 0; if (attElement != null && !attElement.isJsonNull()) { offerStatus = attElement.getAsInt(); } attElement = qrObj.get("quotation_min_price"); double initialMinPrice = 0.0; if (attElement != null && !attElement.isJsonNull()) { initialMinPrice = attElement.getAsDouble(); } attElement = qrObj.get("quotation_max_price"); double initialMaxPrice = 0.0; if (attElement != null && !attElement.isJsonNull()) { initialMaxPrice = attElement.getAsDouble(); } attElement = qrObj.get("diagnostic_price"); double diagnosticPrice = 0.0; if (attElement != null && !attElement.isJsonNull()) { diagnosticPrice = attElement.getAsDouble(); } attElement = qrObj.get("offer_final_price"); double finalQuotationPrice = 0.0; if (attElement != null && !attElement.isJsonNull()) { finalQuotationPrice = attElement.getAsDouble(); } attElement = qrObj.get("offer_est_complete_time"); Timestamp estCompletionDateTime = null; String dateTimeString = "1990-01-01 00:00:00"; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Date parsedDate = dateFormat.parse(dateTimeString); estCompletionDateTime = new java.sql.Timestamp(parsedDate.getTime()); if (attElement != null && !attElement.isJsonNull()) { dateTimeString = attElement.getAsString(); dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); parsedDate = dateFormat.parse(dateTimeString); estCompletionDateTime = new java.sql.Timestamp(parsedDate.getTime()); } attElement = qrObj.get("requested_datetime"); Timestamp requestDateTime = null; dateTimeString = "1990-01-01 00:00:00"; dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); parsedDate = dateFormat.parse(dateTimeString); requestDateTime = new java.sql.Timestamp(parsedDate.getTime()); if (!attElement.isJsonNull()) { dateTimeString = attElement.getAsString(); dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); parsedDate = dateFormat.parse(dateTimeString); requestDateTime = new java.sql.Timestamp(parsedDate.getTime()); } attElement = qrObj.get("shop_id"); int wsId = 0; if (attElement != null && !attElement.isJsonNull()) { wsId = attElement.getAsInt(); } attElement = qrObj.get("vehicle_id"); int vehicleId = 0; if (!attElement.isJsonNull()) { vehicleId = attElement.getAsInt(); } attElement = qrObj.get("car_make"); String carMake = ""; if (!attElement.isJsonNull()) { carMake = attElement.getAsString(); } attElement = qrObj.get("car_model"); String carModel = ""; if (!attElement.isJsonNull()) { carModel = attElement.getAsString(); } attElement = qrObj.get("car_year_manufactured"); int carYear = 0; if (!attElement.isJsonNull()) { carYear = attElement.getAsInt(); } attElement = qrObj.get("car_plate_number"); String carPlate = ""; if (!attElement.isJsonNull()) { carPlate = attElement.getAsString(); } attElement = qrObj.get("car_color"); String carColor = ""; if (!attElement.isJsonNull()) { carColor = attElement.getAsString(); } attElement = qrObj.get("car_type_of_control_of_car"); String carControl = ""; if (!attElement.isJsonNull()) { carControl = attElement.getAsString(); } attElement = qrObj.get("customer_id"); int customerId = 0; if (!attElement.isJsonNull()) { customerId = attElement.getAsInt(); } attElement = qrObj.get("customer_name"); String customerName = ""; if (!attElement.isJsonNull()) { customerName = attElement.getAsString(); } attElement = qrObj.get("customer_email"); String customerEmail = ""; if (!attElement.isJsonNull()) { customerEmail = attElement.getAsString(); } attElement = qrObj.get("customer_mobile_number"); String customerHpNo = ""; if (!attElement.isJsonNull()) { customerHpNo = attElement.getAsString(); } attElement = qrObj.get("service_category"); String category = ""; if (!attElement.isJsonNull()) { category = attElement.getAsString(); } attElement = qrObj.get("service_rejection_times"); int noOfRejections = 0; if (!attElement.isJsonNull()) { noOfRejections = attElement.getAsInt(); } Vehicle vehicle = new Vehicle(vehicleId, carMake, carModel, carYear, carPlate, customerId, carColor, carControl); Customer customer = new Customer(customerId, customerEmail, customerName, customerHpNo); Offer offer = new Offer(offerId, id, wsId, offerStatus, initialMinPrice, initialMaxPrice, diagnosticPrice, finalQuotationPrice, estCompletionDateTime); QuotationRequest qr = new QuotationRequest(id, name, details, description, vehicle, mileage, urgency, amenities, latitude, longitude, address, photos, requestDateTime, category, noOfRejections, wsId, customer, offer); allQuotationRequests.put(i, qr); } return allQuotationRequests; }
From source file:dao.QuotationRequestDAO.java
public HashMap<Integer, QuotationRequest> retrieveAllQuotationRequests(int staffId, String token, int givenWsId, int givenStatus, String orderBy, String order) throws SQLException, UnsupportedEncodingException, IOException, ParseException { HashMap<Integer, QuotationRequest> allQuotationRequests = new HashMap<Integer, QuotationRequest>(); String url = "http://119.81.43.85/erp/quotation_request/get_quotation_request_info"; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); // add header post.setHeader("User-Agent", USER_AGENT); List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("staff_id", staffId + "")); urlParameters.add(new BasicNameValuePair("token", token)); urlParameters.add(new BasicNameValuePair("workshop_id", givenWsId + "")); urlParameters.add(new BasicNameValuePair("status", givenStatus + "")); urlParameters.add(new BasicNameValuePair("order_by", orderBy)); urlParameters.add(new BasicNameValuePair("asc_of_desc", order)); post.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) { result.append(line);//from ww w . ja v a 2s . c om } String str = result.toString(); JsonParser jsonParser = new JsonParser(); JsonElement element = jsonParser.parse(str); JsonObject jobj = element.getAsJsonObject(); JsonArray arr = jobj.getAsJsonObject("payload").getAsJsonArray("quotation_request_info"); int arrSize = arr.size(); if (arrSize > 20) { arrSize = 20; } for (int i = 0; i < arrSize; i++) { // for (int i = 0; i < arr.size(); i++) { JsonElement qrElement = arr.get(i); JsonObject qrObj = qrElement.getAsJsonObject(); JsonElement attElement = qrObj.get("service_id"); int id = 0; if (!attElement.isJsonNull()) { id = attElement.getAsInt(); } attElement = qrObj.get("service_name"); String name = ""; if (!attElement.isJsonNull()) { name = attElement.getAsString(); } attElement = qrObj.get("service_details"); String details = ""; if (!attElement.isJsonNull()) { details = attElement.getAsString(); } attElement = qrObj.get("service_description"); String description = ""; if (!attElement.isJsonNull()) { description = attElement.getAsString(); } attElement = qrObj.get("service_mileage"); String mileage = ""; if (!attElement.isJsonNull()) { mileage = attElement.getAsString(); } attElement = qrObj.get("service_urgency"); String urgency = ""; if (!attElement.isJsonNull()) { urgency = attElement.getAsString(); } attElement = qrObj.get("service_address"); String address = ""; if (!attElement.isJsonNull()) { address = attElement.getAsString(); } attElement = qrObj.get("service_longitude"); double longitude = 0.0; if (!attElement.isJsonNull()) { longitude = attElement.getAsDouble(); } attElement = qrObj.get("service_latitude"); double latitude = 0.0; if (!attElement.isJsonNull()) { latitude = attElement.getAsDouble(); } attElement = qrObj.get("service_amenities"); String amenities = ""; if (!attElement.isJsonNull()) { amenities = attElement.getAsString(); } attElement = qrObj.get("service_photos"); String photos = ""; if (!attElement.isJsonNull()) { photos = attElement.getAsString(); } attElement = qrObj.get("offer_id"); int offerId = 0; if (attElement != null && !attElement.isJsonNull()) { offerId = attElement.getAsInt(); } attElement = qrObj.get("offer_status"); int offerStatus = 0; if (attElement != null && !attElement.isJsonNull()) { offerStatus = attElement.getAsInt(); } attElement = qrObj.get("quotation_min_price"); double initialMinPrice = 0.0; if (attElement != null && !attElement.isJsonNull()) { initialMinPrice = attElement.getAsDouble(); } attElement = qrObj.get("quotation_max_price"); double initialMaxPrice = 0.0; if (attElement != null && !attElement.isJsonNull()) { initialMaxPrice = attElement.getAsDouble(); } attElement = qrObj.get("diagnostic_price"); double diagnosticPrice = 0.0; if (attElement != null && !attElement.isJsonNull()) { diagnosticPrice = attElement.getAsDouble(); } attElement = qrObj.get("offer_final_price"); double finalQuotationPrice = 0.0; if (attElement != null && !attElement.isJsonNull()) { finalQuotationPrice = attElement.getAsDouble(); } attElement = qrObj.get("offer_est_complete_time"); Timestamp estCompletionDateTime = null; String dateTimeString = "1990-01-01 00:00:00"; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Date parsedDate = dateFormat.parse(dateTimeString); estCompletionDateTime = new java.sql.Timestamp(parsedDate.getTime()); if (attElement != null && !attElement.isJsonNull()) { dateTimeString = attElement.getAsString(); dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); parsedDate = dateFormat.parse(dateTimeString); estCompletionDateTime = new java.sql.Timestamp(parsedDate.getTime()); } attElement = qrObj.get("requested_datetime"); Timestamp requestDateTime = null; dateTimeString = "1990-01-01 00:00:00"; dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); parsedDate = dateFormat.parse(dateTimeString); requestDateTime = new java.sql.Timestamp(parsedDate.getTime()); if (!attElement.isJsonNull()) { dateTimeString = attElement.getAsString(); dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); parsedDate = dateFormat.parse(dateTimeString); requestDateTime = new java.sql.Timestamp(parsedDate.getTime()); } attElement = qrObj.get("shop_id"); int wsId = 0; if (attElement != null && !attElement.isJsonNull()) { wsId = attElement.getAsInt(); } attElement = qrObj.get("vehicle_id"); int vehicleId = 0; if (!attElement.isJsonNull()) { vehicleId = attElement.getAsInt(); } attElement = qrObj.get("car_make"); String carMake = ""; if (!attElement.isJsonNull()) { carMake = attElement.getAsString(); } attElement = qrObj.get("car_model"); String carModel = ""; if (!attElement.isJsonNull()) { carModel = attElement.getAsString(); } attElement = qrObj.get("car_year_manufactured"); int carYear = 0; if (!attElement.isJsonNull()) { carYear = attElement.getAsInt(); } attElement = qrObj.get("car_plate_number"); String carPlate = ""; if (!attElement.isJsonNull()) { carPlate = attElement.getAsString(); } attElement = qrObj.get("car_color"); String carColor = ""; if (!attElement.isJsonNull()) { carColor = attElement.getAsString(); } attElement = qrObj.get("car_type_of_control_of_car"); String carControl = ""; if (!attElement.isJsonNull()) { carControl = attElement.getAsString(); } attElement = qrObj.get("customer_id"); int customerId = 0; if (!attElement.isJsonNull()) { customerId = attElement.getAsInt(); } attElement = qrObj.get("customer_name"); String customerName = ""; if (!attElement.isJsonNull()) { customerName = attElement.getAsString(); } attElement = qrObj.get("customer_email"); String customerEmail = ""; if (!attElement.isJsonNull()) { customerEmail = attElement.getAsString(); } attElement = qrObj.get("customer_mobile_number"); String customerHpNo = ""; if (!attElement.isJsonNull()) { customerHpNo = attElement.getAsString(); } attElement = qrObj.get("service_category"); String category = ""; if (!attElement.isJsonNull()) { category = attElement.getAsString(); } attElement = qrObj.get("service_rejection_times"); int noOfRejections = 0; if (!attElement.isJsonNull()) { noOfRejections = attElement.getAsInt(); } Vehicle vehicle = new Vehicle(vehicleId, carMake, carModel, carYear, carPlate, customerId, carColor, carControl); Customer customer = new Customer(customerId, customerEmail, customerName, customerHpNo); Offer offer = new Offer(offerId, id, wsId, offerStatus, initialMinPrice, initialMaxPrice, diagnosticPrice, finalQuotationPrice, estCompletionDateTime); QuotationRequest qr = new QuotationRequest(id, name, details, description, vehicle, mileage, urgency, amenities, latitude, longitude, address, photos, requestDateTime, category, noOfRejections, wsId, customer, offer); allQuotationRequests.put(i, qr); } return allQuotationRequests; }
From source file:dao.QuotationRequestDAO.java
public Offer retrieveOffer(int staffId, String token, int offerId) throws SQLException, ParseException, UnsupportedEncodingException, IOException { Offer offer = null;//w w w. j av a 2s . c om String url = "http://119.81.43.85/quotation_request/retrieve_min_max_quotation_or_diagnostic_price"; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); // add header post.setHeader("User-Agent", USER_AGENT); List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("staff_id", staffId + "")); urlParameters.add(new BasicNameValuePair("token", token)); urlParameters.add(new BasicNameValuePair("offer_id", offerId + "")); post.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) { result.append(line); } String str = result.toString(); JsonParser jsonParser = new JsonParser(); JsonElement element = jsonParser.parse(str); JsonObject jobj = element.getAsJsonObject(); JsonElement oElement = jobj.get("payload"); JsonObject oObj = null; if (oElement.isJsonNull()) { return offer; } oObj = oElement.getAsJsonObject(); JsonElement attElement = oObj.get("service_id"); int serviceId = 0; if (!attElement.isJsonNull()) { serviceId = attElement.getAsInt(); } attElement = oObj.get("est_complete_time"); Timestamp estCompletionDateTime = null; String dateTimeString = "1990-01-01 00:00:00"; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Date parsedDate = dateFormat.parse(dateTimeString); estCompletionDateTime = new java.sql.Timestamp(parsedDate.getTime()); if (attElement != null && !attElement.isJsonNull()) { dateTimeString = attElement.getAsString(); dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); parsedDate = dateFormat.parse(dateTimeString); estCompletionDateTime = new java.sql.Timestamp(parsedDate.getTime()); } attElement = oObj.get("final_price"); double finalPrice = 0.0; if (!attElement.isJsonNull()) { finalPrice = attElement.getAsDouble(); } attElement = oObj.get("offer_status"); int status = 0; if (!attElement.isJsonNull()) { status = attElement.getAsInt(); } attElement = oObj.get("shop_id"); int wsId = 0; if (!attElement.isJsonNull()) { wsId = attElement.getAsInt(); } attElement = oObj.get("min_price"); double initialMinPrice = 0.0; if (attElement != null && !attElement.isJsonNull()) { initialMinPrice = attElement.getAsDouble(); } attElement = oObj.get("max_price"); double initialMaxPrice = 0.0; if (attElement != null && !attElement.isJsonNull()) { initialMaxPrice = attElement.getAsDouble(); } attElement = oObj.get("diagnostic_price"); double diagnosticPrice = 0.0; if (attElement != null && !attElement.isJsonNull()) { diagnosticPrice = attElement.getAsDouble(); } offer = new Offer(offerId, serviceId, wsId, status, initialMinPrice, initialMaxPrice, diagnosticPrice, finalPrice, estCompletionDateTime); return offer; }
From source file:dao.QuotationRequestDAO.java
public HashMap<Integer, QuotationRequest> retrieveQuotationRequestsWithoutOffer(int staffId, String token) throws SQLException, UnsupportedEncodingException, IOException, ParseException { HashMap<Integer, QuotationRequest> allQuotationRequests = new HashMap<Integer, QuotationRequest>(); String url = "http://119.81.43.85/erp/quotation_request/get_request_quotation_without_offer"; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); // add header post.setHeader("User-Agent", USER_AGENT); List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("staff_id", staffId + "")); urlParameters.add(new BasicNameValuePair("token", token)); post.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) { result.append(line);//from ww w. java 2s .c o m } String str = result.toString(); JsonParser jsonParser = new JsonParser(); JsonElement element = jsonParser.parse(str); JsonObject jobj = element.getAsJsonObject(); JsonArray arr = jobj.getAsJsonObject("payload").getAsJsonArray("quotation_request_info"); int arrSize = arr.size(); if (arrSize > 20) { arrSize = 20; } for (int i = 0; i < arrSize; i++) { // for (int i = 0; i < arr.size(); i++) { JsonElement qrElement = arr.get(i); JsonObject qrObj = qrElement.getAsJsonObject(); JsonElement attElement = qrObj.get("service_id"); int id = 0; if (!attElement.isJsonNull()) { id = attElement.getAsInt(); } attElement = qrObj.get("service_name"); String name = ""; if (!attElement.isJsonNull()) { name = attElement.getAsString(); } attElement = qrObj.get("service_details"); String details = ""; if (!attElement.isJsonNull()) { details = attElement.getAsString(); } attElement = qrObj.get("service_description"); String description = ""; if (!attElement.isJsonNull()) { description = attElement.getAsString(); } attElement = qrObj.get("service_mileage"); String mileage = ""; if (!attElement.isJsonNull()) { mileage = attElement.getAsString(); } attElement = qrObj.get("service_urgency"); String urgency = ""; if (!attElement.isJsonNull()) { urgency = attElement.getAsString(); } attElement = qrObj.get("service_address"); String address = ""; if (!attElement.isJsonNull()) { address = attElement.getAsString(); } attElement = qrObj.get("service_longitude"); double longitude = 0.0; if (!attElement.isJsonNull()) { longitude = attElement.getAsDouble(); } attElement = qrObj.get("service_latitude"); double latitude = 0.0; if (!attElement.isJsonNull()) { latitude = attElement.getAsDouble(); } attElement = qrObj.get("service_amenities"); String amenities = ""; if (!attElement.isJsonNull()) { amenities = attElement.getAsString(); } attElement = qrObj.get("service_photos"); String photos = ""; if (!attElement.isJsonNull()) { photos = attElement.getAsString(); } attElement = qrObj.get("offer_id"); int offerId = 0; if (attElement != null && !attElement.isJsonNull()) { offerId = attElement.getAsInt(); } attElement = qrObj.get("offer_status"); int offerStatus = 0; if (attElement != null && !attElement.isJsonNull()) { offerStatus = attElement.getAsInt(); } attElement = qrObj.get("quotation_min_price"); double initialMinPrice = 0.0; if (attElement != null && !attElement.isJsonNull()) { initialMinPrice = attElement.getAsDouble(); } attElement = qrObj.get("quotation_max_price"); double initialMaxPrice = 0.0; if (attElement != null && !attElement.isJsonNull()) { initialMaxPrice = attElement.getAsDouble(); } attElement = qrObj.get("diagnostic_price"); double diagnosticPrice = 0.0; if (attElement != null && !attElement.isJsonNull()) { diagnosticPrice = attElement.getAsDouble(); } attElement = qrObj.get("offer_final_price"); double finalQuotationPrice = 0.0; if (attElement != null && !attElement.isJsonNull()) { finalQuotationPrice = attElement.getAsDouble(); } attElement = qrObj.get("offer_est_complete_time"); Timestamp estCompletionDateTime = null; String dateTimeString = "1990-01-01 00:00:00"; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Date parsedDate = dateFormat.parse(dateTimeString); estCompletionDateTime = new java.sql.Timestamp(parsedDate.getTime()); if (attElement != null && !attElement.isJsonNull()) { dateTimeString = attElement.getAsString(); dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); parsedDate = dateFormat.parse(dateTimeString); estCompletionDateTime = new java.sql.Timestamp(parsedDate.getTime()); } attElement = qrObj.get("requested_datetime"); Timestamp requestDateTime = null; dateTimeString = "1990-01-01 00:00:00"; dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); parsedDate = dateFormat.parse(dateTimeString); requestDateTime = new java.sql.Timestamp(parsedDate.getTime()); if (!attElement.isJsonNull()) { dateTimeString = attElement.getAsString(); dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); parsedDate = dateFormat.parse(dateTimeString); requestDateTime = new java.sql.Timestamp(parsedDate.getTime()); } attElement = qrObj.get("shop_id"); int wsId = 0; if (attElement != null && !attElement.isJsonNull()) { wsId = attElement.getAsInt(); } attElement = qrObj.get("vehicle_id"); int vehicleId = 0; if (!attElement.isJsonNull()) { vehicleId = attElement.getAsInt(); } attElement = qrObj.get("car_make"); String carMake = ""; if (!attElement.isJsonNull()) { carMake = attElement.getAsString(); } attElement = qrObj.get("car_model"); String carModel = ""; if (!attElement.isJsonNull()) { carModel = attElement.getAsString(); } attElement = qrObj.get("car_year_manufactured"); int carYear = 0; if (!attElement.isJsonNull()) { carYear = attElement.getAsInt(); } attElement = qrObj.get("car_plate_number"); String carPlate = ""; if (!attElement.isJsonNull()) { carPlate = attElement.getAsString(); } attElement = qrObj.get("car_color"); String carColor = ""; if (!attElement.isJsonNull()) { carColor = attElement.getAsString(); } attElement = qrObj.get("car_type_of_control_of_car"); String carControl = ""; if (!attElement.isJsonNull()) { carControl = attElement.getAsString(); } attElement = qrObj.get("customer_id"); int customerId = 0; if (!attElement.isJsonNull()) { customerId = attElement.getAsInt(); } attElement = qrObj.get("customer_name"); String customerName = ""; if (!attElement.isJsonNull()) { customerName = attElement.getAsString(); } attElement = qrObj.get("customer_email"); String customerEmail = ""; if (!attElement.isJsonNull()) { customerEmail = attElement.getAsString(); } attElement = qrObj.get("customer_mobile_number"); String customerHpNo = ""; if (!attElement.isJsonNull()) { customerHpNo = attElement.getAsString(); } attElement = qrObj.get("service_category"); String category = ""; if (!attElement.isJsonNull()) { category = attElement.getAsString(); } attElement = qrObj.get("service_rejection_times"); int noOfRejections = 0; if (!attElement.isJsonNull()) { noOfRejections = attElement.getAsInt(); } Vehicle vehicle = new Vehicle(vehicleId, carMake, carModel, carYear, carPlate, customerId, carColor, carControl); Customer customer = new Customer(customerId, customerEmail, customerName, customerHpNo); Offer offer = new Offer(offerId, id, wsId, offerStatus, initialMinPrice, initialMaxPrice, diagnosticPrice, finalQuotationPrice, estCompletionDateTime); QuotationRequest qr = new QuotationRequest(id, name, details, description, vehicle, mileage, urgency, amenities, latitude, longitude, address, photos, requestDateTime, category, noOfRejections, wsId, customer, offer); allQuotationRequests.put(i, qr); } return allQuotationRequests; }
From source file:dao.QuotationRequestDAO.java
public HashMap<Integer, QuotationRequest> retrieveCompletedQuotationRequests(int staffId, String token) throws SQLException, UnsupportedEncodingException, IOException, ParseException { HashMap<Integer, QuotationRequest> allQuotationRequests = new HashMap<Integer, QuotationRequest>(); String url = "http://119.81.43.85/erp/quotation_request/get_completed_quotation_request"; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); // add header post.setHeader("User-Agent", USER_AGENT); List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("staff_id", staffId + "")); urlParameters.add(new BasicNameValuePair("token", token)); post.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) { result.append(line);//from w ww .j a va2s.c o m } String str = result.toString(); JsonParser jsonParser = new JsonParser(); JsonElement element = jsonParser.parse(str); JsonObject jobj = element.getAsJsonObject(); JsonArray arr = jobj.getAsJsonObject("payload").getAsJsonArray("quotation_request_info"); int arrSize = arr.size(); if (arrSize > 20) { arrSize = 20; } for (int i = 0; i < arrSize; i++) { // for (int i = 0; i < arr.size(); i++) { JsonElement qrElement = arr.get(i); JsonObject qrObj = qrElement.getAsJsonObject(); JsonElement attElement = qrObj.get("service_id"); int id = 0; if (!attElement.isJsonNull()) { id = attElement.getAsInt(); } attElement = qrObj.get("service_name"); String name = ""; if (!attElement.isJsonNull()) { name = attElement.getAsString(); } attElement = qrObj.get("service_details"); String details = ""; if (!attElement.isJsonNull()) { details = attElement.getAsString(); } attElement = qrObj.get("service_description"); String description = ""; if (!attElement.isJsonNull()) { description = attElement.getAsString(); } attElement = qrObj.get("service_mileage"); String mileage = ""; if (!attElement.isJsonNull()) { mileage = attElement.getAsString(); } attElement = qrObj.get("service_urgency"); String urgency = ""; if (!attElement.isJsonNull()) { urgency = attElement.getAsString(); } attElement = qrObj.get("service_address"); String address = ""; if (!attElement.isJsonNull()) { address = attElement.getAsString(); } attElement = qrObj.get("service_longitude"); double longitude = 0.0; if (!attElement.isJsonNull()) { longitude = attElement.getAsDouble(); } attElement = qrObj.get("service_latitude"); double latitude = 0.0; if (!attElement.isJsonNull()) { latitude = attElement.getAsDouble(); } attElement = qrObj.get("service_amenities"); String amenities = ""; if (!attElement.isJsonNull()) { amenities = attElement.getAsString(); } attElement = qrObj.get("service_photos"); String photos = ""; if (!attElement.isJsonNull()) { photos = attElement.getAsString(); } attElement = qrObj.get("offer_id"); int offerId = 0; if (attElement != null && !attElement.isJsonNull()) { offerId = attElement.getAsInt(); } attElement = qrObj.get("offer_status"); int offerStatus = 0; if (attElement != null && !attElement.isJsonNull()) { offerStatus = attElement.getAsInt(); } attElement = qrObj.get("quotation_min_price"); double initialMinPrice = 0.0; if (attElement != null && !attElement.isJsonNull()) { initialMinPrice = attElement.getAsDouble(); } attElement = qrObj.get("quotation_max_price"); double initialMaxPrice = 0.0; if (attElement != null && !attElement.isJsonNull()) { initialMaxPrice = attElement.getAsDouble(); } attElement = qrObj.get("diagnostic_price"); double diagnosticPrice = 0.0; if (attElement != null && !attElement.isJsonNull()) { diagnosticPrice = attElement.getAsDouble(); } attElement = qrObj.get("offer_final_price"); double finalQuotationPrice = 0.0; if (attElement != null && !attElement.isJsonNull()) { finalQuotationPrice = attElement.getAsDouble(); } attElement = qrObj.get("offer_est_complete_time"); Timestamp estCompletionDateTime = null; String dateTimeString = "1990-01-01 00:00:00"; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Date parsedDate = dateFormat.parse(dateTimeString); estCompletionDateTime = new java.sql.Timestamp(parsedDate.getTime()); if (attElement != null && !attElement.isJsonNull()) { dateTimeString = attElement.getAsString(); dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); parsedDate = dateFormat.parse(dateTimeString); estCompletionDateTime = new java.sql.Timestamp(parsedDate.getTime()); } attElement = qrObj.get("requested_datetime"); Timestamp requestDateTime = null; dateTimeString = "1990-01-01 00:00:00"; dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); parsedDate = dateFormat.parse(dateTimeString); requestDateTime = new java.sql.Timestamp(parsedDate.getTime()); if (!attElement.isJsonNull()) { dateTimeString = attElement.getAsString(); dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); parsedDate = dateFormat.parse(dateTimeString); requestDateTime = new java.sql.Timestamp(parsedDate.getTime()); } attElement = qrObj.get("shop_id"); int wsId = 0; if (attElement != null && !attElement.isJsonNull()) { wsId = attElement.getAsInt(); } attElement = qrObj.get("vehicle_id"); int vehicleId = 0; if (!attElement.isJsonNull()) { vehicleId = attElement.getAsInt(); } attElement = qrObj.get("car_make"); String carMake = ""; if (!attElement.isJsonNull()) { carMake = attElement.getAsString(); } attElement = qrObj.get("car_model"); String carModel = ""; if (!attElement.isJsonNull()) { carModel = attElement.getAsString(); } attElement = qrObj.get("car_year_manufactured"); int carYear = 0; if (!attElement.isJsonNull()) { carYear = attElement.getAsInt(); } attElement = qrObj.get("car_plate_number"); String carPlate = ""; if (!attElement.isJsonNull()) { carPlate = attElement.getAsString(); } attElement = qrObj.get("car_color"); String carColor = ""; if (!attElement.isJsonNull()) { carColor = attElement.getAsString(); } attElement = qrObj.get("car_type_of_control_of_car"); String carControl = ""; if (!attElement.isJsonNull()) { carControl = attElement.getAsString(); } attElement = qrObj.get("customer_id"); int customerId = 0; if (!attElement.isJsonNull()) { customerId = attElement.getAsInt(); } attElement = qrObj.get("customer_name"); String customerName = ""; if (!attElement.isJsonNull()) { customerName = attElement.getAsString(); } attElement = qrObj.get("customer_email"); String customerEmail = ""; if (!attElement.isJsonNull()) { customerEmail = attElement.getAsString(); } attElement = qrObj.get("customer_mobile_number"); String customerHpNo = ""; if (!attElement.isJsonNull()) { customerHpNo = attElement.getAsString(); } attElement = qrObj.get("service_category"); String category = ""; if (!attElement.isJsonNull()) { category = attElement.getAsString(); } attElement = qrObj.get("service_rejection_times"); int noOfRejections = 0; if (!attElement.isJsonNull()) { noOfRejections = attElement.getAsInt(); } Vehicle vehicle = new Vehicle(vehicleId, carMake, carModel, carYear, carPlate, customerId, carColor, carControl); Customer customer = new Customer(customerId, customerEmail, customerName, customerHpNo); Offer offer = new Offer(offerId, id, wsId, offerStatus, initialMinPrice, initialMaxPrice, diagnosticPrice, finalQuotationPrice, estCompletionDateTime); QuotationRequest qr = new QuotationRequest(id, name, details, description, vehicle, mileage, urgency, amenities, latitude, longitude, address, photos, requestDateTime, category, noOfRejections, wsId, customer, offer); allQuotationRequests.put(i, qr); } return allQuotationRequests; }
From source file:dao.ScheduleDAO.java
public HashMap<Integer, Schedule> retrieveSchedule(int staffId, String token, int shopId, int month, int year) throws UnsupportedEncodingException, IOException, ParseException { HashMap<Integer, Schedule> monthlySchedule = new HashMap<Integer, Schedule>(); String url = "http://119.81.43.85/erp/schedule/retrieve_schedule"; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); // add header post.setHeader("User-Agent", USER_AGENT); List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("staff_id", staffId + "")); urlParameters.add(new BasicNameValuePair("token", token)); urlParameters.add(new BasicNameValuePair("shop_id", shopId + "")); urlParameters.add(new BasicNameValuePair("month", month + "")); urlParameters.add(new BasicNameValuePair("year", year + "")); post.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) { result.append(line);//from w ww .j ava 2s. c o m } String str = result.toString(); JsonParser jsonParser = new JsonParser(); JsonElement element = jsonParser.parse(str); JsonObject jobj = element.getAsJsonObject(); JsonArray arr = jobj.getAsJsonObject("payload").getAsJsonArray("schedule"); for (int i = 0; i < arr.size(); i++) { JsonElement qrElement = arr.get(i); JsonObject obj = qrElement.getAsJsonObject(); JsonElement attElement = obj.get("id"); int id = 0; if (!attElement.isJsonNull()) { id = attElement.getAsInt(); } attElement = obj.get("service_id"); int serviceId = 0; if (!attElement.isJsonNull()) { serviceId = attElement.getAsInt(); } attElement = obj.get("start_time"); Timestamp startTime = null; String dateTimeString = "1990-01-01 00:00:00"; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Date parsedDate = dateFormat.parse(dateTimeString); startTime = new java.sql.Timestamp(parsedDate.getTime()); if (attElement != null && !attElement.isJsonNull()) { dateTimeString = attElement.getAsString(); dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); parsedDate = dateFormat.parse(dateTimeString); startTime = new java.sql.Timestamp(parsedDate.getTime()); } attElement = obj.get("end_time"); Timestamp endTime = null; dateTimeString = "1990-01-01 00:00:00"; dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); parsedDate = dateFormat.parse(dateTimeString); endTime = new java.sql.Timestamp(parsedDate.getTime()); if (!attElement.isJsonNull()) { dateTimeString = attElement.getAsString(); dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); parsedDate = dateFormat.parse(dateTimeString); endTime = new java.sql.Timestamp(parsedDate.getTime()); } Schedule schedule = new Schedule(id, serviceId, shopId, startTime, endTime); monthlySchedule.put(i, schedule); } return monthlySchedule; }
From source file:dao.VehicleDAO.java
public Vehicle getVehicle(int staffId, String token, int givenId) throws UnsupportedEncodingException, IOException { //Add URL here String url = "http://119.81.43.85/erp/vehicle/get_vehicle_by_id"; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); // add header post.setHeader("User-Agent", USER_AGENT); //Add parameters here List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("staff_id", staffId + "")); urlParameters.add(new BasicNameValuePair("token", token)); urlParameters.add(new BasicNameValuePair("id", givenId + "")); post.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) { result.append(line);/*from w w w. j a va 2 s . c om*/ } String str = result.toString(); JsonParser jsonParser = new JsonParser(); JsonElement element = jsonParser.parse(str); JsonObject jobj = element.getAsJsonObject(); JsonElement isSuccess = jobj.get("is_success"); Vehicle vehicle = null; if (isSuccess.getAsString().equals("false")) { return vehicle; } else { jobj = element.getAsJsonObject().getAsJsonObject("payload").getAsJsonObject("vehicle"); JsonElement attElement = jobj.get("id"); int id = attElement.getAsInt(); attElement = jobj.get("make"); String make = attElement.getAsString(); attElement = jobj.get("model"); String model = attElement.getAsString(); attElement = jobj.get("year"); int year = attElement.getAsInt(); attElement = jobj.get("plate_number"); String plateNumber = attElement.getAsString(); attElement = jobj.get("user_id"); int customerID = attElement.getAsInt(); attElement = jobj.get("car_color"); String color = attElement.getAsString(); attElement = jobj.get("type_of_control_of_car"); String control = attElement.getAsString(); vehicle = new Vehicle(id, make, model, year, plateNumber, customerID, color, control); return vehicle; } }