5652 |
10 Jun 11 |
nicklas |
1 |
/* |
5652 |
10 Jun 11 |
nicklas |
$Id$ |
5652 |
10 Jun 11 |
nicklas |
3 |
|
5652 |
10 Jun 11 |
nicklas |
Copyright (C) 2005 Nicklas Nordborg |
5652 |
10 Jun 11 |
nicklas |
Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg |
5652 |
10 Jun 11 |
nicklas |
6 |
|
5652 |
10 Jun 11 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
5652 |
10 Jun 11 |
nicklas |
Available at http://base.thep.lu.se/ |
5652 |
10 Jun 11 |
nicklas |
9 |
|
5652 |
10 Jun 11 |
nicklas |
BASE is free software; you can redistribute it and/or |
5652 |
10 Jun 11 |
nicklas |
modify it under the terms of the GNU General Public License |
5652 |
10 Jun 11 |
nicklas |
as published by the Free Software Foundation; either version 3 |
5652 |
10 Jun 11 |
nicklas |
of the License, or (at your option) any later version. |
5652 |
10 Jun 11 |
nicklas |
14 |
|
5652 |
10 Jun 11 |
nicklas |
BASE is distributed in the hope that it will be useful, |
5652 |
10 Jun 11 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5652 |
10 Jun 11 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5652 |
10 Jun 11 |
nicklas |
GNU General Public License for more details. |
5652 |
10 Jun 11 |
nicklas |
19 |
|
5652 |
10 Jun 11 |
nicklas |
You should have received a copy of the GNU General Public License |
5652 |
10 Jun 11 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5652 |
10 Jun 11 |
nicklas |
22 |
*/ |
5652 |
10 Jun 11 |
nicklas |
23 |
import net.sf.basedb.core.*; |
5652 |
10 Jun 11 |
nicklas |
24 |
|
6092 |
27 Aug 12 |
nicklas |
25 |
import java.util.ArrayList; |
5652 |
10 Jun 11 |
nicklas |
26 |
import java.util.Date; |
5652 |
10 Jun 11 |
nicklas |
27 |
import java.util.Set; |
5652 |
10 Jun 11 |
nicklas |
28 |
|
5685 |
04 Aug 11 |
nicklas |
29 |
public class TestDerivedBioAssay |
5652 |
10 Jun 11 |
nicklas |
30 |
{ |
5652 |
10 Jun 11 |
nicklas |
31 |
|
5652 |
10 Jun 11 |
nicklas |
32 |
static boolean ok = true; |
5652 |
10 Jun 11 |
nicklas |
33 |
public static void main(String[] args) |
5652 |
10 Jun 11 |
nicklas |
34 |
{ |
5652 |
10 Jun 11 |
nicklas |
35 |
TestUtil.checkArgs(args); |
5652 |
10 Jun 11 |
nicklas |
36 |
TestUtil.begin(); |
5652 |
10 Jun 11 |
nicklas |
37 |
ok = test_all(); |
5652 |
10 Jun 11 |
nicklas |
38 |
TestUtil.stop(); |
5652 |
10 Jun 11 |
nicklas |
39 |
} |
5652 |
10 Jun 11 |
nicklas |
40 |
|
5652 |
10 Jun 11 |
nicklas |
41 |
static boolean test_all() |
5652 |
10 Jun 11 |
nicklas |
42 |
{ |
5685 |
04 Aug 11 |
nicklas |
43 |
write("++Testing derived bioassays"); |
5652 |
10 Jun 11 |
nicklas |
44 |
write_header(); |
5652 |
10 Jun 11 |
nicklas |
45 |
|
5653 |
13 Jun 11 |
nicklas |
46 |
int extractId1 = TestExtract.test_create(0, "Extract #1", 0, 0, false); |
5653 |
13 Jun 11 |
nicklas |
47 |
int extractId2 = TestExtract.test_create(0, "Extract #2", 0, 0, false); |
5653 |
13 Jun 11 |
nicklas |
48 |
|
5653 |
13 Jun 11 |
nicklas |
49 |
int hybridizationId = TestPhysicalBioAssay.test_create(0, "Test hyb", 0, 2, extractId1, extractId2); |
5652 |
10 Jun 11 |
nicklas |
50 |
int scannerId = TestHardware.test_create(SystemItems.getId(Hardware.SCANNER), null, false); |
5652 |
10 Jun 11 |
nicklas |
51 |
int protocolId = TestProtocol.test_create(SystemItems.getId(Protocol.SCANNING), null, false); |
5652 |
10 Jun 11 |
nicklas |
52 |
|
5652 |
10 Jun 11 |
nicklas |
// Standard tests: create, load, list |
6100 |
04 Sep 12 |
nicklas |
54 |
int id = test_create_root("Scan #1", hybridizationId, SystemItems.getId(DerivedBioAssay.SCAN), 0, protocolId, scannerId, 0); |
6100 |
04 Sep 12 |
nicklas |
55 |
int id2 = test_create_root("Scan #2", hybridizationId, 0, 0, 0, 0, 0); |
5652 |
10 Jun 11 |
nicklas |
56 |
|
5652 |
10 Jun 11 |
nicklas |
// Children and bioassays |
6082 |
14 Aug 12 |
nicklas |
58 |
int child1 = test_create_child("Child #1", 0, 0, 0, 0, 0, id); |
6082 |
14 Aug 12 |
nicklas |
59 |
int child2 = test_create_child("Child #2", 0, 0, 0, 0, 0, id); |
5652 |
10 Jun 11 |
nicklas |
60 |
|
5652 |
10 Jun 11 |
nicklas |
// Listing |
5652 |
10 Jun 11 |
nicklas |
62 |
test_load(id); |
5652 |
10 Jun 11 |
nicklas |
63 |
test_list(hybridizationId, 2); |
5652 |
10 Jun 11 |
nicklas |
64 |
test_list_children(id, 2); |
5652 |
10 Jun 11 |
nicklas |
65 |
|
5652 |
10 Jun 11 |
nicklas |
// Adding files |
5652 |
10 Jun 11 |
nicklas |
67 |
int samId = TestFile.test_create("data/test.assembly.sam", false, false); |
5688 |
10 Aug 11 |
nicklas |
68 |
TestDataFileType.test_set_file(Item.DERIVEDBIOASSAY, child1, DataFileType.SAM, samId); |
5652 |
10 Jun 11 |
nicklas |
69 |
|
6082 |
14 Aug 12 |
nicklas |
// A more complex setup: |
6082 |
14 Aug 12 |
nicklas |
// Extract #1 and #2 get four child items |
6082 |
14 Aug 12 |
nicklas |
// Two of each are put on two different physical bioassays |
6082 |
14 Aug 12 |
nicklas |
// A derived bioassay is created for each child extract (2+2=4) |
6082 |
14 Aug 12 |
nicklas |
// Two merged derived bioassays are created (one for each extract) |
6082 |
14 Aug 12 |
nicklas |
75 |
int tag1 = TestTag.test_create("T1", SystemItems.getId(Tag.BARCODE), false); |
6082 |
14 Aug 12 |
nicklas |
76 |
int tag2 = TestTag.test_create("T2", SystemItems.getId(Tag.BARCODE), false); |
6082 |
14 Aug 12 |
nicklas |
77 |
|
6082 |
14 Aug 12 |
nicklas |
78 |
int e1a1 = TestExtract.test_create(extractId1, "Extract #1.a1", SystemItems.getId(Extract.LIBRARY), tag1, false); |
6082 |
14 Aug 12 |
nicklas |
79 |
int e1a2 = TestExtract.test_create(extractId1, "Extract #1.a2", SystemItems.getId(Extract.LIBRARY), tag1, false); |
6082 |
14 Aug 12 |
nicklas |
80 |
int e1a3 = TestExtract.test_create(extractId1, "Extract #1.a3", SystemItems.getId(Extract.LIBRARY), tag1, false); |
6082 |
14 Aug 12 |
nicklas |
81 |
int e1a4 = TestExtract.test_create(extractId1, "Extract #1.a4", SystemItems.getId(Extract.LIBRARY), tag1, false); |
6082 |
14 Aug 12 |
nicklas |
82 |
int e2a1 = TestExtract.test_create(extractId2, "Extract #2.a1", SystemItems.getId(Extract.LIBRARY), tag2, false); |
6082 |
14 Aug 12 |
nicklas |
83 |
int e2a2 = TestExtract.test_create(extractId2, "Extract #2.a2", SystemItems.getId(Extract.LIBRARY), tag2, false); |
6082 |
14 Aug 12 |
nicklas |
84 |
int e2a3 = TestExtract.test_create(extractId2, "Extract #2.a3", SystemItems.getId(Extract.LIBRARY), tag2, false); |
6082 |
14 Aug 12 |
nicklas |
85 |
int e2a4 = TestExtract.test_create(extractId2, "Extract #2.a4", SystemItems.getId(Extract.LIBRARY), tag2, false); |
6082 |
14 Aug 12 |
nicklas |
86 |
|
6082 |
14 Aug 12 |
nicklas |
87 |
int flowCell1 = TestPhysicalBioAssay.test_create(0, "Flow cell #1", SystemItems.getId(PhysicalBioAssay.CLONAL_AMPLIFICATION), 2); |
6082 |
14 Aug 12 |
nicklas |
88 |
TestPhysicalBioAssay.test_add_extract(flowCell1, e1a1, 1, null); |
6082 |
14 Aug 12 |
nicklas |
89 |
TestPhysicalBioAssay.test_add_extract(flowCell1, e1a2, 2, null); |
6082 |
14 Aug 12 |
nicklas |
90 |
TestPhysicalBioAssay.test_add_extract(flowCell1, e2a1, 1, null); |
6082 |
14 Aug 12 |
nicklas |
91 |
TestPhysicalBioAssay.test_add_extract(flowCell1, e2a2, 2, null); |
6082 |
14 Aug 12 |
nicklas |
92 |
|
6082 |
14 Aug 12 |
nicklas |
93 |
int flowCell2 = TestPhysicalBioAssay.test_create(0, "Flow cell #2", SystemItems.getId(PhysicalBioAssay.CLONAL_AMPLIFICATION), 2); |
6082 |
14 Aug 12 |
nicklas |
94 |
TestPhysicalBioAssay.test_add_extract(flowCell2, e1a3, 1, null); |
6082 |
14 Aug 12 |
nicklas |
95 |
TestPhysicalBioAssay.test_add_extract(flowCell2, e1a4, 2, null); |
6082 |
14 Aug 12 |
nicklas |
96 |
TestPhysicalBioAssay.test_add_extract(flowCell2, e2a3, 1, null); |
6082 |
14 Aug 12 |
nicklas |
97 |
TestPhysicalBioAssay.test_add_extract(flowCell2, e2a4, 2, null); |
6082 |
14 Aug 12 |
nicklas |
98 |
|
6082 |
14 Aug 12 |
nicklas |
// Root derived bioassay -> one per flow cell |
6100 |
04 Sep 12 |
nicklas |
100 |
int root1 = test_create_root("Seq #1", flowCell1, SystemItems.getId(DerivedBioAssay.SEQUENCES), 0, 0, 0, 0); |
6100 |
04 Sep 12 |
nicklas |
101 |
int root2 = test_create_root("Seq #2", flowCell2, SystemItems.getId(DerivedBioAssay.SEQUENCES), 0, 0, 0, 0); |
6082 |
14 Aug 12 |
nicklas |
102 |
|
6082 |
14 Aug 12 |
nicklas |
// First child derived bioassay -> one per aliquot |
6082 |
14 Aug 12 |
nicklas |
104 |
int ARRANGEMENT = SystemItems.getId(DerivedBioAssay.ARRANGEMENT); |
6082 |
14 Aug 12 |
nicklas |
105 |
int bam1l1t1 = test_create_child("BAM #1.lane1.tag1", e1a1, ARRANGEMENT, 0, 0, 0, root1); |
6082 |
14 Aug 12 |
nicklas |
106 |
int bam1l1t2 = test_create_child("BAM #1.lane1.tag2", e2a1, ARRANGEMENT, 0, 0, 0, root1); |
6082 |
14 Aug 12 |
nicklas |
107 |
int bam1l2t1 = test_create_child("BAM #1.lane2.tag1", e1a2, ARRANGEMENT, 0, 0, 0, root1); |
6082 |
14 Aug 12 |
nicklas |
108 |
int bam1l2t2 = test_create_child("BAM #1.lane2.tag2", e2a2, ARRANGEMENT, 0, 0, 0, root1); |
6082 |
14 Aug 12 |
nicklas |
109 |
|
6082 |
14 Aug 12 |
nicklas |
110 |
int bam2l1t1 = test_create_child("BAM #2.lane1.tag1", e1a3, ARRANGEMENT, 0, 0, 0, root2); |
6082 |
14 Aug 12 |
nicklas |
111 |
int bam2l1t2 = test_create_child("BAM #2.lane1.tag2", e2a3, ARRANGEMENT, 0, 0, 0, root2); |
6082 |
14 Aug 12 |
nicklas |
112 |
int bam2l2t1 = test_create_child("BAM #2.lane2.tag1", e1a4, ARRANGEMENT, 0, 0, 0, root2); |
6082 |
14 Aug 12 |
nicklas |
113 |
int bam2l2t2 = test_create_child("BAM #2.lane2.tag2", e2a4, ARRANGEMENT, 0, 0, 0, root2); |
6082 |
14 Aug 12 |
nicklas |
114 |
|
6082 |
14 Aug 12 |
nicklas |
// Merged child derived bioassay -> one per original extract |
6082 |
14 Aug 12 |
nicklas |
116 |
int merged1 = test_create_child("Extract #1.merged", extractId1, ARRANGEMENT, 0, 0, 0, bam1l1t1, bam1l2t1, bam2l1t1, bam2l2t1); |
6082 |
14 Aug 12 |
nicklas |
117 |
int merged2 = test_create_child("Extract #2.merged", extractId2, ARRANGEMENT, 0, 0, 0, bam1l1t2, bam1l2t2, bam2l1t2, bam2l2t2); |
6082 |
14 Aug 12 |
nicklas |
118 |
|
5652 |
10 Jun 11 |
nicklas |
// Standard test: Delete |
5652 |
10 Jun 11 |
nicklas |
120 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
6082 |
14 Aug 12 |
nicklas |
121 |
|
6082 |
14 Aug 12 |
nicklas |
122 |
test_delete(merged1); |
6082 |
14 Aug 12 |
nicklas |
123 |
test_delete(merged2); |
6082 |
14 Aug 12 |
nicklas |
124 |
test_delete(bam1l1t1); |
6082 |
14 Aug 12 |
nicklas |
125 |
test_delete(bam1l1t2); |
6082 |
14 Aug 12 |
nicklas |
126 |
test_delete(bam1l2t1); |
6082 |
14 Aug 12 |
nicklas |
127 |
test_delete(bam1l2t2); |
6082 |
14 Aug 12 |
nicklas |
128 |
test_delete(bam2l1t1); |
6082 |
14 Aug 12 |
nicklas |
129 |
test_delete(bam2l1t2); |
6082 |
14 Aug 12 |
nicklas |
130 |
test_delete(bam2l2t1); |
6082 |
14 Aug 12 |
nicklas |
131 |
test_delete(bam2l2t2); |
6082 |
14 Aug 12 |
nicklas |
132 |
test_delete(root1); |
6082 |
14 Aug 12 |
nicklas |
133 |
test_delete(root2); |
6082 |
14 Aug 12 |
nicklas |
134 |
TestPhysicalBioAssay.test_delete(flowCell1); |
6082 |
14 Aug 12 |
nicklas |
135 |
TestPhysicalBioAssay.test_delete(flowCell2); |
6082 |
14 Aug 12 |
nicklas |
136 |
|
6082 |
14 Aug 12 |
nicklas |
137 |
TestExtract.test_delete(e1a1); |
6082 |
14 Aug 12 |
nicklas |
138 |
TestExtract.test_delete(e1a2); |
6082 |
14 Aug 12 |
nicklas |
139 |
TestExtract.test_delete(e1a3); |
6082 |
14 Aug 12 |
nicklas |
140 |
TestExtract.test_delete(e1a4); |
6082 |
14 Aug 12 |
nicklas |
141 |
TestExtract.test_delete(e2a1); |
6082 |
14 Aug 12 |
nicklas |
142 |
TestExtract.test_delete(e2a2); |
6082 |
14 Aug 12 |
nicklas |
143 |
TestExtract.test_delete(e2a3); |
6082 |
14 Aug 12 |
nicklas |
144 |
TestExtract.test_delete(e2a4); |
6082 |
14 Aug 12 |
nicklas |
145 |
|
6082 |
14 Aug 12 |
nicklas |
146 |
TestTag.test_delete(tag1); |
6082 |
14 Aug 12 |
nicklas |
147 |
TestTag.test_delete(tag2); |
6082 |
14 Aug 12 |
nicklas |
148 |
|
5652 |
10 Jun 11 |
nicklas |
149 |
test_delete(child1); |
5652 |
10 Jun 11 |
nicklas |
150 |
test_delete(child2); |
5652 |
10 Jun 11 |
nicklas |
151 |
test_delete(id); |
5652 |
10 Jun 11 |
nicklas |
152 |
test_delete(id2); |
5652 |
10 Jun 11 |
nicklas |
153 |
|
5652 |
10 Jun 11 |
nicklas |
154 |
TestFile.test_delete(samId); |
5652 |
10 Jun 11 |
nicklas |
155 |
TestPhysicalBioAssay.test_delete(hybridizationId); |
5720 |
06 Sep 11 |
nicklas |
156 |
TestExtract.test_delete(extractId2); |
5720 |
06 Sep 11 |
nicklas |
157 |
TestExtract.test_delete(extractId1); |
5652 |
10 Jun 11 |
nicklas |
158 |
TestHardware.test_delete(scannerId); |
5652 |
10 Jun 11 |
nicklas |
159 |
TestProtocol.test_delete(protocolId); |
5685 |
04 Aug 11 |
nicklas |
160 |
write("++Testing derived bioassays "+(ok ? "OK" : "Failed")+"\n"); |
5652 |
10 Jun 11 |
nicklas |
161 |
return ok; |
5652 |
10 Jun 11 |
nicklas |
162 |
} |
5652 |
10 Jun 11 |
nicklas |
163 |
|
6100 |
04 Sep 12 |
nicklas |
164 |
static int test_create_root(String name, int bioAssayId, int subtypeId, int extractId, int protocolId, int hardwareId, int softwareId) |
5652 |
10 Jun 11 |
nicklas |
165 |
{ |
5685 |
04 Aug 11 |
nicklas |
166 |
if (bioAssayId == 0 || !TestUtil.hasPermission(Permission.CREATE, Item.DERIVEDBIOASSAY)) return 0; |
5652 |
10 Jun 11 |
nicklas |
167 |
int id = 0; |
5652 |
10 Jun 11 |
nicklas |
168 |
DbControl dc = null; |
5652 |
10 Jun 11 |
nicklas |
169 |
try |
5652 |
10 Jun 11 |
nicklas |
170 |
{ |
5652 |
10 Jun 11 |
nicklas |
171 |
dc = TestUtil.getDbControl(); |
5729 |
08 Sep 11 |
nicklas |
172 |
DerivedBioAssay dbas = DerivedBioAssay.getNew(dc, PhysicalBioAssay.getById(dc, bioAssayId), null); |
5652 |
10 Jun 11 |
nicklas |
173 |
dbas.setName(name); |
5652 |
10 Jun 11 |
nicklas |
174 |
dbas.setDescription("Added at "+new Date()); |
5652 |
10 Jun 11 |
nicklas |
175 |
if (subtypeId != 0) |
5652 |
10 Jun 11 |
nicklas |
176 |
{ |
5652 |
10 Jun 11 |
nicklas |
177 |
dbas.setItemSubtype(ItemSubtype.getById(dc, subtypeId)); |
5652 |
10 Jun 11 |
nicklas |
178 |
} |
6100 |
04 Sep 12 |
nicklas |
179 |
if (extractId != 0) |
6100 |
04 Sep 12 |
nicklas |
180 |
{ |
6100 |
04 Sep 12 |
nicklas |
181 |
dbas.setExtract(Extract.getById(dc, extractId)); |
6100 |
04 Sep 12 |
nicklas |
182 |
} |
5652 |
10 Jun 11 |
nicklas |
183 |
if (hardwareId != 0) |
5652 |
10 Jun 11 |
nicklas |
184 |
{ |
5652 |
10 Jun 11 |
nicklas |
185 |
dbas.setHardware(Hardware.getById(dc, hardwareId)); |
5652 |
10 Jun 11 |
nicklas |
186 |
} |
5652 |
10 Jun 11 |
nicklas |
187 |
if (softwareId != 0) |
5652 |
10 Jun 11 |
nicklas |
188 |
{ |
5652 |
10 Jun 11 |
nicklas |
189 |
dbas.setSoftware(Software.getById(dc, softwareId)); |
5652 |
10 Jun 11 |
nicklas |
190 |
} |
5652 |
10 Jun 11 |
nicklas |
191 |
if (protocolId != 0) |
5652 |
10 Jun 11 |
nicklas |
192 |
{ |
5652 |
10 Jun 11 |
nicklas |
193 |
dbas.setProtocol(Protocol.getById(dc, protocolId)); |
5652 |
10 Jun 11 |
nicklas |
194 |
} |
5652 |
10 Jun 11 |
nicklas |
195 |
dc.saveItem(dbas); |
5652 |
10 Jun 11 |
nicklas |
196 |
dc.commit(); |
5652 |
10 Jun 11 |
nicklas |
197 |
id = dbas.getId(); |
5652 |
10 Jun 11 |
nicklas |
198 |
dc = TestUtil.getDbControl(); |
5652 |
10 Jun 11 |
nicklas |
199 |
dc.reattachItem(dbas, false); |
5652 |
10 Jun 11 |
nicklas |
200 |
write_item(0, dbas); |
5685 |
04 Aug 11 |
nicklas |
201 |
write("--Create root derived bioassay OK"); |
5652 |
10 Jun 11 |
nicklas |
202 |
} |
5652 |
10 Jun 11 |
nicklas |
203 |
catch (Throwable ex) |
5652 |
10 Jun 11 |
nicklas |
204 |
{ |
5685 |
04 Aug 11 |
nicklas |
205 |
write("--Create root derived bioassay FAILED"); |
5652 |
10 Jun 11 |
nicklas |
206 |
ex.printStackTrace(); |
5652 |
10 Jun 11 |
nicklas |
207 |
ok = false; |
5652 |
10 Jun 11 |
nicklas |
208 |
} |
5652 |
10 Jun 11 |
nicklas |
209 |
finally |
5652 |
10 Jun 11 |
nicklas |
210 |
{ |
5652 |
10 Jun 11 |
nicklas |
211 |
if (dc != null) dc.close(); |
5652 |
10 Jun 11 |
nicklas |
212 |
} |
5652 |
10 Jun 11 |
nicklas |
213 |
return id; |
5652 |
10 Jun 11 |
nicklas |
214 |
} |
5652 |
10 Jun 11 |
nicklas |
215 |
|
6082 |
14 Aug 12 |
nicklas |
216 |
static int test_create_child(String name, int extractId, int subtypeId, |
6082 |
14 Aug 12 |
nicklas |
217 |
int protocolId, int hardwareId, int softwareId, int... parents) |
5652 |
10 Jun 11 |
nicklas |
218 |
{ |
6082 |
14 Aug 12 |
nicklas |
219 |
if (parents == null || parents.length == 0) return 0; |
5652 |
10 Jun 11 |
nicklas |
220 |
int id = 0; |
5652 |
10 Jun 11 |
nicklas |
221 |
DbControl dc = null; |
5652 |
10 Jun 11 |
nicklas |
222 |
try |
5652 |
10 Jun 11 |
nicklas |
223 |
{ |
5652 |
10 Jun 11 |
nicklas |
224 |
dc = TestUtil.getDbControl(); |
6082 |
14 Aug 12 |
nicklas |
225 |
DerivedBioAssay dbas = DerivedBioAssay.getNew(dc, false, null); |
5652 |
10 Jun 11 |
nicklas |
226 |
dbas.setName(name); |
5652 |
10 Jun 11 |
nicklas |
227 |
dbas.setDescription("Added at "+new Date()); |
6082 |
14 Aug 12 |
nicklas |
228 |
for (int parentId: parents) |
6082 |
14 Aug 12 |
nicklas |
229 |
{ |
6082 |
14 Aug 12 |
nicklas |
230 |
dbas.addParent(DerivedBioAssay.getById(dc, parentId)); |
6082 |
14 Aug 12 |
nicklas |
231 |
} |
6082 |
14 Aug 12 |
nicklas |
232 |
|
5748 |
19 Sep 11 |
nicklas |
233 |
if (extractId != 0) |
5748 |
19 Sep 11 |
nicklas |
234 |
{ |
5748 |
19 Sep 11 |
nicklas |
235 |
dbas.setExtract(Extract.getById(dc, extractId)); |
5748 |
19 Sep 11 |
nicklas |
236 |
} |
5652 |
10 Jun 11 |
nicklas |
237 |
if (subtypeId != 0) |
5652 |
10 Jun 11 |
nicklas |
238 |
{ |
5652 |
10 Jun 11 |
nicklas |
239 |
dbas.setItemSubtype(ItemSubtype.getById(dc, subtypeId)); |
5652 |
10 Jun 11 |
nicklas |
240 |
} |
5652 |
10 Jun 11 |
nicklas |
241 |
if (hardwareId != 0) |
5652 |
10 Jun 11 |
nicklas |
242 |
{ |
5652 |
10 Jun 11 |
nicklas |
243 |
dbas.setHardware(Hardware.getById(dc, hardwareId)); |
5652 |
10 Jun 11 |
nicklas |
244 |
} |
5652 |
10 Jun 11 |
nicklas |
245 |
if (softwareId != 0) |
5652 |
10 Jun 11 |
nicklas |
246 |
{ |
5652 |
10 Jun 11 |
nicklas |
247 |
dbas.setSoftware(Software.getById(dc, softwareId)); |
5652 |
10 Jun 11 |
nicklas |
248 |
} |
5652 |
10 Jun 11 |
nicklas |
249 |
if (protocolId != 0) |
5652 |
10 Jun 11 |
nicklas |
250 |
{ |
5652 |
10 Jun 11 |
nicklas |
251 |
dbas.setProtocol(Protocol.getById(dc, protocolId)); |
5652 |
10 Jun 11 |
nicklas |
252 |
} |
5652 |
10 Jun 11 |
nicklas |
253 |
dc.saveItem(dbas); |
5652 |
10 Jun 11 |
nicklas |
254 |
dc.commit(); |
5652 |
10 Jun 11 |
nicklas |
255 |
id = dbas.getId(); |
5652 |
10 Jun 11 |
nicklas |
256 |
dc = TestUtil.getDbControl(); |
5652 |
10 Jun 11 |
nicklas |
257 |
dc.reattachItem(dbas, false); |
5652 |
10 Jun 11 |
nicklas |
258 |
write_item(0, dbas); |
5685 |
04 Aug 11 |
nicklas |
259 |
write("--Create child derived bioassay OK"); |
5652 |
10 Jun 11 |
nicklas |
260 |
} |
5652 |
10 Jun 11 |
nicklas |
261 |
catch (Throwable ex) |
5652 |
10 Jun 11 |
nicklas |
262 |
{ |
5685 |
04 Aug 11 |
nicklas |
263 |
write("--Create child derived bioassay FAILED"); |
5652 |
10 Jun 11 |
nicklas |
264 |
ex.printStackTrace(); |
5652 |
10 Jun 11 |
nicklas |
265 |
ok = false; |
5652 |
10 Jun 11 |
nicklas |
266 |
} |
5652 |
10 Jun 11 |
nicklas |
267 |
finally |
5652 |
10 Jun 11 |
nicklas |
268 |
{ |
5652 |
10 Jun 11 |
nicklas |
269 |
if (dc != null) dc.close(); |
5652 |
10 Jun 11 |
nicklas |
270 |
} |
5652 |
10 Jun 11 |
nicklas |
271 |
return id; |
5652 |
10 Jun 11 |
nicklas |
272 |
} |
5652 |
10 Jun 11 |
nicklas |
273 |
|
5652 |
10 Jun 11 |
nicklas |
274 |
|
5652 |
10 Jun 11 |
nicklas |
275 |
static void test_load(int id) |
5652 |
10 Jun 11 |
nicklas |
276 |
{ |
5652 |
10 Jun 11 |
nicklas |
277 |
if (id == 0) return; |
5652 |
10 Jun 11 |
nicklas |
278 |
DbControl dc = null; |
5652 |
10 Jun 11 |
nicklas |
279 |
try |
5652 |
10 Jun 11 |
nicklas |
280 |
{ |
5652 |
10 Jun 11 |
nicklas |
281 |
dc = TestUtil.getDbControl(); |
5685 |
04 Aug 11 |
nicklas |
282 |
DerivedBioAssay dbas = DerivedBioAssay.getById(dc, id); |
5652 |
10 Jun 11 |
nicklas |
283 |
write_item(0, dbas); |
5685 |
04 Aug 11 |
nicklas |
284 |
write("--Load derived bioassay OK"); |
5652 |
10 Jun 11 |
nicklas |
285 |
} |
5652 |
10 Jun 11 |
nicklas |
286 |
catch (Throwable ex) |
5652 |
10 Jun 11 |
nicklas |
287 |
{ |
5685 |
04 Aug 11 |
nicklas |
288 |
write("--Load derived bioassay FAILED"); |
5652 |
10 Jun 11 |
nicklas |
289 |
ex.printStackTrace(); |
5652 |
10 Jun 11 |
nicklas |
290 |
ok = false; |
5652 |
10 Jun 11 |
nicklas |
291 |
} |
5652 |
10 Jun 11 |
nicklas |
292 |
finally |
5652 |
10 Jun 11 |
nicklas |
293 |
{ |
5652 |
10 Jun 11 |
nicklas |
294 |
if (dc != null) dc.close(); |
5652 |
10 Jun 11 |
nicklas |
295 |
} |
5652 |
10 Jun 11 |
nicklas |
296 |
} |
5652 |
10 Jun 11 |
nicklas |
297 |
|
5696 |
12 Aug 11 |
nicklas |
298 |
static boolean test_list(int physicalBioAssayId, int expectedResults) |
5652 |
10 Jun 11 |
nicklas |
299 |
{ |
5652 |
10 Jun 11 |
nicklas |
300 |
DbControl dc = null; |
5652 |
10 Jun 11 |
nicklas |
301 |
try |
5652 |
10 Jun 11 |
nicklas |
302 |
{ |
5652 |
10 Jun 11 |
nicklas |
303 |
dc = TestUtil.getDbControl(); |
5685 |
04 Aug 11 |
nicklas |
304 |
ItemQuery<DerivedBioAssay> query = null; |
5652 |
10 Jun 11 |
nicklas |
305 |
if (physicalBioAssayId == 0) |
5652 |
10 Jun 11 |
nicklas |
306 |
{ |
5685 |
04 Aug 11 |
nicklas |
307 |
query = DerivedBioAssay.getQuery(); |
5652 |
10 Jun 11 |
nicklas |
308 |
} |
5652 |
10 Jun 11 |
nicklas |
309 |
else |
5652 |
10 Jun 11 |
nicklas |
310 |
{ |
5652 |
10 Jun 11 |
nicklas |
311 |
PhysicalBioAssay bioAssay = PhysicalBioAssay.getById(dc, physicalBioAssayId); |
5685 |
04 Aug 11 |
nicklas |
312 |
query = bioAssay.getRootDerivedBioAssays(); |
5652 |
10 Jun 11 |
nicklas |
313 |
} |
5685 |
04 Aug 11 |
nicklas |
314 |
ItemResultList<DerivedBioAssay> l = query.list(dc); |
5652 |
10 Jun 11 |
nicklas |
315 |
for (int i = 0; i<l.size(); i++) |
5652 |
10 Jun 11 |
nicklas |
316 |
{ |
5652 |
10 Jun 11 |
nicklas |
317 |
write_item(i, l.get(i)); |
5652 |
10 Jun 11 |
nicklas |
318 |
} |
5652 |
10 Jun 11 |
nicklas |
319 |
if (expectedResults >= 0 && expectedResults != l.size()) |
5652 |
10 Jun 11 |
nicklas |
320 |
{ |
5652 |
10 Jun 11 |
nicklas |
321 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
5652 |
10 Jun 11 |
nicklas |
322 |
} |
5685 |
04 Aug 11 |
nicklas |
323 |
write("--List derived bioassays OK ("+l.size()+")"); |
5652 |
10 Jun 11 |
nicklas |
324 |
} |
5652 |
10 Jun 11 |
nicklas |
325 |
catch (Throwable ex) |
5652 |
10 Jun 11 |
nicklas |
326 |
{ |
5685 |
04 Aug 11 |
nicklas |
327 |
write("--List derived bioassays FAILED"); |
5652 |
10 Jun 11 |
nicklas |
328 |
ex.printStackTrace(); |
5652 |
10 Jun 11 |
nicklas |
329 |
ok = false; |
5696 |
12 Aug 11 |
nicklas |
330 |
return false; |
5652 |
10 Jun 11 |
nicklas |
331 |
} |
5652 |
10 Jun 11 |
nicklas |
332 |
finally |
5652 |
10 Jun 11 |
nicklas |
333 |
{ |
5652 |
10 Jun 11 |
nicklas |
334 |
if (dc != null) dc.close(); |
5652 |
10 Jun 11 |
nicklas |
335 |
} |
5696 |
12 Aug 11 |
nicklas |
336 |
return true; |
5652 |
10 Jun 11 |
nicklas |
337 |
} |
5652 |
10 Jun 11 |
nicklas |
338 |
|
5652 |
10 Jun 11 |
nicklas |
339 |
static void test_delete(int id) |
5652 |
10 Jun 11 |
nicklas |
340 |
{ |
5652 |
10 Jun 11 |
nicklas |
341 |
if (id == 0) return; |
5652 |
10 Jun 11 |
nicklas |
342 |
DbControl dc = null; |
5652 |
10 Jun 11 |
nicklas |
343 |
try |
5652 |
10 Jun 11 |
nicklas |
344 |
{ |
5652 |
10 Jun 11 |
nicklas |
345 |
dc = TestUtil.getDbControl(); |
5685 |
04 Aug 11 |
nicklas |
346 |
DerivedBioAssay dbas = DerivedBioAssay.getById(dc, id); |
5652 |
10 Jun 11 |
nicklas |
347 |
dc.deleteItem(dbas); |
5652 |
10 Jun 11 |
nicklas |
348 |
Set<ItemProxy> using = dbas.getUsingItems(); |
5652 |
10 Jun 11 |
nicklas |
349 |
if (using.size() > 0) |
5652 |
10 Jun 11 |
nicklas |
350 |
{ |
5652 |
10 Jun 11 |
nicklas |
351 |
throw new BaseException(dbas + " is used by " + using); |
5652 |
10 Jun 11 |
nicklas |
352 |
} |
5652 |
10 Jun 11 |
nicklas |
353 |
dc.commit(); |
5685 |
04 Aug 11 |
nicklas |
354 |
write("--Delete derived bioassay OK"); |
5652 |
10 Jun 11 |
nicklas |
355 |
} |
5652 |
10 Jun 11 |
nicklas |
356 |
catch (Throwable ex) |
5652 |
10 Jun 11 |
nicklas |
357 |
{ |
5685 |
04 Aug 11 |
nicklas |
358 |
write("--Delete derived bioassay FAILED"); |
5652 |
10 Jun 11 |
nicklas |
359 |
ex.printStackTrace(); |
5652 |
10 Jun 11 |
nicklas |
360 |
ok = false; |
5652 |
10 Jun 11 |
nicklas |
361 |
} |
5652 |
10 Jun 11 |
nicklas |
362 |
finally |
5652 |
10 Jun 11 |
nicklas |
363 |
{ |
5652 |
10 Jun 11 |
nicklas |
364 |
if (dc != null) dc.close(); |
5652 |
10 Jun 11 |
nicklas |
365 |
} |
5652 |
10 Jun 11 |
nicklas |
366 |
} |
5652 |
10 Jun 11 |
nicklas |
367 |
|
5652 |
10 Jun 11 |
nicklas |
368 |
static void test_delete_all() |
5652 |
10 Jun 11 |
nicklas |
369 |
{ |
5652 |
10 Jun 11 |
nicklas |
370 |
DbControl dc = null; |
5652 |
10 Jun 11 |
nicklas |
371 |
try |
5652 |
10 Jun 11 |
nicklas |
372 |
{ |
5652 |
10 Jun 11 |
nicklas |
373 |
dc = TestUtil.getDbControl(); |
5685 |
04 Aug 11 |
nicklas |
374 |
ItemResultList<DerivedBioAssay> l = DerivedBioAssay.getQuery().list(dc); |
5688 |
10 Aug 11 |
nicklas |
375 |
int numDeleted = Trashcan.delete(dc.getSessionControl(), l, true, null); |
5688 |
10 Aug 11 |
nicklas |
376 |
if (numDeleted != l.size()) throw new BaseException("Could not delete all items: " + numDeleted + " of " + l.size()); |
5652 |
10 Jun 11 |
nicklas |
377 |
dc.commit(); |
5685 |
04 Aug 11 |
nicklas |
378 |
write("--Delete all derived bioassays OK ("+l.size()+")"); |
5652 |
10 Jun 11 |
nicklas |
379 |
} |
5652 |
10 Jun 11 |
nicklas |
380 |
catch (Throwable ex) |
5652 |
10 Jun 11 |
nicklas |
381 |
{ |
5685 |
04 Aug 11 |
nicklas |
382 |
write("--Delete all derived bioassays FAILED"); |
5652 |
10 Jun 11 |
nicklas |
383 |
ex.printStackTrace(); |
5652 |
10 Jun 11 |
nicklas |
384 |
ok = false; |
5652 |
10 Jun 11 |
nicklas |
385 |
} |
5652 |
10 Jun 11 |
nicklas |
386 |
finally |
5652 |
10 Jun 11 |
nicklas |
387 |
{ |
5652 |
10 Jun 11 |
nicklas |
388 |
if (dc != null) dc.close(); |
5652 |
10 Jun 11 |
nicklas |
389 |
} |
5652 |
10 Jun 11 |
nicklas |
390 |
} |
5652 |
10 Jun 11 |
nicklas |
391 |
|
5652 |
10 Jun 11 |
nicklas |
392 |
|
5652 |
10 Jun 11 |
nicklas |
393 |
static void write_header() |
5652 |
10 Jun 11 |
nicklas |
394 |
{ |
5652 |
10 Jun 11 |
nicklas |
395 |
if (!TestUtil.getSilent()) |
5652 |
10 Jun 11 |
nicklas |
396 |
{ |
6092 |
27 Aug 12 |
nicklas |
397 |
write(" \tID \tName \tType\tDescription\tParents\tPhysical bioassays\tProtocol\tHardware\tSoftware"); |
6092 |
27 Aug 12 |
nicklas |
398 |
write("-- \t-- \t--------- \t----\t-----------\t-------\t------------------\t--------\t--------\t--------"); |
5652 |
10 Jun 11 |
nicklas |
399 |
} |
5652 |
10 Jun 11 |
nicklas |
400 |
} |
5685 |
04 Aug 11 |
nicklas |
401 |
static void write_item(int i, DerivedBioAssay dbas) |
5652 |
10 Jun 11 |
nicklas |
402 |
throws BaseException |
5652 |
10 Jun 11 |
nicklas |
403 |
{ |
5652 |
10 Jun 11 |
nicklas |
404 |
if (!TestUtil.getSilent()) |
5652 |
10 Jun 11 |
nicklas |
405 |
{ |
6092 |
27 Aug 12 |
nicklas |
406 |
DbControl dc = dbas.getDbControl(); |
5652 |
10 Jun 11 |
nicklas |
407 |
System.out.println(i+":\t"+dbas.getId()+"\t"+dbas.getName()+"\t"+dbas.getItemSubtype()+"\t"+dbas.getDescription()+ |
6092 |
27 Aug 12 |
nicklas |
408 |
"\t"+new ArrayList<DerivedBioAssay>(dbas.getParents().list(dc))+ |
6092 |
27 Aug 12 |
nicklas |
409 |
"\t"+new ArrayList<PhysicalBioAssay>(dbas.getPhysicalBioAssays().list(dc))+ |
5652 |
10 Jun 11 |
nicklas |
410 |
"\t"+dbas.getProtocol()+"\t"+dbas.getHardware()+"\t"+dbas.getSoftware()); |
5652 |
10 Jun 11 |
nicklas |
411 |
} |
5652 |
10 Jun 11 |
nicklas |
412 |
} |
5652 |
10 Jun 11 |
nicklas |
413 |
|
5652 |
10 Jun 11 |
nicklas |
414 |
static void write(String message) |
5652 |
10 Jun 11 |
nicklas |
415 |
{ |
5652 |
10 Jun 11 |
nicklas |
416 |
System.out.println(message); |
5652 |
10 Jun 11 |
nicklas |
417 |
} |
5652 |
10 Jun 11 |
nicklas |
418 |
|
5652 |
10 Jun 11 |
nicklas |
419 |
static void test_list_children(int id, int expectedResults) |
5652 |
10 Jun 11 |
nicklas |
420 |
{ |
5652 |
10 Jun 11 |
nicklas |
421 |
if (id == 0) return; |
5652 |
10 Jun 11 |
nicklas |
422 |
DbControl dc = null; |
5652 |
10 Jun 11 |
nicklas |
423 |
try |
5652 |
10 Jun 11 |
nicklas |
424 |
{ |
5652 |
10 Jun 11 |
nicklas |
425 |
dc = TestUtil.getDbControl(); |
5685 |
04 Aug 11 |
nicklas |
426 |
DerivedBioAssay parent = DerivedBioAssay.getById(dc, id); |
5685 |
04 Aug 11 |
nicklas |
427 |
ItemResultList<DerivedBioAssay> l = parent.getChildren().list(dc); |
5652 |
10 Jun 11 |
nicklas |
428 |
for (int i = 0; i<l.size(); i++) |
5652 |
10 Jun 11 |
nicklas |
429 |
{ |
5652 |
10 Jun 11 |
nicklas |
430 |
write_item(i, l.get(i)); |
5652 |
10 Jun 11 |
nicklas |
431 |
} |
5652 |
10 Jun 11 |
nicklas |
432 |
if (expectedResults >= 0 && expectedResults != l.size()) |
5652 |
10 Jun 11 |
nicklas |
433 |
{ |
5652 |
10 Jun 11 |
nicklas |
434 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
5652 |
10 Jun 11 |
nicklas |
435 |
} |
5652 |
10 Jun 11 |
nicklas |
436 |
write("--List child derived bioassays OK ("+l.size()+")"); |
5652 |
10 Jun 11 |
nicklas |
437 |
} |
5652 |
10 Jun 11 |
nicklas |
438 |
catch (Throwable ex) |
5652 |
10 Jun 11 |
nicklas |
439 |
{ |
5652 |
10 Jun 11 |
nicklas |
440 |
write("--List child derived bioassays FAILED"); |
5652 |
10 Jun 11 |
nicklas |
441 |
ex.printStackTrace(); |
5652 |
10 Jun 11 |
nicklas |
442 |
ok = false; |
5652 |
10 Jun 11 |
nicklas |
443 |
} |
5652 |
10 Jun 11 |
nicklas |
444 |
finally |
5652 |
10 Jun 11 |
nicklas |
445 |
{ |
5652 |
10 Jun 11 |
nicklas |
446 |
if (dc != null) dc.close(); |
5652 |
10 Jun 11 |
nicklas |
447 |
} |
5652 |
10 Jun 11 |
nicklas |
448 |
} |
5652 |
10 Jun 11 |
nicklas |
449 |
|
5652 |
10 Jun 11 |
nicklas |
450 |
} |