PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/java/com/trendmicro/main/Main.java

https://gitlab.com/goodman1209/JiraRestClientDemo
Java | 102 lines | 78 code | 15 blank | 9 comment | 4 complexity | 623f8ee26c69a9b4be265067a2f0460b MD5 | raw file
  1. package com.trendmicro.main;
  2. import java.net.URISyntaxException;
  3. import java.util.Properties;
  4. import org.codehaus.jettison.json.JSONArray;
  5. import org.codehaus.jettison.json.JSONException;
  6. import org.codehaus.jettison.json.JSONObject;
  7. import org.slf4j.Logger;
  8. import org.slf4j.LoggerFactory;
  9. import com.atlassian.jira.rest.client.JiraRestClient;
  10. import com.atlassian.jira.rest.client.domain.Field;
  11. import com.google.common.util.concurrent.FutureCallback;
  12. import com.trendmicro.rdhelpdesk.command.CodeSignService;
  13. import com.trendmicro.rdhelpdesk.command.IssueService;
  14. import com.trendmicro.rdhelpdesk.command.utils.ConnectJiraUtils;
  15. import com.trendmicro.rdhelpdesk.common.SystemEntryConstant;
  16. public class Main {
  17. private static final Logger LOG = LoggerFactory.getLogger(Main.class);
  18. public static void main(String args[]) throws URISyntaxException, JSONException {
  19. JiraRestClient restClient = makeRestClientObject();
  20. LOG.info("restClient.getIssueClient() {} key : {}", restClient, args[0]);
  21. String event = args[0];
  22. String issueKey = args[1];
  23. if (SystemEntryConstant.CODE_SIGN_APPROVE.equals(event)) {
  24. CodeSignService css = new CodeSignService(restClient);
  25. css.approveCodeSignByManager(issueKey);
  26. } else if (SystemEntryConstant.CODE_SIGN_TRIGGER.equals(event)) {
  27. LOG.info("{} transition if error ", issueKey);
  28. // CodeSignService css = new CodeSignService(restClient);
  29. // css.sign(issueKey);
  30. } else {
  31. LOG.info("{} test function ", issueKey);
  32. IssueService is = new IssueService(restClient);
  33. LOG.info("{} ", jsonTransitionIssue(null, null));
  34. ConnectJiraUtils.update(is.findIssue(issueKey), jsonTransitionIssue(null, null), true, "s-codesign",
  35. "jirajira");
  36. }
  37. }
  38. public static JiraRestClient makeRestClientObject() {
  39. try {
  40. Properties properties = new Properties();
  41. properties.load(Main.class.getClassLoader().getResourceAsStream("system.properties"));
  42. return ConnectJiraUtils.GetJiraRestClientInstance(properties.getProperty("username"),
  43. properties.getProperty("password"));
  44. } catch (Exception e) {
  45. LOG.error("restClient Error {}", e.getMessage());
  46. e.printStackTrace();
  47. return null;
  48. }
  49. }
  50. private static JSONObject jsonEditIssue(Field field, String value) throws JSONException {
  51. // "timetracking":{"remainingEstimate":"0m","timeSpent":"3w","remainingEstimateSeconds":0,"timeSpentSeconds":432000}
  52. JSONObject summary = new JSONObject().accumulate(field.getId(), value);
  53. JSONObject fields = new JSONObject().accumulate("fields", summary);
  54. return fields;
  55. }
  56. private static JSONObject jsonTransitionIssue(Field field, String value) throws JSONException {
  57. JSONObject commentBody = new JSONObject().accumulate("body", "system added");
  58. JSONObject commentAdd = new JSONObject().accumulate("add", commentBody);
  59. JSONArray comments = new JSONArray();
  60. comments.put(commentAdd);
  61. JSONObject comment = new JSONObject().put("comment", comments);
  62. JSONObject transitionAction = new JSONObject().accumulate("id", "31");
  63. JSONObject fields = new JSONObject().put("update", comment);
  64. fields = fields.accumulate("transition", transitionAction);
  65. JSONObject assignName = new JSONObject().accumulate("name", "s-codesign");
  66. JSONObject assignee = new JSONObject().accumulate("assignee", assignName);
  67. // JSONObject resoName = new JSONObject().accumulate("name",
  68. // "Unresolved");
  69. // assignee = assignee.accumulate("resolution", resoName);
  70. // fields = fields.accumulate("fields", assignee);
  71. return fields;
  72. }
  73. public static FutureCallback<Void> getCallBackInstamce() {
  74. return new FutureCallback<Void>() {
  75. public void onSuccess(Void result) {
  76. // TODO Auto-generated method stub
  77. LOG.info("Allan result Success");
  78. System.exit(0);
  79. }
  80. public void onFailure(Throwable t) {
  81. // TODO Auto-generated method stub
  82. LOG.info("Allan result Error");
  83. System.exit(0);
  84. }
  85. };
  86. }
  87. }