packagecom.mockCommon.util;importjava.net.URI;importjava.net.URISyntaxException;importjava.util.ArrayList;importjava.util.Iterator;importjava.util.List;importorg.joda.time.DateTime;importcom.atlassian.jira.rest.client.JiraRestClient;importcom.atlassian.jira.rest.client.NullProgressMonitor;importcom.atlassian.jira.rest.client.domain.BasicComponent;importcom.atlassian.jira.rest.client.domain.Comment;importcom.atlassian.jira.rest.client.domain.Issue;importcom.atlassian.jira.rest.client.internal.jersey.JerseyJiraRestClientFactory;importcom.mockCommon.model.JiraInfoModel;importmjson.Json;public classJiraUtil {/*** 登录JIRA并返回指定的JiraRestClient对象
*
*@paramusername
*@parampassword
*@return*@throwsURISyntaxException*/
public static JiraRestClient login_jira(String username, String password) throwsURISyntaxException {try{final JerseyJiraRestClientFactory factory = newJerseyJiraRestClientFactory();final URI jiraServerUri = new URI(“http://jira.ms.netease.com”);final JiraRestClient restClient =factory.createWithBasicHttpAuthentication(jiraServerUri, username,
password);returnrestClient;
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取并返回指定的Issue对象
*
*@paramissueNum
*@paramusername
*@parampassword
*@return*@throwsURISyntaxException*/
public static Issue get_issue(String issueNum, String username, String password) throwsURISyntaxException {try{final JiraRestClient restClient =login_jira(username, password);final NullProgressMonitor pm = newNullProgressMonitor();final Issue issue =restClient.getIssueClient().getIssue(issueNum, pm);returnissue;
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取指定JIRA备注部分的内容
*
*@paramissue
*@paramusername
*@parampassword
*@return*@throwsURISyntaxException*/
public static List get_comments_body(Issue issue) throwsURISyntaxException {try{
List comments = new ArrayList();for(Comment comment : issue.getComments()) {
comments.add(comment.getBody().toString());
}returncomments;
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取指定JIRA的创建时间
*
*@paramissueNum
*@paramusername
*@parampassword
*@return*@throwsURISyntaxException*/
public static DateTime get_create_time(Issue issue) throwsURISyntaxException {try{returnissue.getCreationDate();
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取指定JIRA的描述部分
*
*@paramissueNum
*@paramusername
*@parampassword
*@return*@throwsURISyntaxException*/
public static String get_description(Issue issue) throwsURISyntaxException {try{returnissue.getDescription();
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取指定JIRA的标题
*
*@paramissueNum
*@paramusername
*@parampassword
*@return*@throwsURISyntaxException*/
public static String get_summary(Issue issue) throwsURISyntaxException {try{returnissue.getSummary();
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取指定JIRA的报告人的名字
*
*@paramissueNum
*@paramusername
*@parampassword
*@return*@throwsURISyntaxException*/
public static String get_reporter(Issue issue) throwsURISyntaxException {try{returnissue.getReporter().getDisplayName();
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取指定JIRA的分派人的姓名列表
*
*@paramissue
*@paramusername
*@parampassword
*@return*@throwsURISyntaxException*/
public static ArrayList get_assignees(Issue issue) throwsURISyntaxException {try{
Json json= Json.read(issue.getFieldByName(“分派给”).getValue().toString());
Iterator assignees =json.asJsonList().iterator();
ArrayList assigneesNames = new ArrayList();while(assignees.hasNext()) {
Json assignee=Json.read(assignees.next().toString());
String assigneeName= assignee.at(“displayName”).toString();
assigneesNames.add(assigneeName);
}returnassigneesNames;
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取指定JIRA的状态
*
*@paramissue
*@paramusername
*@parampassword
*@return*@throwsURISyntaxException*/
public static String get_status(Issue issue) throwsURISyntaxException {try{returnissue.getStatus().getName();
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取指定JIRA的类型
*
*@paramissue
*@paramusername
*@parampassword
*@return*@throwsURISyntaxException*/
public static String get_issue_type(Issue issue) throwsURISyntaxException {try{returnissue.getIssueType().getName();
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取指定JIRA的模块
*
*@paramissue
*@paramusername
*@parampassword
*@return*@throwsURISyntaxException*/
public static ArrayList get_modules(Issue issue) throwsURISyntaxException {try{
ArrayList arrayList = new ArrayList();
Iterator basicComponents =issue.getComponents().iterator();while(basicComponents.hasNext()) {
String moduleName=basicComponents.next().getName();
arrayList.add(moduleName);
}returnarrayList;
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取指定JIRA的前端人员的姓名列表
*
*@paramissue
*@paramusername
*@parampassword
*@return*@throwsURISyntaxException*/
public static ArrayList get_qianduans(Issue issue) throwsURISyntaxException {try{
ArrayList qianduanList = new ArrayList();
Json json= Json.read(issue.getFieldByName(“前端”).getValue().toString());
Iterator qianduans =json.asJsonList().iterator();while(qianduans.hasNext()) {
Json qianduan=Json.read(qianduans.next().toString());
String qianduanName= qianduan.at(“displayName”).toString();
qianduanList.add(qianduanName);
}returnqianduanList;
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取指定JIRA的开发的姓名列表
*
*@paramissue
*@paramusername
*@parampassword
*@return*@throwsURISyntaxException*/
public static ArrayList get_developers(Issue issue) throwsURISyntaxException {try{
ArrayList developersList = new ArrayList();
Json json= Json.read(issue.getFieldByName(“开发”).getValue().toString());
Iterator developers =json.asJsonList().iterator();while(developers.hasNext()) {
Json developer=Json.read(developers.next().toString());
String developerName= developer.at(“displayName”).toString();
developersList.add(developerName);
}returndevelopersList;
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取指定JIRA的产品人员的姓名
*
*@paramissue
*@paramusername
*@parampassword
*@return*@throwsURISyntaxException*/
public static String get_product(Issue issue) throwsURISyntaxException {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开始时间
*
*@paramissue
*@return*@throwsURISyntaxException*/
public static String get_UE_start_time(Issue issue) throwsURISyntaxException {try{
String UE_start_time= issue.getFieldByName(“UE开始时间”).getValue().toString();returnUE_start_time;
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取指定JIRA的UE结束时间
*
*@paramissue
*@return*@throwsURISyntaxException*/
public static String get_UE_end_time(Issue issue) throwsURISyntaxException {try{
String UE_end_time= issue.getFieldByName(“UE结束时间”).getValue().toString();returnUE_end_time;
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取指定JIRA的UI开始时间
*
*@paramissue
*@return*@throwsURISyntaxException*/
public static String get_UI_start_time(Issue issue) throwsURISyntaxException {try{
String UI_start_time= issue.getFieldByName(“UI开始时间”).getValue().toString();returnUI_start_time;
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取指定JIRA的UI结束时间
*
*@paramissue
*@return*@throwsURISyntaxException*/
public static String get_UI_end_time(Issue issue) throwsURISyntaxException {try{
String UI_end_time= issue.getFieldByName(“UI结束时间”).getValue().toString();returnUI_end_time;
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取指定JIRA的客户端开始时间
*
*@paramissue
*@return*@throwsURISyntaxException*/
public static String get_app_start_time(Issue issue) throwsURISyntaxException {try{
String app_start_time= issue.getFieldByName(“客户端开始时间”).getValue().toString();returnapp_start_time;
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取指定JIRA的客户端结束时间
*
*@paramissue
*@return*@throwsURISyntaxException*/
public static String get_app_end_time(Issue issue) throwsURISyntaxException {try{
String app_end_time= issue.getFieldByName(“客户端结束时间”).getValue().toString();returnapp_end_time;
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取指定JIRA的前端开始时间
*
*@paramissue
*@return*@throwsURISyntaxException*/
public static String get_qianduan_start_time(Issue issue) throwsURISyntaxException {try{
String qianduan_start_time= issue.getFieldByName(“前端开始时间”).getValue().toString();returnqianduan_start_time;
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取指定JIRA的前端结束时间
*
*@paramissue
*@return*@throwsURISyntaxException*/
public static String get_qianduan_end_time(Issue issue) throwsURISyntaxException {try{
String qianduan_end_time= issue.getFieldByName(“前端结束时间”).getValue().toString();returnqianduan_end_time;
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取指定JIRA的开发开始时间
*
*@paramissue
*@return*@throwsURISyntaxException*/
public static String get_develop_start_time(Issue issue) throwsURISyntaxException {try{
String develop_start_time= issue.getFieldByName(“开发开始时间”).getValue().toString();returndevelop_start_time;
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取指定JIRA的开发结束时间
*
*@paramissue
*@return*@throwsURISyntaxException*/
public static String get_develop_end_time(Issue issue) throwsURISyntaxException {try{
String develop_end_time= issue.getFieldByName(“开发结束时间”).getValue().toString();returndevelop_end_time;
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取指定JIRA的联调开始时间
*
*@paramissue
*@return*@throwsURISyntaxException*/
public static String get_liantiao_start_time(Issue issue) throwsURISyntaxException {try{
String liantiao_start_time= issue.getFieldByName(“联调开始时间”).getValue().toString();returnliantiao_start_time;
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取指定JIRA的联调结束时间
*
*@paramissue
*@return*@throwsURISyntaxException*/
public static String get_liantiao_end_time(Issue issue) throwsURISyntaxException {try{
String liantiao_end_time= issue.getFieldByName(“联调结束时间”).getValue().toString();returnliantiao_end_time;
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取指定JIRA的测试开始时间
*
*@paramissue
*@return*@throwsURISyntaxException*/
public static String get_test_start_time(Issue issue) throwsURISyntaxException {try{
String test_start_time= issue.getFieldByName(“测试开始时间”).getValue().toString();returntest_start_time;
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取指定JIRA的测试结束时间
*
*@paramissue
*@return*@throwsURISyntaxException*/
public static String get_test_end_time(Issue issue) throwsURISyntaxException {try{
String test_end_time= issue.getFieldByName(“测试结束时间”).getValue().toString();returntest_end_time;
}catch(Exception e) {
e.printStackTrace();
}return null;
}/*** 获取所有可以收集到的JIRA信息并返回JiraInfoModel类型对象
*@paramissue
*@return*@throwsURISyntaxException*/
public static JiraInfoModel get_jira_info(Issue issue) throwsURISyntaxException {
List 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 assignees =get_assignees(issue);
String status=get_status(issue);
String issueType=get_issue_type(issue);
ArrayList modules =get_modules(issue);
ArrayList qianduans =get_qianduans(issue);
ArrayList 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= newJiraInfoModel();
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);returnjiraInfoModel;
}/*** 测试函数
*
*@paramargs
*@throwsURISyntaxException*/
public static void main(String[] args) throwsURISyntaxException {
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());
}
}