Changeset 809 for trunk/grails-app/services
- Timestamp:
- Feb 16, 2011, 8:10:39 PM (14 years ago)
- Location:
- trunk/grails-app/services
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/CreateDataService.groovy
r798 r809 140 140 createDemoAssignedGroups() 141 141 createDemoAssignedPersons() 142 createDemoTaskProcedure()143 createDemoMaintenanceActions()142 // createDemoTaskProcedure() 143 // createDemoMaintenanceActions() 144 144 createDemoTaskRecurringSchedules() 145 145 -
trunk/grails-app/services/TaskProcedureService.groovy
r798 r809 7 7 8 8 def authService 9 def dateUtilService 9 10 10 11 /** … … 23 24 result.error = [ code: m.code, args: ["TaskProcedure", params.id] ] 24 25 // Fetch to prevent lazy initialization error. 25 result.taskProcedureInstance?.linkedTask.primaryAsset 26 result.taskProcedureInstance?.createdBy 26 result.taskProcedureInstance.revisions.each {it.createdBy.toString()} 27 27 return result 28 28 } … … 40 40 41 41 result.taskProcedureInstance.properties = params 42 result.taskProcedureInstance.lastUpdatedBy = authService.currentUser43 result.taskProcedureInstance.lastUpdated = new Date() // Required to trigger version increment.44 42 45 43 // Gaps in the html index's can be created by adding 2 items and removing the first one. … … 80 78 } 81 79 80 def r = createRevision(result.taskProcedureInstance) 81 if(r.error) 82 return fail(field:'id', code:"default.create.revision.failure") 83 84 // Also sets: taskInstance.taskProcedureRevision = taskProcedureRevision 85 r.taskProcedureRevision.addToTasks(result.taskProcedureInstance.linkedTask) 86 87 // Update tasks that are using previousRevision. 88 // Only those that are not started and due to be started today or in the future. 89 def previousRevision = result.taskProcedureInstance.getRevision(r.taskProcedureRevision.revision - 1) 90 if(previousRevision) { 91 Task.withCriteria { 92 eq("taskProcedureRevision", previousRevision) 93 ge("targetStartDate", dateUtilService.today) 94 taskStatus { 95 idEq(1L) // Not Started. 96 } 97 maxResults(10000) 98 }.each { 99 it.taskProcedureRevision = r.taskProcedureRevision 100 } 101 } 102 82 103 // Success. 83 104 return result 84 105 85 } // end withTransaction106 } // end withTransaction 86 107 } // end update() 87 108 … … 96 117 def fail = { Map m -> 97 118 status.setRollbackOnly() 98 if(result.taskProcedureInstance && m.field) 119 if(result.taskProcedureInstance && m.field) 99 120 result.taskProcedureInstance.errors.rejectValue(m.field, m.code) 100 121 result.error = [ code: m.code, args: ["TaskProcedure", params.id] ] … … 107 128 108 129 // Optimistic locking check on linkedTask. 109 if(result.taskProcedureInstance.linkedTask.taskProcedure )130 if(result.taskProcedureInstance.linkedTask.taskProcedureRevision) 110 131 return fail(field:"version", code:"default.optimistic.locking.failure") 111 112 result.taskProcedureInstance.createdBy = authService.currentUser113 result.taskProcedureInstance.lastUpdatedBy = authService.currentUser114 132 115 133 // Gaps in the html index's can be created by adding 2 items and removing the first one. … … 124 142 } 125 143 126 // Also sets: taskInstance.taskProcedure = taskProcedureInstance127 result.taskProcedureInstance.addToTasks(result.taskProcedureInstance.linkedTask)128 129 144 if(result.taskProcedureInstance.hasErrors() || !result.taskProcedureInstance.save()) { 130 145 // Populate collection errors for display. … … 134 149 } 135 150 136 } //end withTransaction 137 138 result.taskProcedureInstance.lastUpdated = new Date() // Required to trigger version increment to 1. 139 140 // success 151 def r = createRevision(result.taskProcedureInstance) 152 if(r.error) 153 return fail(field:'id', code:"default.create.revision.failure") 154 155 // Also sets: taskInstance.taskProcedureRevision = taskProcedureRevision 156 r.taskProcedureRevision.addToTasks(result.taskProcedureInstance.linkedTask) 157 158 } // end withTransaction 159 160 // Success. 141 161 return result 142 162 } // end save() 143 163 164 /** 165 * Creates a new taskProcedureRevision. 166 * @param taskProcedureInstance The taskProcedure to create the revision for. 167 * @returns A map containing result.error (if any error) and result.taskProcedureRevision. 168 */ 169 def createRevision(taskProcedureInstance) { 170 def result = [:] 171 TaskProcedureRevision.withTransaction { status -> 172 def fail = { Map m -> 173 status.setRollbackOnly() 174 if(result.taskProcedureRevision && m.field) 175 result.taskProcedureRevision.errors.rejectValue(m.field, m.code) 176 result.error = [ code: m.code, args: ["TaskProcedureRevision"] ] 177 return result 178 } 179 180 result.taskProcedureRevision = new TaskProcedureRevision() 181 taskProcedureInstance.addToRevisions(result.taskProcedureRevision) 182 183 result.taskProcedureRevision.taskProcedure = taskProcedureInstance 184 result.taskProcedureRevision.linkedTask = taskProcedureInstance.linkedTask 185 result.taskProcedureRevision.createdBy = authService.currentUser 186 result.taskProcedureRevision.revision = 0 // init to prevent DataIntegrityViolationException 187 result.taskProcedureRevision.revision = taskProcedureInstance.revision 188 taskProcedureInstance.maintenanceActions.each { 189 result.taskProcedureRevision.addToMaintenanceActions(new MaintenanceAction(it.properties)) 190 } 191 taskProcedureInstance.documentReferences.each { 192 result.taskProcedureRevision.addToDocumentReferences(new DocumentReference(it.properties)) 193 } 194 195 if(result.taskProcedureRevision.hasErrors() || !result.taskProcedureRevision.save()) { 196 log.error result.taskProcedureRevision.errors 197 return fail(code:"default.create.failure") 198 } 199 200 } // end withTransaction 201 202 // Success. 203 return result 204 } // end createRevision() 205 144 206 } // end class -
trunk/grails-app/services/TaskRecurringScheduleService.groovy
r445 r809 68 68 p.targetStartDate = it.nextTargetStartDate 69 69 p.targetCompletionDate = it.nextTargetCompletionDate 70 if(it.task.taskProcedure ) p.taskProcedure = it.task.taskProcedure70 if(it.task.taskProcedureRevision) p.taskProcedureRevision = it.task.taskProcedureRevision 71 71 if(it.task.assignedGroups) p.assignedGroups = new ArrayList(it.task.assignedGroups) 72 72 if(it.task.assignedPersons) p.assignedPersons = new ArrayList(it.task.assignedPersons) -
trunk/grails-app/services/TaskService.groovy
r802 r809 188 188 * Creates a subTask copying sane attributes from the parentTask unless otherwise specified in params. 189 189 * The targetStartDate and targetCompletionDate default to today since that is the sane thing to do. 190 * The taskProcedure is only assigned to the sub task if supplied in params.190 * The taskProcedureRevision is only assigned to the sub task if supplied in params. 191 191 * The assignedPersons and assignedGroups are only added to the sub task if supplied in params. 192 192 * The positiveFault property is never set on the subTask. … … 228 228 229 229 // Supplied by recurring tasks. 230 if(params.taskProcedure ) p.taskProcedure = params.taskProcedure230 if(params.taskProcedureRevision) p.taskProcedureRevision = params.taskProcedureRevision 231 231 if(params.assignedGroups) p.assignedGroups = params.assignedGroups // Collection. 232 232 if(params.assignedPersons) p.assignedPersons = params.assignedPersons // Collection. … … 691 691 } 692 692 693 // Check for taskProcedure using this task as linkedTask. 694 if(result.taskInstance.taskProcedure?.linkedTask?.id == result.taskInstance.id) 695 return fail(field:"taskProcedure", code:"task.operationNotPermittedOnTaskLinkedToProcedure") 693 // Check for taskProcedureRevision using this task as linkedTask. 694 if(result.taskInstance.taskProcedureRevision?.linkedTask?.id == result.taskInstance.id) { 695 if(!authenticateService.ifAnyGranted('ROLE_AppAdmin,ROLE_Manager,ROLE_TaskManager')) 696 return fail(field:"taskProcedureRevision", code:"task.operationNotPermittedOnTaskLinkedToProcedureWithoutAuth") 697 } 696 698 697 699 // Check for Parent PM task type. 698 700 if(result.taskInstance.taskType.id == 6) 699 return fail(field:"task Procedure", code:"task.operationNotPermittedOnParentPmTask")701 return fail(field:"taskType", code:"task.operationNotPermittedOnParentPmTask") 700 702 701 703 result.taskInstance.trash = true
Note: See TracChangeset
for help on using the changeset viewer.