Пример #1
0
 private void populateGenericValueFromComment(Comment updatedComment, GenericValue commentGV) {
   ApplicationUser updateAuthor = updatedComment.getUpdateAuthorApplicationUser();
   commentGV.setString("updateauthor", updateAuthor == null ? null : updateAuthor.getKey());
   commentGV.setString("body", updatedComment.getBody());
   commentGV.setString("level", updatedComment.getGroupLevel());
   commentGV.set("rolelevel", updatedComment.getRoleLevelId());
   commentGV.set(
       "updated", JiraDateUtils.copyOrCreateTimestampNullsafe(updatedComment.getUpdated()));
 }
Пример #2
0
 @Override
 protected String getOwnerId(HttpServletRequest request) {
   String ownerId = super.getOwnerId(request);
   if (StringUtils.isBlank(ownerId)) {
     String username = StringUtils.trim(request.getParameter("username"));
     ApplicationUser user = getUserUtil().getUserByName(username);
     if (user != null) {
       ownerId = user.getKey();
     }
   }
   return ownerId;
 }
Пример #3
0
  public Comment create(
      Issue issue,
      ApplicationUser author,
      ApplicationUser updateAuthor,
      String body,
      String groupLevel,
      Long roleLevelId,
      Date created,
      Date updated,
      Map<String, JSONObject> commentProperties,
      boolean dispatchEvent,
      boolean modifyIssueUpdateDate) {

    if (textFieldCharacterLengthValidator.isTextTooLong(body)) {
      final long maximumNumberOfCharacters =
          textFieldCharacterLengthValidator.getMaximumNumberOfCharacters();
      String errorMessage =
          getText("field.error.text.toolong", String.valueOf(maximumNumberOfCharacters));
      throw new IllegalArgumentException(errorMessage);
    }

    // create new instance of comment
    CommentImpl comment =
        new CommentImpl(
            projectRoleManager,
            author,
            updateAuthor,
            body,
            groupLevel,
            roleLevelId,
            created,
            updated,
            issue);

    // create persistable generic value
    Map<String, Object> fields = new HashMap<String, Object>();
    fields.put("issue", issue.getId());
    fields.put("type", ActionConstants.TYPE_COMMENT);

    ApplicationUser commentAuthor = comment.getAuthorApplicationUser();
    ApplicationUser commentUpdateAuthor = comment.getUpdateAuthorApplicationUser();
    fields.put("author", commentAuthor == null ? null : commentAuthor.getKey());
    fields.put("updateauthor", commentUpdateAuthor == null ? null : commentUpdateAuthor.getKey());
    fields.put("body", comment.getBody());
    fields.put("level", comment.getGroupLevel());
    fields.put("rolelevel", comment.getRoleLevelId());
    fields.put("created", new Timestamp(comment.getCreated().getTime()));
    fields.put("updated", new Timestamp(comment.getUpdated().getTime()));

    GenericValue commentGV = EntityUtils.createValue(COMMENT_ENTITY, fields);
    // set the ID on comment object
    comment.setId(commentGV.getLong(COMMENT_ID));

    // Update the issue object if required
    if (modifyIssueUpdateDate) {
      // JRA-36334: Only modify the Issue updated date if it would move forward - we don't want it
      // to go back in time
      if (comment.getUpdated().getTime() > issue.getUpdated().getTime()) {
        IssueFactory issueFactory = ComponentAccessor.getComponentOfType(IssueFactory.class);
        MutableIssue mutableIssue = issueFactory.getIssue(issue.getGenericValue());
        // JRA-15723: Use the comments updated time for the updated time of the issue.  This allows
        // users to
        // import old comments without setting the updated time on the issue to now, but to the date
        // of the old comments.
        mutableIssue.setUpdated(new Timestamp(comment.getUpdated().getTime()));
        issue.store();
      }
    }

    if (commentProperties != null) {
      setProperties(author, comment, commentProperties);
    }

    // Dispatch an event if required
    if (dispatchEvent) {
      Map<String, Object> params = new HashMap<String, Object>();
      params.put("eventsource", IssueEventSource.ACTION);
      dispatchIssueCommentAddedEvent(comment, params);
    }
    return comment;
  }