- Timestamp:
- Feb 3, 2011, 5:12:40 AM (14 years ago)
- Location:
- branches/features/taskProcedureRework/grails-app
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/features/taskProcedureRework/grails-app/controllers/TaskProcedureDetailedController.groovy
r774 r775 5 5 6 6 def filterService 7 def authService8 7 def taskProcedureService 9 8 … … 69 68 } 70 69 catch(org.springframework.dao.DataIntegrityViolationException e) { 71 flash. message = "TaskProcedure ${params.id} could not be deleted"70 flash.errorMessage = "TaskProcedure ${params.id} could not be deleted" 72 71 redirect(controller:'taskDetailed', 73 72 action:'show', … … 77 76 } 78 77 else { 79 flash. message = "TaskProcedure not found with id ${params.id}"78 flash.errorMessage = "TaskProcedure not found with id ${params.id}" 80 79 redirect(action:list) 81 80 } … … 91 90 92 91 if(!taskProcedureInstance) { 93 flash. message = "TaskProcedure not found with id ${params.id}"92 flash.errorMessage = "TaskProcedure not found with id ${params.id}" 94 93 redirect(action:list) 95 94 } … … 112 111 113 112 if(result.error.code == "default.not.found") { 114 flash. message = g.message(code: result.error.code, args: result.error.args)113 flash.errorMessage = g.message(code: result.error.code, args: result.error.args) 115 114 redirect(action:list) 115 return 116 } 117 118 if(result.error.code == "default.optimistic.locking.failure") { 119 flash.errorMessage = g.message(code: result.error.code, args: result.error.args) 120 redirect(controller:'taskDetailed', 121 action:'show', 122 id:result.taskProcedureInstance.linkedTask.id, 123 params:[showTab:"showProcedureTab"]) 116 124 return 117 125 } … … 130 138 params.linkedTask = Task.get(params.taskInstance.id) 131 139 140 // Task already has a taskProcedure. 141 if(params.linkedTask.taskProcedure) { 142 flash.errorMessage = g.message(code: 'default.optimistic.locking.failure') 143 redirect(controller:'taskDetailed', 144 action:'show', 145 id:params.linkedTask.id, 146 params:[showTab:"showProcedureTab"]) 147 return 148 } 149 150 // Task does not have a primaryAsset. 132 151 if(!params.linkedTask?.primaryAsset) { 133 152 flash.errorMessage = "Please set a Primary Asset first, then go to the Procedure tab." … … 142 161 143 162 def save = { 144 def taskProcedureInstance = new TaskProcedure(params) 145 taskProcedureInstance.createdBy = authService.currentUser 146 taskProcedureInstance.lastUpdatedBy = authService.currentUser 147 def taskInstance = Task.get(params.linkedTask.id) 163 def result = taskProcedureService.save(params) 148 164 149 // Gaps in the html index's can be created by adding 2 items and removing the first one. 150 // This creates a gap at the missing index where LazyList will return a null. 151 def nullMaintenanceActions = taskProcedureInstance.maintenanceActions.findAll {!it} 152 if (nullMaintenanceActions) { 153 taskProcedureInstance.maintenanceActions.removeAll(nullMaintenanceActions) 165 if(!result.error) { 166 flash.message = g.message(code: "default.create.success", args: ["TaskProcedure", result.taskProcedureInstance.id]) 167 redirect(controller:'taskDetailed', 168 action:'show', 169 id:result.taskProcedureInstance.linkedTask.id, 170 params:[showTab:"showProcedureTab"]) 171 return 154 172 } 155 173 156 if(!taskProcedureInstance.hasErrors() && taskProcedureInstance.save(flush: true)) { 157 // Also sets: taskInstance.taskProcedure = taskProcedureInstance 158 taskProcedureInstance.addToTasks(taskInstance) 159 flash.message = "TaskProcedure ${taskProcedureInstance.id} created." 174 if(result.error.code == "default.optimistic.locking.failure") { 175 flash.errorMessage = g.message(code: result.error.code, args: result.error.args) 160 176 redirect(controller:'taskDetailed', 161 177 action:'show', 162 id: taskProcedureInstance.linkedTask.id,178 id:result.taskProcedureInstance.linkedTask.id, 163 179 params:[showTab:"showProcedureTab"]) 180 return 164 181 } 165 else { 166 // Populate maintenanceAction errors for display. 167 taskProcedureInstance.maintenanceActions.each { it.validate() } 168 render(view:'create',model:[taskProcedureInstance:taskProcedureInstance]) 169 } 182 183 render(view:'create', model:[taskProcedureInstance: result.taskProcedureInstance]) 170 184 } 171 185 -
branches/features/taskProcedureRework/grails-app/services/TaskProcedureService.groovy
r774 r775 22 22 result.taskProcedureInstance.errors.rejectValue(m.field, m.code) 23 23 result.error = [ code: m.code, args: ["TaskProcedure", params.id] ] 24 // Fetch to prevent lazy initialization error. 25 result.taskProcedureInstance?.linkedTask.primaryAsset 26 result.taskProcedureInstance?.createdBy 24 27 return result 25 28 } … … 63 66 // Populate maintenanceAction errors for display. 64 67 result.taskProcedureInstance.maintenanceActions.each { it.validate() } 65 // Fetch to prevent lazy initialization error.66 result.taskProcedureInstance.linkedTask.primaryAsset67 result.taskProcedureInstance.createdBy68 68 return fail(code:"default.update.failure") 69 69 } … … 75 75 } // end update() 76 76 77 /** 78 * Creates a new taskProcedure with the given params. 79 * @param params The params to use when creating the new taskProcedure. 80 * @returns A map containing result.error (if any error) and result.taskProcedure. 81 */ 82 def save(params) { 83 def result = [:] 84 TaskProcedure.withTransaction { status -> 85 def fail = { Map m -> 86 status.setRollbackOnly() 87 if(result.taskProcedureInstance && m.field) 88 result.taskProcedureInstance.errors.rejectValue(m.field, m.code) 89 result.error = [ code: m.code, args: ["TaskProcedure", params.id] ] 90 // Fetch to prevent lazy initialization error. 91 result.taskProcedureInstance.linkedTask.primaryAsset 92 return result 93 } 94 95 result.taskProcedureInstance = new TaskProcedure(params) 96 97 // Optimistic locking check on linkedTask. 98 if(result.taskProcedureInstance.linkedTask.taskProcedure) 99 return fail(field:"version", code:"default.optimistic.locking.failure") 100 101 result.taskProcedureInstance.createdBy = authService.currentUser 102 result.taskProcedureInstance.lastUpdatedBy = authService.currentUser 103 104 // Gaps in the html index's can be created by adding 2 items and removing the first one. 105 // This creates a gap at the missing index where LazyList will return a null. 106 def nullMaintenanceActions = result.taskProcedureInstance.maintenanceActions.findAll {!it} 107 if (nullMaintenanceActions) { 108 result.taskProcedureInstance.maintenanceActions.removeAll(nullMaintenanceActions) 109 } 110 111 // Also sets: taskInstance.taskProcedure = taskProcedureInstance 112 result.taskProcedureInstance.addToTasks(result.taskProcedureInstance.linkedTask) 113 114 if(result.taskProcedureInstance.hasErrors() || !result.taskProcedureInstance.save()) { 115 // Populate maintenanceAction errors for display. 116 result.taskProcedureInstance.maintenanceActions.each { it.validate() } 117 return fail(code:"default.create.failure") 118 } 119 120 } //end withTransaction 121 122 result.taskProcedureInstance.lastUpdated = new Date() // Required to trigger version increment to 1. 123 124 // success 125 return result 126 } // end save() 127 77 128 } // end class
Note: See TracChangeset
for help on using the changeset viewer.