PageRenderTime 25ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/JIRAConnect/JMCClasses/Core/transport/JMCCreateIssueDelegate.m

https://bitbucket.org/atlassian/jiraconnect-ios/
Objective C | 67 lines | 40 code | 13 blank | 14 comment | 4 complexity | c5842a74388a3410e2c5de69095c436f MD5 | raw file
Possible License(s): Apache-2.0, MIT
  1. //
  2. // Created by niick on 27/09/11.
  3. //
  4. // To change this template use File | Settings | File Templates.
  5. //
  6. #import "JMCCreateIssueDelegate.h"
  7. #import "JMCIssueStore.h"
  8. #import "JMCRequestQueue.h"
  9. #import "JMC.h"
  10. @implementation JMCCreateIssueDelegate
  11. - (void)transportWillSend:(NSString *)issueJSON requestId:(NSString *)requestId issueKey:(NSString *)issueKey
  12. {
  13. // issueJSON is {"appName":"Angry Nerds","type":"improvement","description":"Looking better...","systemName":"iPhone OS","appVersion":"1.1.3","summary":"Looking better...","systemVersion":"4.3.2","model":"iPhone Simulator","devName":"iPhone Simulator","udid":"667F57ED-92BB-5F36-889B-FA1CF175361D","appId":"com.atlassian.jiraconnect.Angry-Nerds","uuid":"D7A18E9C-C1EE-4747-95DB-41BDC56AB58E"}
  14. // response needs to be an Issue.json... so we can insert one here.
  15. JMCIssue *issue = [JMCIssue issueWith:issueJSON requestId:requestId];
  16. issue.hasUpdates = NO;
  17. issue.dateCreated = [NSDate date];
  18. issue.dateUpdated = [NSDate date];
  19. issue.requestId = requestId;
  20. [[JMCIssueStore instance] insertIssue:issue]; // newly created issues have no comments
  21. // anounce that an issue was added, so the JMCIssuesView can redraw, say
  22. [[NSNotificationCenter defaultCenter] performSelectorOnMainThread:@selector(postNotification:) withObject:[NSNotification notificationWithName:kJMCIssueUpdated object:nil] waitUntilDone:NO];
  23. }
  24. - (void)transportDidFinish:(NSString *)response requestId:(NSString*)requestId
  25. {
  26. // response is JSON like so:
  27. // {"key":"NERDS-49","status":"Open","title":"Gimme feedback","description":"Gimme feedback","dateUpdated":1317106927991,"hasUpdates":false,"dateCreated":1317106927991,"comments":[]}
  28. JMCIssue *issue = [JMCIssue issueWith:response requestId:requestId];
  29. JMCIssueStore *issueStore = [JMCIssueStore instance];
  30. if ([issue.key isEqualToString:@"CRASHES-DISABLED"])
  31. {
  32. // delete this from the issue store. Crashes have been disabled in JIRA. No issue is created.
  33. [issueStore deleteIssueByUUID:requestId];
  34. JMCDLog(@"Crash reporting has been disabled in the JIRA Connect JIRA Plugin. No issues for crash reports will be created in JIRA.");
  35. }
  36. else if ([issueStore issueExistsIssueByUUID:requestId])
  37. {
  38. // this update will ensure the issuekey gets updated in the database
  39. [issueStore updateIssueByUUID:issue];
  40. }
  41. else
  42. {
  43. // this means the issue didn't make it to JIRA before the JMCPing rebuilt the database. So, add a new issue.
  44. [issueStore insertOrUpdateIssue:issue];
  45. }
  46. [[NSNotificationCenter defaultCenter] performSelectorOnMainThread:@selector(postNotification:) withObject:[NSNotification notificationWithName:kJMCIssueUpdated object:nil] waitUntilDone:NO];
  47. JMCDLog(@"Successfully created %@", issue.key);
  48. }
  49. - (void)transportDidFinishWithError:(NSError*)error statusCode:(int)status requestId:(NSString*)requestId
  50. {
  51. // on error - broadcast that the issue could not be sent so views can be re-drawn to display the error
  52. [[NSNotificationCenter defaultCenter] performSelectorOnMainThread:@selector(postNotification:) withObject:[NSNotification notificationWithName:kJMCIssueUpdated object:nil] waitUntilDone:NO];
  53. }
  54. @end