public static void authenticate(String username, String password) { Logger.info("Attempting to authenticate with " + username + ":" + password); Admin admin = Admin.findByUsername(username); if ((admin != null) && (admin.checkPassword(password) == true)) { Logger.info("Successfull authentication of " + admin.username); /** * wanted to put an extra value in session - logged_in_adminid to distinguish an admin, as a * user could be logged in and type the route for admin URLs and get into the restricted * access areas. By putting a new value in session, it can only be set if an admin is logged * in. */ session.put("logged_in_adminid", admin.id); /** * if login successful, communicate back to AJAX call in adminlogin.js and that will handle * the next screen */ JSONObject obj = new JSONObject(); String value = "correct"; obj.put("inputdata", value); renderJSON(obj); } else { /** * if login unsuccessful, communicate back to AJAX call in adminlogin.js and that will * redisplay login.html with error */ Logger.info("Authentication failed"); JSONObject obj = new JSONObject(); String value = "Error: Incorrect Email/Password entered."; obj.put("inputdata", value); renderJSON(obj); } }
public static void closeConnection() { if (twitter != null) { Logger.info("Closing down Twitter stream..."); twitter.cleanUp(); if (esClient != null) esClient.close(); } else { Logger.info("No twitter stream found"); } }
public TweetListener(List<String> terms, Client esClient, String esIndex, String esType) { this.terms = terms; this.esClient = esClient; StringBuilder query = new StringBuilder(); for (int i = 0; i < terms.size(); i++) { if (i > 0) query.append("|"); // query.append("(").append(Pattern.quote(terms.get(i))).append(")"); // query.append("(").append(terms.get(i)).append(")"); query.append(terms.get(i)); } Logger.info("Query match pattern: " + query.toString()); this.matchPattern = Pattern.compile(query.toString(), Pattern.CASE_INSENSITIVE); Logger.info("Query match pattern: " + matchPattern.toString()); }
private static void startStream(List<String> terms) throws TwitterException { if (twitter != null) { twitter.cleanUp(); } if (esClient != null) { esClient.close(); esClient = null; } play.Configuration pconf = Play.application().configuration(); String elasticSearchCluster = pconf.getString("tweet.elasticsearch.cluster.name"); if (elasticSearchCluster != null) { Logger.info("Configuring ElasticSearch..."); Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", elasticSearchCluster).build(); esClient = new TransportClient(settings) .addTransportAddress( new InetSocketTransportAddress( pconf.getString("tweet.elasticsearch.transport.host"), pconf.getInt("tweet.elasticsearch.transport.port"))); } else { esClient = null; } twitter4j.conf.Configuration tconf = Application.getTwitterConfiguration(); TwitterStreamFactory tf = new TwitterStreamFactory(tconf); twitter = tf.getInstance(); StatusListener l = new TweetListener( terms, esClient, pconf.getString("tweet.elasticsearch.index"), pconf.getString("tweet.elasticsearch.type")); twitter.addListener(l); String[] tracks = new String[terms.size()]; StringBuffer termsString = new StringBuffer(); for (int i = 0; i < terms.size(); i++) { tracks[i] = terms.get(i); if (i != 0) termsString.append(","); termsString.append(terms.get(i)); } FilterQuery q = new FilterQuery().track(tracks); twitter.filter(q); Logger.info("Starting listening for tweets using terms " + termsString.toString() + "..."); }
public static Result start() { java.util.Map<String, String[]> map = request().body().asFormUrlEncoded(); List<String> terms = new ArrayList<>(map.size()); for (int i = 0; i < map.size(); i++) { String key = "terms[" + i + "]"; if (map.containsKey(key)) { String[] values = map.get(key); if ((values != null) && (values.length >= 1)) { terms.add(values[0]); } } } StreamConfig config = getConfig(); config.putTerms(terms); config.update(); StringBuilder sb = new StringBuilder(); for (String t : terms) { sb.append(t); sb.append(", "); } sb.delete(sb.length() - 2, sb.length()); try { startStream(terms); flash("success", "Twitter stream started (" + sb.toString() + ")"); } catch (TwitterException e) { Logger.info("Error starting twitter stream", e); flash("error", "Error starting Twitter stream" + e.getMessage()); } return redirect(routes.Streams.listAll()); }
public static void map() throws InterruptedException { Application.mapListeners.addListener(); Logger.info("connecting ws."); while (inbound.isOpen()) { String event = await(MapEvent.instance.event.nextEvent()); outbound.send(event); } Logger.info("disconnecting ws."); Application.mapListeners.removeListener(); }
public static void startConnection() { StreamConfig config = getConfig(); try { startStream(config.listTerms()); } catch (TwitterException e) { Logger.info("Error starting twitter stream", e); } }
public static void fbLogin() { String token = params.get("token"); if (null != token && !token.isEmpty()) { FacebookClient fb = new DefaultFacebookClient(token); User fbUser = fb.fetchObject("me", User.class); Logger.info("Facebook User:"******"Such a user does not exists. Create/Register one..."); // Register a new... // Email uniqueness is controlled by Facebook I suppose, so no need to check on our side... sesUser = new SUser(fbUser.getName(), fbUser.getEmail()); sesUser.fbId = fbUser.getId(); sesUser.save(); } Auth.fbLogin(token, sesUser); } else { redirect("/"); } }
public static void postDate(String code, String userId, int rank) { Logger.info(code); Logger.info(userId); Logger.info("" + rank); if (code.equals(Business.BUSINESS)) { Business b = Business.findById(userId); b.rank = rank; b.save(); } else if (code.equals(Developer.DEVELOPER)) { Developer d = Developer.findById(userId); d.rank = rank; d.save(); } else if (code.equals(Creativo.CREATIVO)) { Creativo c = Creativo.findById(userId); c.rank = rank; c.save(); } render(); }
public static Admin getCurrentAdmin() { /** * get currently logged in admin for Candidate (CandidateController.java) + Office * (OfficeController.java) constructors via new logged_in_adminid written to session on admin * login */ String adminId = session.get("logged_in_adminid"); if (adminId == null) { return null; } Admin logged_in_admin = Admin.findById(Long.parseLong(adminId)); Logger.info("In Admin controller: Logged in admin is " + logged_in_admin.username); return logged_in_admin; }
public void onStatus(twitter4j.Status status) { Logger.info(status.getUser().getName() + " : " + status.getText()); Tweet tweet = new Tweet(status); tweet.conformsToTerms = checkMatch(status); tweet.save(); if (tweet.conformsToTerms && esClient != null) { String json = DataObjectFactory.getRawJSON(status); json = json.replaceAll( "(\"geo\":\\{\"type\":\"Point\",\"coordinates\":)\\[([-0-9.,]*)\\]", "$1\"$2\""); // Logger.debug("geo mangled json"); // Logger.debug(json); IndexResponse response = esClient.prepareIndex("twitter", "tweet").setSource(json).execute().actionGet(); } }
public static Result download() { Exporter exporter = new Exporter("/tmp/tweets.xlsx"); List<Tweet> tweets = Tweet.find.all(); try { for (Tweet t : tweets) { SimpleTweet simple = new SimpleTweet(); simple.id = t.id; simple.createdAt = t.date; simple.userName = t.fromUser; simple.userId = t.fromUserId; simple.text = t.text; simple.inReplyToName = t.inReplyTo; simple.latitude = t.latitude; simple.longitude = t.longitude; exporter.addTweet(simple); } exporter.write(); } catch (FileNotFoundException e) { flash("error", "Bestand niet gevonden"); Logger.info("Bestand niet gevonden", e); return ok("Exception opening file"); } // try { response().setContentType("application/x-download"); response().setHeader("Content-disposition", "attachment; filename=tweets.xlsx"); return ok(new File("/tmp/tweets.xlsx")); /* } catch (IOException e) { Logger.info("Exception sending zipfile", e); return ok("Exception opening file"); */ // } }
public void onTrackLimitationNotice(int numberOfLimitedStatuses) { Logger.info("Track limitation, missed " + numberOfLimitedStatuses); }
public void onStallWarning(StallWarning warning) { Logger.info("Stall warning"); }
public void onScrubGeo(long userId, long upToStatusId) { Logger.info("Scrub geo"); }
public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { Logger.info("Deletion notice"); }
public static void upload(String imei, File data) { try { File pbFile = new File( Play.configuration.getProperty("application.uploadDataDirectory"), imei + "_" + new Date().getTime() + ".pb"); Logger.info(pbFile.toString()); data.renameTo(pbFile); byte[] dataFrame = new byte[(int) pbFile.length()]; ; DataInputStream dataInputStream = new DataInputStream(new BufferedInputStream(new FileInputStream(pbFile))); dataInputStream.read(dataFrame); Upload upload = Upload.parseFrom(dataFrame); Phone phone = Phone.find("imei = ?", imei).first(); if (phone == null) badRequest(); for (Upload.Route r : upload.getRouteList()) { if (r.getPointList().size() <= 1) continue; Agency a = Agency.find("gtfsAgencyId = ?", "DEFAULT").first(); Route route = new Route("", r.getRouteName(), RouteType.BUS, r.getRouteDescription(), a); route.phone = phone; route.routeNotes = r.getRouteNotes(); route.vehicleCapacity = r.getVehicleCapacity(); route.vehicleType = r.getVehicleType(); route.captureTime = new Date(r.getStartTime()); route.save(); List<String> points = new ArrayList<String>(); Integer pointSequence = 1; for (Upload.Route.Point p : r.getPointList()) { points.add(new Double(p.getLon()).toString() + " " + new Double(p.getLat()).toString()); RoutePoint.addRoutePoint(p, route.id, pointSequence); pointSequence++; } String linestring = "LINESTRING(" + StringUtils.join(points, ", ") + ")"; BigInteger tripShapeId = TripShape.nativeInsert(TripShape.em(), "", linestring, 0.0); TripPattern tp = new TripPattern(); tp.route = route; tp.headsign = r.getRouteName(); tp.shape = TripShape.findById(tripShapeId.longValue()); tp.save(); Integer sequenceId = 0; for (Upload.Route.Stop s : r.getStopList()) { BigInteger stopId = Stop.nativeInsert(Stop.em(), s); TripPatternStop tps = new TripPatternStop(); tps.stop = Stop.findById(stopId.longValue()); tps.stopSequence = sequenceId; tps.defaultTravelTime = s.getArrivalTimeoffset(); tps.defaultDwellTime = s.getDepartureTimeoffset() - s.getArrivalTimeoffset(); tps.pattern = tp; tps.board = s.getBoard(); tps.alight = s.getAlight(); tps.save(); sequenceId++; } // ProcessGisExport gisExport = new ProcessGisExport(tp.id); // gisExport.doJob(); } Logger.info("Routes uploaded: " + upload.getRouteList().size()); dataInputStream.close(); ok(); } catch (Exception e) { e.printStackTrace(); badRequest(); } }
public static Result index() { LOG.info("this is home:" + request().toString()); UUIDGenerator uuid = UUIDGenerator.findByUDID(request().username()); return ok(home.render(uuid.getUser().getUsername())); }