1 | package nl.tno.metagenomics |
---|
2 | |
---|
3 | import nl.tno.metagenomics.auth.*; |
---|
4 | |
---|
5 | /** |
---|
6 | * Minimal representation of a study. The studyToken is the link with a study object in GSCF. |
---|
7 | * |
---|
8 | * @see GscfService.getStudy |
---|
9 | */ |
---|
10 | class Study { |
---|
11 | def gscfService |
---|
12 | |
---|
13 | String studyToken |
---|
14 | String name |
---|
15 | |
---|
16 | // Set to true only on the specific study object that acts as |
---|
17 | // a trash can for deleted objects. If objects are deleted in GSCF but still |
---|
18 | // contain data in this module, they will be moved to the trashcan. |
---|
19 | Boolean trashcan = false |
---|
20 | |
---|
21 | // If a study is set to be dirty, it should be updated |
---|
22 | // the next time synchronization takes place. |
---|
23 | Boolean isDirty = true; |
---|
24 | |
---|
25 | public String viewUrl() { |
---|
26 | return gscfService.urlViewStudy( studyToken ); |
---|
27 | } |
---|
28 | |
---|
29 | static hasMany = [assays: Assay, samples: Sample, auth: Auth] |
---|
30 | static mapping = { |
---|
31 | columns { |
---|
32 | studyToken index:'studytoken_idx' |
---|
33 | } |
---|
34 | assays cascade: "all-delete-orphan" |
---|
35 | samples cascade: "all-delete-orphan" |
---|
36 | auth cascade: "all-delete-orphan" |
---|
37 | } |
---|
38 | |
---|
39 | static constraints = { |
---|
40 | studyToken(unique:true) |
---|
41 | trashcan(nullable:true) |
---|
42 | isDirty(nullable:true) |
---|
43 | } |
---|
44 | |
---|
45 | public boolean equals( Object o ) { |
---|
46 | if( o == null ) |
---|
47 | return false |
---|
48 | |
---|
49 | if( o instanceof Study ) { |
---|
50 | return (o.id != null && this.id != null && o.id == this.id); |
---|
51 | } else { |
---|
52 | return false |
---|
53 | } |
---|
54 | } |
---|
55 | |
---|
56 | public boolean canRead( User user ) { |
---|
57 | Auth authorization = auth.find { it.user.equals( user ) } |
---|
58 | |
---|
59 | if( !authorization ) |
---|
60 | return false |
---|
61 | |
---|
62 | return authorization.canRead |
---|
63 | } |
---|
64 | |
---|
65 | public boolean canWrite( User user ) { |
---|
66 | Auth authorization = auth.find { it.user.equals( user ) } |
---|
67 | |
---|
68 | if( !authorization ) |
---|
69 | return false |
---|
70 | |
---|
71 | return authorization.canWrite |
---|
72 | } |
---|
73 | |
---|
74 | public boolean isOwner( User user ) { |
---|
75 | Auth authorization = auth.find { it.user.equals( user ) } |
---|
76 | |
---|
77 | if( !authorization ) |
---|
78 | return false |
---|
79 | |
---|
80 | return authorization.isOwner |
---|
81 | } |
---|
82 | |
---|
83 | } |
---|