Jira REST Java Client API实战应用

 

前提

1、需要安装maven环境;

2、在本地创建maven项目并修改maven配置文件“pom.xml”,添加如下内容:

<dependency>
    <groupId>com.atlassian.jira</groupId>
    <artifactId>jira-rest-java-client</artifactId>
    <version>0.5-m6</version>
</dependency>
<dependency>
    <groupId>com.atlassian.util.concurrent</groupId>
    <artifactId>atlassian-util-concurrent</artifactId>
    <version>3.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.sharegov/mjson -->
<dependency>
    <groupId>org.sharegov</groupId>
    <artifactId>mjson</artifactId>
    <version>1.4.1</version>
</dependency>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.

以上三个依赖中,前两个是用来和jira进行交互的类库,最后一个是可以让我能够像在python中处理json一样处理json的mjson类库。

封装方法

对JIRA的操作进行简单封装,示例如下:

JIRA REST java client API实际应用_jiraJIRA REST java client API实际应用_jira_02
package com.mockCommon.util;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.joda.time.DateTime;
import com.atlassian.jira.rest.client.JiraRestClient;
import com.atlassian.jira.rest.client.NullProgressMonitor;
import com.atlassian.jira.rest.client.domain.BasicComponent;
import com.atlassian.jira.rest.client.domain.Comment;
import com.atlassian.jira.rest.client.domain.Issue;
import com.atlassian.jira.rest.client.internal.jersey.JerseyJiraRestClientFactory;
import com.mockCommon.model.JiraInfoModel;

import mjson.Json;

public class JiraUtil {

    /**
     * 登录JIRA并返回指定的JiraRestClient对象
     * 
     * @param username
     * @param password
     * @return
     * @throws URISyntaxException
     */
    public static JiraRestClient login_jira(String username, String password) throws URISyntaxException {
        try {
            final JerseyJiraRestClientFactory factory = new JerseyJiraRestClientFactory();
            final URI jiraServerUri = new URI("http://jira.ms.netease.com");
            final JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri, username,
                    password);
            return restClient;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取并返回指定的Issue对象
     * 
     * @param issueNum
     * @param username
     * @param password
     * @return
     * @throws URISyntaxException
     */
    public static Issue get_issue(String issueNum, String username, String password) throws URISyntaxException {
        try {
            final JiraRestClient restClient = login_jira(username, password);
            final NullProgressMonitor pm = new NullProgressMonitor();
            final Issue issue = restClient.getIssueClient().getIssue(issueNum, pm);
            return issue;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取指定JIRA备注部分的内容
     * 
     * @param issue
     * @param username
     * @param password
     * @return
     * @throws URISyntaxException
     */
    public static List<String> get_comments_body(Issue issue) throws URISyntaxException {
        try {
            List<String> comments = new ArrayList<String>();
            for (Comment comment : issue.getComments()) {
                comments.add(comment.getBody().toString());
            }
            return comments;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取指定JIRA的创建时间
     * 
     * @param issueNum
     * @param username
     * @param password
     * @return
     * @throws URISyntaxException
     */
    public static DateTime get_create_time(Issue issue) throws URISyntaxException {
        try {
            return issue.getCreationDate();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取指定JIRA的描述部分
     * 
     * @param issueNum
     * @param username
     * @param password
     * @return
     * @throws URISyntaxException
     */
    public static String get_description(Issue issue) throws URISyntaxException {
        try {
            return issue.getDescription();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取指定JIRA的标题
     * 
     * @param issueNum
     * @param username
     * @param password
     * @return
     * @throws URISyntaxException
     */
    public static String get_summary(Issue issue) throws URISyntaxException {
        try {
            return issue.getSummary();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取指定JIRA的报告人的名字
     * 
     * @param issueNum
     * @param username
     * @param password
     * @return
     * @throws URISyntaxException
     */
    public static String get_reporter(Issue issue) throws URISyntaxException {
        try {
            return issue.getReporter().getDisplayName();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取指定JIRA的分派人的姓名列表
     * 
     * @param issue
     * @param username
     * @param password
     * @return
     * @throws URISyntaxException
     */
    public static ArrayList<String> get_assignees(Issue issue) throws URISyntaxException {
        try {
            Json json = Json.read(issue.getFieldByName("分派给").getValue().toString());
            Iterator<Json> assignees = json.asJsonList().iterator();
            ArrayList<String> assigneesNames = new ArrayList<String>();
            while (assignees.hasNext()) {
                Json assignee = Json.read(assignees.next().toString());
                String assigneeName = assignee.at("displayName").toString();
                assigneesNames.add(assigneeName);
            }
            return assigneesNames;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取指定JIRA的状态
     * 
     * @param issue
     * @param username
     * @param password
     * @return
     * @throws URISyntaxException
     */
    public static String get_status(Issue issue) throws URISyntaxException {
        try {
            return issue.getStatus().getName();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取指定JIRA的类型
     * 
     * @param issue
     * @param username
     * @param password
     * @return
     * @throws URISyntaxException
     */
    public static String get_issue_type(Issue issue) throws URISyntaxException {
        try {
            return issue.getIssueType().getName();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取指定JIRA的模块
     * 
     * @param issue
     * @param username
     * @param password
     * @return
     * @throws URISyntaxException
     */
    public static ArrayList<String> get_modules(Issue issue) throws URISyntaxException {
        try {
            ArrayList<String> arrayList = new ArrayList<String>();
            Iterator<BasicComponent> basicComponents = issue.getComponents().iterator();
            while (basicComponents.hasNext()) {
                String moduleName = basicComponents.next().getName();
                arrayList.add(moduleName);
            }
            return arrayList;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取指定JIRA的前端人员的姓名列表
     * 
     * @param issue
     * @param username
     * @param password
     * @return
     * @throws URISyntaxException
     */
    public static ArrayList<String> get_qianduans(Issue issue) throws URISyntaxException {
        try {
            ArrayList<String> qianduanList = new ArrayList<String>();
            Json json = Json.read(issue.getFieldByName("前端").getValue().toString());
            Iterator<Json> qianduans = json.asJsonList().iterator();
            while (qianduans.hasNext()) {
                Json qianduan = Json.read(qianduans.next().toString());
                String qianduanName = qianduan.at("displayName").toString();
                qianduanList.add(qianduanName);
            }
            return qianduanList;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取指定JIRA的开发的姓名列表
     * 
     * @param issue
     * @param username
     * @param password
     * @return
     * @throws URISyntaxException
     */
    public static ArrayList<String> get_developers(Issue issue) throws URISyntaxException {
        try {
            ArrayList<String> developersList = new ArrayList<String>();
            Json json = Json.read(issue.getFieldByName("开发").getValue().toString());
            Iterator<Json> developers = json.asJsonList().iterator();
            while (developers.hasNext()) {
                Json developer = Json.read(developers.next().toString());
                String developerName = developer.at("displayName").toString();
                developersList.add(developerName);
            }
            return developersList;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取指定JIRA的产品人员的姓名
     * 
     * @param issue
     * @param username
     * @param password
     * @return
     * @throws URISyntaxException
     */
    public static String get_product(Issue issue) throws URISyntaxException {
        try {
            String product_field = issue.getFieldByName("产品人员").getValue().toString();
            return Json.read(product_field).at("displayName").toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取指定JIRA的UE开始时间
     * 
     * @param issue
     * @return
     * @throws URISyntaxException
     */
    public static String get_UE_start_time(Issue issue) throws URISyntaxException {
        try {
            String UE_start_time = issue.getFieldByName("UE开始时间").getValue().toString();
            return UE_start_time;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取指定JIRA的UE结束时间
     * 
     * @param issue
     * @return
     * @throws URISyntaxException
     */
    public static String get_UE_end_time(Issue issue) throws URISyntaxException {
        try {
            String UE_end_time = issue.getFieldByName("UE结束时间").getValue().toString();
            return UE_end_time;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取指定JIRA的UI开始时间
     * 
     * @param issue
     * @return
     * @throws URISyntaxException
     */
    public static String get_UI_start_time(Issue issue) throws URISyntaxException {
        try {
            String UI_start_time = issue.getFieldByName("UI开始时间").getValue().toString();
            return UI_start_time;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取指定JIRA的UI结束时间
     * 
     * @param issue
     * @return
     * @throws URISyntaxException
     */
    public static String get_UI_end_time(Issue issue) throws URISyntaxException {
        try {
            String UI_end_time = issue.getFieldByName("UI结束时间").getValue().toString();
            return UI_end_time;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取指定JIRA的客户端开始时间
     * 
     * @param issue
     * @return
     * @throws URISyntaxException
     */
    public static String get_app_start_time(Issue issue) throws URISyntaxException {
        try {
            String app_start_time = issue.getFieldByName("客户端开始时间").getValue().toString();
            return app_start_time;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取指定JIRA的客户端结束时间
     * 
     * @param issue
     * @return
     * @throws URISyntaxException
     */
    public static String get_app_end_time(Issue issue) throws URISyntaxException {
        try {
            String app_end_time = issue.getFieldByName("客户端结束时间").getValue().toString();
            return app_end_time;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取指定JIRA的前端开始时间
     * 
     * @param issue
     * @return
     * @throws URISyntaxException
     */
    public static String get_qianduan_start_time(Issue issue) throws URISyntaxException {
        try {
            String qianduan_start_time = issue.getFieldByName("前端开始时间").getValue().toString();
            return qianduan_start_time;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取指定JIRA的前端结束时间
     * 
     * @param issue
     * @return
     * @throws URISyntaxException
     */
    public static String get_qianduan_end_time(Issue issue) throws URISyntaxException {
        try {
            String qianduan_end_time = issue.getFieldByName("前端结束时间").getValue().toString();
            return qianduan_end_time;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取指定JIRA的开发开始时间
     * 
     * @param issue
     * @return
     * @throws URISyntaxException
     */
    public static String get_develop_start_time(Issue issue) throws URISyntaxException {
        try {
            String develop_start_time = issue.getFieldByName("开发开始时间").getValue().toString();
            return develop_start_time;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取指定JIRA的开发结束时间
     * 
     * @param issue
     * @return
     * @throws URISyntaxException
     */
    public static String get_develop_end_time(Issue issue) throws URISyntaxException {
        try {
            String develop_end_time = issue.getFieldByName("开发结束时间").getValue().toString();
            return develop_end_time;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取指定JIRA的联调开始时间
     * 
     * @param issue
     * @return
     * @throws URISyntaxException
     */
    public static String get_liantiao_start_time(Issue issue) throws URISyntaxException {
        try {
            String liantiao_start_time = issue.getFieldByName("联调开始时间").getValue().toString();
            return liantiao_start_time;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取指定JIRA的联调结束时间
     * 
     * @param issue
     * @return
     * @throws URISyntaxException
     */
    public static String get_liantiao_end_time(Issue issue) throws URISyntaxException {
        try {
            String liantiao_end_time = issue.getFieldByName("联调结束时间").getValue().toString();
            return liantiao_end_time;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取指定JIRA的测试开始时间
     * 
     * @param issue
     * @return
     * @throws URISyntaxException
     */
    public static String get_test_start_time(Issue issue) throws URISyntaxException {
        try {
            String test_start_time = issue.getFieldByName("测试开始时间").getValue().toString();
            return test_start_time;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取指定JIRA的测试结束时间
     * 
     * @param issue
     * @return
     * @throws URISyntaxException
     */
    public static String get_test_end_time(Issue issue) throws URISyntaxException {
        try {
            String test_end_time = issue.getFieldByName("测试结束时间").getValue().toString();
            return test_end_time;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取所有可以收集到的JIRA信息并返回JiraInfoModel类型对象
     * @param issue
     * @return
     * @throws URISyntaxException
     */
    public static JiraInfoModel get_jira_info(Issue issue) throws URISyntaxException {
        List<String> jiraCommentsBody = get_comments_body(issue);
        DateTime jiraCreateTime = get_create_time(issue);
        String description = get_description(issue);
        String summary = get_summary(issue);
        String reporter = get_reporter(issue);
        ArrayList<String> assignees = get_assignees(issue);
        String status = get_status(issue);
        String issueType = get_issue_type(issue);
        ArrayList<String> modules = get_modules(issue);
        ArrayList<String> qianduans = get_qianduans(issue);
        ArrayList<String> developers = get_developers(issue);
        String product = get_product(issue);
        String UE_start_time = get_UE_start_time(issue);
        String UE_end_time = get_UE_end_time(issue);
        String UI_start_time = get_UI_start_time(issue);
        String UI_end_time = get_UI_end_time(issue);
        String app_start_time = get_app_start_time(issue);
        String app_end_time = get_app_end_time(issue);
        String qianduan_start_time = get_qianduan_start_time(issue);
        String qianduan_end_time = get_qianduan_end_time(issue);
        String develop_start_time = get_develop_start_time(issue);
        String develop_end_time = get_develop_end_time(issue);
        String liantiao_start_time = get_liantiao_start_time(issue);
        String liantiao_end_time = get_liantiao_end_time(issue);
        String test_start_time = get_test_start_time(issue);
        String test_end_time = get_test_end_time(issue);
        JiraInfoModel jiraInfoModel = new JiraInfoModel();
        jiraInfoModel.setJiraCommentsBody(jiraCommentsBody);
        jiraInfoModel.setJiraCreateTime(jiraCreateTime);
        jiraInfoModel.setDescription(description);
        jiraInfoModel.setSummary(summary);
        jiraInfoModel.setReporter(reporter);
        jiraInfoModel.setAssignees(assignees);
        jiraInfoModel.setStatus(status);
        jiraInfoModel.setIssueType(issueType);
        jiraInfoModel.setModules(modules);
        jiraInfoModel.setQianduans(qianduans);
        jiraInfoModel.setDevelopers(developers);
        jiraInfoModel.setProduct(product);
        jiraInfoModel.setUE_start_time(UE_start_time);
        jiraInfoModel.setUE_end_time(UE_end_time);
        jiraInfoModel.setUI_start_time(UI_start_time);
        jiraInfoModel.setUI_end_time(UI_end_time);
        jiraInfoModel.setApp_start_time(app_start_time);
        jiraInfoModel.setApp_end_time(app_end_time);
        jiraInfoModel.setQianduan_start_time(qianduan_start_time);
        jiraInfoModel.setQianduan_end_time(qianduan_end_time);
        jiraInfoModel.setDevelop_start_time(develop_start_time);
        jiraInfoModel.setDevelop_end_time(develop_end_time);
        jiraInfoModel.setLiantiao_start_time(liantiao_start_time);
        jiraInfoModel.setLiantiao_end_time(liantiao_end_time);
        jiraInfoModel.setTest_start_time(test_start_time);
        jiraInfoModel.setTest_end_time(test_end_time);
        return jiraInfoModel;
    }

    /**
     * 测试函数
     * 
     * @param args
     * @throws URISyntaxException
     */
    public static void main(String[] args) throws URISyntaxException {
        String username = "用户名";
        String password = "密码";
        String issueNum = "JIRA号";
        final Issue issue = get_issue(issueNum, username, password);
        JiraInfoModel jiraInfoModel = get_jira_info(issue);
        System.out.println(jiraInfoModel.getSummary());
    }

}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.
  • 135.
  • 136.
  • 137.
  • 138.
  • 139.
  • 140.
  • 141.
  • 142.
  • 143.
  • 144.
  • 145.
  • 146.
  • 147.
  • 148.
  • 149.
  • 150.
  • 151.
  • 152.
  • 153.
  • 154.
  • 155.
  • 156.
  • 157.
  • 158.
  • 159.
  • 160.
  • 161.
  • 162.
  • 163.
  • 164.
  • 165.
  • 166.
  • 167.
  • 168.
  • 169.
  • 170.
  • 171.
  • 172.
  • 173.
  • 174.
  • 175.
  • 176.
  • 177.
  • 178.
  • 179.
  • 180.
  • 181.
  • 182.
  • 183.
  • 184.
  • 185.
  • 186.
  • 187.
  • 188.
  • 189.
  • 190.
  • 191.
  • 192.
  • 193.
  • 194.
  • 195.
  • 196.
  • 197.
  • 198.
  • 199.
  • 200.
  • 201.
  • 202.
  • 203.
  • 204.
  • 205.
  • 206.
  • 207.
  • 208.
  • 209.
  • 210.
  • 211.
  • 212.
  • 213.
  • 214.
  • 215.
  • 216.
  • 217.
  • 218.
  • 219.
  • 220.
  • 221.
  • 222.
  • 223.
  • 224.
  • 225.
  • 226.
  • 227.
  • 228.
  • 229.
  • 230.
  • 231.
  • 232.
  • 233.
  • 234.
  • 235.
  • 236.
  • 237.
  • 238.
  • 239.
  • 240.
  • 241.
  • 242.
  • 243.
  • 244.
  • 245.
  • 246.
  • 247.
  • 248.
  • 249.
  • 250.
  • 251.
  • 252.
  • 253.
  • 254.
  • 255.
  • 256.
  • 257.
  • 258.
  • 259.
  • 260.
  • 261.
  • 262.
  • 263.
  • 264.
  • 265.
  • 266.
  • 267.
  • 268.
  • 269.
  • 270.
  • 271.
  • 272.
  • 273.
  • 274.
  • 275.
  • 276.
  • 277.
  • 278.
  • 279.
  • 280.
  • 281.
  • 282.
  • 283.
  • 284.
  • 285.
  • 286.
  • 287.
  • 288.
  • 289.
  • 290.
  • 291.
  • 292.
  • 293.
  • 294.
  • 295.
  • 296.
  • 297.
  • 298.
  • 299.
  • 300.
  • 301.
  • 302.
  • 303.
  • 304.
  • 305.
  • 306.
  • 307.
  • 308.
  • 309.
  • 310.
  • 311.
  • 312.
  • 313.
  • 314.
  • 315.
  • 316.
  • 317.
  • 318.
  • 319.
  • 320.
  • 321.
  • 322.
  • 323.
  • 324.
  • 325.
  • 326.
  • 327.
  • 328.
  • 329.
  • 330.
  • 331.
  • 332.
  • 333.
  • 334.
  • 335.
  • 336.
  • 337.
  • 338.
  • 339.
  • 340.
  • 341.
  • 342.
  • 343.
  • 344.
  • 345.
  • 346.
  • 347.
  • 348.
  • 349.
  • 350.
  • 351.
  • 352.
  • 353.
  • 354.
  • 355.
  • 356.
  • 357.
  • 358.
  • 359.
  • 360.
  • 361.
  • 362.
  • 363.
  • 364.
  • 365.
  • 366.
  • 367.
  • 368.
  • 369.
  • 370.
  • 371.
  • 372.
  • 373.
  • 374.
  • 375.
  • 376.
  • 377.
  • 378.
  • 379.
  • 380.
  • 381.
  • 382.
  • 383.
  • 384.
  • 385.
  • 386.
  • 387.
  • 388.
  • 389.
  • 390.
  • 391.
  • 392.
  • 393.
  • 394.
  • 395.
  • 396.
  • 397.
  • 398.
  • 399.
  • 400.
  • 401.
  • 402.
  • 403.
  • 404.
  • 405.
  • 406.
  • 407.
  • 408.
  • 409.
  • 410.
  • 411.
  • 412.
  • 413.
  • 414.
  • 415.
  • 416.
  • 417.
  • 418.
  • 419.
  • 420.
  • 421.
  • 422.
  • 423.
  • 424.
  • 425.
  • 426.
  • 427.
  • 428.
  • 429.
  • 430.
  • 431.
  • 432.
  • 433.
  • 434.
  • 435.
  • 436.
  • 437.
  • 438.
  • 439.
  • 440.
  • 441.
  • 442.
  • 443.
  • 444.
  • 445.
  • 446.
  • 447.
  • 448.
  • 449.
  • 450.
  • 451.
  • 452.
  • 453.
  • 454.
  • 455.
  • 456.
  • 457.
  • 458.
  • 459.
  • 460.
  • 461.
  • 462.
  • 463.
  • 464.
  • 465.
  • 466.
  • 467.
  • 468.
  • 469.
  • 470.
  • 471.
  • 472.
  • 473.
  • 474.
  • 475.
  • 476.
  • 477.
  • 478.
  • 479.
  • 480.
  • 481.
  • 482.
  • 483.
  • 484.
  • 485.
  • 486.
  • 487.
  • 488.
  • 489.
  • 490.
  • 491.
  • 492.
  • 493.
  • 494.
  • 495.
  • 496.
  • 497.
  • 498.
  • 499.
  • 500.
  • 501.
  • 502.
  • 503.
  • 504.
  • 505.
  • 506.
  • 507.
  • 508.
  • 509.
  • 510.
  • 511.
  • 512.
  • 513.
  • 514.
  • 515.
  • 516.
  • 517.
  • 518.
  • 519.
  • 520.
  • 521.
  • 522.
  • 523.
  • 524.
  • 525.
  • 526.
  • 527.
  • 528.
  • 529.
  • 530.
  • 531.
  • 532.
  • 533.
  • 534.
  • 535.
  • 536.
  • 537.
  • 538.
  • 539.
  • 540.
  • 541.
  • 542.
  • 543.
  • 544.
  • 545.
  • 546.
  • 547.
  • 548.
  • 549.
  • 550.
  • 551.
  • 552.
  • 553.
  • 554.
  • 555.
  • 556.
  • 557.
  • 558.
  • 559.
  • 560.
  • 561.
  • 562.
  • 563.
  • 564.
  • 565.
  • 566.
  • 567.
  • 568.
  • 569.
  • 570.
  • 571.
  • 572.
  • 573.
  • 574.
  • 575.
  • 576.
  • 577.
  • 578.
  • 579.
  • 580.
  • 581.
  • 582.
  • 583.
  • 584.
  • 585.
  • 586.
  • 587.
  • 588.
  • 589.
  • 590.
  • 591.
  • 592.
  • 593.
  • 594.
  • 595.
  • 596.
  • 597.
  • 598.
  • 599.
  • 600.
  • 601.
  • 602.
  • 603.
  • 604.
  • 605.
  • 606.
  • 607.
  • 608.
  • 609.
  • 610.
  • 611.
  • 612.
  • 613.
  • 614.
  • 615.
  • 616.
  • 617.
  • 618.
  • 619.
  • 620.
  • 621.
  • 622.
  • 623.
  • 624.
  • 625.
  • 626.
  • 627.
  • 628.
  • 629.
  • 630.
  • 631.
View Code

对应需要创建model类,JiraInfoModel类,包含所有收集到的数据:

JIRA REST java client API实际应用_jiraJIRA REST java client API实际应用_jira_02
package com.mockCommon.model;

import java.util.ArrayList;
import java.util.List;

import org.joda.time.DateTime;

public class JiraInfoModel {
    List<String> jiraCommentsBody;
    DateTime jiraCreateTime;
    String description;
    String summary;
    String reporter;
    ArrayList<String> assignees;
    String status;
    String issueType;
    ArrayList<String> modules;
    ArrayList<String> qianduans;
    ArrayList<String> developers;
    String product;
    String start_develop_time;
    String UE_start_time;
    String UE_end_time;
    String UI_start_time;
    String UI_end_time;
    String app_start_time;
    String app_end_time;
    String qianduan_start_time;
    String qianduan_end_time;
    String develop_start_time;
    String develop_end_time;
    String liantiao_start_time;
    String liantiao_end_time;
    String test_start_time;
    String test_end_time;

    public List<String> getJiraCommentsBody() {
        return jiraCommentsBody;
    }

    public void setJiraCommentsBody(List<String> jiraCommentsBody) {
        this.jiraCommentsBody = jiraCommentsBody;
    }

    public DateTime getJiraCreateTime() {
        return jiraCreateTime;
    }

    public void setJiraCreateTime(DateTime jiraCreateTime) {
        this.jiraCreateTime = jiraCreateTime;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getSummary() {
        return summary;
    }

    public void setSummary(String summary) {
        this.summary = summary;
    }

    public String getReporter() {
        return reporter;
    }

    public void setReporter(String reporter) {
        this.reporter = reporter;
    }

    public ArrayList<String> getAssignees() {
        return assignees;
    }

    public void setAssignees(ArrayList<String> assignees) {
        this.assignees = assignees;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getIssueType() {
        return issueType;
    }

    public void setIssueType(String issueType) {
        this.issueType = issueType;
    }

    public ArrayList<String> getModules() {
        return modules;
    }

    public void setModules(ArrayList<String> modules) {
        this.modules = modules;
    }

    public ArrayList<String> getQianduans() {
        return qianduans;
    }

    public void setQianduans(ArrayList<String> qianduans) {
        this.qianduans = qianduans;
    }

    public ArrayList<String> getDevelopers() {
        return developers;
    }

    public void setDevelopers(ArrayList<String> developers) {
        this.developers = developers;
    }

    public String getProduct() {
        return product;
    }

    public void setProduct(String product) {
        this.product = product;
    }

    public String getStart_develop_time() {
        return start_develop_time;
    }

    public void setStart_develop_time(String start_develop_time) {
        this.start_develop_time = start_develop_time;
    }

    public String getUE_start_time() {
        return UE_start_time;
    }

    public void setUE_start_time(String uE_start_time) {
        UE_start_time = uE_start_time;
    }

    public String getUE_end_time() {
        return UE_end_time;
    }

    public void setUE_end_time(String uE_end_time) {
        UE_end_time = uE_end_time;
    }

    public String getUI_start_time() {
        return UI_start_time;
    }

    public void setUI_start_time(String uI_start_time) {
        UI_start_time = uI_start_time;
    }

    public String getUI_end_time() {
        return UI_end_time;
    }

    public void setUI_end_time(String uI_end_time) {
        UI_end_time = uI_end_time;
    }

    public String getApp_start_time() {
        return app_start_time;
    }

    public void setApp_start_time(String app_start_time) {
        this.app_start_time = app_start_time;
    }

    public String getApp_end_time() {
        return app_end_time;
    }

    public void setApp_end_time(String app_end_time) {
        this.app_end_time = app_end_time;
    }

    public String getQianduan_start_time() {
        return qianduan_start_time;
    }

    public void setQianduan_start_time(String qianduan_start_time) {
        this.qianduan_start_time = qianduan_start_time;
    }

    public String getQianduan_end_time() {
        return qianduan_end_time;
    }

    public void setQianduan_end_time(String qianduan_end_time) {
        this.qianduan_end_time = qianduan_end_time;
    }

    public String getDevelop_start_time() {
        return develop_start_time;
    }

    public void setDevelop_start_time(String develop_start_time) {
        this.develop_start_time = develop_start_time;
    }

    public String getDevelop_end_time() {
        return develop_end_time;
    }

    public void setDevelop_end_time(String develop_end_time) {
        this.develop_end_time = develop_end_time;
    }

    public String getLiantiao_start_time() {
        return liantiao_start_time;
    }

    public void setLiantiao_start_time(String liantiao_start_time) {
        this.liantiao_start_time = liantiao_start_time;
    }

    public String getLiantiao_end_time() {
        return liantiao_end_time;
    }

    public void setLiantiao_end_time(String liantiao_end_time) {
        this.liantiao_end_time = liantiao_end_time;
    }

    public String getTest_start_time() {
        return test_start_time;
    }

    public void setTest_start_time(String test_start_time) {
        this.test_start_time = test_start_time;
    }

    public String getTest_end_time() {
        return test_end_time;
    }

    public void setTest_end_time(String test_end_time) {
        this.test_end_time = test_end_time;
    }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.
  • 135.
  • 136.
  • 137.
  • 138.
  • 139.
  • 140.
  • 141.
  • 142.
  • 143.
  • 144.
  • 145.
  • 146.
  • 147.
  • 148.
  • 149.
  • 150.
  • 151.
  • 152.
  • 153.
  • 154.
  • 155.
  • 156.
  • 157.
  • 158.
  • 159.
  • 160.
  • 161.
  • 162.
  • 163.
  • 164.
  • 165.
  • 166.
  • 167.
  • 168.
  • 169.
  • 170.
  • 171.
  • 172.
  • 173.
  • 174.
  • 175.
  • 176.
  • 177.
  • 178.
  • 179.
  • 180.
  • 181.
  • 182.
  • 183.
  • 184.
  • 185.
  • 186.
  • 187.
  • 188.
  • 189.
  • 190.
  • 191.
  • 192.
  • 193.
  • 194.
  • 195.
  • 196.
  • 197.
  • 198.
  • 199.
  • 200.
  • 201.
  • 202.
  • 203.
  • 204.
  • 205.
  • 206.
  • 207.
  • 208.
  • 209.
  • 210.
  • 211.
  • 212.
  • 213.
  • 214.
  • 215.
  • 216.
  • 217.
  • 218.
  • 219.
  • 220.
  • 221.
  • 222.
  • 223.
  • 224.
  • 225.
  • 226.
  • 227.
  • 228.
  • 229.
  • 230.
  • 231.
  • 232.
  • 233.
  • 234.
  • 235.
  • 236.
  • 237.
  • 238.
  • 239.
  • 240.
  • 241.
  • 242.
  • 243.
  • 244.
  • 245.
  • 246.
  • 247.
  • 248.
  • 249.
  • 250.
  • 251.
  • 252.
View Code

以上代码中在get_assignees()方法部分用到了mjson中的Json对象,也是主要用来处理json格式的对象。

代码中“用户名”、“密码”、“JIRA号”部分为需要替换的部分。

另外,对于通过jql查询的封装如下:

/**
 * 通过jql语句进行查询并返回一个包含issue的key的数组
 * 
 * @param username 登录JIRA的用户名
 * @param password 登录JIRA的用户密码
 * @param current_user_name 要查询的用户名
 * @param jql
 * @return
 * @throws URISyntaxException
 */
public static ArrayList<String> search_jql(String username, String password, String current_user_name, String jql)
        throws URISyntaxException {
    final JiraRestClient restClient = login_jira(username, password);
    final NullProgressMonitor pm = new NullProgressMonitor();
    SearchResult searchResult = restClient.getSearchClient().searchJql(jql, pm);
    Iterator<BasicIssue> basicIssues = searchResult.getIssues().iterator();
    ArrayList<String> issueKeys = new ArrayList<>();
    while (basicIssues.hasNext()) {
        String issueKey = basicIssues.next().getKey();
        System.out.println(issueKey);
        issueKeys.add(issueKey);
    }
    return issueKeys;
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.

上面这些是基本的例子,后续我又针对实际应用做了很多修改。基于这些封装,再用上Spring MVC框架,我做了一个基于JIRA开发的质量保障平台。

Github地址:https://github.com/OuterCloud/JiraHelper

例图1:

JIRA REST java client API实际应用_jira_05

例图2:

JIRA REST java client API实际应用_jira_06

 

, ,
 
 
 
QR Code
微信扫一扫,欢迎咨询~

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 155-2731-8020
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

手机不正确

公司不为空