@Override protected TreeMap<Float, LotLocation> doInBackground(android.location.Location... location) { TreeMap<Float, LotLocation> locations = new TreeMap<Float, LotLocation>(); try { // null checking party ahead, majority stems form no connection, perhaps a connection // manager could centralize this if (location[0] != null) { android.location.Location currentLocation = location[0]; AmazonSimpleDBClient instance = SimpleDB.getInstance(); if (instance != null) { SelectResult result = instance.select( new SelectRequest("select * from `Locations` where active = '1' limit 50")); if (result != null) { for (Item lot : result.getItems()) { android.location.Location lotLocation = new android.location.Location(currentLocation.getProvider()); LotLocation internalLotLocation = new LotLocation(); internalLotLocation.setId(lot.getName()); // used to temporarily store hours of open and close for each location Hashtable<Integer, String> hoursOpen = new Hashtable<Integer, String>(); Hashtable<Integer, String> hoursClose = new Hashtable<Integer, String>(); for (Attribute attribute : lot.getAttributes()) { if (attribute.getName().equalsIgnoreCase("location")) internalLotLocation.setLocation(attribute.getValue()); if (attribute.getName().equalsIgnoreCase("rating")) internalLotLocation.setRating(Float.parseFloat(attribute.getValue())); if (attribute.getName().equalsIgnoreCase("business")) internalLotLocation.setBusiness(attribute.getValue()); if (attribute.getName().equalsIgnoreCase("description")) internalLotLocation.setDescription(attribute.getValue()); if (attribute.getName().equalsIgnoreCase("amex")) internalLotLocation.setAcceptsAmex( com.experiment.trax.utils.Boolean.valueOf(attribute.getValue())); if (attribute.getName().equalsIgnoreCase("visa")) internalLotLocation.setAcceptsVisa( com.experiment.trax.utils.Boolean.valueOf(attribute.getValue())); if (attribute.getName().equalsIgnoreCase("mastercard")) internalLotLocation.setAcceptsMastercard( com.experiment.trax.utils.Boolean.valueOf(attribute.getValue())); if (attribute.getName().equalsIgnoreCase("discover")) internalLotLocation.setAcceptsDiscover( com.experiment.trax.utils.Boolean.valueOf(attribute.getValue())); if (attribute.getName().equalsIgnoreCase("phone")) internalLotLocation.setPhone(attribute.getValue()); if (attribute.getName().equalsIgnoreCase("verified")) internalLotLocation.setVerified( com.experiment.trax.utils.Boolean.valueOf(attribute.getValue())); // create a key -> value to day of week and time opened or closed if (attribute.getName().equalsIgnoreCase("1_open")) hoursOpen.put(1, attribute.getValue()); if (attribute.getName().equalsIgnoreCase("1_close")) hoursClose.put(1, attribute.getValue()); if (attribute.getName().equalsIgnoreCase("2_open")) hoursOpen.put(2, attribute.getValue()); if (attribute.getName().equalsIgnoreCase("2_close")) hoursClose.put(2, attribute.getValue()); if (attribute.getName().equalsIgnoreCase("3_open")) hoursOpen.put(3, attribute.getValue()); if (attribute.getName().equalsIgnoreCase("3_close")) hoursClose.put(3, attribute.getValue()); if (attribute.getName().equalsIgnoreCase("4_open")) hoursOpen.put(4, attribute.getValue()); if (attribute.getName().equalsIgnoreCase("4_close")) hoursClose.put(4, attribute.getValue()); if (attribute.getName().equalsIgnoreCase("5_open")) hoursOpen.put(5, attribute.getValue()); if (attribute.getName().equalsIgnoreCase("5_close")) hoursClose.put(5, attribute.getValue()); if (attribute.getName().equalsIgnoreCase("6_open")) hoursOpen.put(6, attribute.getValue()); if (attribute.getName().equalsIgnoreCase("6_close")) hoursClose.put(6, attribute.getValue()); if (attribute.getName().equalsIgnoreCase("7_open")) hoursOpen.put(7, attribute.getValue()); if (attribute.getName().equalsIgnoreCase("7_close")) hoursClose.put(7, attribute.getValue()); if (attribute.getName().equalsIgnoreCase("lat")) lotLocation.setLatitude(Double.parseDouble(attribute.getValue())); if (attribute.getName().equalsIgnoreCase("lng")) lotLocation.setLongitude(Double.parseDouble(attribute.getValue())); } // store the times the lot is opened and closed internalLotLocation.setHoursOpen(hoursOpen); internalLotLocation.setHoursClose(hoursClose); // store the location of the lot internalLotLocation.setPoint( new LatLng(lotLocation.getLatitude(), lotLocation.getLongitude())); // save it to our locations listing to return back to the consumer locations.put(currentLocation.distanceTo(lotLocation), internalLotLocation); } } } } } catch (Exception e) { Log.e("GetLocationsTask", "Failure attempting to get locations", e); } return locations; }
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { address = PAConfiguration.getAddress(); port = PAConfiguration.getPort(instantiation); poslAddress = PAConfiguration.getPOSL(instantiation, topic); rdfAddress = PAConfiguration.getRDFTaxonomy(instantiation); messageEndpoint = PAConfiguration.getEndpointName(instantiation, topic); } catch (BadConfigurationException e) { System.out.println(e.getMessage()); e.printStackTrace(); System.exit(0); } response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); try { System.out.println("5 Publicty Chair Servlet"); System.out.println(response.toString()); BufferedReader brd = request.getReader(); String input = ""; String message = ""; while (!input.equals("</RuleML>")) { input = brd.readLine(); message = message + input; } String[] varOrder = getVariableOrder(message); System.out.println("Received Message: " + message); // BackwardReasoner br = new BackwardReasoner(); // Iterator solit =null; // DefiniteClause dc = null; // SymbolTable.reset(); POSLParser pp = new POSLParser(); // String contents = "c(a).\nc(b).\nc(c)."; Date t1 = new GregorianCalendar().getTime(); System.out.println(t1.getHours() + ":" + t1.getMinutes()); // append time to contents System.out.println("day: " + t1.getDay()); System.out.println("day: " + t1.getYear()); System.out.println("day: " + t1.getMonth()); // time String time = "time(" + t1.getHours() + ":integer)."; System.out.println(time); String url = poslAddress; // String url = "http://www.jdrew.org/oojdrew/test.posl"; String contents = ""; // day of the week int day = t1.getDay(); boolean weekday = true; if (day == 0 || day == 6) { weekday = false; } String dayOfWeek; if (weekday) { dayOfWeek = "day(weekday)."; } else { dayOfWeek = "day(weekend)."; } // full date Calendar cal = new GregorianCalendar(); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day2 = cal.get(Calendar.DAY_OF_MONTH); String date; String day3 = "" + day2; if (day2 == 1 || day2 == 2 || day2 == 3 || day2 == 4 || day2 == 5 || day2 == 6 || day2 == 7 || day2 == 8 || day2 == 9) { day3 = "0" + day2; } if (month == 10 || month == 11 || month == 12) date = "" + year + month + day3; else date = "" + year + "0" + month + day3; date = "date(" + date + ":integer)."; System.out.println(date); String url2 = rdfAddress; HttpClient client2 = new HttpClient(); GetMethod method2 = new GetMethod(url2); method2.setFollowRedirects(true); String typestr = ""; // Execute the GET method int statusCode2 = client2.executeMethod(method2); if (statusCode2 != -1) { typestr = method2.getResponseBodyAsString(); } System.out.println("Types: " + typestr); Types.reset(); RDFSParser.parseRDFSString(typestr); try { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(url); method.setFollowRedirects(true); // Execute the GET method int statusCode = client.executeMethod(method); if (statusCode != -1) { contents = method.getResponseBodyAsString(); } } catch (Exception e) { e.printStackTrace(); } contents = contents + "\n" + time; contents = contents + "\n" + dayOfWeek; contents = contents + "\n" + date; BackwardReasoner br = new BackwardReasoner(); Iterator solit = null; DefiniteClause dc = null; SymbolTable.reset(); pp.parseDefiniteClauses(contents); br.loadClauses(pp.iterator()); System.out.println("TEST"); Iterator it = pp.iterator(); while (it.hasNext()) { DefiniteClause d = (DefiniteClause) it.next(); System.out.println("Loaded clause: " + d.toPOSLString()); } br = new BackwardReasoner(br.clauses, br.oids); MessageParser m = new MessageParser(message); Element atom = null; try { atom = m.parseForContent(); } catch (Exception e) { System.out.println("Invalid Message"); // out.flush(); } QueryBuilder q = new QueryBuilder(atom); String query = q.generateDoc(); System.out.println("ABOUT TO INPUT THIS QUERY:" + query); RuleMLParser qp = new RuleMLParser(); try { dc = qp.parseRuleMLQuery(query); } catch (Exception e) { System.out.println("Invalid Query"); // out.flush(); } // solit = br.iterativeDepthFirstSolutionIterator(dc); solit = br.iterativeDepthFirstSolutionIterator(dc); int varSize = 0; while (solit.hasNext()) { Vector data = new Vector(); BackwardReasoner.GoalList gl = (BackwardReasoner.GoalList) solit.next(); Hashtable varbind = gl.varBindings; javax.swing.tree.DefaultMutableTreeNode root = br.toTree(); root.setAllowsChildren(true); javax.swing.tree.DefaultTreeModel dtm = new DefaultTreeModel(root); int i = 0; Object[][] rowdata = new Object[varbind.size()][2]; varSize = varbind.size(); Enumeration e = varbind.keys(); while (e.hasMoreElements()) { Object k = e.nextElement(); Object val = varbind.get(k); String ks = (String) k; rowdata[i][0] = ks; rowdata[i][1] = val; i++; } data.addElement(rowdata); String[] messages = new String[data.size()]; MessageGenerator g = new MessageGenerator( data, varSize, messageEndpoint, m.getId(), m.getProtocol(), m.getRel(), varOrder); messages = g.Messages2(); String appender = ""; URL sender = new URL(address + ":" + port); HttpMessage msg = new HttpMessage(sender); Properties props = new Properties(); for (int i1 = 0; i1 < data.size(); i1++) { System.out.println(i1 + ")" + messages[i1].toString()); props.put("text", messages[i1].toString()); InputStream in = msg.sendGetMessage(props); } System.out.println("NEXT MESSAGE"); } MessageGenerator g = new MessageGenerator( null, varSize, messageEndpoint, m.getId(), m.getProtocol(), m.getRel()); URL sender = new URL(address + ":" + port); HttpMessage msg = new HttpMessage(sender); Properties props = new Properties(); String finalMessage = g.finalMessage(query); System.out.println(finalMessage); props.put("text", finalMessage); InputStream in = msg.sendGetMessage(props); System.out.println("Stop_Communication"); } catch (Exception e) { System.out.println("ERROR has occured : " + e.toString()); } out.close(); }