Search in sources :

Example 1 with ExtendedJiraRestClient

use of hudson.plugins.jira.extension.ExtendedJiraRestClient in project jira-plugin by jenkinsci.

the class JiraSite method createSession.

/**
 * Creates a remote access session to this Jira.
 *
 * @return null if remote access is not supported.
 */
private JiraSession createSession(Item item) {
    ItemGroup itemGroup = map(item);
    item = itemGroup instanceof Folder ? ((Folder) itemGroup) : item;
    StandardUsernamePasswordCredentials credentials = resolveCredentials(item);
    if (credentials == null) {
        LOGGER.fine("no Jira credentials available for " + item);
        // remote access not supported
        return null;
    }
    URI uri;
    try {
        uri = url.toURI();
    } catch (URISyntaxException e) {
        LOGGER.warning("convert URL to URI error: " + e.getMessage());
        throw new RuntimeException("failed to create JiraSession due to convert URI error");
    }
    LOGGER.fine("creating Jira Session: " + uri);
    ExtendedJiraRestClient jiraRestClient = new ExtendedAsynchronousJiraRestClientFactory().create(uri, new BasicHttpAuthenticationHandler(credentials.getUsername(), credentials.getPassword().getPlainText()), getHttpClientOptions());
    return new JiraSession(this, new JiraRestService(uri, jiraRestClient, credentials.getUsername(), credentials.getPassword().getPlainText(), readTimeout));
}
Also used : StandardUsernamePasswordCredentials(com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials) ItemGroup(hudson.model.ItemGroup) BasicHttpAuthenticationHandler(com.atlassian.jira.rest.client.auth.BasicHttpAuthenticationHandler) URISyntaxException(java.net.URISyntaxException) ExtendedJiraRestClient(hudson.plugins.jira.extension.ExtendedJiraRestClient) Folder(com.cloudbees.hudson.plugins.folder.Folder) AbstractFolder(com.cloudbees.hudson.plugins.folder.AbstractFolder) URI(java.net.URI)

Example 2 with ExtendedJiraRestClient

use of hudson.plugins.jira.extension.ExtendedJiraRestClient in project jira-plugin by jenkinsci.

the class JiraTester method main.

public static void main(String[] args) throws Exception {
    final URI uri = new URL(JiraConfig.getUrl()).toURI();
    final ExtendedJiraRestClient jiraRestClient = new ExtendedAsynchronousJiraRestClientFactory().createWithBasicHttpAuthentication(uri, JiraConfig.getUsername(), JiraConfig.getPassword());
    final JiraRestService restService = new JiraRestService(uri, jiraRestClient, JiraConfig.getUsername(), JiraConfig.getPassword(), JiraSite.DEFAULT_TIMEOUT);
    final String projectKey = "TESTPROJECT";
    final String issueId = "TESTPROJECT-425";
    final Integer actionId = 21;
    final Issue issue = restService.getIssue(issueId);
    System.out.println("issue:" + issue);
    final List<Transition> availableActions = restService.getAvailableActions(issueId);
    for (Transition action : availableActions) {
        System.out.println("Action:" + action);
    }
    for (IssueType issueType : restService.getIssueTypes()) {
        System.out.println(" issue type: " + issueType);
    }
    // restService.addVersion("TESTPROJECT", "0.0.2");
    final List<Component> components = restService.getComponents(projectKey);
    for (Component component : components) {
        System.out.println("component: " + component);
    }
    // BasicComponent backendComponent = null;
    // final Iterable<BasicComponent> components1 = Lists.newArrayList(backendComponent);
    // restService.createIssue("TESTPROJECT", "This is a test issue created using Jira jenkins plugin. Please ignore it.", "TESTUSER", components1, "test issue from Jira jenkins plugin");
    final List<Issue> searchResults = restService.getIssuesFromJqlSearch("project = \"TESTPROJECT\"", 3);
    for (Issue searchResult : searchResults) {
        System.out.println("JQL search result: " + searchResult);
    }
    final List<String> projectsKeys = restService.getProjectsKeys();
    for (String projectsKey : projectsKeys) {
        System.out.println("project key: " + projectsKey);
    }
    final List<Status> statuses = restService.getStatuses();
    for (Status status : statuses) {
        System.out.println("status:" + status);
    }
    final User user = restService.getUser("TESTUSER");
    System.out.println("user: " + user);
    final List<ExtendedVersion> versions = restService.getVersions(projectKey);
    for (ExtendedVersion version : versions) {
        System.out.println("version: " + version);
    }
    for (int i = 0; i < 10; i++) {
        callUniq(restService);
    }
    for (int i = 0; i < 10; i++) {
        callDuplicate(restService);
    }
}
Also used : Status(com.atlassian.jira.rest.client.api.domain.Status) Issue(com.atlassian.jira.rest.client.api.domain.Issue) User(com.atlassian.jira.rest.client.api.domain.User) IssueType(com.atlassian.jira.rest.client.api.domain.IssueType) ExtendedJiraRestClient(hudson.plugins.jira.extension.ExtendedJiraRestClient) URI(java.net.URI) URL(java.net.URL) ExtendedAsynchronousJiraRestClientFactory(hudson.plugins.jira.JiraSite.ExtendedAsynchronousJiraRestClientFactory) Transition(com.atlassian.jira.rest.client.api.domain.Transition) ExtendedVersion(hudson.plugins.jira.extension.ExtendedVersion) JiraRestService(hudson.plugins.jira.JiraRestService) Component(com.atlassian.jira.rest.client.api.domain.Component)

Aggregations

ExtendedJiraRestClient (hudson.plugins.jira.extension.ExtendedJiraRestClient)2 URI (java.net.URI)2 Component (com.atlassian.jira.rest.client.api.domain.Component)1 Issue (com.atlassian.jira.rest.client.api.domain.Issue)1 IssueType (com.atlassian.jira.rest.client.api.domain.IssueType)1 Status (com.atlassian.jira.rest.client.api.domain.Status)1 Transition (com.atlassian.jira.rest.client.api.domain.Transition)1 User (com.atlassian.jira.rest.client.api.domain.User)1 BasicHttpAuthenticationHandler (com.atlassian.jira.rest.client.auth.BasicHttpAuthenticationHandler)1 AbstractFolder (com.cloudbees.hudson.plugins.folder.AbstractFolder)1 Folder (com.cloudbees.hudson.plugins.folder.Folder)1 StandardUsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials)1 ItemGroup (hudson.model.ItemGroup)1 JiraRestService (hudson.plugins.jira.JiraRestService)1 ExtendedAsynchronousJiraRestClientFactory (hudson.plugins.jira.JiraSite.ExtendedAsynchronousJiraRestClientFactory)1 ExtendedVersion (hudson.plugins.jira.extension.ExtendedVersion)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1