@Override
  public void update(
      Comment comment, Map<String, JSONObject> commentProperties, boolean dispatchEvent) {
    if (comment == null) {
      throw new IllegalArgumentException("Comment must not be null");
    }
    if (comment.getId() == null) {
      throw new IllegalArgumentException("Comment ID must not be null");
    }

    // create persistable generic value
    GenericValue commentGV;

    // We need an in-memory copy of the old comment so we can pass it through in the fired event and
    // to make sure
    // that some fields have changed.
    Comment originalComment = getCommentById(comment.getId());
    if (originalComment == null) {
      throw new IllegalArgumentException(
          "Can not find a comment in the datastore with id: " + comment.getId());
    }

    // Make sure that either the comment body or visibility data has changed, otherwise do not
    // update the datastore
    if (!areCommentsEquivalent(originalComment, comment)) {
      try {
        commentGV = delegator.findById(COMMENT_ENTITY, comment.getId());
        populateGenericValueFromComment(comment, commentGV);
        commentGV.store();
      } catch (GenericEntityException e) {
        throw new DataAccessException(e);
      }

      // Update the issue object
      IssueFactory issueFactory = ComponentAccessor.getComponentOfType(IssueFactory.class);
      GenericValue issueGV = comment.getIssue().getGenericValue();
      MutableIssue mutableIssue = issueFactory.getIssue(issueGV);
      mutableIssue.setUpdated(UtilDateTime.nowTimestamp());
      mutableIssue.store();
    }

    // Update comment properties
    if (commentProperties != null) {
      setProperties(comment.getAuthorApplicationUser(), comment, commentProperties);
    }

    // Dispatch an event if required
    if (dispatchEvent) {
      dispatchIssueCommentEditedEvent(
          comment,
          MapBuilder.build(
              "eventsource",
              IssueEventSource.ACTION,
              EVENT_ORIGINAL_COMMENT_PARAMETER,
              originalComment));
    }
  }
 @Override
 public ChangeItemBean delete(Comment comment) {
   ChangeItemBean changeItemBean = constructChangeItemBeanForCommentDelete(comment);
   // TODO: move this into the Store (when it gets created)
   delegator.removeByAnd(
       "Action", FieldMap.build("id", comment.getId(), "type", ActionConstants.TYPE_COMMENT));
   this.jsonEntityPropertyManager.deleteByEntity(
       EntityPropertyType.COMMENT_PROPERTY.getDbEntityName(), comment.getId());
   return changeItemBean;
 }
Esempio n. 3
0
 public MessageDetail getMessage() {
   // 现在pub_message接口返回的是comment对象。所以要转成message
   message = new MessageDetail();
   if (comment != null) {
     message.setId(comment.getId());
     message.setPortrait(comment.getPortrait());
     message.setAuthor(comment.getAuthor());
     message.setAuthorId(comment.getId());
     message.setContent(comment.getContent());
     message.setPubDate(comment.getPubDate());
   }
   return message;
 }
 @Test
 public void testDeleteOne() throws Exception {
   MvcResult deleteComment =
       mvc.perform(
               delete("/inns/{innId}/comments/{comment}", comment.getInn(), comment.getId())
                   .principal(MockUser.mock()))
           .andExpect(request().asyncStarted())
           .andReturn();
   mvc.perform(asyncDispatch(deleteComment)).andExpect(status().isNoContent());
   assertThat(
       "Object must not exist after deletion",
       repo.findOne(comment.getId()),
       is(nullValue(Comment.class)));
 }
  public void testDeleteComment() throws Exception {
    Comment c = new Comment();
    c.setAuthor("lolcat");
    c.setContent("Can I haz ID?");
    c.setTargetId(UUID.randomUUID());
    c.setId(UUID.randomUUID());

    boolean result = es.putComment(c);
    assertTrue(es.getErrorMessage(), result);

    System.out.println("Comment ID: " + c.getId());

    result = es.deleteComment(c.getId());
    assertTrue(es.getErrorMessage(), result);
  }
Esempio n. 6
0
 /** Test that a Comment instance can be created correctly. */
 public void testConstructionOfSimpleInstance() {
   assertNotNull(comment);
   assertEquals("Title", comment.getTitle());
   assertEquals("Body", comment.getBody());
   assertEquals("Author", comment.getAuthor());
   assertEquals("*****@*****.**", comment.getEmail());
   assertEquals("http://www.google.com", comment.getWebsite());
   assertEquals("http://graph.facebook.com/user/picture", comment.getAvatar());
   assertEquals("127.0.0.1", comment.getIpAddress());
   assertNotNull(comment.getDate());
   assertEquals(comment.getDate().getTime(), comment.getId());
   assertNotNull(comment.getBlogEntry());
   assertEquals(State.APPROVED, comment.getState());
   assertEquals("c/" + comment.getBlogEntry().getId() + "/" + comment.getId(), comment.getGuid());
 }
Esempio n. 7
0
  /** Tests that a comment can be cloned. */
  public void testClone() {
    Comment clonedComment = (Comment) comment.clone();

    assertEquals(comment.getTitle(), clonedComment.getTitle());
    assertEquals(comment.getBody(), clonedComment.getBody());
    assertEquals(comment.getWebsite(), clonedComment.getWebsite());
    assertEquals(comment.getAvatar(), clonedComment.getAvatar());
    assertEquals(comment.getAuthor(), clonedComment.getAuthor());
    assertEquals(comment.getIpAddress(), clonedComment.getIpAddress());
    assertEquals(comment.getDate(), clonedComment.getDate());
    assertEquals(comment.getId(), clonedComment.getId());
    assertEquals(comment.getState(), clonedComment.getState());
    assertEquals(comment.getParent(), clonedComment.getParent());
    assertEquals(comment.getBlogEntry(), clonedComment.getBlogEntry());
  }
Esempio n. 8
0
  /** Tests that listeners are fired when a comment is removed. */
  public void testListenersFiredWhenCommentRemoved() throws Exception {
    final StringBuffer buf = new StringBuffer("123");
    final Comment comment =
        blogEntry.createComment(
            "title", "body", "author", "email", "website", "avatar", "127.0.0.1");
    blogEntry.addComment(comment);
    service.putBlogEntry(blogEntry);

    CommentListener listener =
        new CommentListener() {
          public void commentAdded(CommentEvent event) {
            fail();
          }

          public void commentRemoved(CommentEvent event) {
            assertEquals(comment, event.getSource());
            buf.reverse();
          }

          public void commentApproved(CommentEvent event) {
            fail();
          }

          public void commentRejected(CommentEvent event) {
            fail();
          }
        };

    blog.getEventListenerList().addCommentListener(listener);
    blogEntry.removeComment(comment.getId());
    service.putBlogEntry(blogEntry);
    assertEquals("321", buf.toString());
  }
  // smartsheet.sheetResources().commentResources().attachmentResources().attachFile(sheetId,
  // commentId, file,"text/plain");
  public void testattachFileComment() throws SmartsheetException, IOException {
    // create comment to add to discussion
    Comment comment = new Comment.AddCommentBuilder().setText("This is a test comment").build();

    Discussion discussion =
        new Discussion.CreateDiscussionBuilder()
            .setTitle("New Discussion")
            .setComment(comment)
            .build();
    discussion =
        smartsheet.sheetResources().discussionResources().createDiscussion(sheetId, discussion);

    // comment =
    // smartsheet.sheetResources().discussionResources().comments().addComment(sheetId,discussion.getId(), comment);
    comment = discussion.getComments().get(0);
    commentId = comment.getId();
    discussionId = discussion.getId();

    File file1 = new File("src/integration-test/resources/small-text.txt");
    // attach file to comment
    Attachment attachment =
        smartsheet
            .sheetResources()
            .commentResources()
            .attachmentResources()
            .attachFile(sheetId, commentId, file1, "text/plain");
    testGetAttachmentComment(attachment.getId());
  }
Esempio n. 10
0
 private void checkCommentLinks(String url, Comment comment) {
   Assert.assertNotNull(comment);
   Assert.assertEquals(0, comment.getId());
   RESTServiceDiscovery links = comment.getRest();
   Assert.assertNotNull(links);
   Assert.assertEquals(6, links.size());
   // self
   AtomLink atomLink = links.getLinkForRel("self");
   Assert.assertNotNull(atomLink);
   Assert.assertEquals(url + "/book/foo/comment/0", atomLink.getHref());
   // update
   atomLink = links.getLinkForRel("update");
   Assert.assertNotNull(atomLink);
   Assert.assertEquals(url + "/book/foo/comment/0", atomLink.getHref());
   // remove
   atomLink = links.getLinkForRel("remove");
   Assert.assertNotNull(atomLink);
   Assert.assertEquals(url + "/book/foo/comment/0", atomLink.getHref());
   // list
   atomLink = links.getLinkForRel("list");
   Assert.assertNotNull(atomLink);
   Assert.assertEquals(url + "/book/foo/comments", atomLink.getHref());
   // add
   atomLink = links.getLinkForRel("add");
   Assert.assertNotNull(atomLink);
   Assert.assertEquals(url + "/book/foo/comments", atomLink.getHref());
   // collection
   atomLink = links.getLinkForRel("collection");
   Assert.assertNotNull(atomLink);
   Assert.assertEquals(url + "/book/foo/comment-collection", atomLink.getHref());
 }
Esempio n. 11
0
  private void mapImagesToComments(List<Comment> comments) throws Exception {
    if (comments == null || comments.size() == 0) return;

    // Get the thumbnails
    List<UUID> ids = new ArrayList<UUID>();
    for (Comment c : comments) {
      ids.add(c.getId());
    }

    List<Image> images = getImages(ids);

    for (Image i : images) {
      for (Comment c : comments) {
        if (c.getId().equals(i.getId())) {
          c.setImage(i.getEncodedBitmap());
          break;
        }
      }
    }
  }
  public void testGetComments() throws Exception {
    List<Comment> comments = new ArrayList<Comment>();
    List<Comment> returned = new ArrayList<Comment>();
    UUID targetId = UUID.randomUUID();

    for (int i = 0; i < 5; i++) {
      comments.add(createComment(i, targetId));
    }

    for (Comment c : comments) {
      boolean result = es.putComment(c);
      assertTrue(es.getErrorMessage(), result);
    }

    // give elasticsearch some time to sort out its life issues
    Thread.sleep(4000);

    returned = es.getComments(targetId, 0, 10);

    assertEquals(
        "Lists different size!, " + es.getErrorMessage(), comments.size(), returned.size());

    for (Comment c : returned) {
      try {
        es.deleteComment(c.getId());
      } catch (Exception e) {

      }
    }

    for (Comment c : comments) {
      assertTrue("Comment missing from results", returned.contains(c));
    }

    for (Comment c : returned) {
      assertEquals(c.getId(), c.getImage().getId());
      assertNotNull(c.getImage().getEncodedBitmap());
    }
  }
Esempio n. 13
0
  private static final void printPostsAndComments(Blog blog) {
    UUID blogId = blog.getId();
    int maxPageToPrint = 3;
    int pageSize = 2; // 2 posts per page
    System.out.println("###################################################");
    System.out.println(blog.getBlogName().toUpperCase() + ":: by " + blog.getAuthor());
    System.out.println("###################################################");
    System.out.println("");

    try (SessionWrapper sessionWrapper = new SessionWrapper()) {
      UUID lastPostId = null;
      for (int i = 1; i <= maxPageToPrint; i++) {
        List<Post> posts = Post.getPosts(blogId, lastPostId, pageSize, sessionWrapper);
        for (Post post : posts) {
          System.out.println(
              post.getTitle().toUpperCase() + "\t" + "" + new Date(post.getPostedOn()).toString());
          PostVotes pvotes = new PostVotes().get(sessionWrapper, post.getId());
          System.out.println("Votes: +" + pvotes.getUpvotes() + "/-" + pvotes.getDownvotes());
          System.out.println("--------------------------------------------");
          System.out.println(post.getContent());
          System.out.println("Tags: " + post.getTags().toString());

          System.out.println("### COMMENTS:\n");

          List<Comment> comments = Comment.getComments(post.getId(), sessionWrapper);
          for (Comment comment : comments) {
            System.out.println("  >> " + comment.getTitle().toUpperCase());
            System.out.println("  " + comment.getContent());
            System.out.println(
                "   -- "
                    + comment.getCommenter()
                    + " on "
                    + new Date(comment.getPostedOn()).toString());
            CommentVotes cvotes = new CommentVotes().get(sessionWrapper, comment.getId());
            System.out.println("  Votes: +" + cvotes.getUpvotes() + "/-" + cvotes.getDownvotes());
            System.out.println("  -.-.-.-.-.-.-");
          }
          System.out.println();
          System.out.println("============================================");
          System.out.println();
        }
        System.out.println("END OF PAGE: " + i);
        System.out.println();
        System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
        System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
        System.out.println();
      }
    }
  }
Esempio n. 14
0
 private void setProperties(
     final ApplicationUser applicationUser,
     final Comment comment,
     Map<String, JSONObject> properties) {
   for (Map.Entry<String, JSONObject> property : properties.entrySet()) {
     jsonEntityPropertyManager.put(
         applicationUser,
         commentPropertyHelper.getEntityPropertyType().getDbEntityName(),
         comment.getId(),
         property.getKey(),
         property.getValue().toString(),
         commentPropertyHelper.createSetPropertyEventFunction(),
         true);
   }
 }
Esempio n. 15
0
  /**
   * Removes the Comment specified by the commentId.
   *
   * @param commentId id of Comment to remove
   * @return removed Comment or null if one was not found with the id
   */
  public Comment removeComment(final long commentId) {
    Comment removedComment = null;

    if (comments != null) {
      for (int index = comments.size() - 1; index >= 0; --index) {
        Comment currentComment = comments.get(index);

        if (currentComment.getId() == commentId) {
          removedComment = comments.remove(index);
          break;
        }
      }
    }

    return removedComment;
  }
Esempio n. 16
0
  /* (non-Javadoc)
   * @see ca.cmput301f13t03.adventure_datetime.model.IWebStorage#putComment(ca.cmput301f13t03.adventure_datetime.model.Comment)
   */
  @Override
  public boolean putComment(Comment comment) throws Exception {
    Index index =
        new Index.Builder(comment)
            .index(_index)
            .type("comment")
            .id(comment.getId().toString())
            .build();
    JestResult result = execute(index);

    boolean success = result.isSucceeded();
    if (comment.getImage() != null) {
      success &= putImage(comment.getImage());
    }

    return success;
  }
 @Test
 public void testEditComment() throws Exception {
   MvcResult editAction =
       mvc.perform(
               put("/inns/{innId}/comments/{comment}", comment.getInn(), comment.getId())
                   .principal(MockUser.mock())
                   .contentType(MediaType.APPLICATION_JSON)
                   .content(parser.encode(contentBody("The pool is awesome, you should try it!!")))
                   .accept(MediaType.APPLICATION_JSON))
           .andExpect(request().asyncStarted())
           .andExpect(request().asyncResult(instanceOf(ResponseEntity.class)))
           .andReturn();
   mvc.perform(asyncDispatch(editAction))
       .andExpect(status().isOk())
       .andExpect(content().contentType(MediaType.APPLICATION_JSON))
       .andExpect(jsonPath("$.id").isString())
       .andExpect(jsonPath("$.content", is("The pool is awesome, you should try it!!")));
 }
Esempio n. 18
0
  private static void insertComments(SessionWrapper sessionWrapper, Post post, int numComments) {
    for (int i = 0; i < numComments; i++) {
      Comment com = new Comment();
      com.setCommenter(getCommenter());
      com.setContent(getString(1, 10));
      com.setId(getTimeUUID());
      com.setPostedOn(System.currentTimeMillis());
      com.setPostId(post.getId());
      com.setTitle(getString(1, 3));
      com.save(sessionWrapper);

      CommentVotes votes = new CommentVotes();
      votes.setCommentId(com.getId());
      votes.setDownvotes(getInt(0, 10));
      votes.setUpvotes(getInt(0, 10));
      votes.save(sessionWrapper);
    }
  }
Esempio n. 19
0
  public void testNestedCommentsAreUnindexedWhenParentDeleted() throws Exception {
    BlogService service = new BlogService();
    Comment comment2 =
        blogEntry.createComment(
            "Title",
            "Body",
            "Author",
            "*****@*****.**",
            "http://www.google.com",
            "http://graph.facebook.com/user/picture",
            "127.0.0.1");
    Comment comment3 =
        blogEntry.createComment(
            "Title",
            "Body",
            "Author",
            "*****@*****.**",
            "http://www.google.com",
            "http://graph.facebook.com/user/picture",
            "127.0.0.1");

    service.putBlogEntry(blogEntry);
    blogEntry.addComment(comment);

    comment2.setParent(comment);
    blogEntry.addComment(comment2);
    service.putBlogEntry(blogEntry);

    comment3.setParent(comment);
    blogEntry.addComment(comment3);
    service.putBlogEntry(blogEntry);

    assertTrue(blog.getResponseIndex().getPendingResponses().contains(comment.getGuid()));
    assertTrue(blog.getResponseIndex().getPendingResponses().contains(comment2.getGuid()));
    assertTrue(blog.getResponseIndex().getPendingResponses().contains(comment3.getGuid()));

    blogEntry.removeComment(comment.getId());
    service.putBlogEntry(blogEntry);

    assertFalse(blog.getResponseIndex().getPendingResponses().contains(comment.getGuid()));
    assertFalse(blog.getResponseIndex().getPendingResponses().contains(comment2.getGuid()));
    assertFalse(blog.getResponseIndex().getPendingResponses().contains(comment3.getGuid()));
  }
  public void testAddRemoveComment() {
    Map vars = fillVariables(users, groups);

    String str =
        "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { createdOn = now, activationTime = now}), ";
    str += "deadlines = new Deadlines(),";
    str += "delegation = new Delegation(),";
    str += "peopleAssignments = new PeopleAssignments(),";
    str += "names = [ new I18NText( 'en-UK', 'This is my task name')] })";

    Task task = (Task) eval(new StringReader(str), vars);
    client.addTask(task, null);

    long taskId = task.getId();

    Comment comment = new Comment();
    Date addedAt = new Date(System.currentTimeMillis());
    comment.setAddedAt(addedAt);
    comment.setAddedBy(users.get("luke"));
    comment.setText("This is my comment1!!!!!");

    client.addComment(taskId, comment);

    long commentId = comment.getId();

    Task task1 = client.getTask(taskId);
    // We are reusing this for local clients where the object is the same
    // assertNotSame(task, task1);
    // assertFalse(task.equals(task1));

    List<Comment> comments1 = task1.getTaskData().getComments();
    assertEquals(1, comments1.size());
    Comment returnedComment = comments1.get(0);
    assertEquals("This is my comment1!!!!!", returnedComment.getText());
    assertEquals(addedAt, returnedComment.getAddedAt());
    assertEquals(users.get("luke"), returnedComment.getAddedBy());

    assertEquals(commentId, (long) returnedComment.getId());

    // Make the same as the returned tasks, so we can test equals
    task.getTaskData().setComments(comments1);
    task.getTaskData().setStatus(Status.Created);
    assertEquals(task, task1);

    // test we can have multiple comments
    comment = new Comment();
    addedAt = new Date(System.currentTimeMillis());
    comment.setAddedAt(addedAt);
    comment.setAddedBy(users.get("tony"));
    comment.setText("This is my comment2!!!!!");

    client.addComment(taskId, comment);
    long commentId2 = comment.getId();

    task1 = client.getTask(taskId);
    List<Comment> comments2 = task1.getTaskData().getComments();
    assertEquals(2, comments2.size());

    // make two collections the same and compare
    comments1.add(comment);
    assertTrue(CollectionUtils.equals(comments1, comments2));

    client.deleteComment(taskId, commentId2);

    task1 = client.getTask(taskId);
    comments2 = task1.getTaskData().getComments();
    assertEquals(1, comments2.size());

    assertEquals("This is my comment1!!!!!", comments2.get(0).getText());
  }
Esempio n. 21
0
  public synchronized boolean send() {
    Boolean complete_send_to_crm = true;

    SimpleDateFormat format = new SimpleDateFormat();
    format.applyPattern("dd/MM/yyyy HH:mm:ss");

    try {
      BasicXmlData xml = new BasicXmlData("action");
      xml.setAttribute("name", "Comment");

      BasicXmlData xml_level_1 = new BasicXmlData("parameters");

      BasicXmlData xml_level_2_id_trouble = new BasicXmlData("parameter");
      xml_level_2_id_trouble.setAttribute("name", "id_trouble");
      xml_level_2_id_trouble.setAttribute("value", String.valueOf(trouble.getId()));
      xml_level_1.addKid(xml_level_2_id_trouble);

      BasicXmlData xml_level_2_id_comment = new BasicXmlData("parameter");
      xml_level_2_id_comment.setAttribute("name", "id_comment");
      xml_level_2_id_comment.setAttribute("value", String.valueOf(comment.getId()));
      xml_level_1.addKid(xml_level_2_id_comment);

      BasicXmlData xml_level_2_author = new BasicXmlData("parameter");
      xml_level_2_author.setAttribute("name", "author");
      xml_level_2_author.setAttribute("value", comment.getAuthor().getFio());
      xml_level_1.addKid(xml_level_2_author);

      BasicXmlData xml_level_2_desc = new BasicXmlData("parameter");
      xml_level_2_desc.setAttribute("name", "content");
      xml_level_2_desc.setAttribute("value", comment.getText());
      xml_level_1.addKid(xml_level_2_desc);

      BasicXmlData xml_level_2_date = new BasicXmlData("parameter");
      xml_level_2_date.setAttribute("name", "date");
      xml_level_2_date.setAttribute(
          "value", format.format(new Date(Long.valueOf(comment.getTime()))));
      xml_level_1.addKid(xml_level_2_date);

      xml.addKid(xml_level_1);

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      xml.save(baos);

      SendToCrm.send(baos);
    } catch (Exception e) {
      log.error(
          "Comment ["
              + comment.getId()
              + "] to trouble "
              + trouble.getTitle()
              + " ["
              + trouble.getId()
              + "] is not sent to CRM - "
              + e.getMessage());
      e.printStackTrace();
      complete_send_to_crm = false;
    }

    if (complete_send_to_crm) {
      log.info(
          "Comment ["
              + trouble.getId()
              + "] to trouble "
              + trouble.getTitle()
              + " ["
              + trouble.getId()
              + "] successfully submitted to CRM successfully.");
    }

    return complete_send_to_crm;
  }
Esempio n. 22
0
 public void deleteComment(Comment comment) {
   long id = comment.getId();
   System.out.println("Comment deleted with id: " + id);
   database.delete(MySQLiteHelper.TABLE_COMMENTS, MySQLiteHelper.COLUMN_ID + " = " + id, null);
 }