5523 |
02 Dec 10 |
nicklas |
1 |
/** |
5523 |
02 Dec 10 |
nicklas |
$Id$ |
5523 |
02 Dec 10 |
nicklas |
3 |
|
5523 |
02 Dec 10 |
nicklas |
Copyright (C) 2010 Nicklas Nordborg |
5523 |
02 Dec 10 |
nicklas |
5 |
|
5523 |
02 Dec 10 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
5523 |
02 Dec 10 |
nicklas |
Available at http://base.thep.lu.se/ |
5523 |
02 Dec 10 |
nicklas |
8 |
|
5523 |
02 Dec 10 |
nicklas |
BASE is free software; you can redistribute it and/or |
5523 |
02 Dec 10 |
nicklas |
modify it under the terms of the GNU General Public License |
5523 |
02 Dec 10 |
nicklas |
as published by the Free Software Foundation; either version 3 |
5523 |
02 Dec 10 |
nicklas |
of the License, or (at your option) any later version. |
5523 |
02 Dec 10 |
nicklas |
13 |
|
5523 |
02 Dec 10 |
nicklas |
BASE is distributed in the hope that it will be useful, |
5523 |
02 Dec 10 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5523 |
02 Dec 10 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5523 |
02 Dec 10 |
nicklas |
GNU General Public License for more details. |
5523 |
02 Dec 10 |
nicklas |
18 |
|
5523 |
02 Dec 10 |
nicklas |
You should have received a copy of the GNU General Public License |
5523 |
02 Dec 10 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5523 |
02 Dec 10 |
nicklas |
21 |
*/ |
5523 |
02 Dec 10 |
nicklas |
22 |
|
5523 |
02 Dec 10 |
nicklas |
23 |
import net.sf.basedb.core.BaseException; |
5523 |
02 Dec 10 |
nicklas |
24 |
import net.sf.basedb.core.BioMaterialEvent; |
5523 |
02 Dec 10 |
nicklas |
25 |
import net.sf.basedb.core.BioPlateEvent; |
5523 |
02 Dec 10 |
nicklas |
26 |
import net.sf.basedb.core.BioPlateEventParticipant; |
5523 |
02 Dec 10 |
nicklas |
27 |
import net.sf.basedb.core.BioPlateEventType; |
5523 |
02 Dec 10 |
nicklas |
28 |
import net.sf.basedb.core.BioWell; |
5523 |
02 Dec 10 |
nicklas |
29 |
import net.sf.basedb.core.BioWell.LockMode; |
5523 |
02 Dec 10 |
nicklas |
30 |
import net.sf.basedb.core.BioPlate; |
5523 |
02 Dec 10 |
nicklas |
31 |
import net.sf.basedb.core.DbControl; |
5523 |
02 Dec 10 |
nicklas |
32 |
import net.sf.basedb.core.Extract; |
5523 |
02 Dec 10 |
nicklas |
33 |
import net.sf.basedb.core.Hardware; |
5523 |
02 Dec 10 |
nicklas |
34 |
import net.sf.basedb.core.Item; |
5523 |
02 Dec 10 |
nicklas |
35 |
import net.sf.basedb.core.ItemProxy; |
5523 |
02 Dec 10 |
nicklas |
36 |
import net.sf.basedb.core.ItemResultList; |
5523 |
02 Dec 10 |
nicklas |
37 |
import net.sf.basedb.core.MeasuredBioMaterial; |
5523 |
02 Dec 10 |
nicklas |
38 |
import net.sf.basedb.core.Permission; |
5523 |
02 Dec 10 |
nicklas |
39 |
import net.sf.basedb.core.Protocol; |
5523 |
02 Dec 10 |
nicklas |
40 |
import net.sf.basedb.core.Sample; |
5523 |
02 Dec 10 |
nicklas |
41 |
import net.sf.basedb.core.SystemItems; |
5523 |
02 Dec 10 |
nicklas |
42 |
import net.sf.basedb.core.Trashcan; |
5523 |
02 Dec 10 |
nicklas |
43 |
|
5523 |
02 Dec 10 |
nicklas |
44 |
import java.util.Date; |
5523 |
02 Dec 10 |
nicklas |
45 |
import java.util.List; |
5523 |
02 Dec 10 |
nicklas |
46 |
import java.util.Set; |
5523 |
02 Dec 10 |
nicklas |
47 |
|
5523 |
02 Dec 10 |
nicklas |
48 |
/** |
5523 |
02 Dec 10 |
nicklas |
@author Nicklas |
5523 |
02 Dec 10 |
nicklas |
@since 2.17 |
5523 |
02 Dec 10 |
nicklas |
@base.modified $Date$ |
5523 |
02 Dec 10 |
nicklas |
52 |
*/ |
5523 |
02 Dec 10 |
nicklas |
53 |
public class TestBioPlateEvent |
5523 |
02 Dec 10 |
nicklas |
54 |
{ |
5523 |
02 Dec 10 |
nicklas |
55 |
static boolean ok = true; |
5523 |
02 Dec 10 |
nicklas |
56 |
public static void main(String[] args) |
5523 |
02 Dec 10 |
nicklas |
57 |
{ |
5523 |
02 Dec 10 |
nicklas |
58 |
TestUtil.checkArgs(args); |
5523 |
02 Dec 10 |
nicklas |
59 |
TestUtil.begin(); |
5523 |
02 Dec 10 |
nicklas |
60 |
ok = test_all(); |
5523 |
02 Dec 10 |
nicklas |
61 |
TestUtil.stop(); |
5523 |
02 Dec 10 |
nicklas |
62 |
} |
5523 |
02 Dec 10 |
nicklas |
63 |
|
5523 |
02 Dec 10 |
nicklas |
64 |
static boolean test_all() |
5523 |
02 Dec 10 |
nicklas |
65 |
{ |
5523 |
02 Dec 10 |
nicklas |
66 |
write("++Testing bioplate events"); |
5523 |
02 Dec 10 |
nicklas |
67 |
write_header(); |
5523 |
02 Dec 10 |
nicklas |
68 |
|
5523 |
02 Dec 10 |
nicklas |
// Create bioplate types and bioplates |
5523 |
02 Dec 10 |
nicklas |
70 |
int samplePlateTypeId = TestBioPlateType.test_create("Sample plate", Item.SAMPLE, LockMode.LOCKED_AFTER_MOVE); |
5523 |
02 Dec 10 |
nicklas |
71 |
int extractPlateTypeId = TestBioPlateType.test_create("Extract plate", Item.EXTRACT, LockMode.LOCKED_AFTER_MOVE); |
5523 |
02 Dec 10 |
nicklas |
72 |
int storagePlateTypeId = TestBioPlateType.test_create("Storage plate", null, LockMode.UNLOCKED); |
5523 |
02 Dec 10 |
nicklas |
73 |
int plateGeometryId = TestPlateGeometry.test_create(2, 4, false); |
5523 |
02 Dec 10 |
nicklas |
74 |
int samplePlateId = TestBioPlate.test_create("Samples #1", plateGeometryId, samplePlateTypeId, 0, false); |
5523 |
02 Dec 10 |
nicklas |
75 |
int extractPlateId = TestBioPlate.test_create("Extracts #1", plateGeometryId, extractPlateTypeId, 0, false); |
5523 |
02 Dec 10 |
nicklas |
76 |
int storagePlateId = TestBioPlate.test_create("Storage #1", plateGeometryId, storagePlateTypeId, 0, false); |
5523 |
02 Dec 10 |
nicklas |
77 |
|
5523 |
02 Dec 10 |
nicklas |
// Create biomaterial |
6100 |
04 Sep 12 |
nicklas |
79 |
int sampleId1 = TestSample.test_create(0, "Foo.s1", 0, false); |
6100 |
04 Sep 12 |
nicklas |
80 |
int sampleId2 = TestSample.test_create(0, "Bar.s2", 0, false); |
6100 |
04 Sep 12 |
nicklas |
81 |
int sampleId3 = TestSample.test_create(0, "Ref.s3", 0, false); |
5523 |
02 Dec 10 |
nicklas |
82 |
|
5630 |
13 May 11 |
nicklas |
83 |
int protocolId = TestProtocol.test_create(SystemItems.getId(Protocol.EXTRACTION), "Extract on plate", false); |
5630 |
13 May 11 |
nicklas |
84 |
int hardwareId = TestHardware.test_create(SystemItems.getId(Hardware.OTHER), "Extraction bot", false); |
5523 |
02 Dec 10 |
nicklas |
85 |
|
5523 |
02 Dec 10 |
nicklas |
// Place the biomaterial on a plate using an event |
5523 |
02 Dec 10 |
nicklas |
87 |
int id1 = test_place_on_plate_event("Place samples", samplePlateId, Item.SAMPLE, sampleId1, sampleId2, sampleId3); |
5523 |
02 Dec 10 |
nicklas |
88 |
test_load(id1); |
5523 |
02 Dec 10 |
nicklas |
89 |
test_list_participants(id1, 1); |
5523 |
02 Dec 10 |
nicklas |
90 |
|
5523 |
02 Dec 10 |
nicklas |
// Create extracts from the samples on a reaction plate |
5523 |
02 Dec 10 |
nicklas |
92 |
int id2 = test_extraction_event("Create extracts", samplePlateId, extractPlateId, protocolId, hardwareId); |
5523 |
02 Dec 10 |
nicklas |
93 |
test_list_participants(id2, 2); |
5523 |
02 Dec 10 |
nicklas |
94 |
|
5523 |
02 Dec 10 |
nicklas |
// Move the samples to a storage plate |
5523 |
02 Dec 10 |
nicklas |
96 |
int id3 = test_move_event("Move samples to storage", samplePlateId, storagePlateId); |
5523 |
02 Dec 10 |
nicklas |
97 |
test_list_participants(id3, 2); |
5523 |
02 Dec 10 |
nicklas |
98 |
|
5523 |
02 Dec 10 |
nicklas |
99 |
test_list(-1); |
5523 |
02 Dec 10 |
nicklas |
100 |
|
5523 |
02 Dec 10 |
nicklas |
101 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
5523 |
02 Dec 10 |
nicklas |
// Standard test: Delete |
5523 |
02 Dec 10 |
nicklas |
103 |
test_delete(id1); |
5523 |
02 Dec 10 |
nicklas |
104 |
test_delete(id2); |
5523 |
02 Dec 10 |
nicklas |
105 |
test_delete(id3); |
5523 |
02 Dec 10 |
nicklas |
106 |
|
5689 |
11 Aug 11 |
nicklas |
// Delete the plates and the biomaterial on them |
5523 |
02 Dec 10 |
nicklas |
108 |
TestBioPlate.test_delete_contents(extractPlateId); |
5523 |
02 Dec 10 |
nicklas |
109 |
TestBioPlate.test_delete_contents(storagePlateId); |
5523 |
02 Dec 10 |
nicklas |
110 |
TestBioPlate.test_delete_contents(samplePlateId); |
5523 |
02 Dec 10 |
nicklas |
111 |
|
5523 |
02 Dec 10 |
nicklas |
112 |
TestHardware.test_delete(hardwareId); |
5523 |
02 Dec 10 |
nicklas |
113 |
TestProtocol.test_delete(protocolId); |
5523 |
02 Dec 10 |
nicklas |
114 |
|
5523 |
02 Dec 10 |
nicklas |
115 |
TestBioPlate.test_delete(storagePlateId); |
5523 |
02 Dec 10 |
nicklas |
116 |
TestBioPlate.test_delete(samplePlateId); |
5523 |
02 Dec 10 |
nicklas |
117 |
TestBioPlate.test_delete(extractPlateId); |
5523 |
02 Dec 10 |
nicklas |
118 |
TestPlateGeometry.test_delete(plateGeometryId); |
5523 |
02 Dec 10 |
nicklas |
119 |
TestBioPlateType.test_delete(samplePlateTypeId); |
5523 |
02 Dec 10 |
nicklas |
120 |
TestBioPlateType.test_delete(extractPlateTypeId); |
5523 |
02 Dec 10 |
nicklas |
121 |
TestBioPlateType.test_delete(storagePlateTypeId); |
5523 |
02 Dec 10 |
nicklas |
122 |
|
5523 |
02 Dec 10 |
nicklas |
123 |
write("++Testing bioplate events "+(ok ? "OK" : "Failed")+"\n"); |
5523 |
02 Dec 10 |
nicklas |
124 |
return ok; |
5523 |
02 Dec 10 |
nicklas |
125 |
} |
5523 |
02 Dec 10 |
nicklas |
126 |
|
5523 |
02 Dec 10 |
nicklas |
127 |
static void test_delete(int id) |
5523 |
02 Dec 10 |
nicklas |
128 |
{ |
5523 |
02 Dec 10 |
nicklas |
129 |
if (id == 0) return; |
5523 |
02 Dec 10 |
nicklas |
130 |
DbControl dc = null; |
5523 |
02 Dec 10 |
nicklas |
131 |
try |
5523 |
02 Dec 10 |
nicklas |
132 |
{ |
5523 |
02 Dec 10 |
nicklas |
133 |
dc = TestUtil.getDbControl(); |
5523 |
02 Dec 10 |
nicklas |
134 |
BioPlateEvent event = BioPlateEvent.getById(dc, id); |
5523 |
02 Dec 10 |
nicklas |
135 |
dc.deleteItem(event); |
5523 |
02 Dec 10 |
nicklas |
136 |
Set<ItemProxy> using = event.getUsingItems(); |
5523 |
02 Dec 10 |
nicklas |
137 |
if (using.size() > 0) |
5523 |
02 Dec 10 |
nicklas |
138 |
{ |
5523 |
02 Dec 10 |
nicklas |
139 |
throw new BaseException(event + " is used by " + using); |
5523 |
02 Dec 10 |
nicklas |
140 |
} |
5523 |
02 Dec 10 |
nicklas |
141 |
dc.commit(); |
5523 |
02 Dec 10 |
nicklas |
142 |
write("--Delete bioplate event OK"); |
5523 |
02 Dec 10 |
nicklas |
143 |
} |
5523 |
02 Dec 10 |
nicklas |
144 |
catch (Throwable ex) |
5523 |
02 Dec 10 |
nicklas |
145 |
{ |
5523 |
02 Dec 10 |
nicklas |
146 |
write("--Delete bioplate event FAILED"); |
5523 |
02 Dec 10 |
nicklas |
147 |
ex.printStackTrace(); |
5523 |
02 Dec 10 |
nicklas |
148 |
ok = false; |
5523 |
02 Dec 10 |
nicklas |
149 |
} |
5523 |
02 Dec 10 |
nicklas |
150 |
finally |
5523 |
02 Dec 10 |
nicklas |
151 |
{ |
5523 |
02 Dec 10 |
nicklas |
152 |
if (dc != null) dc.close(); |
5523 |
02 Dec 10 |
nicklas |
153 |
} |
5523 |
02 Dec 10 |
nicklas |
154 |
|
5523 |
02 Dec 10 |
nicklas |
155 |
} |
5523 |
02 Dec 10 |
nicklas |
156 |
|
5523 |
02 Dec 10 |
nicklas |
157 |
static void test_list(int expectedResults) |
5523 |
02 Dec 10 |
nicklas |
158 |
{ |
5523 |
02 Dec 10 |
nicklas |
159 |
DbControl dc = null; |
5523 |
02 Dec 10 |
nicklas |
160 |
try |
5523 |
02 Dec 10 |
nicklas |
161 |
{ |
5523 |
02 Dec 10 |
nicklas |
162 |
dc = TestUtil.getDbControl(); |
5523 |
02 Dec 10 |
nicklas |
163 |
ItemResultList<BioPlateEvent> events = BioPlateEvent.getQuery().list(dc); |
5523 |
02 Dec 10 |
nicklas |
164 |
for (int i = 0; i<events.size(); i++) |
5523 |
02 Dec 10 |
nicklas |
165 |
{ |
5523 |
02 Dec 10 |
nicklas |
166 |
write_item(i, events.get(i)); |
5523 |
02 Dec 10 |
nicklas |
167 |
} |
5523 |
02 Dec 10 |
nicklas |
168 |
if (expectedResults >=0 && expectedResults != events.size()) |
5523 |
02 Dec 10 |
nicklas |
169 |
{ |
5523 |
02 Dec 10 |
nicklas |
170 |
throw new BaseException("Expected " + expectedResults + " results, " + |
5523 |
02 Dec 10 |
nicklas |
171 |
"not " + events.size()); |
5523 |
02 Dec 10 |
nicklas |
172 |
} |
5523 |
02 Dec 10 |
nicklas |
173 |
write ("--List bioplate events OK (" + events.size() +")"); |
5523 |
02 Dec 10 |
nicklas |
174 |
} |
5523 |
02 Dec 10 |
nicklas |
175 |
catch (Throwable ex) |
5523 |
02 Dec 10 |
nicklas |
176 |
{ |
5523 |
02 Dec 10 |
nicklas |
177 |
write("--List bioplate events FAILED"); |
5523 |
02 Dec 10 |
nicklas |
178 |
ex.printStackTrace(); |
5523 |
02 Dec 10 |
nicklas |
179 |
ok = false; |
5523 |
02 Dec 10 |
nicklas |
180 |
} |
5523 |
02 Dec 10 |
nicklas |
181 |
finally |
5523 |
02 Dec 10 |
nicklas |
182 |
{ |
5523 |
02 Dec 10 |
nicklas |
183 |
if (dc != null) dc.close(); |
5523 |
02 Dec 10 |
nicklas |
184 |
} |
5523 |
02 Dec 10 |
nicklas |
185 |
} |
5523 |
02 Dec 10 |
nicklas |
186 |
|
5523 |
02 Dec 10 |
nicklas |
187 |
static void test_load(int id) |
5523 |
02 Dec 10 |
nicklas |
188 |
{ |
5523 |
02 Dec 10 |
nicklas |
189 |
if (id == 0) return; |
5523 |
02 Dec 10 |
nicklas |
190 |
DbControl dc = null; |
5523 |
02 Dec 10 |
nicklas |
191 |
try |
5523 |
02 Dec 10 |
nicklas |
192 |
{ |
5523 |
02 Dec 10 |
nicklas |
193 |
dc = TestUtil.getDbControl(); |
5523 |
02 Dec 10 |
nicklas |
194 |
BioPlateEvent event = BioPlateEvent.getById(dc, id); |
5523 |
02 Dec 10 |
nicklas |
195 |
write_item(0, event); |
5523 |
02 Dec 10 |
nicklas |
196 |
write("--Load bioplate event OK"); |
5523 |
02 Dec 10 |
nicklas |
197 |
} |
5523 |
02 Dec 10 |
nicklas |
198 |
catch (Throwable ex) |
5523 |
02 Dec 10 |
nicklas |
199 |
{ |
5523 |
02 Dec 10 |
nicklas |
200 |
write("--Load bioplate event FAILED"); |
5523 |
02 Dec 10 |
nicklas |
201 |
ex.printStackTrace(); |
5523 |
02 Dec 10 |
nicklas |
202 |
ok = false; |
5523 |
02 Dec 10 |
nicklas |
203 |
} |
5523 |
02 Dec 10 |
nicklas |
204 |
finally |
5523 |
02 Dec 10 |
nicklas |
205 |
{ |
5523 |
02 Dec 10 |
nicklas |
206 |
if (dc != null) dc.close(); |
5523 |
02 Dec 10 |
nicklas |
207 |
} |
5523 |
02 Dec 10 |
nicklas |
208 |
} |
5523 |
02 Dec 10 |
nicklas |
209 |
|
5523 |
02 Dec 10 |
nicklas |
210 |
static void test_delete_all() |
5523 |
02 Dec 10 |
nicklas |
211 |
{ |
5523 |
02 Dec 10 |
nicklas |
212 |
DbControl dc = null; |
5523 |
02 Dec 10 |
nicklas |
213 |
try |
5523 |
02 Dec 10 |
nicklas |
214 |
{ |
5523 |
02 Dec 10 |
nicklas |
215 |
dc = TestUtil.getDbControl(); |
5523 |
02 Dec 10 |
nicklas |
216 |
ItemResultList<BioPlateEvent> l = BioPlateEvent.getQuery().list(dc); |
5688 |
10 Aug 11 |
nicklas |
217 |
int numDeleted = Trashcan.delete(dc.getSessionControl(), l, true, null); |
5688 |
10 Aug 11 |
nicklas |
218 |
if (numDeleted != l.size()) throw new BaseException("Could not delete all items: " + numDeleted + " of " + l.size()); |
5523 |
02 Dec 10 |
nicklas |
219 |
dc.commit(); |
5523 |
02 Dec 10 |
nicklas |
220 |
write("--Delete all bioplate events OK ("+l.size()+")"); |
5523 |
02 Dec 10 |
nicklas |
221 |
} |
5523 |
02 Dec 10 |
nicklas |
222 |
catch (Throwable ex) |
5523 |
02 Dec 10 |
nicklas |
223 |
{ |
5523 |
02 Dec 10 |
nicklas |
224 |
write("--Delete all bioplate events FAILED"); |
5523 |
02 Dec 10 |
nicklas |
225 |
ex.printStackTrace(); |
5523 |
02 Dec 10 |
nicklas |
226 |
ok = false; |
5523 |
02 Dec 10 |
nicklas |
227 |
} |
5523 |
02 Dec 10 |
nicklas |
228 |
finally |
5523 |
02 Dec 10 |
nicklas |
229 |
{ |
5523 |
02 Dec 10 |
nicklas |
230 |
if (dc != null) dc.close(); |
5523 |
02 Dec 10 |
nicklas |
231 |
} |
5523 |
02 Dec 10 |
nicklas |
232 |
} |
5523 |
02 Dec 10 |
nicklas |
233 |
|
5523 |
02 Dec 10 |
nicklas |
234 |
static void write_header() |
5523 |
02 Dec 10 |
nicklas |
235 |
{ |
5523 |
02 Dec 10 |
nicklas |
236 |
if (!TestUtil.getSilent()) |
5523 |
02 Dec 10 |
nicklas |
237 |
{ |
5523 |
02 Dec 10 |
nicklas |
238 |
System.out.println(" \tID \tName \tEvent type\tEvent date\tEntry date\tDescription\tProtocol\tHardware"); |
5523 |
02 Dec 10 |
nicklas |
239 |
System.out.println("-- \t-- \t----------\t----------\t----------\t----------\t-----------\t--------\t--------"); |
5523 |
02 Dec 10 |
nicklas |
240 |
} |
5523 |
02 Dec 10 |
nicklas |
241 |
} |
5523 |
02 Dec 10 |
nicklas |
242 |
|
5523 |
02 Dec 10 |
nicklas |
243 |
static void write(String message) |
5523 |
02 Dec 10 |
nicklas |
244 |
{ |
5523 |
02 Dec 10 |
nicklas |
245 |
System.out.println(message); |
5523 |
02 Dec 10 |
nicklas |
246 |
} |
5523 |
02 Dec 10 |
nicklas |
247 |
|
5523 |
02 Dec 10 |
nicklas |
248 |
static void write_item(int i, BioPlateEvent event) |
5523 |
02 Dec 10 |
nicklas |
249 |
{ |
5523 |
02 Dec 10 |
nicklas |
250 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+event.getId()+"\t"+event.getName()+"\t"+event.getEventType()+ |
5523 |
02 Dec 10 |
nicklas |
251 |
"\t" + event.getEventDate()+"\t"+event.getEntryDate()+"\t"+event.getDescription()+ |
5523 |
02 Dec 10 |
nicklas |
252 |
"\t"+event.getProtocol()+"\t"+event.getHardware()); |
5523 |
02 Dec 10 |
nicklas |
253 |
} |
5523 |
02 Dec 10 |
nicklas |
254 |
|
5523 |
02 Dec 10 |
nicklas |
255 |
static void write_item(int i, BioPlateEventParticipant participant) |
5523 |
02 Dec 10 |
nicklas |
256 |
{ |
5523 |
02 Dec 10 |
nicklas |
257 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+participant.getId()+"\t"+participant.getRole()+ |
5523 |
02 Dec 10 |
nicklas |
258 |
"\t"+participant.getIndex()+"\t" + participant.getBioPlate()); |
5523 |
02 Dec 10 |
nicklas |
259 |
} |
5523 |
02 Dec 10 |
nicklas |
260 |
|
5523 |
02 Dec 10 |
nicklas |
261 |
|
5523 |
02 Dec 10 |
nicklas |
262 |
static int test_place_on_plate_event(String name, int bioPlateId, Item bioMaterialType, int... bioMaterialIds) |
5523 |
02 Dec 10 |
nicklas |
263 |
{ |
5523 |
02 Dec 10 |
nicklas |
264 |
if (!TestUtil.hasPermission(Permission.CREATE, Item.BIOPLATEEVENT) || bioPlateId == 0) |
5523 |
02 Dec 10 |
nicklas |
265 |
{ |
5523 |
02 Dec 10 |
nicklas |
266 |
return 0; |
5523 |
02 Dec 10 |
nicklas |
267 |
} |
5523 |
02 Dec 10 |
nicklas |
268 |
int id = 0; |
5523 |
02 Dec 10 |
nicklas |
269 |
DbControl dc = null; |
5523 |
02 Dec 10 |
nicklas |
270 |
try |
5523 |
02 Dec 10 |
nicklas |
271 |
{ |
5523 |
02 Dec 10 |
nicklas |
272 |
dc = TestUtil.getDbControl(); |
5523 |
02 Dec 10 |
nicklas |
273 |
|
5523 |
02 Dec 10 |
nicklas |
274 |
BioPlate plate = BioPlate.getById(dc, bioPlateId); |
5523 |
02 Dec 10 |
nicklas |
275 |
BioPlateEventType eventType = BioPlateEventType.getById(dc, BioPlateEventType.PLACE_ON_PLATE); |
5523 |
02 Dec 10 |
nicklas |
276 |
|
5523 |
02 Dec 10 |
nicklas |
277 |
BioPlateEvent event = BioPlateEvent.getNew(dc, eventType); |
5523 |
02 Dec 10 |
nicklas |
278 |
event.setName(name); |
5523 |
02 Dec 10 |
nicklas |
279 |
event.setEventDate(new Date()); |
5523 |
02 Dec 10 |
nicklas |
280 |
BioPlateEventParticipant destination = event.addParticipant(plate, "destination", 1); |
5523 |
02 Dec 10 |
nicklas |
281 |
dc.saveItem(event); |
5523 |
02 Dec 10 |
nicklas |
282 |
|
5523 |
02 Dec 10 |
nicklas |
283 |
if (bioMaterialType != null && bioMaterialIds != null) |
5523 |
02 Dec 10 |
nicklas |
284 |
{ |
5523 |
02 Dec 10 |
nicklas |
285 |
List<BioWell> wells = plate.getBioWells().list(dc); |
5523 |
02 Dec 10 |
nicklas |
286 |
for (int i = 0; i < wells.size() && i < bioMaterialIds.length; ++i) |
5523 |
02 Dec 10 |
nicklas |
287 |
{ |
5523 |
02 Dec 10 |
nicklas |
288 |
MeasuredBioMaterial bm = (MeasuredBioMaterial)bioMaterialType.getById(dc, bioMaterialIds[i]); |
5523 |
02 Dec 10 |
nicklas |
289 |
BioWell well = wells.get(i); |
5523 |
02 Dec 10 |
nicklas |
290 |
bm.setBioWell(well); |
5523 |
02 Dec 10 |
nicklas |
291 |
BioMaterialEvent bmEvent = bm.newEvent(destination); |
5525 |
06 Dec 10 |
nicklas |
292 |
bmEvent.setComment("Well: " + well.getCoordinate()); |
5523 |
02 Dec 10 |
nicklas |
293 |
dc.saveItem(bmEvent); |
5523 |
02 Dec 10 |
nicklas |
294 |
} |
5523 |
02 Dec 10 |
nicklas |
295 |
} |
5523 |
02 Dec 10 |
nicklas |
296 |
dc.commit(); |
5523 |
02 Dec 10 |
nicklas |
297 |
id = event.getId(); |
5523 |
02 Dec 10 |
nicklas |
298 |
dc = TestUtil.getDbControl(); |
5523 |
02 Dec 10 |
nicklas |
299 |
dc.reattachItem(event, false); |
5523 |
02 Dec 10 |
nicklas |
300 |
write_item(0, event); |
5523 |
02 Dec 10 |
nicklas |
301 |
write("--Create 'place-on-plate' event OK"); |
5523 |
02 Dec 10 |
nicklas |
302 |
} |
5523 |
02 Dec 10 |
nicklas |
303 |
catch (Throwable ex) |
5523 |
02 Dec 10 |
nicklas |
304 |
{ |
5523 |
02 Dec 10 |
nicklas |
305 |
write("--Create 'place-on-plate' event FAIILED"); |
5523 |
02 Dec 10 |
nicklas |
306 |
ex.printStackTrace(); |
5523 |
02 Dec 10 |
nicklas |
307 |
ok = false; |
5523 |
02 Dec 10 |
nicklas |
308 |
} |
5523 |
02 Dec 10 |
nicklas |
309 |
finally |
5523 |
02 Dec 10 |
nicklas |
310 |
{ |
5523 |
02 Dec 10 |
nicklas |
311 |
if (dc != null) dc.close(); |
5523 |
02 Dec 10 |
nicklas |
312 |
} |
5523 |
02 Dec 10 |
nicklas |
313 |
return id; |
5523 |
02 Dec 10 |
nicklas |
314 |
} |
5523 |
02 Dec 10 |
nicklas |
315 |
|
5523 |
02 Dec 10 |
nicklas |
316 |
static int test_extraction_event(String name, int samplePlateId, int extractPlateId, int protocolId, int hardwareId) |
5523 |
02 Dec 10 |
nicklas |
317 |
{ |
5523 |
02 Dec 10 |
nicklas |
318 |
if (!TestUtil.hasPermission(Permission.CREATE, Item.BIOPLATEEVENT) || samplePlateId == 0 || extractPlateId == 0) |
5523 |
02 Dec 10 |
nicklas |
319 |
{ |
5523 |
02 Dec 10 |
nicklas |
320 |
return 0; |
5523 |
02 Dec 10 |
nicklas |
321 |
} |
5523 |
02 Dec 10 |
nicklas |
322 |
int id = 0; |
5523 |
02 Dec 10 |
nicklas |
323 |
DbControl dc = null; |
5523 |
02 Dec 10 |
nicklas |
324 |
try |
5523 |
02 Dec 10 |
nicklas |
325 |
{ |
5523 |
02 Dec 10 |
nicklas |
326 |
dc = TestUtil.getDbControl(); |
5523 |
02 Dec 10 |
nicklas |
327 |
|
5523 |
02 Dec 10 |
nicklas |
328 |
BioPlate samples = BioPlate.getById(dc, samplePlateId); |
5523 |
02 Dec 10 |
nicklas |
329 |
BioPlate extracts = BioPlate.getById(dc, extractPlateId); |
5523 |
02 Dec 10 |
nicklas |
330 |
BioPlateEventType eventType = BioPlateEventType.getById(dc, BioPlateEventType.CREATE_BIOMATERIAL); |
5523 |
02 Dec 10 |
nicklas |
331 |
|
5523 |
02 Dec 10 |
nicklas |
// Create the master event |
5523 |
02 Dec 10 |
nicklas |
333 |
BioPlateEvent event = BioPlateEvent.getNew(dc, eventType); |
5523 |
02 Dec 10 |
nicklas |
334 |
event.setName(name); |
5523 |
02 Dec 10 |
nicklas |
335 |
event.setEventDate(new Date()); |
5523 |
02 Dec 10 |
nicklas |
336 |
if (protocolId != 0) |
5523 |
02 Dec 10 |
nicklas |
337 |
{ |
5523 |
02 Dec 10 |
nicklas |
338 |
event.setProtocol(Protocol.getById(dc, protocolId)); |
5523 |
02 Dec 10 |
nicklas |
339 |
} |
5523 |
02 Dec 10 |
nicklas |
340 |
if (hardwareId != 0) |
5523 |
02 Dec 10 |
nicklas |
341 |
{ |
5523 |
02 Dec 10 |
nicklas |
342 |
event.setHardware(Hardware.getById(dc, hardwareId)); |
5523 |
02 Dec 10 |
nicklas |
343 |
} |
5523 |
02 Dec 10 |
nicklas |
// Add participating plates |
5523 |
02 Dec 10 |
nicklas |
345 |
BioPlateEventParticipant source = event.addParticipant(samples, "source", 1); |
5523 |
02 Dec 10 |
nicklas |
346 |
BioPlateEventParticipant destination = event.addParticipant(extracts, "destination", 1); |
5523 |
02 Dec 10 |
nicklas |
347 |
dc.saveItem(event); |
5523 |
02 Dec 10 |
nicklas |
348 |
|
5523 |
02 Dec 10 |
nicklas |
// Create child extracts |
5523 |
02 Dec 10 |
nicklas |
350 |
for (BioWell well : samples.getBioWells().list(dc)) |
5523 |
02 Dec 10 |
nicklas |
351 |
{ |
5523 |
02 Dec 10 |
nicklas |
352 |
Sample s = (Sample)well.getBioMaterial(); |
5523 |
02 Dec 10 |
nicklas |
353 |
if (s != null) |
5523 |
02 Dec 10 |
nicklas |
354 |
{ |
5523 |
02 Dec 10 |
nicklas |
// Create a new extract and put it in the same coordinate on the |
5523 |
02 Dec 10 |
nicklas |
// extracts plate |
5523 |
02 Dec 10 |
nicklas |
357 |
Extract e = s.newExtract(null, destination); |
5525 |
06 Dec 10 |
nicklas |
358 |
e.setBioWell(extracts.getBioWell(well.getPlateCoordinate())); |
5523 |
02 Dec 10 |
nicklas |
359 |
e.setName(s.getName()+".e"+s.countChildren(false)); |
5525 |
06 Dec 10 |
nicklas |
360 |
e.getCreationEvent().setComment("Well: " + well.getCoordinate()); |
5523 |
02 Dec 10 |
nicklas |
361 |
dc.saveItem(e); |
5523 |
02 Dec 10 |
nicklas |
362 |
} |
5523 |
02 Dec 10 |
nicklas |
363 |
} |
5523 |
02 Dec 10 |
nicklas |
364 |
|
5523 |
02 Dec 10 |
nicklas |
365 |
dc.commit(); |
5523 |
02 Dec 10 |
nicklas |
366 |
id = event.getId(); |
5523 |
02 Dec 10 |
nicklas |
367 |
dc = TestUtil.getDbControl(); |
5523 |
02 Dec 10 |
nicklas |
368 |
dc.reattachItem(event, false); |
5523 |
02 Dec 10 |
nicklas |
369 |
write_item(0, event); |
5523 |
02 Dec 10 |
nicklas |
370 |
write("--Create extraction plate event OK"); |
5523 |
02 Dec 10 |
nicklas |
371 |
} |
5523 |
02 Dec 10 |
nicklas |
372 |
catch (Throwable ex) |
5523 |
02 Dec 10 |
nicklas |
373 |
{ |
5523 |
02 Dec 10 |
nicklas |
374 |
write("--Create extraction plate event FAIILED"); |
5523 |
02 Dec 10 |
nicklas |
375 |
ex.printStackTrace(); |
5523 |
02 Dec 10 |
nicklas |
376 |
ok = false; |
5523 |
02 Dec 10 |
nicklas |
377 |
} |
5523 |
02 Dec 10 |
nicklas |
378 |
finally |
5523 |
02 Dec 10 |
nicklas |
379 |
{ |
5523 |
02 Dec 10 |
nicklas |
380 |
if (dc != null) dc.close(); |
5523 |
02 Dec 10 |
nicklas |
381 |
} |
5523 |
02 Dec 10 |
nicklas |
382 |
return id; |
5523 |
02 Dec 10 |
nicklas |
383 |
} |
5523 |
02 Dec 10 |
nicklas |
384 |
|
5523 |
02 Dec 10 |
nicklas |
385 |
static int test_move_event(String name, int sourcePlateId, int destinationPlateId) |
5523 |
02 Dec 10 |
nicklas |
386 |
{ |
5523 |
02 Dec 10 |
nicklas |
387 |
if (!TestUtil.hasPermission(Permission.CREATE, Item.BIOPLATEEVENT) || sourcePlateId == 0 || destinationPlateId == 0) |
5523 |
02 Dec 10 |
nicklas |
388 |
{ |
5523 |
02 Dec 10 |
nicklas |
389 |
return 0; |
5523 |
02 Dec 10 |
nicklas |
390 |
} |
5523 |
02 Dec 10 |
nicklas |
391 |
int id = 0; |
5523 |
02 Dec 10 |
nicklas |
392 |
DbControl dc = null; |
5523 |
02 Dec 10 |
nicklas |
393 |
try |
5523 |
02 Dec 10 |
nicklas |
394 |
{ |
5523 |
02 Dec 10 |
nicklas |
395 |
dc = TestUtil.getDbControl(); |
5523 |
02 Dec 10 |
nicklas |
396 |
|
5523 |
02 Dec 10 |
nicklas |
397 |
BioPlate source = BioPlate.getById(dc, sourcePlateId); |
5523 |
02 Dec 10 |
nicklas |
398 |
BioPlate destination = BioPlate.getById(dc, destinationPlateId); |
5523 |
02 Dec 10 |
nicklas |
399 |
BioPlateEventType eventType = BioPlateEventType.getById(dc, BioPlateEventType.MOVE); |
5523 |
02 Dec 10 |
nicklas |
400 |
|
5523 |
02 Dec 10 |
nicklas |
// Create the master event |
5523 |
02 Dec 10 |
nicklas |
402 |
BioPlateEvent event = BioPlateEvent.getNew(dc, eventType); |
5523 |
02 Dec 10 |
nicklas |
403 |
event.setName(name); |
5523 |
02 Dec 10 |
nicklas |
404 |
event.setEventDate(new Date()); |
5523 |
02 Dec 10 |
nicklas |
405 |
|
5523 |
02 Dec 10 |
nicklas |
// Add participating plates |
5523 |
02 Dec 10 |
nicklas |
407 |
event.addParticipant(source, "source", 1); |
5523 |
02 Dec 10 |
nicklas |
408 |
BioPlateEventParticipant destParticipant = event.addParticipant(destination, "destination", 1); |
5523 |
02 Dec 10 |
nicklas |
409 |
dc.saveItem(event); |
5523 |
02 Dec 10 |
nicklas |
410 |
|
5523 |
02 Dec 10 |
nicklas |
// Move the biomaterial |
5523 |
02 Dec 10 |
nicklas |
412 |
for (BioWell well : source.getBioWells().list(dc)) |
5523 |
02 Dec 10 |
nicklas |
413 |
{ |
5523 |
02 Dec 10 |
nicklas |
414 |
MeasuredBioMaterial bm = well.getBioMaterial(); |
5523 |
02 Dec 10 |
nicklas |
415 |
if (bm != null) |
5523 |
02 Dec 10 |
nicklas |
416 |
{ |
5523 |
02 Dec 10 |
nicklas |
// Move the sample to the storage plate |
5523 |
02 Dec 10 |
nicklas |
418 |
bm.setBioWell(destination.getBioWell(well.getRow(), well.getColumn())); |
5523 |
02 Dec 10 |
nicklas |
419 |
BioMaterialEvent bmEvent = bm.newEvent(destParticipant); |
5523 |
02 Dec 10 |
nicklas |
420 |
bmEvent.setComment(source.getName() + " [" + well.getCoordinate() + "] → "+ |
5523 |
02 Dec 10 |
nicklas |
421 |
destination.getName() + " [" + well.getCoordinate() + "]"); |
5523 |
02 Dec 10 |
nicklas |
422 |
dc.saveItem(bmEvent); |
5523 |
02 Dec 10 |
nicklas |
423 |
} |
5523 |
02 Dec 10 |
nicklas |
424 |
} |
5523 |
02 Dec 10 |
nicklas |
425 |
|
5523 |
02 Dec 10 |
nicklas |
426 |
dc.commit(); |
5523 |
02 Dec 10 |
nicklas |
427 |
id = event.getId(); |
5523 |
02 Dec 10 |
nicklas |
428 |
dc = TestUtil.getDbControl(); |
5523 |
02 Dec 10 |
nicklas |
429 |
dc.reattachItem(event, false); |
5523 |
02 Dec 10 |
nicklas |
430 |
write_item(0, event); |
5523 |
02 Dec 10 |
nicklas |
431 |
write("--Create move event OK"); |
5523 |
02 Dec 10 |
nicklas |
432 |
} |
5523 |
02 Dec 10 |
nicklas |
433 |
catch (Throwable ex) |
5523 |
02 Dec 10 |
nicklas |
434 |
{ |
5523 |
02 Dec 10 |
nicklas |
435 |
write("--Create move event FAIILED"); |
5523 |
02 Dec 10 |
nicklas |
436 |
ex.printStackTrace(); |
5523 |
02 Dec 10 |
nicklas |
437 |
ok = false; |
5523 |
02 Dec 10 |
nicklas |
438 |
} |
5523 |
02 Dec 10 |
nicklas |
439 |
finally |
5523 |
02 Dec 10 |
nicklas |
440 |
{ |
5523 |
02 Dec 10 |
nicklas |
441 |
if (dc != null) dc.close(); |
5523 |
02 Dec 10 |
nicklas |
442 |
} |
5523 |
02 Dec 10 |
nicklas |
443 |
return id; |
5523 |
02 Dec 10 |
nicklas |
444 |
} |
5523 |
02 Dec 10 |
nicklas |
445 |
|
5523 |
02 Dec 10 |
nicklas |
446 |
|
5523 |
02 Dec 10 |
nicklas |
447 |
static void test_list_participants(int eventId, int expectedResults) |
5523 |
02 Dec 10 |
nicklas |
448 |
{ |
5523 |
02 Dec 10 |
nicklas |
449 |
if (eventId == 0) return; |
5523 |
02 Dec 10 |
nicklas |
450 |
DbControl dc = null; |
5523 |
02 Dec 10 |
nicklas |
451 |
try |
5523 |
02 Dec 10 |
nicklas |
452 |
{ |
5523 |
02 Dec 10 |
nicklas |
453 |
dc = TestUtil.getDbControl(); |
5523 |
02 Dec 10 |
nicklas |
454 |
BioPlateEvent event = BioPlateEvent.getById(dc, eventId); |
5523 |
02 Dec 10 |
nicklas |
455 |
ItemResultList<BioPlateEventParticipant> participants = event.getParticipants().list(dc); |
5523 |
02 Dec 10 |
nicklas |
456 |
for (int i = 0; i<participants.size(); i++) |
5523 |
02 Dec 10 |
nicklas |
457 |
{ |
5523 |
02 Dec 10 |
nicklas |
458 |
write_item(i, participants.get(i)); |
5523 |
02 Dec 10 |
nicklas |
459 |
} |
5523 |
02 Dec 10 |
nicklas |
460 |
if (expectedResults >=0 && expectedResults != participants.size()) |
5523 |
02 Dec 10 |
nicklas |
461 |
{ |
5523 |
02 Dec 10 |
nicklas |
462 |
throw new BaseException("Expected " + expectedResults + " results, " + |
5523 |
02 Dec 10 |
nicklas |
463 |
"not " + participants.size()); |
5523 |
02 Dec 10 |
nicklas |
464 |
} |
5523 |
02 Dec 10 |
nicklas |
465 |
write ("--List bioplate event participants OK (" + participants.size() +")"); |
5523 |
02 Dec 10 |
nicklas |
466 |
} |
5523 |
02 Dec 10 |
nicklas |
467 |
catch (Throwable ex) |
5523 |
02 Dec 10 |
nicklas |
468 |
{ |
5523 |
02 Dec 10 |
nicklas |
469 |
write("--List bioplate event participants FAILED"); |
5523 |
02 Dec 10 |
nicklas |
470 |
ex.printStackTrace(); |
5523 |
02 Dec 10 |
nicklas |
471 |
ok = false; |
5523 |
02 Dec 10 |
nicklas |
472 |
} |
5523 |
02 Dec 10 |
nicklas |
473 |
finally |
5523 |
02 Dec 10 |
nicklas |
474 |
{ |
5523 |
02 Dec 10 |
nicklas |
475 |
if (dc != null) dc.close(); |
5523 |
02 Dec 10 |
nicklas |
476 |
} |
5523 |
02 Dec 10 |
nicklas |
477 |
} |
5523 |
02 Dec 10 |
nicklas |
478 |
|
5523 |
02 Dec 10 |
nicklas |
479 |
} |