Exemplo n.º 1
0
  public Result onLabel() {
    long millis = System.currentTimeMillis() % 1000;
    long result = millis - currentTimestamp;
    currentTimestamp = System.currentTimeMillis() % 1000;

    String label = request().getQueryString("action");
    String id = request().getQueryString("id");
    String reason =
        request()
            .getQueryString(
                "reason"); // remove the cluster header from Tweets and add it to labelled at the
                           // end.
    String databaseName = request().getQueryString("databaseName");
    String timestamp = Long.toString(result);

    DataAccess.labelTweet(databaseName, id, label, timestamp);

    TweetDTO tweetDTO = DataAccess.getNextTweet(databaseName);
    return ok(labelling.render(tweetDTO, databaseName));
  }
Exemplo n.º 2
0
@Entity
public class Squad extends Model {

  @Unique("school")
  @Required
  public String name;

  @Required @ManyToOne public School school;

  public Long reservedTill = (System.currentTimeMillis() + 7200000);
  public User reservedFor = NoLoginRequired.userLogged;

  public Squad(String name, School school) {
    this.name = name;
    this.school = school;
  }

  public void deleteReservation() {
    this.reservedFor = null;
    this.reservedTill = null;
  }

  public void addAdmin(User admin) {
    this.admins.add(admin);
    this.users.add(admin);
  }

  public void addUser(User user) {
    this.users.add(user);
  }

  public Boolean dropAdmin(User admin) {
    this.users.remove(admin);
    return this.admins.remove(admin);
  }

  public Boolean dropUser(User user) {
    return this.admins.remove(user);
  }

  @ManyToMany
  @JoinTable(name = "SQUAD_USER")
  public List<User> users;

  @ManyToMany
  @JoinTable(name = "SQUAD_ADMIN")
  public List<User> admins;

  @ManyToMany
  @JoinTable(name = "SQUAD_APPLYER")
  public List<User> appliers;
}
Exemplo n.º 3
0
  public void onStart(Application app) {
    try {
      // if database is empty, pre-load database
      boolean databaseReset = databaseEmpty();
      if (databaseReset) {
        readInBeaches(); // read in beaches
      }

      // If test mode, make fake data.  Otherwise, start scraping cron job
      if (controllers.Application.config.isTestMode()) {
        if (databaseReset) {
          // makeFakeData();
        }
      } else {
        startScrapingCron();
      }
    } catch (Exception e) {
      // if unable to start the program, print to console and exit.
      e.printStackTrace();
      System.exit(-2);
    }
  }
Exemplo n.º 4
0
  public Result upload() {
    String databaseName = "";
    System.out.println("upload function call");

    MultipartFormData body = request().body().asMultipartFormData();
    FilePart filePart1 = body.getFile("filePart1");
    String[] searchTag = body.asFormUrlEncoded().get("db");
    String[] uploadDBName = body.asFormUrlEncoded().get("db_upload");

    databaseName = uploadDBName[0];
    System.out.println("FILE SEND!!");
    if (filePart1 != null) {
      // System.out.println("ifin ici");

    }
    File newFile1 = filePart1.getFile();
    InputStream isFile1;
    try {
      isFile1 = new FileInputStream(newFile1);
    } catch (FileNotFoundException e1) {
      isFile1 = null;
    }

    byte[] byteFile1;

    try {
      byteFile1 = IOUtils.toByteArray(isFile1);
    } catch (IOException e2) {
      byteFile1 = null;
    }
    BufferedReader reader;
    String line;
    StringBuilder stringBuilder;
    String ls;
    try {
      reader = new BufferedReader(new FileReader(newFile1));
      line = null;
      stringBuilder = new StringBuilder();
      ls = System.getProperty("line.separator");
    } catch (FileNotFoundException e1) {
      reader = null;
      line = null;
      stringBuilder = null;
      ls = null;
    }
    // System.out.println(reader);
    String[] parts;
    try {
      while ((line = reader.readLine()) != null) {
        String[] a_line_list = line.split("\t");
        String tweet = a_line_list[2];
        String id = a_line_list[0];
        String owner = a_line_list[1];
        String label = "-2";
        DataAccess.addDocument(databaseName, "tweets_unlabelled", id, owner, tweet, label, "0");
      }
    } catch (IOException e) {

    }
    try {
      FileUtils.writeByteArrayToFile(newFile1, byteFile1);
      isFile1.close();
    } catch (IOException e3) {

    }
    try {
      Thread.sleep(1000); // thread sleep for concurrent operations on ES
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    TweetDTO tweet = DataAccess.getNextTweet(databaseName);
    System.out.println(tweet.getId() + " " + tweet.getOwner() + " " + tweet.getLabel());
    return ok(labelling.render(tweet, databaseName));
  }