Пример #1
0
 private void dispatchIssueCommentEditedEvent(Comment comment, Map<String, Object> parameters) {
   IssueEventBundle issueCommentBundle =
       issueEventBundleFactory.createCommentEditedBundle(
           comment.getIssue(), comment.getUpdateAuthorApplicationUser(), comment, parameters);
   issueEventManager.dispatchEvent(issueCommentBundle);
   dispatchEvent(EventType.ISSUE_COMMENT_EDITED_ID, comment, parameters);
 }
Пример #2
0
  @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));
    }
  }
Пример #3
0
 // TODO: the event generation should live in the service
 // This is mostly here for testing purposes so we do not really need to dispatch the event to know
 // it was called correctly
 void dispatchEvent(Long eventTypeId, Comment comment, Map<String, Object> parameters) {
   issueEventManager.dispatchRedundantEvent(
       eventTypeId,
       comment.getIssue(),
       comment.getUpdateAuthorUser(),
       comment,
       null,
       null,
       parameters);
 }