Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. Trigger SynchronizeWithJIRAIssue on Case (after update) {
  2. if (JIRA.currentUserIsNotJiraAgent()) {
  3. if(System.isFuture() == false || System.isBatch() == false || System.isScheduled() == false) { //Check, If Not in any Async Apex context, only then execute the Future Method.
  4. system.debug('System.isFuture()---->'+System.isFuture());
  5. system.debug('System.isBatch()--->'+System.isBatch());
  6. system.debug('System.isScheduled()--->'+System.isScheduled());
  7. system.debug('entering@@@@@@@@');
  8. system.debug('@@@@JIRA.currentUserIsNotJiraAgent()@@@@----->'+JIRA.currentUserIsNotJiraAgent());
  9. for (Case c : Trigger.new) {
  10. String objectType ='Case'; //Please change this according to the object type
  11. String objectId = c.Id;
  12. JIRAConnectorWebserviceCalloutSync.synchronizeWithJIRAIssue(JIRA.baseUrl, JIRA.systemId, objectType, objectId);
  13. }
  14. }
  15. }
  16.  
  17. global class JIRAConnectorWebserviceCalloutSync {
  18. @future (callout=true)
  19. WebService static void synchronizeWithJIRAIssue(String baseUrl, String systemId, String objectType, String caseId) {
  20. system.debug('baseurl@@@@@----->'+baseUrl+'systemId@@@---->'+systemId+'objectType@@@@--->'+objectType+'casid@@@@---->'+caseId);
  21. try {
  22. HttpRequest req = buildRequest(baseUrl, JIRA.username, JIRA.password, systemId, objectType, caseId);
  23. JIRA.sendRequest(req);
  24. } catch(System.CalloutException e) {
  25. System.debug(e);
  26. }
  27. }
  28.  
  29. // Constructs request needed to synchronize a JIRA issue from provided parameters.
  30. public static HttpRequest buildRequest(String baseUrl, String username, String password,
  31. String systemId, String objectType, String caseId) {
  32. HttpRequest req = new HttpRequest();
  33. String basicAuthHeader = JIRA.authHeader(username, password);
  34. String endpoint = getEndpoint(baseUrl, systemId, objectType, caseId);
  35. system.debug('end point @@@@@------>'+endpoint);
  36. system.debug('basicAuthHeader@@@@----->'+basicAuthHeader);
  37. req.setHeader('Authorization', basicAuthHeader);
  38. req.setHeader('Content-Type', 'application/json');
  39. req.setHeader('Content-Length', '0');
  40. req.setEndpoint(endpoint);
  41. req.setMethod('PUT');
  42. return req;
  43. }
  44.  
  45. // Creates the endpoint to synchronize the issue from provided parameters.
  46. private static String getEndpoint(String baseUrl, String systemId, String objectType, String caseId) {
  47. return baseUrl + '/rest/customware/connector/1.0/' + systemId + '/' + objectType + '/' + caseId + '/issue/synchronize.json';
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement