PageRenderTime 38ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/src/test/resources/examples/Adam.groovy

https://bitbucket.org/sorin/jira-plugin-intellij
Groovy | 64 lines | 58 code | 6 blank | 0 comment | 1 complexity | 7acdadc2707f1f59c0b7b897e60a1023 MD5 | raw file
  1. package examples
  2. import com.atlassian.jira.ComponentManager
  3. import com.atlassian.jira.issue.MutableIssue
  4. import groovy.sql.Sql
  5. import org.ofbiz.core.entity.ConnectionFactory
  6. import org.ofbiz.core.entity.DelegatorInterface
  7. import java.sql.Connection
  8. MutableIssue issue = issue
  9. String sClient = issue.getSummary()
  10. ComponentManager componentManager = ComponentManager.getInstance()
  11. delegator = (DelegatorInterface) componentManager.getComponentInstanceOfType(DelegatorInterface.class)
  12. String helperName = delegator.getGroupHelperName("default");
  13. def sqlStmt = """
  14. SELECT *
  15. FROM jiraissue
  16. WHERE issuetype = '11' AND issuestatus = '10009' AND summary = '${sClient}'
  17. """
  18. Connection conn = null
  19. Sql sql = null
  20. try {
  21. conn = ConnectionFactory.getConnection(helperName);
  22. sql = new Sql(conn)
  23. StringBuffer sb = new StringBuffer()
  24. sCounter = 0
  25. sql.eachRow(sqlStmt) {
  26. sDueDate = it[14]
  27. def sqlStmt2 = """
  28. SELECT *
  29. FROM customfieldvalue
  30. WHERE customfield = '10400' AND stringvalue = '${sClient}'
  31. """
  32. sql.eachRow(sqlStmt2) {
  33. def sqlStmt3 = """
  34. SELECT *
  35. FROM customfieldvalue
  36. WHERE customfield = '10800' AND stringvalue = '10500' AND issue = '${it.issue}'
  37. """
  38. sql.eachRow(sqlStmt3) {
  39. def sqlStmt4 = """
  40. SELECT count(*)
  41. FROM jiraissue
  42. WHERE id = '${it.issue}' AND duedate between DATE_SUB('${sDueDate}', INTERVAL 1 YEAR) and '${sDueDate}'
  43. """
  44. sql.eachRow(sqlStmt4) {
  45. if(it[0]>0) {
  46. sCounter++
  47. }
  48. }
  49. }
  50. }
  51. }
  52. sql.close()
  53. return sCounter.toDouble()
  54. }
  55. finally {
  56. sql.close()
  57. conn.close()
  58. }