List of usage examples for com.google.gson JsonElement getAsDouble
public double getAsDouble()
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 . ja v a2 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);// w w w. ja v a2 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 Offer retrieveOffer(int staffId, String token, int offerId) throws SQLException, ParseException, UnsupportedEncodingException, IOException { Offer offer = null;//w w w . j a v a2 s . com 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 w w w . j ava 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> 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);// w w w .j a v a2s. 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.WorkshopDAO.java
public Workshop retrieveWorkshop(String givenEmail, int staffId, String token) throws UnsupportedEncodingException, IOException { Workshop ws = null;/*from w w w .j a v a 2s .c om*/ String url = "http://119.81.43.85/erp/workshop/get_shop_by_id_or_email"; 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("email", givenEmail)); 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 shopElement = jobj.get("payload"); JsonObject shop = null; if (shopElement.isJsonNull()) { return ws; } else { shop = shopElement.getAsJsonObject().getAsJsonObject("shop"); JsonElement attElement = shop.get("id"); int id = 0; if (!attElement.isJsonNull()) { id = attElement.getAsInt(); } attElement = shop.get("name"); String name = ""; if (!attElement.isJsonNull()) { name = attElement.getAsString(); } attElement = shop.get("email"); String email = ""; if (!attElement.isJsonNull()) { email = attElement.getAsString(); } attElement = shop.get("description"); String description = ""; if (!attElement.isJsonNull()) { description = attElement.getAsString(); } attElement = shop.get("website"); String website = ""; if (!attElement.isJsonNull()) { website = attElement.getAsString(); } attElement = shop.get("address"); String address = ""; if (!attElement.isJsonNull()) { address = attElement.getAsString(); } attElement = shop.get("opening_hour_full"); String openingHour = ""; if (!attElement.isJsonNull()) { openingHour = attElement.getAsString(); } attElement = shop.get("opening_hour_format"); String openingHourFormat = ""; if (!attElement.isJsonNull()) { openingHourFormat = attElement.getAsString(); } attElement = shop.get("latitude"); double latitude = 0.0; if (!attElement.isJsonNull()) { latitude = attElement.getAsDouble(); } attElement = shop.get("longitude"); double longitude = 0.0; if (!attElement.isJsonNull()) { longitude = attElement.getAsDouble(); } attElement = shop.get("contact"); String contact = ""; if (!attElement.isJsonNull()) { contact = attElement.getAsString(); } attElement = shop.get("contact2"); String contact2 = ""; if (!attElement.isJsonNull()) { contact2 = attElement.getAsString(); } attElement = shop.get("location"); String location = ""; if (!attElement.isJsonNull()) { location = attElement.getAsString(); } attElement = shop.get("specialize"); String specialize = ""; if (!attElement.isJsonNull()) { specialize = attElement.getAsString(); } attElement = shop.get("category"); String category = ""; if (!attElement.isJsonNull()) { category = attElement.getAsString(); } attElement = shop.get("brand_carried"); String brandsCarried = ""; if (!attElement.isJsonNull()) { brandsCarried = attElement.getAsString(); } attElement = shop.get("remark"); String remark = ""; if (!attElement.isJsonNull()) { remark = attElement.getAsString(); } attElement = shop.get("status"); int status = 0; if (!attElement.isJsonNull()) { status = attElement.getAsInt(); } ws = new Workshop(id, email, name, description, website, address, openingHour, openingHourFormat, latitude, longitude, contact, contact2, location, specialize, category, brandsCarried, remark, status); } return ws; }
From source file:dao.WorkshopDAO.java
public Workshop retrieveWorkshop(int givenID, int staffId, String token) throws IOException { Workshop ws = null;// www .ja va2 s .c o m String url = "http://119.81.43.85/erp/workshop/get_shop_by_id_or_email"; 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("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); } String str = result.toString(); JsonParser jsonParser = new JsonParser(); JsonElement element = jsonParser.parse(str); JsonObject jobj = element.getAsJsonObject(); JsonElement shopElement = jobj.get("payload"); JsonObject shop = null; if (shopElement.isJsonNull()) { return ws; } else { shop = shopElement.getAsJsonObject().getAsJsonObject("shop"); JsonElement attElement = shop.get("id"); int id = 0; if (!attElement.isJsonNull()) { id = attElement.getAsInt(); } attElement = shop.get("name"); String name = ""; if (!attElement.isJsonNull()) { name = attElement.getAsString(); } attElement = shop.get("email"); String email = ""; if (!attElement.isJsonNull()) { email = attElement.getAsString(); } attElement = shop.get("description"); String description = ""; if (!attElement.isJsonNull()) { description = attElement.getAsString(); } attElement = shop.get("website"); String website = ""; if (!attElement.isJsonNull()) { website = attElement.getAsString(); } attElement = shop.get("address"); String address = ""; if (!attElement.isJsonNull()) { address = attElement.getAsString(); } attElement = shop.get("opening_hour_full"); String openingHour = ""; if (!attElement.isJsonNull()) { openingHour = attElement.getAsString(); } attElement = shop.get("opening_hour_format"); String openingHourFormat = ""; if (!attElement.isJsonNull()) { openingHourFormat = attElement.getAsString(); } attElement = shop.get("latitude"); double latitude = 0.0; if (!attElement.isJsonNull()) { latitude = attElement.getAsDouble(); } attElement = shop.get("longitude"); double longitude = 0.0; if (!attElement.isJsonNull()) { longitude = attElement.getAsDouble(); } attElement = shop.get("contact"); String contact = ""; if (!attElement.isJsonNull()) { contact = attElement.getAsString(); } attElement = shop.get("contact2"); String contact2 = ""; if (!attElement.isJsonNull()) { contact2 = attElement.getAsString(); } attElement = shop.get("location"); String location = ""; if (!attElement.isJsonNull()) { location = attElement.getAsString(); } attElement = shop.get("specialize"); String specialize = ""; if (!attElement.isJsonNull()) { specialize = attElement.getAsString(); } attElement = shop.get("category"); String category = ""; if (!attElement.isJsonNull()) { category = attElement.getAsString(); } attElement = shop.get("brand_carried"); String brandsCarried = ""; if (!attElement.isJsonNull()) { brandsCarried = attElement.getAsString(); } attElement = shop.get("remark"); String remark = ""; if (!attElement.isJsonNull()) { remark = attElement.getAsString(); } attElement = shop.get("status"); int status = 0; if (!attElement.isJsonNull()) { status = attElement.getAsInt(); } ws = new Workshop(id, email, name, description, website, address, openingHour, openingHourFormat, latitude, longitude, contact, contact2, location, specialize, category, brandsCarried, remark, status); } return ws; }
From source file:dao.WorkshopDAO.java
public ArrayList<Workshop> retrieveAllWorkshops(int staffId, String token) throws UnsupportedEncodingException, IOException { ArrayList<Workshop> allWorkshops = new ArrayList<Workshop>(); String url = "http://119.81.43.85/erp/workshop/get_all_shop"; 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 w w .j av a2 s . 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("shops"); for (int i = 0; i < arr.size(); i++) { JsonElement workshop = arr.get(i); JsonObject shop = workshop.getAsJsonObject(); JsonElement attElement = shop.get("id"); int id = 0; if (!attElement.isJsonNull()) { id = attElement.getAsInt(); } attElement = shop.get("name"); String name = ""; if (!attElement.isJsonNull()) { name = attElement.getAsString(); } attElement = shop.get("email"); String email = ""; if (!attElement.isJsonNull()) { email = attElement.getAsString(); } attElement = shop.get("description"); String description = ""; if (!attElement.isJsonNull()) { description = attElement.getAsString(); } attElement = shop.get("website"); String website = ""; if (!attElement.isJsonNull()) { website = attElement.getAsString(); } attElement = shop.get("address"); String address = ""; if (!attElement.isJsonNull()) { address = attElement.getAsString(); } attElement = shop.get("opening_hour_full"); String openingHour = ""; if (!attElement.isJsonNull()) { openingHour = attElement.getAsString(); } attElement = shop.get("opening_hour_format"); String openingHourFormat = ""; if (!attElement.isJsonNull()) { openingHourFormat = attElement.getAsString(); } attElement = shop.get("latitude"); double latitude = 0.0; if (!attElement.isJsonNull()) { latitude = attElement.getAsDouble(); } attElement = shop.get("longitude"); double longitude = 0.0; if (!attElement.isJsonNull()) { longitude = attElement.getAsDouble(); } attElement = shop.get("contact"); String contact = ""; if (!attElement.isJsonNull()) { contact = attElement.getAsString(); } attElement = shop.get("contact2"); String contact2 = ""; if (!attElement.isJsonNull()) { contact2 = attElement.getAsString(); } attElement = shop.get("location"); String location = ""; if (!attElement.isJsonNull()) { location = attElement.getAsString(); } attElement = shop.get("specialize"); String specialize = ""; if (!attElement.isJsonNull()) { specialize = attElement.getAsString(); } attElement = shop.get("category"); String category = ""; if (!attElement.isJsonNull()) { category = attElement.getAsString(); } attElement = shop.get("brand_carried"); String brandsCarried = ""; if (!attElement.isJsonNull()) { brandsCarried = attElement.getAsString(); } attElement = shop.get("remark"); String remark = ""; if (!attElement.isJsonNull()) { remark = attElement.getAsString(); } attElement = shop.get("status"); int status = 0; if (!attElement.isJsonNull()) { status = attElement.getAsInt(); } //int status = attElement.getAsInt(); Workshop ws = new Workshop(id, email, name, description, website, address, openingHour, openingHourFormat, latitude, longitude, contact, contact2, location, specialize, category, brandsCarried, remark, status); allWorkshops.add(ws); } return allWorkshops; }
From source file:de.azapps.mirakel.model.task.TaskDeserializer.java
License:Open Source License
@Override public Task deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException { final JsonObject el = json.getAsJsonObject(); Optional<ListMirakel> taskList = absent(); final JsonElement id = el.get("id"); if (id == null) { throw new JsonParseException("Json malformed"); }// www . j av a2s . co m final Task task = Task.get(id.getAsLong()).or(new Task()); // Name final Set<Entry<String, JsonElement>> entries = el.entrySet(); for (final Entry<String, JsonElement> entry : entries) { final String key = entry.getKey(); final JsonElement val = entry.getValue(); if ((key == null) || "id".equalsIgnoreCase(key)) { continue; } switch (key.toLowerCase()) { case "name": task.setName(val.getAsString()); break; case "content": String content = val.getAsString(); if (content == null) { content = ""; } task.setContent(content); break; case "priority": task.setPriority((int) val.getAsFloat()); break; case "progress": task.setProgress((int) val.getAsDouble()); break; case "list_id": taskList = ListMirakel.get(val.getAsInt()); if (!taskList.isPresent()) { taskList = fromNullable(SpecialList.firstSpecialSafe().getDefaultList()); } break; case "created_at": try { task.setCreatedAt(DateTimeHelper.parseDateTime(val.getAsString().replace(":", ""))); } catch (final ParseException e) { Log.wtf(TAG, "invalid dateformat: ", e); } break; case "updated_at": try { task.setUpdatedAt(DateTimeHelper.parseDateTime(val.getAsString().replace(":", ""))); } catch (final ParseException e) { Log.wtf(TAG, "invalid dateformat: ", e); } break; case "done": task.setDone(val.getAsBoolean()); break; case "due": try { task.setDue(of(DateTimeHelper.createLocalCalendar(val.getAsLong()))); } catch (final NumberFormatException ignored) { task.setDue(Optional.<Calendar>absent()); } break; case "reminder": try { task.setReminder(of(DateTimeHelper.createLocalCalendar(val.getAsLong()))); } catch (final NumberFormatException ignored) { task.setReminder(Optional.<Calendar>absent()); } break; case "tags": handleTags(task, val); break; case "sync_state": task.setSyncState(DefinitionsHelper.SYNC_STATE.valueOf((short) val.getAsFloat())); break; case "show_recurring": task.setIsRecurringShown(val.getAsBoolean()); break; default: handleAdditionalEntries(task, key, val); break; } } if (!taskList.isPresent()) { taskList = of(ListMirakel.safeFirst()); } task.setList(taskList.get(), true); return task; }
From source file:donky.microsoft.aspnet.signalr.client.transport.NegotiationResponse.java
License:Open Source License
/** * Initializes the negotiation response with Json data * //from www . j a va2 s . co m * @param jsonContent * Json data */ public NegotiationResponse(String jsonContent, JsonParser parser) { if (jsonContent == null || "".equals(jsonContent)) { return; } JsonObject json = parser.parse(jsonContent).getAsJsonObject(); setConnectionId(json.get("ConnectionId").getAsString()); setConnectionToken(json.get("ConnectionToken").getAsString()); setUrl(json.get("Url").getAsString()); setProtocolVersion(json.get("ProtocolVersion").getAsString()); setDisconnectTimeout(json.get("DisconnectTimeout").getAsDouble()); setTryWebSockets(json.get("TryWebSockets").getAsBoolean()); JsonElement keepAliveElement = json.get("KeepAliveTimeout"); if (keepAliveElement != null && !keepAliveElement.isJsonNull()) { setKeepAliveTimeout(keepAliveElement.getAsDouble()); } else { setKeepAliveTimeout(INVALID_KEEP_ALIVE_TIMEOUT); } }