/grails-app/services/icescrum/plugin/planning/poker/PlanningPokerService.groovy

http://github.com/icescrum/iceScrum-plugin-planning-poker · Groovy · 156 lines · 109 code · 20 blank · 27 comment · 11 complexity · a19015ba8eb7f0f95dac89889e89e900 MD5 · raw file

  1. /*
  2. * Copyright (c) 2011 BE ISI iSPlugins Université Paul Sabatier.
  3. *
  4. * This file is part of Planning Poker plugin for icescrum.
  5. *
  6. * This icescrum plugin is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License.
  9. *
  10. * This icescrum plugin is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this icescrum plugin. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * Authors: Marc-Antoine BEAUVAIS (marcantoine.beauvais@gmail.com)
  19. * Gabriel GIL (contact.gabrielgil@gmail.com)
  20. * Julien GOUDEAUX (julien.goudeaux@orange.fr)
  21. * Jihane KHALIL (khaliljihane@gmail.com)
  22. * Paul LABONNE (paul.labonne@gmail.com)
  23. * Nicolas NOULLET (nicolas.noullet@gmail.com)
  24. * Jérémy SIMONKLEIN (jeremy.simonklein@gmail.com)
  25. *
  26. *
  27. */
  28. package icescrum.plugin.planning.poker
  29. import org.icescrum.core.domain.Product
  30. import org.icescrum.core.domain.User
  31. import org.icescrum.core.domain.Story
  32. class PlanningPokerService {
  33. def VALUE_BEFORE_VOTE = -10;
  34. def VALUE_UNVOTED = -1;
  35. def springSecurityService
  36. def productBacklogService
  37. def createSession(productid) {
  38. PlanningPokerSession session = new PlanningPokerSession(product:Product.get(productid))
  39. return session.save(flush:true)
  40. }
  41. def getSession(productid) {
  42. return PlanningPokerSession.findByProduct(Product.get(productid))
  43. }
  44. def deleteSession(productid) {
  45. getSession(productid)?.delete()
  46. }
  47. def setStory(productid, storyid) {
  48. PlanningPokerSession currentSession = getSession(productid)
  49. currentSession.story = Story.get(storyid)
  50. return currentSession.save(flush:true)
  51. }
  52. def getStory(productid) {
  53. return getSession(productid).story
  54. }
  55. def createVote(productid, userid) {
  56. User currentUser = User.get(userid)
  57. PlanningPokerSession currentSession = getSession(productid)
  58. PlanningPokerVote vote = new PlanningPokerVote(user:currentUser, session:currentSession)
  59. return vote.save(flush:true)
  60. }
  61. def initVotes(productid){
  62. getVotes(productid).each{
  63. it.voteValue = VALUE_BEFORE_VOTE
  64. it.save(flush:true)
  65. }
  66. }
  67. def getVotes(productid) {
  68. return getSession(productid)?.votes
  69. }
  70. def setUnvoted(productid, userid) {
  71. setVote(productid, userid, VALUE_UNVOTED);
  72. }
  73. def setVote(productid, userid, value) {
  74. User currentUser = User.get(userid)
  75. def vote = null
  76. getVotes(productid).each{
  77. if(it.user == currentUser)
  78. vote = it;
  79. }
  80. if(!vote)
  81. return false
  82. vote.voteValue = value
  83. return vote.save(flush:true)
  84. }
  85. boolean hasVoted(productid, userid) {
  86. def currentUser = User.get(userid)
  87. def hasVoted = false;
  88. getVotes(productid).each{
  89. if(it.user == currentUser)
  90. if (it.voteValue != VALUE_BEFORE_VOTE)
  91. hasVoted = true;
  92. }
  93. return hasVoted
  94. }
  95. def isVoteTerminated (productid) {
  96. def terminated = true
  97. getVotes(productid).each{
  98. if(it.voteValue == VALUE_BEFORE_VOTE)
  99. terminated = false
  100. }
  101. return terminated
  102. }
  103. def printVotes (commentaire) {
  104. println "Votes - " + commentaire
  105. PlanningPokerVote.list().each{
  106. println it.user.username + ": " + it.voteValue
  107. }
  108. }
  109. def getResult (productid) {
  110. def votes = getVotes(productid)
  111. int totalVotes = 0
  112. int nbVotes = 0
  113. votes.each{
  114. if(it.voteValue >= 0) {
  115. totalVotes += it.voteValue
  116. nbVotes ++
  117. }
  118. }
  119. String result = "?"
  120. if(nbVotes > 0){
  121. int resulttmp = totalVotes/nbVotes
  122. result = String.valueOf(resulttmp)
  123. }
  124. return result
  125. }
  126. def acceptResult (productid) {
  127. def story = getStory(productid)
  128. def result = getResult(productid)
  129. productBacklogService.estimateStory(story,result);
  130. }
  131. def acceptEstimate (productid, presult) {
  132. def story = getStory(productid)
  133. def result = presult
  134. productBacklogService.estimateStory(story,result)
  135. }
  136. }