Search in sources :

Example 1 with AttachmentInput

use of com.atlassian.jira.rest.client.api.domain.input.AttachmentInput in project staf by simpleworks-gmbh.

the class Jira method uploadAttachements.

public boolean uploadAttachements(final String subTaskKey, final List<Attachment> attachements) throws SystemException {
    if (Convert.isEmpty(subTaskKey)) {
        throw new IllegalArgumentException("subTaskKey can't be null.");
    }
    if (Convert.isEmpty(attachements)) {
        throw new IllegalArgumentException("attachements can't be null.");
    }
    try {
        final IssueRestClient issueClient = getIssueRestClient();
        for (final Attachment attachement : attachements) {
            final Promise<Issue> promise = issueClient.getIssue(subTaskKey);
            final Issue newIssue = promise.claim();
            final AsynchronousIssueRestClient asynchronousIssueRestClient = (AsynchronousIssueRestClient) issueClient;
            final Promise<InputStream> attachment = asynchronousIssueRestClient.getAttachment(attachement.getContentUri());
            try (final InputStream inputStream = attachment.get()) {
                final Promise<Void> upload = issueClient.addAttachments(newIssue.getAttachmentsUri(), new AttachmentInput(attachement.getFilename(), inputStream));
                upload.claim();
            }
        }
    } catch (final Exception ex) {
        final String message = "can't upload attachements.";
        Jira.logger.error(message, ex);
        throw new SystemException(message);
    }
    return true;
}
Also used : AsynchronousIssueRestClient(com.atlassian.jira.rest.client.internal.async.AsynchronousIssueRestClient) Issue(com.atlassian.jira.rest.client.api.domain.Issue) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) InputStream(java.io.InputStream) IssueRestClient(com.atlassian.jira.rest.client.api.IssueRestClient) AsynchronousIssueRestClient(com.atlassian.jira.rest.client.internal.async.AsynchronousIssueRestClient) Attachment(com.atlassian.jira.rest.client.api.domain.Attachment) SystemException(de.simpleworks.staf.commons.exceptions.SystemException) URISyntaxException(java.net.URISyntaxException) SystemException(de.simpleworks.staf.commons.exceptions.SystemException) AttachmentInput(com.atlassian.jira.rest.client.api.domain.input.AttachmentInput)

Aggregations

IssueRestClient (com.atlassian.jira.rest.client.api.IssueRestClient)1 Attachment (com.atlassian.jira.rest.client.api.domain.Attachment)1 BasicIssue (com.atlassian.jira.rest.client.api.domain.BasicIssue)1 Issue (com.atlassian.jira.rest.client.api.domain.Issue)1 AttachmentInput (com.atlassian.jira.rest.client.api.domain.input.AttachmentInput)1 AsynchronousIssueRestClient (com.atlassian.jira.rest.client.internal.async.AsynchronousIssueRestClient)1 SystemException (de.simpleworks.staf.commons.exceptions.SystemException)1 InputStream (java.io.InputStream)1 URISyntaxException (java.net.URISyntaxException)1