Changeset 251
- Timestamp:
- Dec 28, 2009, 1:10:24 AM (15 years ago)
- Location:
- trunk/grails-app/services
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/AssignedGroupService.groovy
r247 r251 1 1 class AssignedGroupService { 2 2 3 boolean transactional = false 4 5 def personService 3 6 4 7 def list(params) { … … 37 40 38 41 def delete(params) { 39 def result = [:] 40 def fail = { Map m -> 41 result.error = [ code: m.code, args: ["AssignedGroup", params.id] ] 42 return result 43 } 42 AssignedGroup.withTransaction { status -> 43 def result = [:] 44 44 45 result.assignedGroupInstance = AssignedGroup.get(params.id) 45 def fail = { Map m -> 46 status.setRollbackOnly() 47 if(result.assignedGroupInstance && m.field) 48 result.assignedGroupInstance.errors.rejectValue(m.field, m.code) 49 result.error = [ code: m.code, args: ["AssignedGroup", params.id] ] 50 return result 51 } 46 52 47 if(!result.assignedGroupInstance) 48 return fail(code:"default.not.found") 53 result.assignedGroupInstance = AssignedGroup.get(params.id) 49 54 50 try { 51 result.assignedGroupInstance.delete(flush:true) 52 return result //Success. 53 } 54 catch(org.springframework.dao.DataIntegrityViolationException e) { 55 return fail(code:"default.delete.failure") 56 } 55 if(!result.assignedGroupInstance) 56 return fail(code:"default.not.found") 57 57 58 } 58 def taskModification = new TaskModification(person: personService.currentUser, 59 taskModificationType: TaskModificationType.get(10), 60 task: result.assignedGroupInstance.task) 61 62 if(!taskModification.save()) 63 return fail(field:"taskModifications", code:"task.modifications.failedToSave") 64 65 try { 66 result.assignedGroupInstance.delete(flush:true) 67 return result //Success. 68 } 69 catch(org.springframework.dao.DataIntegrityViolationException e) { 70 return fail(code:"default.delete.failure") 71 } 72 73 } //end withTransaction 74 } // end delete() 59 75 60 76 def edit(params) { … … 102 118 return fail(code:"default.update.failure") 103 119 120 def taskModification = new TaskModification(person: personService.currentUser, 121 taskModificationType: TaskModificationType.get(10), 122 task: result.assignedGroupInstance.task) 123 124 if(!taskModification.save()) 125 return fail(field:"taskModifications", code:"task.modifications.failedToSave") 126 104 127 // Success. 105 128 return result … … 126 149 127 150 def save(params) { 128 def result = [:] 129 def fail = { Map m -> 130 if(result.assignedGroupInstance && m.field) 131 result.assignedGroupInstance.errors.rejectValue(m.field, m.code) 132 result.error = [ code: m.code, args: ["AssignedGroup", params.id] ] 151 AssignedGroup.withTransaction { status -> 152 def result = [:] 153 154 def fail = { Map m -> 155 if(result.assignedGroupInstance && m.field) 156 result.assignedGroupInstance.errors.rejectValue(m.field, m.code) 157 result.error = [ code: m.code, args: ["AssignedGroup", params.id] ] 158 return result 159 } 160 161 result.assignedGroupInstance = new AssignedGroup(params) 162 163 if(result.assignedGroupInstance.hasErrors() || !result.assignedGroupInstance.save()) 164 return fail(code:"default.create.failure") 165 166 // Record a taskModification for every one except "system". 167 if(personService.currentUser.id != 1) { 168 def taskModification = new TaskModification(person: personService.currentUser, 169 taskModificationType: TaskModificationType.get(10), 170 task: result.assignedGroupInstance.task) 171 172 if(!taskModification.save()) 173 return fail(field:"taskModifications", code:"task.modifications.failedToSave") 174 } 175 176 // success 133 177 return result 134 }135 178 136 result.assignedGroupInstance = new AssignedGroup(params) 137 138 if(result.assignedGroupInstance.hasErrors() || !result.assignedGroupInstance.save(flush: true)) 139 return fail(code:"default.create.failure") 140 141 // success 142 return result 143 } 179 } //end withTransaction 180 } // end save() 144 181 145 182 } // end class -
trunk/grails-app/services/AssignedPersonService.groovy
r249 r251 1 1 class AssignedPersonService { 2 2 3 boolean transactional = false 4 5 def personService 3 6 4 7 def list(params) { … … 37 40 38 41 def delete(params) { 39 def result = [:] 40 def fail = { Map m -> 41 result.error = [ code: m.code, args: ["AssignedPerson", params.id] ] 42 return result 43 } 42 AssignedPerson.withTransaction { status -> 43 def result = [:] 44 44 45 result.assignedPersonInstance = AssignedPerson.get(params.id) 45 def fail = { Map m -> 46 status.setRollbackOnly() 47 if(result.assignedPersonInstance && m.field) 48 result.assignedPersonInstance.errors.rejectValue(m.field, m.code) 49 result.error = [ code: m.code, args: ["AssignedPerson", params.id] ] 50 return result 51 } 46 52 47 if(!result.assignedPersonInstance) 48 return fail(code:"default.not.found") 53 result.assignedPersonInstance = AssignedPerson.get(params.id) 49 54 50 try { 51 result.assignedPersonInstance.delete(flush:true) 52 return result //Success. 53 } 54 catch(org.springframework.dao.DataIntegrityViolationException e) { 55 return fail(code:"default.delete.failure") 56 } 55 if(!result.assignedPersonInstance) 56 return fail(code:"default.not.found") 57 57 58 } 58 def taskModification = new TaskModification(person: personService.currentUser, 59 taskModificationType: TaskModificationType.get(11), 60 task: result.assignedPersonInstance.task) 61 62 if(!taskModification.save()) 63 return fail(field:"taskModifications", code:"task.modifications.failedToSave") 64 65 try { 66 result.assignedPersonInstance.delete(flush:true) 67 return result //Success. 68 } 69 catch(org.springframework.dao.DataIntegrityViolationException e) { 70 return fail(code:"default.delete.failure") 71 } 72 73 } //end withTransaction 74 } // end delete() 59 75 60 76 def edit(params) { … … 102 118 return fail(code:"default.update.failure") 103 119 120 def taskModification = new TaskModification(person: personService.currentUser, 121 taskModificationType: TaskModificationType.get(11), 122 task: result.assignedPersonInstance.task) 123 124 if(!taskModification.save()) 125 return fail(field:"taskModifications", code:"task.modifications.failedToSave") 126 104 127 // Success. 105 128 return result … … 126 149 127 150 def save(params) { 128 def result = [:] 129 def fail = { Map m -> 130 if(result.assignedPersonInstance && m.field) 131 result.assignedPersonInstance.errors.rejectValue(m.field, m.code) 132 result.error = [ code: m.code, args: ["AssignedPerson", params.id] ] 151 AssignedPerson.withTransaction { status -> 152 def result = [:] 153 154 def fail = { Map m -> 155 if(result.assignedPersonInstance && m.field) 156 result.assignedPersonInstance.errors.rejectValue(m.field, m.code) 157 result.error = [ code: m.code, args: ["AssignedPerson", params.id] ] 158 return result 159 } 160 161 result.assignedPersonInstance = new AssignedPerson(params) 162 163 if(result.assignedPersonInstance.hasErrors() || !result.assignedPersonInstance.save()) 164 return fail(code:"default.create.failure") 165 166 // Record a taskModification for every one except "system". 167 if(personService.currentUser.id != 1) { 168 def taskModification = new TaskModification(person: personService.currentUser, 169 taskModificationType: TaskModificationType.get(11), 170 task: result.assignedPersonInstance.task) 171 172 if(!taskModification.save()) 173 return fail(field:"taskModifications", code:"task.modifications.failedToSave") 174 } 175 176 // success 133 177 return result 134 }135 178 136 result.assignedPersonInstance = new AssignedPerson(params) 137 138 if(result.assignedPersonInstance.hasErrors() || !result.assignedPersonInstance.save(flush: true)) 139 return fail(code:"default.create.failure") 140 141 // success 142 return result 143 } 179 } //end withTransaction 180 } // end save() 144 181 145 182 } // end class -
trunk/grails-app/services/CreateDataService.groovy
r242 r251 13 13 def dateUtilService 14 14 def appConfigService 15 def assignedGroupService 16 def assignedPersonService 15 17 16 18 /******************************************* … … 531 533 taskModificationTypeInstance = new TaskModificationType(name:"Approved").save() // #8 532 534 taskModificationTypeInstance = new TaskModificationType(name:"Renege approval").save() // #9 535 taskModificationTypeInstance = new TaskModificationType(name:"Modified (Assigned Groups)").save() // #10 536 taskModificationTypeInstance = new TaskModificationType(name:"Modified (Assigned Persons)").save() // #11 533 537 } 534 538 … … 658 662 def createDemoAssignedGroups() { 659 663 660 //AssignedGroup661 def assignedGroupInstance664 def result 665 def p = [:] 662 666 663 667 //AssignedGroup #1 664 assignedGroupInstance = new AssignedGroup(personGroup: PersonGroup.get(1),665 666 667 estimatedMinute: 30)668 saveAndTest(assignedGroupInstance)668 p = [personGroup: PersonGroup.get(1), 669 task: Task.get(1), 670 estimatedHour: 2, 671 estimatedMinute: 30] 672 result = assignedGroupService.save(p) 669 673 670 674 //AssignedGroup #2 671 assignedGroupInstance = new AssignedGroup(personGroup: PersonGroup.get(2),672 673 674 estimatedMinute: 0)675 saveAndTest(assignedGroupInstance)675 p = [personGroup: PersonGroup.get(2), 676 task: Task.get(1), 677 estimatedHour: 1, 678 estimatedMinute: 0] 679 result = assignedGroupService.save(p) 676 680 } 677 681 678 682 def createDemoAssignedPersons() { 679 683 680 //AssignedPerson681 def assignedPersonInstance684 def result 685 def p = [:] 682 686 683 687 //AssignedPerson #1 684 assignedPersonInstance = new AssignedPerson(person: Person.get(4),685 686 687 estimatedMinute: 20)688 saveAndTest(assignedPersonInstance)688 p = [person: Person.get(4), 689 task: Task.get(1), 690 estimatedHour: 1, 691 estimatedMinute: 20] 692 result = assignedPersonService.save(p) 689 693 690 694 //AssignedPerson #2 691 assignedPersonInstance = new AssignedPerson(person: Person.get(5),692 693 694 estimatedMinute: 30)695 saveAndTest(assignedPersonInstance)695 p = [person: Person.get(5), 696 task: Task.get(1), 697 estimatedHour: 3, 698 estimatedMinute: 30] 699 result = assignedPersonService.save(p) 696 700 } 697 701 -
trunk/grails-app/services/TaskService.groovy
r245 r251 8 8 9 9 def personService 10 def assignedGroupService 11 def assignedPersonService 10 12 11 13 /** … … 60 62 //Add the assignedGroups, provided by a new ArrayList(task.assignedGroups) 61 63 if(params.assignedGroups) { 62 def assignedGroupInstance 64 def assignedGroupsResult 65 def assignedGroupParams = [:] 63 66 params.assignedGroups.each() { 64 assignedGroupInstance = new AssignedGroup(personGroup: it.personGroup, 65 task: taskInstance, 66 estimatedHour: it.estimatedHour, 67 estimatedMinute: it.estimatedMinute) 68 69 if(!assignedGroupInstance.save()) { 67 68 assignedGroupParams = [personGroup: it.personGroup, 69 task: taskInstance, 70 estimatedHour: it.estimatedHour, 71 estimatedMinute: it.estimatedMinute] 72 73 assignedGroupsResult = assignedGroupService.save(assignedGroupParams) 74 75 if(assignedGroupsResult.error) { 70 76 status.setRollbackOnly() 71 77 taskInstance.errors.rejectValue("assignedGroups", "task.assignedGroups.failedToSave") … … 73 79 return result 74 80 } 81 75 82 } 76 83 } … … 78 85 //Add the assignedPersons, provided by a new ArrayList(task.assignedPersons) 79 86 if(params.assignedPersons) { 80 def assignedPersonInstance 87 def assignedPersonsResult 88 def assignedPersonsParams = [:] 81 89 params.assignedPersons.each() { 82 assignedPersonInstance = new AssignedPerson(person: it.person, 83 task: taskInstance, 84 estimatedHour: it.estimatedHour, 85 estimatedMinute: it.estimatedMinute) 86 87 if(!assignedPersonInstance.save()) { 90 91 assignedPersonsParams = [person: it.person, 92 task: taskInstance, 93 estimatedHour: it.estimatedHour, 94 estimatedMinute: it.estimatedMinute] 95 96 assignedPersonsResult = assignedPersonService.save(assignedPersonsParams) 97 98 if(assignedPersonsResult.error) { 88 99 status.setRollbackOnly() 89 100 taskInstance.errors.rejectValue("assignedPersons", "task.assignedPersons.failedToSave") … … 91 102 return result 92 103 } 104 93 105 } 94 106 }
Note: See TracChangeset
for help on using the changeset viewer.