802 |
21 Jun 05 |
nicklas |
1 |
/* |
802 |
21 Jun 05 |
nicklas |
$Id$ |
802 |
21 Jun 05 |
nicklas |
3 |
|
3675 |
16 Aug 07 |
jari |
Copyright (C) 2005 Nicklas Nordborg |
4889 |
06 Apr 09 |
nicklas |
Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg |
3675 |
16 Aug 07 |
jari |
Copyright (C) 2007 Nicklas Nordborg |
802 |
21 Jun 05 |
nicklas |
7 |
|
2304 |
22 May 06 |
jari |
This file is part of BASE - BioArray Software Environment. |
2304 |
22 May 06 |
jari |
Available at http://base.thep.lu.se/ |
802 |
21 Jun 05 |
nicklas |
10 |
|
802 |
21 Jun 05 |
nicklas |
BASE is free software; you can redistribute it and/or |
802 |
21 Jun 05 |
nicklas |
modify it under the terms of the GNU General Public License |
4480 |
05 Sep 08 |
jari |
as published by the Free Software Foundation; either version 3 |
802 |
21 Jun 05 |
nicklas |
of the License, or (at your option) any later version. |
802 |
21 Jun 05 |
nicklas |
15 |
|
802 |
21 Jun 05 |
nicklas |
BASE is distributed in the hope that it will be useful, |
802 |
21 Jun 05 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
802 |
21 Jun 05 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
802 |
21 Jun 05 |
nicklas |
GNU General Public License for more details. |
802 |
21 Jun 05 |
nicklas |
20 |
|
802 |
21 Jun 05 |
nicklas |
You should have received a copy of the GNU General Public License |
4514 |
11 Sep 08 |
jari |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
802 |
21 Jun 05 |
nicklas |
23 |
*/ |
802 |
21 Jun 05 |
nicklas |
24 |
import net.sf.basedb.core.*; |
5688 |
10 Aug 11 |
nicklas |
25 |
import net.sf.basedb.core.query.Expressions; |
5688 |
10 Aug 11 |
nicklas |
26 |
import net.sf.basedb.core.query.Hql; |
5688 |
10 Aug 11 |
nicklas |
27 |
import net.sf.basedb.core.query.Restrictions; |
5663 |
22 Jun 11 |
nicklas |
28 |
import net.sf.basedb.core.query.ResultList; |
6775 |
17 Mar 15 |
nicklas |
29 |
import net.sf.basedb.util.listable.ExtractToChildExtractTransformer; |
6775 |
17 Mar 15 |
nicklas |
30 |
import net.sf.basedb.util.listable.ExtractToParentExtractTransformer; |
6775 |
17 Mar 15 |
nicklas |
31 |
import net.sf.basedb.util.listable.ExtractToSampleTransformer; |
6775 |
17 Mar 15 |
nicklas |
32 |
import net.sf.basedb.util.listable.SampleToExtractTransformer; |
6775 |
17 Mar 15 |
nicklas |
33 |
import net.sf.basedb.util.listable.SourceItemTransformer; |
6775 |
17 Mar 15 |
nicklas |
34 |
import net.sf.basedb.util.listable.TransformContext; |
4372 |
04 Jul 08 |
nicklas |
35 |
|
5663 |
22 Jun 11 |
nicklas |
36 |
import java.util.Collections; |
802 |
21 Jun 05 |
nicklas |
37 |
import java.util.Date; |
5340 |
10 May 10 |
nicklas |
38 |
import java.util.Set; |
802 |
21 Jun 05 |
nicklas |
39 |
|
802 |
21 Jun 05 |
nicklas |
40 |
public class TestExtract |
802 |
21 Jun 05 |
nicklas |
41 |
{ |
802 |
21 Jun 05 |
nicklas |
42 |
|
802 |
21 Jun 05 |
nicklas |
43 |
static boolean ok = true; |
802 |
21 Jun 05 |
nicklas |
44 |
public static void main(String[] args) |
802 |
21 Jun 05 |
nicklas |
45 |
{ |
802 |
21 Jun 05 |
nicklas |
46 |
TestUtil.checkArgs(args); |
802 |
21 Jun 05 |
nicklas |
47 |
TestUtil.begin(); |
802 |
21 Jun 05 |
nicklas |
48 |
ok = test_all(); |
802 |
21 Jun 05 |
nicklas |
49 |
TestUtil.stop(); |
802 |
21 Jun 05 |
nicklas |
50 |
} |
802 |
21 Jun 05 |
nicklas |
51 |
|
802 |
21 Jun 05 |
nicklas |
52 |
static boolean test_all() |
802 |
21 Jun 05 |
nicklas |
53 |
{ |
802 |
21 Jun 05 |
nicklas |
54 |
write("++Testing extracts"); |
802 |
21 Jun 05 |
nicklas |
55 |
write_header(); |
802 |
21 Jun 05 |
nicklas |
// Standard tests: create, load, list |
6100 |
04 Sep 12 |
nicklas |
57 |
int sampleId = TestSample.test_create(0, "Parent sample", 0, true); |
5641 |
25 May 11 |
nicklas |
58 |
int tagId = TestTag.test_create("Test", SystemItems.getId(Tag.LABEL), true); |
5641 |
25 May 11 |
nicklas |
59 |
int id = test_create(0, "Extract #1 (standalone)", 0, 0, true); |
5663 |
22 Jun 11 |
nicklas |
60 |
int id2 = test_create(sampleId, "Extract #2 (sample parent)", 0, 0, false); |
5663 |
22 Jun 11 |
nicklas |
61 |
int id3 = test_create(id, "Extract #3 (extract parent+labeled)", SystemItems.getId(Extract.LABELED), tagId, false); |
5663 |
22 Jun 11 |
nicklas |
62 |
int id4 = test_create_pooled("Extract #4 (pooled)", id, id2, id3); |
802 |
21 Jun 05 |
nicklas |
63 |
|
5663 |
22 Jun 11 |
nicklas |
64 |
|
802 |
21 Jun 05 |
nicklas |
65 |
test_load(id); |
5688 |
10 Aug 11 |
nicklas |
66 |
test_list(0, -1); |
802 |
21 Jun 05 |
nicklas |
67 |
|
814 |
23 Jun 05 |
nicklas |
68 |
write_events_header(); |
814 |
23 Jun 05 |
nicklas |
69 |
test_add_event(id, 100.0f); |
5663 |
22 Jun 11 |
nicklas |
70 |
test_list_events(id, 4); // creation event, create event for id3+id4, and extra event |
814 |
23 Jun 05 |
nicklas |
71 |
|
5663 |
22 Jun 11 |
nicklas |
72 |
write_parents_header(); |
5663 |
22 Jun 11 |
nicklas |
73 |
test_list_sources(id4, 3); // The three id, id2 and id3 samples |
5663 |
22 Jun 11 |
nicklas |
74 |
test_list_children(id, 2); // id3 and id4 |
802 |
21 Jun 05 |
nicklas |
75 |
|
5663 |
22 Jun 11 |
nicklas |
// Transformers |
5663 |
22 Jun 11 |
nicklas |
77 |
test_childrenTransformer(id, 2); |
5663 |
22 Jun 11 |
nicklas |
78 |
test_parentsTransformer(id4, 3); |
5663 |
22 Jun 11 |
nicklas |
79 |
test_extractToSampleTransformer(id2, 1); |
5663 |
22 Jun 11 |
nicklas |
80 |
test_sampleToExtractTransformer(sampleId, 1); |
5663 |
22 Jun 11 |
nicklas |
81 |
|
5663 |
22 Jun 11 |
nicklas |
82 |
|
1529 |
27 Oct 05 |
nicklas |
83 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
802 |
21 Jun 05 |
nicklas |
// Standard test: Delete |
814 |
23 Jun 05 |
nicklas |
85 |
test_delete(id4); |
817 |
23 Jun 05 |
nicklas |
86 |
test_delete(id3); |
817 |
23 Jun 05 |
nicklas |
87 |
test_delete(id2); |
816 |
23 Jun 05 |
nicklas |
88 |
test_delete(id); |
814 |
23 Jun 05 |
nicklas |
89 |
TestSample.test_delete(sampleId); |
802 |
21 Jun 05 |
nicklas |
90 |
|
802 |
21 Jun 05 |
nicklas |
91 |
write("++Testing extracts "+(ok ? "OK" : "Failed")+"\n"); |
802 |
21 Jun 05 |
nicklas |
92 |
return ok; |
802 |
21 Jun 05 |
nicklas |
93 |
} |
802 |
21 Jun 05 |
nicklas |
94 |
|
5641 |
25 May 11 |
nicklas |
95 |
static int test_create(int parentId, String name, int subtypeId, int tagId, boolean setAll) |
802 |
21 Jun 05 |
nicklas |
96 |
{ |
802 |
21 Jun 05 |
nicklas |
97 |
if (!TestUtil.hasPermission(Permission.CREATE, Item.EXTRACT)) return 0; |
802 |
21 Jun 05 |
nicklas |
98 |
int id = 0; |
802 |
21 Jun 05 |
nicklas |
99 |
DbControl dc = null; |
802 |
21 Jun 05 |
nicklas |
100 |
try |
802 |
21 Jun 05 |
nicklas |
101 |
{ |
802 |
21 Jun 05 |
nicklas |
102 |
dc = TestUtil.getDbControl(); |
802 |
21 Jun 05 |
nicklas |
103 |
Extract e = Extract.getNew(dc); |
5653 |
13 Jun 11 |
nicklas |
104 |
e.setName(name); |
802 |
21 Jun 05 |
nicklas |
105 |
if (setAll) |
802 |
21 Jun 05 |
nicklas |
106 |
{ |
802 |
21 Jun 05 |
nicklas |
107 |
e.setDescription("Added at "+new Date()); |
802 |
21 Jun 05 |
nicklas |
108 |
e.setExternalId("XCV-455-EXTRACT"); |
802 |
21 Jun 05 |
nicklas |
109 |
e.setOriginalQuantity(500.0f); |
802 |
21 Jun 05 |
nicklas |
110 |
} |
5641 |
25 May 11 |
nicklas |
111 |
if (parentId != 0) |
802 |
21 Jun 05 |
nicklas |
112 |
{ |
5641 |
25 May 11 |
nicklas |
113 |
BioMaterial parent = BioMaterial.getById(dc, parentId); |
5663 |
22 Jun 11 |
nicklas |
114 |
BioMaterialEventSource evtSrc = e.getCreationEvent().setSource(parent); |
5663 |
22 Jun 11 |
nicklas |
115 |
evtSrc.setUsedQuantity(200.0f); |
802 |
21 Jun 05 |
nicklas |
116 |
} |
5641 |
25 May 11 |
nicklas |
117 |
if (subtypeId > 0) |
5641 |
25 May 11 |
nicklas |
118 |
{ |
5641 |
25 May 11 |
nicklas |
119 |
e.setItemSubtype(ItemSubtype.getById(dc, subtypeId)); |
5641 |
25 May 11 |
nicklas |
120 |
} |
5641 |
25 May 11 |
nicklas |
121 |
if (tagId > 0) |
5641 |
25 May 11 |
nicklas |
122 |
{ |
5641 |
25 May 11 |
nicklas |
123 |
e.setTag(Tag.getById(dc, tagId)); |
5641 |
25 May 11 |
nicklas |
124 |
} |
802 |
21 Jun 05 |
nicklas |
125 |
dc.saveItem(e); |
802 |
21 Jun 05 |
nicklas |
126 |
dc.commit(); |
802 |
21 Jun 05 |
nicklas |
127 |
id = e.getId(); |
806 |
22 Jun 05 |
nicklas |
128 |
dc = TestUtil.getDbControl(); |
5060 |
19 Aug 09 |
nicklas |
129 |
dc.reattachItem(e, false); |
802 |
21 Jun 05 |
nicklas |
130 |
write_item(0, e); |
802 |
21 Jun 05 |
nicklas |
131 |
write("--Create extract OK"); |
802 |
21 Jun 05 |
nicklas |
132 |
} |
802 |
21 Jun 05 |
nicklas |
133 |
catch (Throwable ex) |
802 |
21 Jun 05 |
nicklas |
134 |
{ |
802 |
21 Jun 05 |
nicklas |
135 |
write("--Create extract FAILED"); |
802 |
21 Jun 05 |
nicklas |
136 |
ex.printStackTrace(); |
802 |
21 Jun 05 |
nicklas |
137 |
ok = false; |
802 |
21 Jun 05 |
nicklas |
138 |
} |
802 |
21 Jun 05 |
nicklas |
139 |
finally |
802 |
21 Jun 05 |
nicklas |
140 |
{ |
802 |
21 Jun 05 |
nicklas |
141 |
if (dc != null) dc.close(); |
802 |
21 Jun 05 |
nicklas |
142 |
} |
802 |
21 Jun 05 |
nicklas |
143 |
return id; |
802 |
21 Jun 05 |
nicklas |
144 |
} |
802 |
21 Jun 05 |
nicklas |
145 |
|
5663 |
22 Jun 11 |
nicklas |
146 |
static int test_create_pooled(String name, int... sourceIds) |
811 |
22 Jun 05 |
nicklas |
147 |
{ |
811 |
22 Jun 05 |
nicklas |
148 |
if (!TestUtil.hasPermission(Permission.CREATE, Item.EXTRACT)) return 0; |
811 |
22 Jun 05 |
nicklas |
149 |
int id = 0; |
811 |
22 Jun 05 |
nicklas |
150 |
DbControl dc = null; |
811 |
22 Jun 05 |
nicklas |
151 |
try |
811 |
22 Jun 05 |
nicklas |
152 |
{ |
811 |
22 Jun 05 |
nicklas |
153 |
dc = TestUtil.getDbControl(); |
811 |
22 Jun 05 |
nicklas |
154 |
Extract e = Extract.getNew(dc); |
5663 |
22 Jun 11 |
nicklas |
155 |
e.setName(name); |
811 |
22 Jun 05 |
nicklas |
156 |
e.setDescription("Added at "+new Date()); |
811 |
22 Jun 05 |
nicklas |
157 |
e.setExternalId("POOLED-455-EXTRACT"); |
811 |
22 Jun 05 |
nicklas |
158 |
e.setOriginalQuantity(500.0f); |
811 |
22 Jun 05 |
nicklas |
159 |
BioMaterialEvent evt = e.getCreationEvent(); |
811 |
22 Jun 05 |
nicklas |
160 |
for (int sourceId : sourceIds) |
811 |
22 Jun 05 |
nicklas |
161 |
{ |
811 |
22 Jun 05 |
nicklas |
162 |
Extract s = Extract.getById(dc, sourceId); |
817 |
23 Jun 05 |
nicklas |
163 |
Float original = s.getOriginalQuantity(); |
5662 |
20 Jun 11 |
nicklas |
164 |
BioMaterialEventSource eventSource = evt.addSource(s); |
5662 |
20 Jun 11 |
nicklas |
165 |
if (original != null) |
5662 |
20 Jun 11 |
nicklas |
166 |
{ |
5662 |
20 Jun 11 |
nicklas |
167 |
eventSource.setUsedQuantity(original/2); |
5662 |
20 Jun 11 |
nicklas |
168 |
} |
811 |
22 Jun 05 |
nicklas |
169 |
} |
811 |
22 Jun 05 |
nicklas |
170 |
dc.saveItem(e); |
811 |
22 Jun 05 |
nicklas |
171 |
dc.commit(); |
811 |
22 Jun 05 |
nicklas |
172 |
id = e.getId(); |
811 |
22 Jun 05 |
nicklas |
173 |
dc = TestUtil.getDbControl(); |
5060 |
19 Aug 09 |
nicklas |
174 |
dc.reattachItem(e, false); |
811 |
22 Jun 05 |
nicklas |
175 |
write_item(0, e); |
811 |
22 Jun 05 |
nicklas |
176 |
write("--Create pooled extract OK"); |
811 |
22 Jun 05 |
nicklas |
177 |
} |
811 |
22 Jun 05 |
nicklas |
178 |
catch (Throwable ex) |
811 |
22 Jun 05 |
nicklas |
179 |
{ |
811 |
22 Jun 05 |
nicklas |
180 |
write("--Create pooled extract FAILED"); |
811 |
22 Jun 05 |
nicklas |
181 |
ex.printStackTrace(); |
811 |
22 Jun 05 |
nicklas |
182 |
ok = false; |
811 |
22 Jun 05 |
nicklas |
183 |
} |
811 |
22 Jun 05 |
nicklas |
184 |
finally |
811 |
22 Jun 05 |
nicklas |
185 |
{ |
811 |
22 Jun 05 |
nicklas |
186 |
if (dc != null) dc.close(); |
811 |
22 Jun 05 |
nicklas |
187 |
} |
811 |
22 Jun 05 |
nicklas |
188 |
return id; |
811 |
22 Jun 05 |
nicklas |
189 |
} |
811 |
22 Jun 05 |
nicklas |
190 |
|
802 |
21 Jun 05 |
nicklas |
191 |
static void test_load(int id) |
802 |
21 Jun 05 |
nicklas |
192 |
{ |
802 |
21 Jun 05 |
nicklas |
193 |
if (id == 0) return; |
802 |
21 Jun 05 |
nicklas |
194 |
DbControl dc = null; |
802 |
21 Jun 05 |
nicklas |
195 |
try |
802 |
21 Jun 05 |
nicklas |
196 |
{ |
802 |
21 Jun 05 |
nicklas |
197 |
dc = TestUtil.getDbControl(); |
802 |
21 Jun 05 |
nicklas |
198 |
Extract e = Extract.getById(dc, id); |
802 |
21 Jun 05 |
nicklas |
199 |
write_item(0, e); |
802 |
21 Jun 05 |
nicklas |
200 |
write("--Load extract OK"); |
802 |
21 Jun 05 |
nicklas |
201 |
} |
802 |
21 Jun 05 |
nicklas |
202 |
catch (Throwable ex) |
802 |
21 Jun 05 |
nicklas |
203 |
{ |
802 |
21 Jun 05 |
nicklas |
204 |
write("--Load extract FAILED"); |
802 |
21 Jun 05 |
nicklas |
205 |
ex.printStackTrace(); |
802 |
21 Jun 05 |
nicklas |
206 |
ok = false; |
802 |
21 Jun 05 |
nicklas |
207 |
} |
802 |
21 Jun 05 |
nicklas |
208 |
finally |
802 |
21 Jun 05 |
nicklas |
209 |
{ |
802 |
21 Jun 05 |
nicklas |
210 |
if (dc != null) dc.close(); |
802 |
21 Jun 05 |
nicklas |
211 |
} |
802 |
21 Jun 05 |
nicklas |
212 |
} |
802 |
21 Jun 05 |
nicklas |
213 |
|
5696 |
12 Aug 11 |
nicklas |
214 |
static boolean test_list(int subtypeId, int expectedResults) |
802 |
21 Jun 05 |
nicklas |
215 |
{ |
802 |
21 Jun 05 |
nicklas |
216 |
DbControl dc = null; |
802 |
21 Jun 05 |
nicklas |
217 |
try |
802 |
21 Jun 05 |
nicklas |
218 |
{ |
802 |
21 Jun 05 |
nicklas |
219 |
dc = TestUtil.getDbControl(); |
5688 |
10 Aug 11 |
nicklas |
220 |
ItemQuery<Extract> query = Extract.getQuery(); |
5688 |
10 Aug 11 |
nicklas |
221 |
if (subtypeId > 0) |
5688 |
10 Aug 11 |
nicklas |
222 |
{ |
5688 |
10 Aug 11 |
nicklas |
223 |
query.restrict(Restrictions.eq(Hql.property("itemSubtype"), Expressions.integer(subtypeId))); |
5688 |
10 Aug 11 |
nicklas |
224 |
} |
5688 |
10 Aug 11 |
nicklas |
225 |
ItemResultList<Extract> l = query.list(dc); |
802 |
21 Jun 05 |
nicklas |
226 |
for (int i = 0; i<l.size(); i++) |
802 |
21 Jun 05 |
nicklas |
227 |
{ |
802 |
21 Jun 05 |
nicklas |
228 |
write_item(i, l.get(i)); |
802 |
21 Jun 05 |
nicklas |
229 |
} |
802 |
21 Jun 05 |
nicklas |
230 |
if (expectedResults >= 0 && expectedResults != l.size()) |
802 |
21 Jun 05 |
nicklas |
231 |
{ |
802 |
21 Jun 05 |
nicklas |
232 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
802 |
21 Jun 05 |
nicklas |
233 |
} |
802 |
21 Jun 05 |
nicklas |
234 |
write("--List extracts OK ("+l.size()+")"); |
802 |
21 Jun 05 |
nicklas |
235 |
} |
802 |
21 Jun 05 |
nicklas |
236 |
catch (Throwable ex) |
802 |
21 Jun 05 |
nicklas |
237 |
{ |
802 |
21 Jun 05 |
nicklas |
238 |
write("--List extracts FAILED"); |
802 |
21 Jun 05 |
nicklas |
239 |
ex.printStackTrace(); |
802 |
21 Jun 05 |
nicklas |
240 |
ok = false; |
5696 |
12 Aug 11 |
nicklas |
241 |
return false; |
802 |
21 Jun 05 |
nicklas |
242 |
} |
802 |
21 Jun 05 |
nicklas |
243 |
finally |
802 |
21 Jun 05 |
nicklas |
244 |
{ |
802 |
21 Jun 05 |
nicklas |
245 |
if (dc != null) dc.close(); |
802 |
21 Jun 05 |
nicklas |
246 |
} |
5696 |
12 Aug 11 |
nicklas |
247 |
return true; |
802 |
21 Jun 05 |
nicklas |
248 |
} |
802 |
21 Jun 05 |
nicklas |
249 |
|
802 |
21 Jun 05 |
nicklas |
250 |
static void test_delete(int id) |
802 |
21 Jun 05 |
nicklas |
251 |
{ |
802 |
21 Jun 05 |
nicklas |
252 |
if (id == 0) return; |
802 |
21 Jun 05 |
nicklas |
253 |
DbControl dc = null; |
802 |
21 Jun 05 |
nicklas |
254 |
try |
802 |
21 Jun 05 |
nicklas |
255 |
{ |
802 |
21 Jun 05 |
nicklas |
256 |
dc = TestUtil.getDbControl(); |
802 |
21 Jun 05 |
nicklas |
257 |
Extract e = Extract.getById(dc, id); |
802 |
21 Jun 05 |
nicklas |
258 |
dc.deleteItem(e); |
5340 |
10 May 10 |
nicklas |
259 |
Set<ItemProxy> using = e.getUsingItems(); |
5340 |
10 May 10 |
nicklas |
260 |
if (using.size() > 0) |
5340 |
10 May 10 |
nicklas |
261 |
{ |
5340 |
10 May 10 |
nicklas |
262 |
throw new BaseException(e + " is used by " + using); |
5340 |
10 May 10 |
nicklas |
263 |
} |
802 |
21 Jun 05 |
nicklas |
264 |
dc.commit(); |
802 |
21 Jun 05 |
nicklas |
265 |
write("--Delete extract OK"); |
802 |
21 Jun 05 |
nicklas |
266 |
} |
802 |
21 Jun 05 |
nicklas |
267 |
catch (Throwable ex) |
802 |
21 Jun 05 |
nicklas |
268 |
{ |
802 |
21 Jun 05 |
nicklas |
269 |
write("--Delete extract FAILED"); |
802 |
21 Jun 05 |
nicklas |
270 |
ex.printStackTrace(); |
802 |
21 Jun 05 |
nicklas |
271 |
ok = false; |
802 |
21 Jun 05 |
nicklas |
272 |
} |
802 |
21 Jun 05 |
nicklas |
273 |
finally |
802 |
21 Jun 05 |
nicklas |
274 |
{ |
802 |
21 Jun 05 |
nicklas |
275 |
if (dc != null) dc.close(); |
802 |
21 Jun 05 |
nicklas |
276 |
} |
802 |
21 Jun 05 |
nicklas |
277 |
} |
802 |
21 Jun 05 |
nicklas |
278 |
|
4372 |
04 Jul 08 |
nicklas |
279 |
static void test_delete_all() |
4372 |
04 Jul 08 |
nicklas |
280 |
{ |
4372 |
04 Jul 08 |
nicklas |
281 |
DbControl dc = null; |
4372 |
04 Jul 08 |
nicklas |
282 |
try |
4372 |
04 Jul 08 |
nicklas |
283 |
{ |
4372 |
04 Jul 08 |
nicklas |
284 |
dc = TestUtil.getDbControl(); |
4372 |
04 Jul 08 |
nicklas |
285 |
ItemResultList<Extract> l = Extract.getQuery().list(dc); |
5688 |
10 Aug 11 |
nicklas |
286 |
int numDeleted = Trashcan.delete(dc.getSessionControl(), l, true, null); |
5688 |
10 Aug 11 |
nicklas |
287 |
if (numDeleted != l.size()) throw new BaseException("Could not delete all items: " + numDeleted + " of " + l.size()); |
4372 |
04 Jul 08 |
nicklas |
288 |
dc.commit(); |
4372 |
04 Jul 08 |
nicklas |
289 |
write("--Delete all extracts OK ("+l.size()+")"); |
4372 |
04 Jul 08 |
nicklas |
290 |
} |
4372 |
04 Jul 08 |
nicklas |
291 |
catch (Throwable ex) |
4372 |
04 Jul 08 |
nicklas |
292 |
{ |
4372 |
04 Jul 08 |
nicklas |
293 |
write("--Delete all extracts FAILED"); |
4372 |
04 Jul 08 |
nicklas |
294 |
ex.printStackTrace(); |
4372 |
04 Jul 08 |
nicklas |
295 |
ok = false; |
4372 |
04 Jul 08 |
nicklas |
296 |
} |
4372 |
04 Jul 08 |
nicklas |
297 |
finally |
4372 |
04 Jul 08 |
nicklas |
298 |
{ |
4372 |
04 Jul 08 |
nicklas |
299 |
if (dc != null) dc.close(); |
4372 |
04 Jul 08 |
nicklas |
300 |
} |
4372 |
04 Jul 08 |
nicklas |
301 |
} |
4372 |
04 Jul 08 |
nicklas |
302 |
|
4372 |
04 Jul 08 |
nicklas |
303 |
|
802 |
21 Jun 05 |
nicklas |
304 |
static void write_header() |
802 |
21 Jun 05 |
nicklas |
305 |
{ |
802 |
21 Jun 05 |
nicklas |
306 |
if (!TestUtil.getSilent()) |
802 |
21 Jun 05 |
nicklas |
307 |
{ |
5663 |
22 Jun 11 |
nicklas |
308 |
write(" \tID \tName \tSubtype\tDescription\tExternal id\tParent type\tParent\tTag\tQuantity\tRemain"); |
5663 |
22 Jun 11 |
nicklas |
309 |
write("-- \t-- \t--------- \t-------\t-----------\t-----------\t-----------\t------\t---\t--------\t------"); |
802 |
21 Jun 05 |
nicklas |
310 |
} |
802 |
21 Jun 05 |
nicklas |
311 |
} |
802 |
21 Jun 05 |
nicklas |
312 |
static void write_item(int i, Extract e) |
802 |
21 Jun 05 |
nicklas |
313 |
throws BaseException |
802 |
21 Jun 05 |
nicklas |
314 |
{ |
5641 |
25 May 11 |
nicklas |
315 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+e.getId()+"\t"+e.getName()+"\t"+e.getItemSubtype()+"\t"+e.getDescription()+ |
5663 |
22 Jun 11 |
nicklas |
316 |
"\t"+e.getExternalId()+"\t"+e.getParentType()+"\t"+e.getParent()+"\t"+e.getTag()+"\t"+e.getOriginalQuantity()+"\t"+e.getRemainingQuantity()); |
802 |
21 Jun 05 |
nicklas |
317 |
} |
814 |
23 Jun 05 |
nicklas |
318 |
static void write_events_header() |
814 |
23 Jun 05 |
nicklas |
319 |
{ |
814 |
23 Jun 05 |
nicklas |
320 |
if (!TestUtil.getSilent()) |
814 |
23 Jun 05 |
nicklas |
321 |
{ |
814 |
23 Jun 05 |
nicklas |
322 |
write(" \tID \tBiomaterial\tEvent type\tEvent date\tEntry date\tUsed quantity\tComment"); |
814 |
23 Jun 05 |
nicklas |
323 |
write("-- \t-- \t-----------\t----------\t----------\t----------\t-------------\t-------"); |
814 |
23 Jun 05 |
nicklas |
324 |
} |
814 |
23 Jun 05 |
nicklas |
325 |
} |
814 |
23 Jun 05 |
nicklas |
326 |
static void write_item(int i, BioMaterialEvent evt, Extract e) |
814 |
23 Jun 05 |
nicklas |
327 |
throws BaseException |
814 |
23 Jun 05 |
nicklas |
328 |
{ |
814 |
23 Jun 05 |
nicklas |
329 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+evt.getId()+"\t"+evt.getBioMaterial()+"\t"+evt.getEventType()+ |
814 |
23 Jun 05 |
nicklas |
330 |
"\t"+evt.getEventDate()+"\t"+evt.getEntryDate()+"\t"+evt.getUsedQuantity(e)+"\t"+evt.getComment()); |
814 |
23 Jun 05 |
nicklas |
331 |
} |
5642 |
26 May 11 |
nicklas |
332 |
static void write_item(int i, PhysicalBioAssay h) |
5641 |
25 May 11 |
nicklas |
333 |
throws BaseException |
5641 |
25 May 11 |
nicklas |
334 |
{ |
5641 |
25 May 11 |
nicklas |
335 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+h.getId()+"\t"+h.getName()+"\t"+h.getDescription()); |
5641 |
25 May 11 |
nicklas |
336 |
} |
5663 |
22 Jun 11 |
nicklas |
337 |
|
5663 |
22 Jun 11 |
nicklas |
338 |
static void write_parents_header() |
814 |
23 Jun 05 |
nicklas |
339 |
{ |
814 |
23 Jun 05 |
nicklas |
340 |
if (!TestUtil.getSilent()) |
814 |
23 Jun 05 |
nicklas |
341 |
{ |
5663 |
22 Jun 11 |
nicklas |
342 |
write(" \tID \tName \tDescription\tExternal id\tQuantity\tRemain\tUsed"); |
5663 |
22 Jun 11 |
nicklas |
343 |
write("-- \t-- \t--------- \t-----------\t-----------\t--------\t------\t----"); |
814 |
23 Jun 05 |
nicklas |
344 |
} |
814 |
23 Jun 05 |
nicklas |
345 |
} |
5663 |
22 Jun 11 |
nicklas |
346 |
|
814 |
23 Jun 05 |
nicklas |
347 |
static void write_item(int i, MeasuredBioMaterial b, BioMaterialEvent evt) |
814 |
23 Jun 05 |
nicklas |
348 |
throws BaseException |
814 |
23 Jun 05 |
nicklas |
349 |
{ |
814 |
23 Jun 05 |
nicklas |
350 |
if (!TestUtil.getSilent()) System.out.println(i+":\t"+b.getId()+"\t"+b.getName()+"\t"+b.getDescription()+ |
5663 |
22 Jun 11 |
nicklas |
351 |
"\t"+b.getExternalId()+"\t"+b.getParentType()+"\t"+b.getOriginalQuantity()+"\t"+b.getRemainingQuantity()+ |
814 |
23 Jun 05 |
nicklas |
352 |
"\t"+evt.getUsedQuantity(b)); |
814 |
23 Jun 05 |
nicklas |
353 |
} |
802 |
21 Jun 05 |
nicklas |
354 |
static void write(String message) |
802 |
21 Jun 05 |
nicklas |
355 |
{ |
802 |
21 Jun 05 |
nicklas |
356 |
System.out.println(message); |
802 |
21 Jun 05 |
nicklas |
357 |
} |
814 |
23 Jun 05 |
nicklas |
358 |
|
814 |
23 Jun 05 |
nicklas |
359 |
|
814 |
23 Jun 05 |
nicklas |
360 |
static int test_add_event(int extractId, float usedQuantity) |
814 |
23 Jun 05 |
nicklas |
361 |
{ |
814 |
23 Jun 05 |
nicklas |
362 |
if (extractId == 0) return 0; |
814 |
23 Jun 05 |
nicklas |
363 |
int eventId = 0; |
814 |
23 Jun 05 |
nicklas |
364 |
DbControl dc = null; |
814 |
23 Jun 05 |
nicklas |
365 |
try |
814 |
23 Jun 05 |
nicklas |
366 |
{ |
814 |
23 Jun 05 |
nicklas |
367 |
dc = TestUtil.getDbControl(); |
814 |
23 Jun 05 |
nicklas |
368 |
Extract e = Extract.getById(dc, extractId); |
947 |
18 Jul 05 |
nicklas |
369 |
BioMaterialEvent bme = e.newEvent(); |
947 |
18 Jul 05 |
nicklas |
370 |
bme.setUsedQuantity(usedQuantity); |
814 |
23 Jun 05 |
nicklas |
371 |
bme.setComment("Added a new event"); |
814 |
23 Jun 05 |
nicklas |
372 |
dc.saveItem(bme); |
814 |
23 Jun 05 |
nicklas |
373 |
dc.commit(); |
814 |
23 Jun 05 |
nicklas |
374 |
eventId = bme.getId(); |
814 |
23 Jun 05 |
nicklas |
375 |
dc = TestUtil.getDbControl(); |
5060 |
19 Aug 09 |
nicklas |
376 |
dc.reattachItem(bme, false); |
814 |
23 Jun 05 |
nicklas |
377 |
write_item(0, bme, e); |
814 |
23 Jun 05 |
nicklas |
378 |
write("--Add event for extract OK"); |
814 |
23 Jun 05 |
nicklas |
379 |
} |
816 |
23 Jun 05 |
nicklas |
380 |
catch (Throwable ex) |
814 |
23 Jun 05 |
nicklas |
381 |
{ |
814 |
23 Jun 05 |
nicklas |
382 |
write("--Add event for extract FAILED"); |
814 |
23 Jun 05 |
nicklas |
383 |
ex.printStackTrace(); |
814 |
23 Jun 05 |
nicklas |
384 |
ok = false; |
814 |
23 Jun 05 |
nicklas |
385 |
} |
814 |
23 Jun 05 |
nicklas |
386 |
finally |
814 |
23 Jun 05 |
nicklas |
387 |
{ |
814 |
23 Jun 05 |
nicklas |
388 |
if (dc != null) dc.close(); |
814 |
23 Jun 05 |
nicklas |
389 |
} |
814 |
23 Jun 05 |
nicklas |
390 |
return eventId; |
814 |
23 Jun 05 |
nicklas |
391 |
} |
814 |
23 Jun 05 |
nicklas |
392 |
|
814 |
23 Jun 05 |
nicklas |
393 |
static void test_list_events(int extractId, int expectedResults) |
814 |
23 Jun 05 |
nicklas |
394 |
{ |
814 |
23 Jun 05 |
nicklas |
395 |
if (extractId == 0) return; |
814 |
23 Jun 05 |
nicklas |
396 |
DbControl dc = null; |
814 |
23 Jun 05 |
nicklas |
397 |
try |
814 |
23 Jun 05 |
nicklas |
398 |
{ |
814 |
23 Jun 05 |
nicklas |
399 |
dc = TestUtil.getDbControl(); |
814 |
23 Jun 05 |
nicklas |
400 |
Extract e = Extract.getById(dc, extractId); |
1418 |
07 Oct 05 |
nicklas |
401 |
ItemResultList<BioMaterialEvent> l = e.getEvents().list(dc); |
814 |
23 Jun 05 |
nicklas |
402 |
for (int i = 0; i<l.size(); i++) |
814 |
23 Jun 05 |
nicklas |
403 |
{ |
814 |
23 Jun 05 |
nicklas |
404 |
write_item(i, l.get(i), e); |
814 |
23 Jun 05 |
nicklas |
405 |
} |
814 |
23 Jun 05 |
nicklas |
406 |
if (expectedResults >= 0 && expectedResults != l.size()) |
814 |
23 Jun 05 |
nicklas |
407 |
{ |
814 |
23 Jun 05 |
nicklas |
408 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
814 |
23 Jun 05 |
nicklas |
409 |
} |
814 |
23 Jun 05 |
nicklas |
410 |
write("--List events for extract OK ("+l.size()+")"); |
814 |
23 Jun 05 |
nicklas |
411 |
} |
816 |
23 Jun 05 |
nicklas |
412 |
catch (Throwable ex) |
814 |
23 Jun 05 |
nicklas |
413 |
{ |
814 |
23 Jun 05 |
nicklas |
414 |
write("--List events for extract FAILED"); |
814 |
23 Jun 05 |
nicklas |
415 |
ex.printStackTrace(); |
814 |
23 Jun 05 |
nicklas |
416 |
ok = false; |
814 |
23 Jun 05 |
nicklas |
417 |
} |
814 |
23 Jun 05 |
nicklas |
418 |
finally |
814 |
23 Jun 05 |
nicklas |
419 |
{ |
814 |
23 Jun 05 |
nicklas |
420 |
if (dc != null) dc.close(); |
814 |
23 Jun 05 |
nicklas |
421 |
} |
814 |
23 Jun 05 |
nicklas |
422 |
} |
5663 |
22 Jun 11 |
nicklas |
423 |
|
814 |
23 Jun 05 |
nicklas |
424 |
static void test_list_sources(int extractId, int expectedResults) |
814 |
23 Jun 05 |
nicklas |
425 |
{ |
814 |
23 Jun 05 |
nicklas |
426 |
if (extractId == 0) return; |
814 |
23 Jun 05 |
nicklas |
427 |
DbControl dc = null; |
814 |
23 Jun 05 |
nicklas |
428 |
try |
814 |
23 Jun 05 |
nicklas |
429 |
{ |
814 |
23 Jun 05 |
nicklas |
430 |
dc = TestUtil.getDbControl(); |
814 |
23 Jun 05 |
nicklas |
431 |
Extract e = Extract.getById(dc, extractId); |
814 |
23 Jun 05 |
nicklas |
432 |
BioMaterialEvent evt = e.getCreationEvent(); |
5663 |
22 Jun 11 |
nicklas |
433 |
ResultList<BioMaterialEventSource> l = evt.getEventSources().list(dc); |
814 |
23 Jun 05 |
nicklas |
434 |
for (int i = 0; i<l.size(); i++) |
814 |
23 Jun 05 |
nicklas |
435 |
{ |
5663 |
22 Jun 11 |
nicklas |
436 |
TestSample.write_item(i, l.get(i)); |
814 |
23 Jun 05 |
nicklas |
437 |
} |
814 |
23 Jun 05 |
nicklas |
438 |
if (expectedResults >= 0 && expectedResults != l.size()) |
814 |
23 Jun 05 |
nicklas |
439 |
{ |
814 |
23 Jun 05 |
nicklas |
440 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
814 |
23 Jun 05 |
nicklas |
441 |
} |
814 |
23 Jun 05 |
nicklas |
442 |
write("--List sources for extract OK ("+l.size()+")"); |
814 |
23 Jun 05 |
nicklas |
443 |
} |
816 |
23 Jun 05 |
nicklas |
444 |
catch (Throwable ex) |
814 |
23 Jun 05 |
nicklas |
445 |
{ |
814 |
23 Jun 05 |
nicklas |
446 |
write("--List sources for extract FAILED"); |
814 |
23 Jun 05 |
nicklas |
447 |
ex.printStackTrace(); |
814 |
23 Jun 05 |
nicklas |
448 |
ok = false; |
814 |
23 Jun 05 |
nicklas |
449 |
} |
814 |
23 Jun 05 |
nicklas |
450 |
finally |
814 |
23 Jun 05 |
nicklas |
451 |
{ |
814 |
23 Jun 05 |
nicklas |
452 |
if (dc != null) dc.close(); |
814 |
23 Jun 05 |
nicklas |
453 |
} |
814 |
23 Jun 05 |
nicklas |
454 |
} |
5663 |
22 Jun 11 |
nicklas |
455 |
|
5663 |
22 Jun 11 |
nicklas |
456 |
static void test_list_children(int extractId, int expectedResults) |
4559 |
03 Oct 08 |
martin |
457 |
{ |
4559 |
03 Oct 08 |
martin |
458 |
if (extractId == 0) return; |
4559 |
03 Oct 08 |
martin |
459 |
DbControl dc = null; |
4559 |
03 Oct 08 |
martin |
460 |
try |
4559 |
03 Oct 08 |
martin |
461 |
{ |
4559 |
03 Oct 08 |
martin |
462 |
dc = TestUtil.getDbControl(); |
4559 |
03 Oct 08 |
martin |
463 |
Extract e = Extract.getById(dc, extractId); |
5663 |
22 Jun 11 |
nicklas |
464 |
ItemResultList<Extract> ev = e.getChildExtracts().list(dc); |
4559 |
03 Oct 08 |
martin |
465 |
|
4559 |
03 Oct 08 |
martin |
466 |
for (int i=0; i<ev.size(); i++) |
4559 |
03 Oct 08 |
martin |
467 |
{ |
5663 |
22 Jun 11 |
nicklas |
468 |
write_item(i, ev.get(i)); |
4559 |
03 Oct 08 |
martin |
469 |
} |
4559 |
03 Oct 08 |
martin |
470 |
if (expectedResults >= 0 && expectedResults != ev.size()) |
4559 |
03 Oct 08 |
martin |
471 |
{ |
4559 |
03 Oct 08 |
martin |
472 |
throw new BaseException("Expected "+expectedResults+" results, not "+ev.size()); |
4559 |
03 Oct 08 |
martin |
473 |
} |
5663 |
22 Jun 11 |
nicklas |
474 |
write("--List children for extract OK ("+ev.size()+")"); |
4559 |
03 Oct 08 |
martin |
475 |
} |
4559 |
03 Oct 08 |
martin |
476 |
catch (Throwable ex) |
4559 |
03 Oct 08 |
martin |
477 |
{ |
5663 |
22 Jun 11 |
nicklas |
478 |
write("--List children for extract FAILED"); |
4559 |
03 Oct 08 |
martin |
479 |
ex.printStackTrace(); |
4559 |
03 Oct 08 |
martin |
480 |
ok = false; |
4559 |
03 Oct 08 |
martin |
481 |
} |
4559 |
03 Oct 08 |
martin |
482 |
finally |
4559 |
03 Oct 08 |
martin |
483 |
{ |
4559 |
03 Oct 08 |
martin |
484 |
if (dc != null) dc.close(); |
4559 |
03 Oct 08 |
martin |
485 |
} |
4559 |
03 Oct 08 |
martin |
486 |
} |
5663 |
22 Jun 11 |
nicklas |
487 |
|
5641 |
25 May 11 |
nicklas |
488 |
|
5642 |
26 May 11 |
nicklas |
489 |
static void test_list_bioassays(int extractId, int expectedResults) |
5641 |
25 May 11 |
nicklas |
490 |
{ |
5641 |
25 May 11 |
nicklas |
491 |
if (extractId == 0) return; |
5641 |
25 May 11 |
nicklas |
492 |
DbControl dc = null; |
5641 |
25 May 11 |
nicklas |
493 |
try |
5641 |
25 May 11 |
nicklas |
494 |
{ |
5641 |
25 May 11 |
nicklas |
495 |
dc = TestUtil.getDbControl(); |
5641 |
25 May 11 |
nicklas |
496 |
Extract le = Extract.getById(dc, extractId); |
5642 |
26 May 11 |
nicklas |
497 |
ItemResultList<PhysicalBioAssay> l = le.getPhysicalBioAssays().list(dc); |
5641 |
25 May 11 |
nicklas |
498 |
for (int i = 0; i<l.size(); i++) |
5641 |
25 May 11 |
nicklas |
499 |
{ |
5641 |
25 May 11 |
nicklas |
500 |
write_item(i, l.get(i)); |
5641 |
25 May 11 |
nicklas |
501 |
} |
5641 |
25 May 11 |
nicklas |
502 |
if (expectedResults >= 0 && expectedResults != l.size()) |
5641 |
25 May 11 |
nicklas |
503 |
{ |
5641 |
25 May 11 |
nicklas |
504 |
throw new BaseException("Expected "+expectedResults+" results, not "+l.size()); |
5641 |
25 May 11 |
nicklas |
505 |
} |
5642 |
26 May 11 |
nicklas |
506 |
write("--List bioassays for extract OK ("+l.size()+")"); |
5641 |
25 May 11 |
nicklas |
507 |
} |
5641 |
25 May 11 |
nicklas |
508 |
catch (Throwable ex) |
5641 |
25 May 11 |
nicklas |
509 |
{ |
5642 |
26 May 11 |
nicklas |
510 |
write("--List bioassays for extract FAILED"); |
5641 |
25 May 11 |
nicklas |
511 |
ex.printStackTrace(); |
5641 |
25 May 11 |
nicklas |
512 |
ok = false; |
5641 |
25 May 11 |
nicklas |
513 |
} |
5641 |
25 May 11 |
nicklas |
514 |
finally |
5641 |
25 May 11 |
nicklas |
515 |
{ |
5641 |
25 May 11 |
nicklas |
516 |
if (dc != null) dc.close(); |
5641 |
25 May 11 |
nicklas |
517 |
} |
5641 |
25 May 11 |
nicklas |
518 |
} |
5641 |
25 May 11 |
nicklas |
519 |
|
5663 |
22 Jun 11 |
nicklas |
520 |
|
5663 |
22 Jun 11 |
nicklas |
521 |
static void test_childrenTransformer(int extractId, int expectedResults) |
5663 |
22 Jun 11 |
nicklas |
522 |
{ |
5663 |
22 Jun 11 |
nicklas |
523 |
if (extractId == 0) return; |
5663 |
22 Jun 11 |
nicklas |
524 |
DbControl dc = null; |
5663 |
22 Jun 11 |
nicklas |
525 |
try |
5663 |
22 Jun 11 |
nicklas |
526 |
{ |
5663 |
22 Jun 11 |
nicklas |
527 |
dc = TestUtil.getDbControl(); |
5663 |
22 Jun 11 |
nicklas |
528 |
Extract e = Extract.getById(dc, extractId); |
6775 |
17 Mar 15 |
nicklas |
529 |
SourceItemTransformer transformer = new ExtractToChildExtractTransformer(false); |
6775 |
17 Mar 15 |
nicklas |
530 |
TransformContext tfc = new TransformContext(dc); |
6775 |
17 Mar 15 |
nicklas |
531 |
Set<Integer> children = transformer.transform(tfc, Collections.singleton(e.getId())); |
5663 |
22 Jun 11 |
nicklas |
532 |
|
5663 |
22 Jun 11 |
nicklas |
533 |
int i = 0; |
6775 |
17 Mar 15 |
nicklas |
534 |
for (int childId : children) |
5663 |
22 Jun 11 |
nicklas |
535 |
{ |
6775 |
17 Mar 15 |
nicklas |
536 |
write_item(i, Extract.getById(dc, childId)); |
5663 |
22 Jun 11 |
nicklas |
537 |
i++; |
5663 |
22 Jun 11 |
nicklas |
538 |
} |
5663 |
22 Jun 11 |
nicklas |
539 |
if (expectedResults >= 0 && expectedResults != children.size()) |
5663 |
22 Jun 11 |
nicklas |
540 |
{ |
5663 |
22 Jun 11 |
nicklas |
541 |
throw new BaseException("Expected "+expectedResults+" results, not "+children.size()); |
5663 |
22 Jun 11 |
nicklas |
542 |
} |
5663 |
22 Jun 11 |
nicklas |
543 |
write("--List children for extract using transformer OK ("+children.size()+")"); |
5663 |
22 Jun 11 |
nicklas |
544 |
} |
5663 |
22 Jun 11 |
nicklas |
545 |
catch (Throwable ex) |
5663 |
22 Jun 11 |
nicklas |
546 |
{ |
5663 |
22 Jun 11 |
nicklas |
547 |
write("--List children for extract using transformer FAILED"); |
5663 |
22 Jun 11 |
nicklas |
548 |
ex.printStackTrace(); |
5663 |
22 Jun 11 |
nicklas |
549 |
ok = false; |
5663 |
22 Jun 11 |
nicklas |
550 |
} |
5663 |
22 Jun 11 |
nicklas |
551 |
finally |
5663 |
22 Jun 11 |
nicklas |
552 |
{ |
5663 |
22 Jun 11 |
nicklas |
553 |
if (dc != null) dc.close(); |
5663 |
22 Jun 11 |
nicklas |
554 |
} |
5663 |
22 Jun 11 |
nicklas |
555 |
} |
5663 |
22 Jun 11 |
nicklas |
556 |
|
5663 |
22 Jun 11 |
nicklas |
557 |
static void test_parentsTransformer(int extractId, int expectedResults) |
5663 |
22 Jun 11 |
nicklas |
558 |
{ |
5663 |
22 Jun 11 |
nicklas |
559 |
if (extractId == 0) return; |
5663 |
22 Jun 11 |
nicklas |
560 |
DbControl dc = null; |
5663 |
22 Jun 11 |
nicklas |
561 |
try |
5663 |
22 Jun 11 |
nicklas |
562 |
{ |
5663 |
22 Jun 11 |
nicklas |
563 |
dc = TestUtil.getDbControl(); |
5663 |
22 Jun 11 |
nicklas |
564 |
Extract e = Extract.getById(dc, extractId); |
5663 |
22 Jun 11 |
nicklas |
565 |
|
6775 |
17 Mar 15 |
nicklas |
566 |
SourceItemTransformer transformer = new ExtractToParentExtractTransformer(false); |
6775 |
17 Mar 15 |
nicklas |
567 |
TransformContext tfc = new TransformContext(dc); |
6775 |
17 Mar 15 |
nicklas |
568 |
Set<Integer> parents = transformer.transform(tfc, Collections.singleton(e.getId())); |
6775 |
17 Mar 15 |
nicklas |
569 |
|
5663 |
22 Jun 11 |
nicklas |
570 |
int i = 0; |
6775 |
17 Mar 15 |
nicklas |
571 |
for (int parentId : parents) |
5663 |
22 Jun 11 |
nicklas |
572 |
{ |
6775 |
17 Mar 15 |
nicklas |
573 |
write_item(i, Extract.getById(dc, parentId)); |
5663 |
22 Jun 11 |
nicklas |
574 |
i++; |
5663 |
22 Jun 11 |
nicklas |
575 |
} |
5663 |
22 Jun 11 |
nicklas |
576 |
if (expectedResults >= 0 && expectedResults != parents.size()) |
5663 |
22 Jun 11 |
nicklas |
577 |
{ |
5663 |
22 Jun 11 |
nicklas |
578 |
throw new BaseException("Expected "+expectedResults+" results, not "+parents.size()); |
5663 |
22 Jun 11 |
nicklas |
579 |
} |
5663 |
22 Jun 11 |
nicklas |
580 |
write("--List parents for extract using transformer OK ("+parents.size()+")"); |
5663 |
22 Jun 11 |
nicklas |
581 |
} |
5663 |
22 Jun 11 |
nicklas |
582 |
catch (Throwable ex) |
5663 |
22 Jun 11 |
nicklas |
583 |
{ |
5663 |
22 Jun 11 |
nicklas |
584 |
write("--List parents for extract using transformer FAILED"); |
5663 |
22 Jun 11 |
nicklas |
585 |
ex.printStackTrace(); |
5663 |
22 Jun 11 |
nicklas |
586 |
ok = false; |
5663 |
22 Jun 11 |
nicklas |
587 |
} |
5663 |
22 Jun 11 |
nicklas |
588 |
finally |
5663 |
22 Jun 11 |
nicklas |
589 |
{ |
5663 |
22 Jun 11 |
nicklas |
590 |
if (dc != null) dc.close(); |
5663 |
22 Jun 11 |
nicklas |
591 |
} |
5663 |
22 Jun 11 |
nicklas |
592 |
} |
5663 |
22 Jun 11 |
nicklas |
593 |
|
5663 |
22 Jun 11 |
nicklas |
594 |
static void test_extractToSampleTransformer(int extractId, int expectedResults) |
5663 |
22 Jun 11 |
nicklas |
595 |
{ |
5663 |
22 Jun 11 |
nicklas |
596 |
if (extractId == 0) return; |
5663 |
22 Jun 11 |
nicklas |
597 |
DbControl dc = null; |
5663 |
22 Jun 11 |
nicklas |
598 |
try |
5663 |
22 Jun 11 |
nicklas |
599 |
{ |
5663 |
22 Jun 11 |
nicklas |
600 |
dc = TestUtil.getDbControl(); |
5663 |
22 Jun 11 |
nicklas |
601 |
Extract e = Extract.getById(dc, extractId); |
6775 |
17 Mar 15 |
nicklas |
602 |
|
6775 |
17 Mar 15 |
nicklas |
603 |
SourceItemTransformer transformer = new ExtractToSampleTransformer(); |
6775 |
17 Mar 15 |
nicklas |
604 |
TransformContext tfc = new TransformContext(dc); |
6775 |
17 Mar 15 |
nicklas |
605 |
Set<Integer> parents = transformer.transform(tfc, Collections.singleton(e.getId())); |
5663 |
22 Jun 11 |
nicklas |
606 |
|
5663 |
22 Jun 11 |
nicklas |
607 |
int i = 0; |
6775 |
17 Mar 15 |
nicklas |
608 |
for (int parentId : parents) |
5663 |
22 Jun 11 |
nicklas |
609 |
{ |
6775 |
17 Mar 15 |
nicklas |
610 |
TestSample.write_item(i, Sample.getById(dc, parentId)); |
5663 |
22 Jun 11 |
nicklas |
611 |
i++; |
5663 |
22 Jun 11 |
nicklas |
612 |
} |
5663 |
22 Jun 11 |
nicklas |
613 |
if (expectedResults >= 0 && expectedResults != parents.size()) |
5663 |
22 Jun 11 |
nicklas |
614 |
{ |
5663 |
22 Jun 11 |
nicklas |
615 |
throw new BaseException("Expected "+expectedResults+" results, not "+parents.size()); |
5663 |
22 Jun 11 |
nicklas |
616 |
} |
5663 |
22 Jun 11 |
nicklas |
617 |
write("--List sample for extract using transformer OK ("+parents.size()+")"); |
5663 |
22 Jun 11 |
nicklas |
618 |
} |
5663 |
22 Jun 11 |
nicklas |
619 |
catch (Throwable ex) |
5663 |
22 Jun 11 |
nicklas |
620 |
{ |
5663 |
22 Jun 11 |
nicklas |
621 |
write("--List sample for extract using transformer FAILED"); |
5663 |
22 Jun 11 |
nicklas |
622 |
ex.printStackTrace(); |
5663 |
22 Jun 11 |
nicklas |
623 |
ok = false; |
5663 |
22 Jun 11 |
nicklas |
624 |
} |
5663 |
22 Jun 11 |
nicklas |
625 |
finally |
5663 |
22 Jun 11 |
nicklas |
626 |
{ |
5663 |
22 Jun 11 |
nicklas |
627 |
if (dc != null) dc.close(); |
5663 |
22 Jun 11 |
nicklas |
628 |
} |
5663 |
22 Jun 11 |
nicklas |
629 |
} |
5663 |
22 Jun 11 |
nicklas |
630 |
|
5663 |
22 Jun 11 |
nicklas |
631 |
static void test_sampleToExtractTransformer(int sampleId, int expectedResults) |
5663 |
22 Jun 11 |
nicklas |
632 |
{ |
5663 |
22 Jun 11 |
nicklas |
633 |
if (sampleId == 0) return; |
5663 |
22 Jun 11 |
nicklas |
634 |
DbControl dc = null; |
5663 |
22 Jun 11 |
nicklas |
635 |
try |
5663 |
22 Jun 11 |
nicklas |
636 |
{ |
5663 |
22 Jun 11 |
nicklas |
637 |
dc = TestUtil.getDbControl(); |
5663 |
22 Jun 11 |
nicklas |
638 |
Sample s = Sample.getById(dc, sampleId); |
6775 |
17 Mar 15 |
nicklas |
639 |
|
6775 |
17 Mar 15 |
nicklas |
640 |
SourceItemTransformer transformer = new SampleToExtractTransformer(); |
6775 |
17 Mar 15 |
nicklas |
641 |
TransformContext tfc = new TransformContext(dc); |
6775 |
17 Mar 15 |
nicklas |
642 |
Set<Integer> children = transformer.transform(tfc, Collections.singleton(s.getId())); |
5663 |
22 Jun 11 |
nicklas |
643 |
|
5663 |
22 Jun 11 |
nicklas |
644 |
int i = 0; |
6775 |
17 Mar 15 |
nicklas |
645 |
for (int childId : children) |
5663 |
22 Jun 11 |
nicklas |
646 |
{ |
6775 |
17 Mar 15 |
nicklas |
647 |
write_item(i, Extract.getById(dc, childId)); |
5663 |
22 Jun 11 |
nicklas |
648 |
i++; |
5663 |
22 Jun 11 |
nicklas |
649 |
} |
5663 |
22 Jun 11 |
nicklas |
650 |
if (expectedResults >= 0 && expectedResults != children.size()) |
5663 |
22 Jun 11 |
nicklas |
651 |
{ |
5663 |
22 Jun 11 |
nicklas |
652 |
throw new BaseException("Expected "+expectedResults+" results, not "+children.size()); |
5663 |
22 Jun 11 |
nicklas |
653 |
} |
5663 |
22 Jun 11 |
nicklas |
654 |
write("--List extracts for sample using transformer OK ("+children.size()+")"); |
5663 |
22 Jun 11 |
nicklas |
655 |
} |
5663 |
22 Jun 11 |
nicklas |
656 |
catch (Throwable ex) |
5663 |
22 Jun 11 |
nicklas |
657 |
{ |
5663 |
22 Jun 11 |
nicklas |
658 |
write("--List extracts for sample using transformer FAILED"); |
5663 |
22 Jun 11 |
nicklas |
659 |
ex.printStackTrace(); |
5663 |
22 Jun 11 |
nicklas |
660 |
ok = false; |
5663 |
22 Jun 11 |
nicklas |
661 |
} |
5663 |
22 Jun 11 |
nicklas |
662 |
finally |
5663 |
22 Jun 11 |
nicklas |
663 |
{ |
5663 |
22 Jun 11 |
nicklas |
664 |
if (dc != null) dc.close(); |
5663 |
22 Jun 11 |
nicklas |
665 |
} |
5663 |
22 Jun 11 |
nicklas |
666 |
} |
5663 |
22 Jun 11 |
nicklas |
667 |
|
5663 |
22 Jun 11 |
nicklas |
668 |
|
802 |
21 Jun 05 |
nicklas |
669 |
} |