Search in sources :

Example 1 with Attachment

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

the class DebugTestFLOClientMojo method dumpIssue.

public void dumpIssue() {
    final Issue issue = client.getIssue(testPlanId).claim();
    DebugTestFLOClientMojo.logger.debug(String.format("key: '%s', issue: id: %d.", issue.getKey(), issue.getId()));
    final IssueType type = issue.getIssueType();
    DebugTestFLOClientMojo.logger.debug(String.format("issue type: id: %d, name: '%s'.", type.getId(), type.getName()));
    final Status status = issue.getStatus();
    DebugTestFLOClientMojo.logger.debug(String.format("status: id: %d, name: '%s'.", status.getId(), status.getName()));
    DebugTestFLOClientMojo.dumpFields("fields for issue.", issue.getFields());
    DebugTestFLOClientMojo.logger.debug("attachments:");
    for (final Attachment attachment : issue.getAttachments()) {
        DebugTestFLOClientMojo.logger.debug(String.format("attachment: '%s'.", attachment));
    }
    final IssueField field = issue.getField("Test Plan Iteration");
    Assert.assertNotNull("field \"Test Plan Iteration\" can't be null.", field);
    final Object obj = field.getValue();
    DebugTestFLOClientMojo.logger.debug(String.format("class for field: \"Iteration\" is: '%s'.", obj.getClass().getName()));
    {
        DebugTestFLOClientMojo.logger.debug("transition:");
        final Iterable<Transition> transitions = client.getTransitions(issue).claim();
        for (final Transition transition : transitions) {
            DebugTestFLOClientMojo.logger.debug(String.format("transition: name: '%s', id: %d.", transition.getName(), Integer.valueOf(transition.getId())));
        }
    }
    for (final Subtask subtask : issue.getSubtasks()) {
        final Issue i = client.getIssue(subtask.getIssueKey()).claim();
        final IssueField steps = i.getFieldByName("Steps");
        DebugTestFLOClientMojo.logger.debug(String.format("steps: '%s'.", steps.getValue()));
        final IssueField template = i.getFieldByName("TC Template");
        DebugTestFLOClientMojo.logger.debug(String.format("template: '%s'.", template.getValue()));
        final Iterable<Transition> transitions = client.getTransitions(i).claim();
        for (final Transition transition : transitions) {
            DebugTestFLOClientMojo.logger.debug(String.format("subtask: '%s', transition: name: '%s', id: %d.", subtask.getIssueKey(), transition.getName(), Integer.valueOf(transition.getId())));
        }
    }
}
Also used : Status(com.atlassian.jira.rest.client.api.domain.Status) Subtask(com.atlassian.jira.rest.client.api.domain.Subtask) Issue(com.atlassian.jira.rest.client.api.domain.Issue) IssueField(com.atlassian.jira.rest.client.api.domain.IssueField) IssueType(com.atlassian.jira.rest.client.api.domain.IssueType) Transition(com.atlassian.jira.rest.client.api.domain.Transition) Attachment(com.atlassian.jira.rest.client.api.domain.Attachment)

Example 2 with Attachment

use of com.atlassian.jira.rest.client.api.domain.Attachment in project camel-quarkus by apache.

the class JiraTest method attachments.

@Test
public void attachments() {
    // Create issue
    String issueKey = createIssue();
    try {
        // Create attachment
        RestAssured.given().contentType(ContentType.TEXT).pathParam("key", issueKey).body(ISSUE_ATTACHMENT).when().post("/jira/issue/{key}/attach").then().statusCode(201);
        // Verify attachment
        await().atMost(10, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until(() -> {
            Issue issue = getClient().getIssueClient().getIssue(issueKey).claim();
            assertNotNull(issue);
            Iterable<Attachment> iterable = issue.getAttachments();
            return iterable != null && iterable.iterator().hasNext();
        });
        Issue issue = getClient().getIssueClient().getIssue(issueKey).claim();
        Attachment attachment = issue.getAttachments().iterator().next();
        assertTrue(attachment.getFilename().startsWith("cq-jira"));
    } finally {
        deleteIssue(issueKey);
    }
}
Also used : Issue(com.atlassian.jira.rest.client.api.domain.Issue) Attachment(com.atlassian.jira.rest.client.api.domain.Attachment) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 3 with Attachment

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

the class Jira method fetchAttachements.

public List<Attachment> fetchAttachements(final Task task) throws SystemException {
    if (task == null) {
        throw new IllegalArgumentException("task can't be null.");
    }
    final List<Attachment> attachements = new ArrayList<>();
    try {
        final IssueRestClient issueClient = getIssueRestClient();
        final Promise<Issue> promise = issueClient.getIssue(task.getKey());
        final Issue issue = promise.claim();
        issue.getAttachments().forEach(attachement -> attachements.add(attachement));
    } catch (final Exception ex) {
        final String message = "can't fetch attachements.";
        Jira.logger.error(message, ex);
        throw new SystemException(message);
    }
    if (Jira.logger.isDebugEnabled()) {
        if (Convert.isEmpty(attachements)) {
            Jira.logger.debug(String.format("No attachements were fetched from Task, identified by '%s'.", task.getKey()));
        }
    }
    return attachements;
}
Also used : Issue(com.atlassian.jira.rest.client.api.domain.Issue) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) SystemException(de.simpleworks.staf.commons.exceptions.SystemException) ArrayList(java.util.ArrayList) 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)

Example 4 with Attachment

use of com.atlassian.jira.rest.client.api.domain.Attachment 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)

Example 5 with Attachment

use of com.atlassian.jira.rest.client.api.domain.Attachment in project camel-spring-boot by apache.

the class AttachFileProducerTest method verifyAttachment.

@Test
public void verifyAttachment() throws InterruptedException, IOException {
    template.sendBody(generateSampleFile());
    Issue retrievedIssue = issueRestClient.getIssue(issue.getKey()).claim();
    assertEquals(issue, retrievedIssue);
    // there is only one attachment
    Attachment attachFile = retrievedIssue.getAttachments().iterator().next();
    assertEquals(attachFile.getFilename(), attachedFile.getName());
    assertEquals(attachFile.getSize(), attachedFile.length());
    mockResult.expectedMessageCount(1);
    mockResult.assertIsSatisfied();
}
Also used : Issue(com.atlassian.jira.rest.client.api.domain.Issue) Utils.createIssue(org.apache.camel.component.jira.springboot.test.Utils.createIssue) Attachment(com.atlassian.jira.rest.client.api.domain.Attachment) Utils.createIssueWithAttachment(org.apache.camel.component.jira.springboot.test.Utils.createIssueWithAttachment) CamelSpringBootTest(org.apache.camel.test.spring.junit5.CamelSpringBootTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Attachment (com.atlassian.jira.rest.client.api.domain.Attachment)6 Issue (com.atlassian.jira.rest.client.api.domain.Issue)5 IssueRestClient (com.atlassian.jira.rest.client.api.IssueRestClient)3 BasicIssue (com.atlassian.jira.rest.client.api.domain.BasicIssue)2 AsynchronousIssueRestClient (com.atlassian.jira.rest.client.internal.async.AsynchronousIssueRestClient)2 SystemException (de.simpleworks.staf.commons.exceptions.SystemException)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 Utils.createIssueWithAttachment (org.apache.camel.component.jira.springboot.test.Utils.createIssueWithAttachment)2 Test (org.junit.jupiter.api.Test)2 JiraRestClient (com.atlassian.jira.rest.client.api.JiraRestClient)1 JiraRestClientFactory (com.atlassian.jira.rest.client.api.JiraRestClientFactory)1 IssueField (com.atlassian.jira.rest.client.api.domain.IssueField)1 IssueType (com.atlassian.jira.rest.client.api.domain.IssueType)1 Status (com.atlassian.jira.rest.client.api.domain.Status)1 Subtask (com.atlassian.jira.rest.client.api.domain.Subtask)1 Transition (com.atlassian.jira.rest.client.api.domain.Transition)1 AttachmentInput (com.atlassian.jira.rest.client.api.domain.input.AttachmentInput)1 QuarkusTest (io.quarkus.test.junit.QuarkusTest)1 File (java.io.File)1