Ejemplo n.º 1
0
 public ArrayList<Project> getProjectsWithoutDetails()
     throws java.rmi.RemoteException, SQLException {
   ResultSet result =
       connection.createStatement().executeQuery("Select * from Projects where active = 1");
   ArrayList<Project> projects = new ArrayList<Project>();
   DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
   while (result.next()) {
     try {
       Date projectDate = format.parse(result.getString(3));
       Project p =
           new Project(
               result.getString(2),
               projectDate,
               result.getDouble(4),
               result.getString(5),
               result.getBoolean(6));
       int projectId = result.getInt(1);
       p.setId(projectId);
       projects.add(p);
     } catch (ParseException e) {
       e.printStackTrace();
     }
   }
   System.out.println("Get Projects without Details Executed");
   return projects;
 }
Ejemplo n.º 2
0
 public boolean postinTumblr(String username, Project project)
     throws SQLException, RemoteException {
   ResultSet result =
       connection
           .createStatement()
           .executeQuery(
               "select userToken,userSecret from users where username = \"" + username + "\"");
   Token token = new Token(result.getString(1), result.getString(2));
   OAuthRequest request =
       new OAuthRequest(
           Verb.POST, "http://api.tumblr.com/v2/blog/" + username + ".tumblr.com/post");
   request.addHeader("Accept", "application/json");
   request.addBodyParameter("type", "text");
   request.addBodyParameter("body", "Criei projeto " + project.getName());
   RMIServer.service.signRequest(token, request);
   org.scribe.model.Response response = request.send();
   System.out.println(response.getBody());
   Long postId = new JSONObject(response.getBody()).getJSONObject("response").getLong("id");
   System.out.println(postId);
   OAuthRequest request2 =
       new OAuthRequest(
           Verb.POST, "http://api.tumblr.com/v2/blog/" + username + ".tumblr.com/posts");
   request.addHeader("Accept", "application/json");
   request.addBodyParameter("type", "text");
   request.addBodyParameter("id", String.valueOf(project.getId()));
   RMIServer.service.signRequest(token, request2);
   org.scribe.model.Response response2 = request2.send();
   System.out.println(response2.getBody());
   String reblog_key =
       new JSONObject(response2.getBody()).getJSONObject("response").getString("reblog_key");
   System.out.println(
       "update projects set TumblrPostId = " + postId + " where id = " + project.getId());
   connection
       .createStatement()
       .execute(
           "update projects set TumblrPostId = "
               + postId
               + ",reblog_key = \""
               + reblog_key
               + "\" whessre id = "
               + project.getId());
   return true;
 }
Ejemplo n.º 3
0
 public ArrayList<Project> getProjects(String query)
     throws java.rmi.RemoteException, SQLException {
   ResultSet result = connection.createStatement().executeQuery(query);
   ArrayList<Project> projects = new ArrayList<Project>();
   DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
   while (result.next()) {
     try {
       System.out.printf(result.getString(3));
       Date projectDate = format.parse(result.getString(3));
       Project p =
           new Project(
               result.getString(2),
               projectDate,
               result.getDouble(4),
               result.getString(5),
               result.getBoolean(6));
       int projectId = result.getInt(1);
       p.setId(projectId);
       p.setPaths(this.getProjectPaths(projectId));
       p.setMessages(this.getProjectMessages(projectId));
       p.setRewards(this.getProjectRewards(projectId));
       p.setExtras(this.getProjectExtraLevels(projectId));
       projects.add(p);
     } catch (ParseException e) {
       e.printStackTrace();
     }
   }
   return projects;
 }
Ejemplo n.º 4
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);
    }
  }