Ignore:
Timestamp:
Feb 16, 2011, 8:10:39 PM (14 years ago)
Author:
gav
Message:

Domain change, first draft of TaskProcedureRevisions.

Location:
trunk/grails-app/services
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/services/CreateDataService.groovy

    r798 r809  
    140140        createDemoAssignedGroups()
    141141        createDemoAssignedPersons()
    142         createDemoTaskProcedure()
    143         createDemoMaintenanceActions()
     142//         createDemoTaskProcedure()
     143//         createDemoMaintenanceActions()
    144144        createDemoTaskRecurringSchedules()
    145145
  • trunk/grails-app/services/TaskProcedureService.groovy

    r798 r809  
    77
    88    def authService
     9    def dateUtilService
    910
    1011    /**
     
    2324                result.error = [ code: m.code, args: ["TaskProcedure", params.id] ]
    2425                // Fetch to prevent lazy initialization error.
    25                 result.taskProcedureInstance?.linkedTask.primaryAsset
    26                 result.taskProcedureInstance?.createdBy
     26                result.taskProcedureInstance.revisions.each {it.createdBy.toString()}
    2727                return result
    2828            }
     
    4040
    4141            result.taskProcedureInstance.properties = params
    42             result.taskProcedureInstance.lastUpdatedBy = authService.currentUser
    43             result.taskProcedureInstance.lastUpdated = new Date() // Required to trigger version increment.
    4442
    4543            // Gaps in the html index's can be created by adding 2 items and removing the first one.
     
    8078            }
    8179
     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
    82103            // Success.
    83104            return result
    84105
    85         } //end withTransaction
     106        } // end withTransaction
    86107    }  // end update()
    87108
     
    96117            def fail = { Map m ->
    97118                status.setRollbackOnly()
    98                 if(result.taskProcedureInstance && m.field) 
     119                if(result.taskProcedureInstance && m.field)
    99120                    result.taskProcedureInstance.errors.rejectValue(m.field, m.code)
    100121                result.error = [ code: m.code, args: ["TaskProcedure", params.id] ]
     
    107128
    108129            // Optimistic locking check on linkedTask.
    109             if(result.taskProcedureInstance.linkedTask.taskProcedure)
     130            if(result.taskProcedureInstance.linkedTask.taskProcedureRevision)
    110131                    return fail(field:"version", code:"default.optimistic.locking.failure")
    111 
    112             result.taskProcedureInstance.createdBy = authService.currentUser
    113             result.taskProcedureInstance.lastUpdatedBy = authService.currentUser
    114132
    115133            // Gaps in the html index's can be created by adding 2 items and removing the first one.
     
    124142            }
    125143
    126             // Also sets: taskInstance.taskProcedure = taskProcedureInstance
    127             result.taskProcedureInstance.addToTasks(result.taskProcedureInstance.linkedTask)
    128 
    129144            if(result.taskProcedureInstance.hasErrors() || !result.taskProcedureInstance.save()) {
    130145                // Populate collection errors for display.
     
    134149            }
    135150
    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.
    141161        return result
    142162    }  // end save()
    143163
     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
    144206} // end class
  • trunk/grails-app/services/TaskRecurringScheduleService.groovy

    r445 r809  
    6868                p.targetStartDate = it.nextTargetStartDate
    6969                p.targetCompletionDate = it.nextTargetCompletionDate
    70                 if(it.task.taskProcedure) p.taskProcedure = it.task.taskProcedure
     70                if(it.task.taskProcedureRevision) p.taskProcedureRevision = it.task.taskProcedureRevision
    7171                if(it.task.assignedGroups) p.assignedGroups = new ArrayList(it.task.assignedGroups)
    7272                if(it.task.assignedPersons) p.assignedPersons = new ArrayList(it.task.assignedPersons)
  • trunk/grails-app/services/TaskService.groovy

    r802 r809  
    188188    * Creates a subTask copying sane attributes from the parentTask unless otherwise specified in params.
    189189    * 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.
    191191    * The assignedPersons and assignedGroups are only added to the sub task if supplied in params.
    192192    * The positiveFault property is never set on the subTask.
     
    228228
    229229        // Supplied by recurring tasks.
    230         if(params.taskProcedure) p.taskProcedure = params.taskProcedure
     230        if(params.taskProcedureRevision) p.taskProcedureRevision = params.taskProcedureRevision
    231231        if(params.assignedGroups) p.assignedGroups = params.assignedGroups // Collection.
    232232        if(params.assignedPersons) p.assignedPersons = params.assignedPersons // Collection.
     
    691691            }
    692692
    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            }
    696698
    697699            // Check for Parent PM task type.
    698700            if(result.taskInstance.taskType.id == 6)
    699                 return fail(field:"taskProcedure", code:"task.operationNotPermittedOnParentPmTask")
     701                return fail(field:"taskType", code:"task.operationNotPermittedOnParentPmTask")
    700702
    701703            result.taskInstance.trash = true
Note: See TracChangeset for help on using the changeset viewer.