Пример #1
0
 public ArrayList<User> getUsers() throws RemoteException, SQLException {
   ResultSet result = connection.createStatement().executeQuery("select * from users");
   ArrayList<User> users = new ArrayList<User>();
   while (result.next()) {
     User user = new User(result.getString(2), result.getString(3));
     user.setId(result.getInt(1));
     users.add(user);
   }
   return users;
 }
Пример #2
0
 public ArrayList<User> getAdmins(int projectId) throws java.rmi.RemoteException, SQLException {
   ResultSet result =
       connection
           .createStatement()
           .executeQuery("Select * from Administrators where projectId = " + projectId);
   ArrayList<User> users = new ArrayList<User>();
   while (result.next()) {
     int userId = result.getInt(3);
     System.out.println("Select * from users where userId = " + userId);
     ResultSet result2 =
         connection.createStatement().executeQuery("Select * from users where id = " + userId);
     User u = new User(result2.getString(2), result2.getString(3));
     u.setId(result2.getInt(1));
     users.add(u);
   }
   System.out.println("Get Admins executed");
   return users;
 }
Пример #3
0
  public boolean createProject(Project project, int requestId, int userId)
      throws RemoteException, SQLException {
    System.out.println(userId);
    ResultSet result =
        connection
            .createStatement()
            .executeQuery(
                "select count(*) from logs where requestId = "
                    + requestId
                    + " and userId = "
                    + userId);
    if (result.getInt(1) == 0) {
      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
      result =
          connection
              .createStatement()
              .executeQuery("select id from projects where Name = \"" + project.getName() + "\"");
      if (result.next()) {
        return false;
      }
      connection.setAutoCommit(false);
      connection
          .createStatement()
          .execute(
              "insert into projects (Name, Deadline, Objective, Description, OwnerUserId,Active) values (\""
                  + project.getName()
                  + "\", \""
                  + dateFormat.format(project.getDeadline())
                  + "\","
                  + project.getObjective()
                  + ", \""
                  + project.getDescription()
                  + "\", "
                  + userId
                  + ","
                  + 1
                  + ")");
      result =
          connection
              .createStatement()
              .executeQuery("select id from projects where Name = \"" + project.getName() + "\"");
      int projectId = result.getInt(1);
      connection
          .createStatement()
          .execute(
              "insert into administrators (ProjectId, UserId) values ("
                  + projectId
                  + ", "
                  + userId
                  + ")");
      connection
          .createStatement()
          .execute(
              "insert into logs (UserId, RequestId, Response) values ("
                  + userId
                  + ", "
                  + requestId
                  + ", 1)");

      for (Reward reward : project.getRewards()) {
        this.createReward(reward, 0, projectId, userId);
      }
      for (Path path : project.getPaths()) {
        this.createPath(path, 0, userId, projectId);
      }
      project.setId(projectId);
      System.out.println("Created Proj");
      User username = getUser(userId);
      if (isTumblr(username.getUsername())) {
        postinTumblr(username.getUsername(), project);
      }
      connection.commit();
      return true;
    } else {
      System.out.println("OUPS");
      result =
          connection
              .createStatement()
              .executeQuery(
                  "select response from logs where requestId = "
                      + requestId
                      + " and userId = "
                      + userId);
      return result.getBoolean(1);
    }
  }