Changeset 510 for trunk/grails-app/services
- Timestamp:
- Apr 28, 2010, 4:19:56 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/TaskService.groovy
r482 r510 1 import grails.util.Environment 2 1 3 /** 2 4 * Provides a service class for the Task domain class. … … 221 223 222 224 /** 225 * In production tasks are NEVER deleted, only the trash flag is set! 226 * However during testing it may be required to delete a task and that 227 * is why this method exists. 228 */ 229 def delete(params) { 230 Task.withTransaction { status -> 231 def result = [:] 232 233 def fail = { Map m -> 234 status.setRollbackOnly() 235 if(result.taskInstance && m.field) 236 result.taskInstance.errors.rejectValue(m.field, m.code) 237 result.error = [ code: m.code, args: ["Task", params.id] ] 238 return result 239 } 240 241 if(Environment.current == Environment.PRODUCTION) 242 return fail(code:"task.delete.failure.production") 243 244 result.taskInstance = Task.get(params.id) 245 246 if(!result.taskInstance) 247 return fail(code:"default.not.found") 248 249 // Handle taskModifications. 250 def taskModifications = TaskModification.findAllByTask(result.taskInstance) 251 taskModifications.each() { 252 result.taskInstance.removeFromTaskModifications(it) 253 it.delete() 254 } 255 256 if(result.error) 257 return result 258 259 try { 260 result.taskInstance.delete(flush:true) 261 return result //Success. 262 } 263 catch(org.springframework.dao.DataIntegrityViolationException e) { 264 return fail(code:"default.delete.failure") 265 } 266 267 } // end withTransaction 268 } // delete() 269 270 /** 223 271 * Creates a new task entry. 224 272 * @param params The params to use when creating the new entry. … … 241 289 242 290 def taskInstance 243 if(result.entryInstance.task .id) {291 if(result.entryInstance.task?.id) { 244 292 result.taskId = result.entryInstance.task.id 245 293 taskInstance = Task.lock(result.entryInstance.task.id) … … 255 303 return fail(field:"task", code:"task.operationNotPermittedOnCompleteTask") 256 304 257 // If task status is "Not Started" and entry type is "Work Done" then we create the started modification and set the status. 258 if(taskInstance.taskStatus.id == 1 && result.entryInstance.entryType.id == 3) { 305 // If task status is "Not Started" and entry type is "Work Done" and time has been booked. 306 // Then we create the started modification and set task status. 307 if(taskInstance.taskStatus.id == 1 && result.entryInstance.entryType.id == 3 308 && (result.entryInstance.durationHour + result.entryInstance.durationMinute > 0)) { 259 309 260 310 // Create the "Started" task modification, this provides the "Actual Started Date". 261 311 def taskModification = new TaskModification(person: authService.currentUser, 262 taskModificationType: TaskModificationType. get(2),312 taskModificationType: TaskModificationType.read(2), 263 313 task: taskInstance) 264 314 … … 267 317 268 318 // Set task status to "In Progress". 269 taskInstance.taskStatus = TaskStatus. get(2)319 taskInstance.taskStatus = TaskStatus.read(2) 270 320 271 321 if(taskInstance.hasErrors() || !taskInstance.save()) … … 494 544 } 495 545 496 result.taskInstance.taskStatus = TaskStatus.get(2) 546 def isInProgress = false 547 result.taskInstance.entries.each() { 548 if(it.entryType.id == 3 && (it.durationHour + it.durationMinute > 0) ) 549 isInProgress = true 550 } 551 552 if(isInProgress) 553 result.taskInstance.taskStatus = TaskStatus.read(2) // In Progress 554 else 555 result.taskInstance.taskStatus = TaskStatus.read(1) // Not Started 497 556 498 557 if(result.taskInstance.hasErrors() || !result.taskInstance.save())
Note: See TracChangeset
for help on using the changeset viewer.