@Override
  public List<ChangeItemBean> convertTemporaryAttachments(
      final User user,
      final Issue issue,
      final List<Long> selectedAttachments,
      final TemporaryAttachmentsMonitor temporaryAttachmentsMonitor)
      throws AttachmentException {
    notNull("issue", issue);
    notNull("selectedAttachments", selectedAttachments);
    notNull("temporaryAttachmentsMonitor", temporaryAttachmentsMonitor);

    final List<ChangeItemBean> ret = new ArrayList<ChangeItemBean>();
    for (final Long selectedAttachment : selectedAttachments) {
      final TemporaryAttachment tempAttachment =
          temporaryAttachmentsMonitor.getById(selectedAttachment);
      final ChangeItemBean cib =
          createAttachment(
              tempAttachment.getFile(),
              tempAttachment.getFilename(),
              tempAttachment.getContentType(),
              user,
              issue,
              Collections.<String, Object>emptyMap(),
              UtilDateTime.nowTimestamp());
      if (cib != null) {
        ret.add(cib);
      }
    }

    return ret;
  }
예제 #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));
    }
  }
 @Override
 public ChangeItemBean createAttachment(
     File file, String filename, String contentType, User remoteUser, Issue issue)
     throws AttachmentException {
   return createAttachment(
       file,
       filename,
       contentType,
       remoteUser,
       issue,
       Collections.<String, Object>emptyMap(),
       UtilDateTime.nowTimestamp());
 }