Ejemplo n.º 1
0
  @Override
  public int parseJson(JSONObject json) {
    // TODO Auto-generated method stub
    try {
      id = json.getString("id");

      JSONObject fromObject = json.getJSONObject("from");
      from = new From(fromObject.getString("id"), fromObject.getString("name"));

      createdTime = json.getString("created_time");

      JSONObject applicationObject = json.getJSONObject("application");
      application =
          new From(applicationObject.getString("id"), applicationObject.getString("name"));

      achievement = new Achievement();
      JSONObject achiveObject = json.getJSONObject("achivement");
      achievement.setId(achiveObject.getString("id"));
      achievement.setUrl(achiveObject.getString("url"));
      achievement.setType(achiveObject.getString("type"));
      achievement.setTitle(achiveObject.getString("title"));

      likes = new Like();
      JSONObject likeObject = json.getJSONObject("likes");
      JSONArray likeArray = likeObject.getJSONArray("data");
      ArrayList<From> likeList = new ArrayList<From>(likeObject.getInt("count"));
      for (int i = 0; i < likeObject.getInt("count"); i++) {
        likeList.add(
            new From(
                likeArray.getJSONObject(i).getString("id"),
                likeArray.getJSONObject(i).getString("name")));
      }
      likes = new Like(likeList, likeObject.getInt("count"));

      comments = new ArrayList<Comment>();
      JSONObject commentObject = json.getJSONObject("comments");
      JSONArray commentArray = commentObject.getJSONArray("data");
      for (int i = 0; i < commentObject.getInt("count"); i++) {
        Comment tmp = new Comment();
        tmp.setId(commentArray.getJSONObject(i).getString("id"));
        tmp.setFrom(
            new From(
                commentArray.getJSONObject(i).getJSONObject("from").getString("id"),
                commentArray.getJSONObject(i).getJSONObject("from").getString("name")));
        tmp.setMessage(commentArray.getJSONObject(i).getString("message"));
        tmp.setCreateTime(commentArray.getJSONObject(i).getString("created_time"));
        comments.add(tmp);
      }

    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return 0;
  }
Ejemplo n.º 2
0
 public Comment addComment(String message, Account currAccount, Task task) {
   Hibernate.initialize(task.getComments());
   Comment comment = new Comment();
   comment.setTask(task);
   comment.setAuthor(currAccount);
   comment.setDate(new Date());
   comment.setMessage(message);
   wlSrv.addActivityLog(task, message, LogType.COMMENT);
   return save(comment);
 }
Ejemplo n.º 3
0
 public boolean editComment(Long id, String message, RedirectAttributes ra) {
   if (commentMessageValid(message, ra)) {
     Comment comment = findById(id);
     if (comment != null) {
       comment.setMessage(message);
       comment.setDate_edited(new Date());
       comment = save(comment);
     }
     return comment != null;
   }
   return false;
 }