source: trunk/grails-app/domain/TaskProcedure.groovy @ 911

Last change on this file since 911 was 809, checked in by gav, 14 years ago

Domain change, first draft of TaskProcedureRevisions.

File size: 2.4 KB
RevLine 
[798]1import org.apache.commons.collections.list.LazyList
2import org.apache.commons.collections.FactoryUtils
3
[131]4class TaskProcedure {
5
[798]6    Task linkedTask
[131]7
[798]8    def getDescription() { linkedTask.description }
9    def getAsset() { linkedTask.primaryAsset }
[131]10
[798]11    List maintenanceActions = new ArrayList()
12    List documentReferences = new ArrayList()
[809]13    List revisions = new ArrayList()
[798]14
[809]15    static hasMany = [maintenanceActions: MaintenanceAction,
16                                    documentReferences: DocumentReference,
17                                    revisions: TaskProcedureRevision]
[798]18
19    def getMaintenanceActionLazyList() {
20        return LazyList.decorate(maintenanceActions, FactoryUtils.instantiateFactory(MaintenanceAction.class))
21    }
22
23    def getDocumentReferenceLazyList() {
24        return LazyList.decorate(documentReferences, FactoryUtils.instantiateFactory(DocumentReference.class))
25    }
26
[809]27    // The current revision number is equal to the count of the revisions created.
28    // More efficient than loading the entire revisions list and using size().
29    // WithTransaction is used to allow calling in a transaction however objects
30    // in the current transaction must not trigger DataIntegrityViolationException.
31    def getRevision() {
32        def revision
33        TaskProcedure.withTransaction {
34            revision = TaskProcedureRevision.countByTaskProcedure(this)
35        }
36        return revision
37    }
[798]38
[809]39    // Get a specific revision.
40    def getRevision(revision) {
41        def taskProcedureRevision
42        TaskProcedure.withTransaction {
43            taskProcedureRevision = TaskProcedureRevision.findByTaskProcedureAndRevision(this, revision)
44        }
45        return taskProcedureRevision
46    }
47
48    // Get the latest revision of this procedure.
49    def getLatestRevision() {
50        def taskProcedureRevision
51        TaskProcedure.withTransaction {
52            taskProcedureRevision = TaskProcedureRevision.findByTaskProcedureAndRevision(this, this.revision)
53        }
54        return taskProcedureRevision
55    }
56
[798]57    static mapping = {
[809]58        linkedTask lazy:false
59        revisions batchSize: 10
[798]60        maintenanceActions cascade:"all-delete-orphan"
61        documentReferences cascade:"all-delete-orphan"
[809]62        revisions cascade:"all-delete-orphan"
[798]63    }
64
[131]65//     static belongsTo = []
66
67    static constraints = {
68    }
69
70    String toString() {
[798]71        "${this.id}"
[131]72    }
73}
Note: See TracBrowser for help on using the repository browser.