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;
}
Aggregations