source: branches/features/purchaseOrders/grails-app/domain/TaskProcedure.groovy @ 967

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

Domain change, first draft of TaskProcedureRevisions.

File size: 2.4 KB
Line 
1import org.apache.commons.collections.list.LazyList
2import org.apache.commons.collections.FactoryUtils
3
4class TaskProcedure {
5
6    Task linkedTask
7
8    def getDescription() { linkedTask.description }
9    def getAsset() { linkedTask.primaryAsset }
10
11    List maintenanceActions = new ArrayList()
12    List documentReferences = new ArrayList()
13    List revisions = new ArrayList()
14
15    static hasMany = [maintenanceActions: MaintenanceAction,
16                                    documentReferences: DocumentReference,
17                                    revisions: TaskProcedureRevision]
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
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    }
38
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
57    static mapping = {
58        linkedTask lazy:false
59        revisions batchSize: 10
60        maintenanceActions cascade:"all-delete-orphan"
61        documentReferences cascade:"all-delete-orphan"
62        revisions cascade:"all-delete-orphan"
63    }
64
65//     static belongsTo = []
66
67    static constraints = {
68    }
69
70    String toString() {
71        "${this.id}"
72    }
73}
Note: See TracBrowser for help on using the repository browser.