[本文出自天外归云的博客园]

前提

1、需要安装maven环境;

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

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

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

封装方法

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

  1. package com.mockCommon.util;
  2.  
  3. import java.net.URI;
  4. import java.net.URISyntaxException;
  5. import java.util.ArrayList;
  6. import java.util.Iterator;
  7. import java.util.List;
  8.  
  9. import org.joda.time.DateTime;
  10. import com.atlassian.jira.rest.client.JiraRestClient;
  11. import com.atlassian.jira.rest.client.NullProgressMonitor;
  12. import com.atlassian.jira.rest.client.domain.BasicComponent;
  13. import com.atlassian.jira.rest.client.domain.Comment;
  14. import com.atlassian.jira.rest.client.domain.Issue;
  15. import com.atlassian.jira.rest.client.internal.jersey.JerseyJiraRestClientFactory;
  16. import com.mockCommon.model.JiraInfoModel;
  17.  
  18. import mjson.Json;
  19.  
  20. public class JiraUtil {
  21.  
  22. /**
  23. * 登录JIRA并返回指定的JiraRestClient对象
  24. *
  25. * @param username
  26. * @param password
  27. * @return
  28. * @throws URISyntaxException
  29. */
  30. public static JiraRestClient login_jira(String username, String password) throws URISyntaxException {
  31. try {
  32. final JerseyJiraRestClientFactory factory = new JerseyJiraRestClientFactory();
  33. final URI jiraServerUri = new URI("http://jira.ms.netease.com");
  34. final JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri, username,
  35. password);
  36. return restClient;
  37. } catch (Exception e) {
  38. e.printStackTrace();
  39. }
  40. return null;
  41. }
  42.  
  43. /**
  44. * 获取并返回指定的Issue对象
  45. *
  46. * @param issueNum
  47. * @param username
  48. * @param password
  49. * @return
  50. * @throws URISyntaxException
  51. */
  52. public static Issue get_issue(String issueNum, String username, String password) throws URISyntaxException {
  53. try {
  54. final JiraRestClient restClient = login_jira(username, password);
  55. final NullProgressMonitor pm = new NullProgressMonitor();
  56. final Issue issue = restClient.getIssueClient().getIssue(issueNum, pm);
  57. return issue;
  58. } catch (Exception e) {
  59. e.printStackTrace();
  60. }
  61. return null;
  62. }
  63.  
  64. /**
  65. * 获取指定JIRA备注部分的内容
  66. *
  67. * @param issue
  68. * @param username
  69. * @param password
  70. * @return
  71. * @throws URISyntaxException
  72. */
  73. public static List<String> get_comments_body(Issue issue) throws URISyntaxException {
  74. try {
  75. List<String> comments = new ArrayList<String>();
  76. for (Comment comment : issue.getComments()) {
  77. comments.add(comment.getBody().toString());
  78. }
  79. return comments;
  80. } catch (Exception e) {
  81. e.printStackTrace();
  82. }
  83. return null;
  84. }
  85.  
  86. /**
  87. * 获取指定JIRA的创建时间
  88. *
  89. * @param issueNum
  90. * @param username
  91. * @param password
  92. * @return
  93. * @throws URISyntaxException
  94. */
  95. public static DateTime get_create_time(Issue issue) throws URISyntaxException {
  96. try {
  97. return issue.getCreationDate();
  98. } catch (Exception e) {
  99. e.printStackTrace();
  100. }
  101. return null;
  102. }
  103.  
  104. /**
  105. * 获取指定JIRA的描述部分
  106. *
  107. * @param issueNum
  108. * @param username
  109. * @param password
  110. * @return
  111. * @throws URISyntaxException
  112. */
  113. public static String get_description(Issue issue) throws URISyntaxException {
  114. try {
  115. return issue.getDescription();
  116. } catch (Exception e) {
  117. e.printStackTrace();
  118. }
  119. return null;
  120. }
  121.  
  122. /**
  123. * 获取指定JIRA的标题
  124. *
  125. * @param issueNum
  126. * @param username
  127. * @param password
  128. * @return
  129. * @throws URISyntaxException
  130. */
  131. public static String get_summary(Issue issue) throws URISyntaxException {
  132. try {
  133. return issue.getSummary();
  134. } catch (Exception e) {
  135. e.printStackTrace();
  136. }
  137. return null;
  138. }
  139.  
  140. /**
  141. * 获取指定JIRA的报告人的名字
  142. *
  143. * @param issueNum
  144. * @param username
  145. * @param password
  146. * @return
  147. * @throws URISyntaxException
  148. */
  149. public static String get_reporter(Issue issue) throws URISyntaxException {
  150. try {
  151. return issue.getReporter().getDisplayName();
  152. } catch (Exception e) {
  153. e.printStackTrace();
  154. }
  155. return null;
  156. }
  157.  
  158. /**
  159. * 获取指定JIRA的分派人的姓名列表
  160. *
  161. * @param issue
  162. * @param username
  163. * @param password
  164. * @return
  165. * @throws URISyntaxException
  166. */
  167. public static ArrayList<String> get_assignees(Issue issue) throws URISyntaxException {
  168. try {
  169. Json json = Json.read(issue.getFieldByName("分派给").getValue().toString());
  170. Iterator<Json> assignees = json.asJsonList().iterator();
  171. ArrayList<String> assigneesNames = new ArrayList<String>();
  172. while (assignees.hasNext()) {
  173. Json assignee = Json.read(assignees.next().toString());
  174. String assigneeName = assignee.at("displayName").toString();
  175. assigneesNames.add(assigneeName);
  176. }
  177. return assigneesNames;
  178. } catch (Exception e) {
  179. e.printStackTrace();
  180. }
  181. return null;
  182. }
  183.  
  184. /**
  185. * 获取指定JIRA的状态
  186. *
  187. * @param issue
  188. * @param username
  189. * @param password
  190. * @return
  191. * @throws URISyntaxException
  192. */
  193. public static String get_status(Issue issue) throws URISyntaxException {
  194. try {
  195. return issue.getStatus().getName();
  196. } catch (Exception e) {
  197. e.printStackTrace();
  198. }
  199. return null;
  200. }
  201.  
  202. /**
  203. * 获取指定JIRA的类型
  204. *
  205. * @param issue
  206. * @param username
  207. * @param password
  208. * @return
  209. * @throws URISyntaxException
  210. */
  211. public static String get_issue_type(Issue issue) throws URISyntaxException {
  212. try {
  213. return issue.getIssueType().getName();
  214. } catch (Exception e) {
  215. e.printStackTrace();
  216. }
  217. return null;
  218. }
  219.  
  220. /**
  221. * 获取指定JIRA的模块
  222. *
  223. * @param issue
  224. * @param username
  225. * @param password
  226. * @return
  227. * @throws URISyntaxException
  228. */
  229. public static ArrayList<String> get_modules(Issue issue) throws URISyntaxException {
  230. try {
  231. ArrayList<String> arrayList = new ArrayList<String>();
  232. Iterator<BasicComponent> basicComponents = issue.getComponents().iterator();
  233. while (basicComponents.hasNext()) {
  234. String moduleName = basicComponents.next().getName();
  235. arrayList.add(moduleName);
  236. }
  237. return arrayList;
  238. } catch (Exception e) {
  239. e.printStackTrace();
  240. }
  241. return null;
  242. }
  243.  
  244. /**
  245. * 获取指定JIRA的前端人员的姓名列表
  246. *
  247. * @param issue
  248. * @param username
  249. * @param password
  250. * @return
  251. * @throws URISyntaxException
  252. */
  253. public static ArrayList<String> get_qianduans(Issue issue) throws URISyntaxException {
  254. try {
  255. ArrayList<String> qianduanList = new ArrayList<String>();
  256. Json json = Json.read(issue.getFieldByName("前端").getValue().toString());
  257. Iterator<Json> qianduans = json.asJsonList().iterator();
  258. while (qianduans.hasNext()) {
  259. Json qianduan = Json.read(qianduans.next().toString());
  260. String qianduanName = qianduan.at("displayName").toString();
  261. qianduanList.add(qianduanName);
  262. }
  263. return qianduanList;
  264. } catch (Exception e) {
  265. e.printStackTrace();
  266. }
  267. return null;
  268. }
  269.  
  270. /**
  271. * 获取指定JIRA的开发的姓名列表
  272. *
  273. * @param issue
  274. * @param username
  275. * @param password
  276. * @return
  277. * @throws URISyntaxException
  278. */
  279. public static ArrayList<String> get_developers(Issue issue) throws URISyntaxException {
  280. try {
  281. ArrayList<String> developersList = new ArrayList<String>();
  282. Json json = Json.read(issue.getFieldByName("开发").getValue().toString());
  283. Iterator<Json> developers = json.asJsonList().iterator();
  284. while (developers.hasNext()) {
  285. Json developer = Json.read(developers.next().toString());
  286. String developerName = developer.at("displayName").toString();
  287. developersList.add(developerName);
  288. }
  289. return developersList;
  290. } catch (Exception e) {
  291. e.printStackTrace();
  292. }
  293. return null;
  294. }
  295.  
  296. /**
  297. * 获取指定JIRA的产品人员的姓名
  298. *
  299. * @param issue
  300. * @param username
  301. * @param password
  302. * @return
  303. * @throws URISyntaxException
  304. */
  305. public static String get_product(Issue issue) throws URISyntaxException {
  306. try {
  307. String product_field = issue.getFieldByName("产品人员").getValue().toString();
  308. return Json.read(product_field).at("displayName").toString();
  309. } catch (Exception e) {
  310. e.printStackTrace();
  311. }
  312. return null;
  313. }
  314.  
  315. /**
  316. * 获取指定JIRA的UE开始时间
  317. *
  318. * @param issue
  319. * @return
  320. * @throws URISyntaxException
  321. */
  322. public static String get_UE_start_time(Issue issue) throws URISyntaxException {
  323. try {
  324. String UE_start_time = issue.getFieldByName("UE开始时间").getValue().toString();
  325. return UE_start_time;
  326. } catch (Exception e) {
  327. e.printStackTrace();
  328. }
  329. return null;
  330. }
  331.  
  332. /**
  333. * 获取指定JIRA的UE结束时间
  334. *
  335. * @param issue
  336. * @return
  337. * @throws URISyntaxException
  338. */
  339. public static String get_UE_end_time(Issue issue) throws URISyntaxException {
  340. try {
  341. String UE_end_time = issue.getFieldByName("UE结束时间").getValue().toString();
  342. return UE_end_time;
  343. } catch (Exception e) {
  344. e.printStackTrace();
  345. }
  346. return null;
  347. }
  348.  
  349. /**
  350. * 获取指定JIRA的UI开始时间
  351. *
  352. * @param issue
  353. * @return
  354. * @throws URISyntaxException
  355. */
  356. public static String get_UI_start_time(Issue issue) throws URISyntaxException {
  357. try {
  358. String UI_start_time = issue.getFieldByName("UI开始时间").getValue().toString();
  359. return UI_start_time;
  360. } catch (Exception e) {
  361. e.printStackTrace();
  362. }
  363. return null;
  364. }
  365.  
  366. /**
  367. * 获取指定JIRA的UI结束时间
  368. *
  369. * @param issue
  370. * @return
  371. * @throws URISyntaxException
  372. */
  373. public static String get_UI_end_time(Issue issue) throws URISyntaxException {
  374. try {
  375. String UI_end_time = issue.getFieldByName("UI结束时间").getValue().toString();
  376. return UI_end_time;
  377. } catch (Exception e) {
  378. e.printStackTrace();
  379. }
  380. return null;
  381. }
  382.  
  383. /**
  384. * 获取指定JIRA的客户端开始时间
  385. *
  386. * @param issue
  387. * @return
  388. * @throws URISyntaxException
  389. */
  390. public static String get_app_start_time(Issue issue) throws URISyntaxException {
  391. try {
  392. String app_start_time = issue.getFieldByName("客户端开始时间").getValue().toString();
  393. return app_start_time;
  394. } catch (Exception e) {
  395. e.printStackTrace();
  396. }
  397. return null;
  398. }
  399.  
  400. /**
  401. * 获取指定JIRA的客户端结束时间
  402. *
  403. * @param issue
  404. * @return
  405. * @throws URISyntaxException
  406. */
  407. public static String get_app_end_time(Issue issue) throws URISyntaxException {
  408. try {
  409. String app_end_time = issue.getFieldByName("客户端结束时间").getValue().toString();
  410. return app_end_time;
  411. } catch (Exception e) {
  412. e.printStackTrace();
  413. }
  414. return null;
  415. }
  416.  
  417. /**
  418. * 获取指定JIRA的前端开始时间
  419. *
  420. * @param issue
  421. * @return
  422. * @throws URISyntaxException
  423. */
  424. public static String get_qianduan_start_time(Issue issue) throws URISyntaxException {
  425. try {
  426. String qianduan_start_time = issue.getFieldByName("前端开始时间").getValue().toString();
  427. return qianduan_start_time;
  428. } catch (Exception e) {
  429. e.printStackTrace();
  430. }
  431. return null;
  432. }
  433.  
  434. /**
  435. * 获取指定JIRA的前端结束时间
  436. *
  437. * @param issue
  438. * @return
  439. * @throws URISyntaxException
  440. */
  441. public static String get_qianduan_end_time(Issue issue) throws URISyntaxException {
  442. try {
  443. String qianduan_end_time = issue.getFieldByName("前端结束时间").getValue().toString();
  444. return qianduan_end_time;
  445. } catch (Exception e) {
  446. e.printStackTrace();
  447. }
  448. return null;
  449. }
  450.  
  451. /**
  452. * 获取指定JIRA的开发开始时间
  453. *
  454. * @param issue
  455. * @return
  456. * @throws URISyntaxException
  457. */
  458. public static String get_develop_start_time(Issue issue) throws URISyntaxException {
  459. try {
  460. String develop_start_time = issue.getFieldByName("开发开始时间").getValue().toString();
  461. return develop_start_time;
  462. } catch (Exception e) {
  463. e.printStackTrace();
  464. }
  465. return null;
  466. }
  467.  
  468. /**
  469. * 获取指定JIRA的开发结束时间
  470. *
  471. * @param issue
  472. * @return
  473. * @throws URISyntaxException
  474. */
  475. public static String get_develop_end_time(Issue issue) throws URISyntaxException {
  476. try {
  477. String develop_end_time = issue.getFieldByName("开发结束时间").getValue().toString();
  478. return develop_end_time;
  479. } catch (Exception e) {
  480. e.printStackTrace();
  481. }
  482. return null;
  483. }
  484.  
  485. /**
  486. * 获取指定JIRA的联调开始时间
  487. *
  488. * @param issue
  489. * @return
  490. * @throws URISyntaxException
  491. */
  492. public static String get_liantiao_start_time(Issue issue) throws URISyntaxException {
  493. try {
  494. String liantiao_start_time = issue.getFieldByName("联调开始时间").getValue().toString();
  495. return liantiao_start_time;
  496. } catch (Exception e) {
  497. e.printStackTrace();
  498. }
  499. return null;
  500. }
  501.  
  502. /**
  503. * 获取指定JIRA的联调结束时间
  504. *
  505. * @param issue
  506. * @return
  507. * @throws URISyntaxException
  508. */
  509. public static String get_liantiao_end_time(Issue issue) throws URISyntaxException {
  510. try {
  511. String liantiao_end_time = issue.getFieldByName("联调结束时间").getValue().toString();
  512. return liantiao_end_time;
  513. } catch (Exception e) {
  514. e.printStackTrace();
  515. }
  516. return null;
  517. }
  518.  
  519. /**
  520. * 获取指定JIRA的测试开始时间
  521. *
  522. * @param issue
  523. * @return
  524. * @throws URISyntaxException
  525. */
  526. public static String get_test_start_time(Issue issue) throws URISyntaxException {
  527. try {
  528. String test_start_time = issue.getFieldByName("测试开始时间").getValue().toString();
  529. return test_start_time;
  530. } catch (Exception e) {
  531. e.printStackTrace();
  532. }
  533. return null;
  534. }
  535.  
  536. /**
  537. * 获取指定JIRA的测试结束时间
  538. *
  539. * @param issue
  540. * @return
  541. * @throws URISyntaxException
  542. */
  543. public static String get_test_end_time(Issue issue) throws URISyntaxException {
  544. try {
  545. String test_end_time = issue.getFieldByName("测试结束时间").getValue().toString();
  546. return test_end_time;
  547. } catch (Exception e) {
  548. e.printStackTrace();
  549. }
  550. return null;
  551. }
  552.  
  553. /**
  554. * 获取所有可以收集到的JIRA信息并返回JiraInfoModel类型对象
  555. * @param issue
  556. * @return
  557. * @throws URISyntaxException
  558. */
  559. public static JiraInfoModel get_jira_info(Issue issue) throws URISyntaxException {
  560. List<String> jiraCommentsBody = get_comments_body(issue);
  561. DateTime jiraCreateTime = get_create_time(issue);
  562. String description = get_description(issue);
  563. String summary = get_summary(issue);
  564. String reporter = get_reporter(issue);
  565. ArrayList<String> assignees = get_assignees(issue);
  566. String status = get_status(issue);
  567. String issueType = get_issue_type(issue);
  568. ArrayList<String> modules = get_modules(issue);
  569. ArrayList<String> qianduans = get_qianduans(issue);
  570. ArrayList<String> developers = get_developers(issue);
  571. String product = get_product(issue);
  572. String UE_start_time = get_UE_start_time(issue);
  573. String UE_end_time = get_UE_end_time(issue);
  574. String UI_start_time = get_UI_start_time(issue);
  575. String UI_end_time = get_UI_end_time(issue);
  576. String app_start_time = get_app_start_time(issue);
  577. String app_end_time = get_app_end_time(issue);
  578. String qianduan_start_time = get_qianduan_start_time(issue);
  579. String qianduan_end_time = get_qianduan_end_time(issue);
  580. String develop_start_time = get_develop_start_time(issue);
  581. String develop_end_time = get_develop_end_time(issue);
  582. String liantiao_start_time = get_liantiao_start_time(issue);
  583. String liantiao_end_time = get_liantiao_end_time(issue);
  584. String test_start_time = get_test_start_time(issue);
  585. String test_end_time = get_test_end_time(issue);
  586. JiraInfoModel jiraInfoModel = new JiraInfoModel();
  587. jiraInfoModel.setJiraCommentsBody(jiraCommentsBody);
  588. jiraInfoModel.setJiraCreateTime(jiraCreateTime);
  589. jiraInfoModel.setDescription(description);
  590. jiraInfoModel.setSummary(summary);
  591. jiraInfoModel.setReporter(reporter);
  592. jiraInfoModel.setAssignees(assignees);
  593. jiraInfoModel.setStatus(status);
  594. jiraInfoModel.setIssueType(issueType);
  595. jiraInfoModel.setModules(modules);
  596. jiraInfoModel.setQianduans(qianduans);
  597. jiraInfoModel.setDevelopers(developers);
  598. jiraInfoModel.setProduct(product);
  599. jiraInfoModel.setUE_start_time(UE_start_time);
  600. jiraInfoModel.setUE_end_time(UE_end_time);
  601. jiraInfoModel.setUI_start_time(UI_start_time);
  602. jiraInfoModel.setUI_end_time(UI_end_time);
  603. jiraInfoModel.setApp_start_time(app_start_time);
  604. jiraInfoModel.setApp_end_time(app_end_time);
  605. jiraInfoModel.setQianduan_start_time(qianduan_start_time);
  606. jiraInfoModel.setQianduan_end_time(qianduan_end_time);
  607. jiraInfoModel.setDevelop_start_time(develop_start_time);
  608. jiraInfoModel.setDevelop_end_time(develop_end_time);
  609. jiraInfoModel.setLiantiao_start_time(liantiao_start_time);
  610. jiraInfoModel.setLiantiao_end_time(liantiao_end_time);
  611. jiraInfoModel.setTest_start_time(test_start_time);
  612. jiraInfoModel.setTest_end_time(test_end_time);
  613. return jiraInfoModel;
  614. }
  615.  
  616. /**
  617. * 测试函数
  618. *
  619. * @param args
  620. * @throws URISyntaxException
  621. */
  622. public static void main(String[] args) throws URISyntaxException {
  623. String username = "用户名";
  624. String password = "密码";
  625. String issueNum = "JIRA号";
  626. final Issue issue = get_issue(issueNum, username, password);
  627. JiraInfoModel jiraInfoModel = get_jira_info(issue);
  628. System.out.println(jiraInfoModel.getSummary());
  629. }
  630.  
  631. }

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

  1. package com.mockCommon.model;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import org.joda.time.DateTime;
  7.  
  8. public class JiraInfoModel {
  9. List<String> jiraCommentsBody;
  10. DateTime jiraCreateTime;
  11. String description;
  12. String summary;
  13. String reporter;
  14. ArrayList<String> assignees;
  15. String status;
  16. String issueType;
  17. ArrayList<String> modules;
  18. ArrayList<String> qianduans;
  19. ArrayList<String> developers;
  20. String product;
  21. String start_develop_time;
  22. String UE_start_time;
  23. String UE_end_time;
  24. String UI_start_time;
  25. String UI_end_time;
  26. String app_start_time;
  27. String app_end_time;
  28. String qianduan_start_time;
  29. String qianduan_end_time;
  30. String develop_start_time;
  31. String develop_end_time;
  32. String liantiao_start_time;
  33. String liantiao_end_time;
  34. String test_start_time;
  35. String test_end_time;
  36.  
  37. public List<String> getJiraCommentsBody() {
  38. return jiraCommentsBody;
  39. }
  40.  
  41. public void setJiraCommentsBody(List<String> jiraCommentsBody) {
  42. this.jiraCommentsBody = jiraCommentsBody;
  43. }
  44.  
  45. public DateTime getJiraCreateTime() {
  46. return jiraCreateTime;
  47. }
  48.  
  49. public void setJiraCreateTime(DateTime jiraCreateTime) {
  50. this.jiraCreateTime = jiraCreateTime;
  51. }
  52.  
  53. public String getDescription() {
  54. return description;
  55. }
  56.  
  57. public void setDescription(String description) {
  58. this.description = description;
  59. }
  60.  
  61. public String getSummary() {
  62. return summary;
  63. }
  64.  
  65. public void setSummary(String summary) {
  66. this.summary = summary;
  67. }
  68.  
  69. public String getReporter() {
  70. return reporter;
  71. }
  72.  
  73. public void setReporter(String reporter) {
  74. this.reporter = reporter;
  75. }
  76.  
  77. public ArrayList<String> getAssignees() {
  78. return assignees;
  79. }
  80.  
  81. public void setAssignees(ArrayList<String> assignees) {
  82. this.assignees = assignees;
  83. }
  84.  
  85. public String getStatus() {
  86. return status;
  87. }
  88.  
  89. public void setStatus(String status) {
  90. this.status = status;
  91. }
  92.  
  93. public String getIssueType() {
  94. return issueType;
  95. }
  96.  
  97. public void setIssueType(String issueType) {
  98. this.issueType = issueType;
  99. }
  100.  
  101. public ArrayList<String> getModules() {
  102. return modules;
  103. }
  104.  
  105. public void setModules(ArrayList<String> modules) {
  106. this.modules = modules;
  107. }
  108.  
  109. public ArrayList<String> getQianduans() {
  110. return qianduans;
  111. }
  112.  
  113. public void setQianduans(ArrayList<String> qianduans) {
  114. this.qianduans = qianduans;
  115. }
  116.  
  117. public ArrayList<String> getDevelopers() {
  118. return developers;
  119. }
  120.  
  121. public void setDevelopers(ArrayList<String> developers) {
  122. this.developers = developers;
  123. }
  124.  
  125. public String getProduct() {
  126. return product;
  127. }
  128.  
  129. public void setProduct(String product) {
  130. this.product = product;
  131. }
  132.  
  133. public String getStart_develop_time() {
  134. return start_develop_time;
  135. }
  136.  
  137. public void setStart_develop_time(String start_develop_time) {
  138. this.start_develop_time = start_develop_time;
  139. }
  140.  
  141. public String getUE_start_time() {
  142. return UE_start_time;
  143. }
  144.  
  145. public void setUE_start_time(String uE_start_time) {
  146. UE_start_time = uE_start_time;
  147. }
  148.  
  149. public String getUE_end_time() {
  150. return UE_end_time;
  151. }
  152.  
  153. public void setUE_end_time(String uE_end_time) {
  154. UE_end_time = uE_end_time;
  155. }
  156.  
  157. public String getUI_start_time() {
  158. return UI_start_time;
  159. }
  160.  
  161. public void setUI_start_time(String uI_start_time) {
  162. UI_start_time = uI_start_time;
  163. }
  164.  
  165. public String getUI_end_time() {
  166. return UI_end_time;
  167. }
  168.  
  169. public void setUI_end_time(String uI_end_time) {
  170. UI_end_time = uI_end_time;
  171. }
  172.  
  173. public String getApp_start_time() {
  174. return app_start_time;
  175. }
  176.  
  177. public void setApp_start_time(String app_start_time) {
  178. this.app_start_time = app_start_time;
  179. }
  180.  
  181. public String getApp_end_time() {
  182. return app_end_time;
  183. }
  184.  
  185. public void setApp_end_time(String app_end_time) {
  186. this.app_end_time = app_end_time;
  187. }
  188.  
  189. public String getQianduan_start_time() {
  190. return qianduan_start_time;
  191. }
  192.  
  193. public void setQianduan_start_time(String qianduan_start_time) {
  194. this.qianduan_start_time = qianduan_start_time;
  195. }
  196.  
  197. public String getQianduan_end_time() {
  198. return qianduan_end_time;
  199. }
  200.  
  201. public void setQianduan_end_time(String qianduan_end_time) {
  202. this.qianduan_end_time = qianduan_end_time;
  203. }
  204.  
  205. public String getDevelop_start_time() {
  206. return develop_start_time;
  207. }
  208.  
  209. public void setDevelop_start_time(String develop_start_time) {
  210. this.develop_start_time = develop_start_time;
  211. }
  212.  
  213. public String getDevelop_end_time() {
  214. return develop_end_time;
  215. }
  216.  
  217. public void setDevelop_end_time(String develop_end_time) {
  218. this.develop_end_time = develop_end_time;
  219. }
  220.  
  221. public String getLiantiao_start_time() {
  222. return liantiao_start_time;
  223. }
  224.  
  225. public void setLiantiao_start_time(String liantiao_start_time) {
  226. this.liantiao_start_time = liantiao_start_time;
  227. }
  228.  
  229. public String getLiantiao_end_time() {
  230. return liantiao_end_time;
  231. }
  232.  
  233. public void setLiantiao_end_time(String liantiao_end_time) {
  234. this.liantiao_end_time = liantiao_end_time;
  235. }
  236.  
  237. public String getTest_start_time() {
  238. return test_start_time;
  239. }
  240.  
  241. public void setTest_start_time(String test_start_time) {
  242. this.test_start_time = test_start_time;
  243. }
  244.  
  245. public String getTest_end_time() {
  246. return test_end_time;
  247. }
  248.  
  249. public void setTest_end_time(String test_end_time) {
  250. this.test_end_time = test_end_time;
  251. }
  252. }

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

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

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

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

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

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

例图1:

例图2:

JIRA REST java client API实际应用的更多相关文章

  1. JIRA Rest JAVA Client API实现问题管理及自定义字段(原创)

    JIRA是一个缺陷跟踪管理系统,被广泛应用于缺陷跟踪.客户服务.需求收集.流程审批.任务跟踪.项目跟踪和敏捷管理等工作领域,当我们需要把第三方业务系统集成进来时,可以调用他的API. JIRA本身的A ...

  2. Memcached Java Client API详解

    针对Memcached官方网站提供的java_memcached-release_2.0.1版本进行阅读分析,Memcached Java客户端lib库主要提供的调用类是SockIOPool和MemC ...

  3. ES系列十五、ES常用Java Client API

    一.简介 1.先看ES的架构图 二.ES支持的客户端连接方式 1.REST API http请求,例如,浏览器请求get方法:利用Postman等工具发起REST请求:java 发起httpClien ...

  4. Java 9 揭秘(14. HTTP/2 Client API)

    Tips 做一个终身学习的人. 在此章中,主要介绍以下内容: 什么是HTTP/2 Client API 如何创建HTTP客户端 如何使HTTP请求 如何接收HTTP响应 如何创建WebSocket的e ...

  5. Elasticsearch Java Rest Client API 整理总结 (一)——Document API

    目录 引言 概述 High REST Client 起步 兼容性 Java Doc 地址 Maven 配置 依赖 初始化 文档 API Index API GET API Exists API Del ...

  6. Elasticsearch Java Rest Client API 整理总结 (二) —— SearchAPI

    目录 引言 Search APIs Search API Search Request 可选参数 使用 SearchSourceBuilder 构建查询条件 指定排序 高亮请求 聚合请求 建议请求 R ...

  7. Elasticsearch Java Rest Client API 整理总结 (三)——Building Queries

    目录 上篇回顾 Building Queries 匹配所有的查询 全文查询 Full Text Queries 什么是全文查询? Match 全文查询 API 列表 基于词项的查询 Term Term ...

  8. JAVA HDFS API Client 连接HA

    如果Hadoop开启HA,那么用Java Client连接Hive的时候,需要指定一些额外的参数 package cn.itacst.hadoop.hdfs; import java.io.FileI ...

  9. Kafka 0.9+Zookeeper3.4.6集群搭建、配置,新Client API的使用要点,高可用性测试,以及各种坑 (转载)

    Kafka 0.9版本对java client的api做出了较大调整,本文主要总结了Kafka 0.9在集群搭建.高可用性.新API方面的相关过程和细节,以及本人在安装调试过程中踩出的各种坑. 关于K ...

随机推荐

  1. 给定数组a[1,2,3],用a里面的元素来生成一个长度为5的数组,打印出其排列组合

    给定数组a[1,2,3],用a里面的元素来生成一个长度为5的数组,打印出其排列组合 ruby代码: def all_possible_arr arr, length = 5 ret = [] leng ...

  2. 【转】细说UI线程和Windows消息队列

    在Windows应用程序中,窗体是由一种称为“UI线程(User Interface Thread)”的特殊类型的线程创建的. 首先,UI线程是一种“线程”,所以它具有一个线程应该具有的所有特征,比如 ...

  3. numpy 基于现有数据创建ndarray(from existing data)

    1 numpy.array array(object[, dtype=None, copy=True, order='K', subok=False, ndmin=0]) 2 numpy.asarra ...

  4. MVC摘记

    2013年9月23日18:04:06 直接cshtml页面的js中使用     var customerId = @(ViewBag.Oppotunity as OppotunityDto==null ...

  5. Linux下实现脚本监测特定进程占用内存情况

    Linux系统下,我们可以利用以下命令来获取特定进程的运行情况: cat /proc/$PID/status 其中PID是具体的进程号,这个命令打印出/proc/特定进程/status文件的内容,信息 ...

  6. 打开Word时出现“The setup controller has encountered a problem during install. Please ...”什么意思

    解决办法:找到C:\Program Files\Common Files\Microsoft Shared\OFFICE12\Office Setup Controller,将这个文件夹删除或改名,就 ...

  7. markdown中的锚点处理

    markdown markdown是一个相对简单的DSL,定义了简单的标签来描述html文档格式. 比如: #一级标题 来生成html <h1>一级标题<h1> ##二级标题 ...

  8. vc++加载透明png图片方法-GDI+和CImage两种

    转载自:http://blog.csdn.net/zhongbin104/article/details/8730935 先看看GDI+的方法方法1:   1.GDI+画透明图层(alpha)的png ...

  9. Android长度单位详解(dp、sp、px、in、pt、mm、dip)

    Android中定义的dimension单位有以下这些:px(Pixels ,像素):对应屏幕上的实际像素点.in(Inches ,英寸):屏幕物理长度单位.mm(Millimeters ,毫米):屏 ...

  10. 转 redis 锁

    原文链接: http://www.promptness.cn/article/34 前言 分布式锁一般有三种实现方式:1. 数据库乐观锁:2. 基于Redis的分布式锁:3. 基于ZooKeeper的 ...