1557 |
02 Nov 05 |
enell |
1 |
/* |
1557 |
02 Nov 05 |
enell |
$Id$ |
1557 |
02 Nov 05 |
enell |
3 |
|
3675 |
16 Aug 07 |
jari |
Copyright (C) 2005 Johan Enell, Nicklas Nordborg |
4889 |
06 Apr 09 |
nicklas |
Copyright (C) 2006 Johan Enell, Jari Häkkinen, Nicklas Nordborg |
3675 |
16 Aug 07 |
jari |
Copyright (C) 2007 Nicklas Nordborg |
1557 |
02 Nov 05 |
enell |
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/ |
1557 |
02 Nov 05 |
enell |
10 |
|
1557 |
02 Nov 05 |
enell |
BASE is free software; you can redistribute it and/or |
1557 |
02 Nov 05 |
enell |
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 |
1557 |
02 Nov 05 |
enell |
of the License, or (at your option) any later version. |
1557 |
02 Nov 05 |
enell |
15 |
|
1557 |
02 Nov 05 |
enell |
BASE is distributed in the hope that it will be useful, |
1557 |
02 Nov 05 |
enell |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1557 |
02 Nov 05 |
enell |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1557 |
02 Nov 05 |
enell |
GNU General Public License for more details. |
1557 |
02 Nov 05 |
enell |
20 |
|
1557 |
02 Nov 05 |
enell |
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/>. |
1557 |
02 Nov 05 |
enell |
23 |
*/ |
1557 |
02 Nov 05 |
enell |
24 |
import net.sf.basedb.core.BaseException; |
1557 |
02 Nov 05 |
enell |
25 |
import net.sf.basedb.core.DbControl; |
1557 |
02 Nov 05 |
enell |
26 |
import net.sf.basedb.core.File; |
1557 |
02 Nov 05 |
enell |
27 |
import net.sf.basedb.core.Item; |
1557 |
02 Nov 05 |
enell |
28 |
import net.sf.basedb.core.Job; |
1557 |
02 Nov 05 |
enell |
29 |
import net.sf.basedb.core.ParameterType; |
1557 |
02 Nov 05 |
enell |
30 |
import net.sf.basedb.core.Permission; |
1557 |
02 Nov 05 |
enell |
31 |
import net.sf.basedb.core.PlateType; |
1557 |
02 Nov 05 |
enell |
32 |
import net.sf.basedb.core.PluginConfiguration; |
1557 |
02 Nov 05 |
enell |
33 |
import net.sf.basedb.core.PluginConfigurationRequest; |
1557 |
02 Nov 05 |
enell |
34 |
import net.sf.basedb.core.PluginDefinition; |
1557 |
02 Nov 05 |
enell |
35 |
import net.sf.basedb.core.PluginParameter; |
1557 |
02 Nov 05 |
enell |
36 |
import net.sf.basedb.core.PluginResponse; |
1557 |
02 Nov 05 |
enell |
37 |
import net.sf.basedb.core.RequestInformation; |
1557 |
02 Nov 05 |
enell |
38 |
import net.sf.basedb.core.plugin.Response; |
1557 |
02 Nov 05 |
enell |
39 |
|
1557 |
02 Nov 05 |
enell |
40 |
public class TestPlateFlatFileImporter |
1557 |
02 Nov 05 |
enell |
41 |
{ |
1557 |
02 Nov 05 |
enell |
42 |
static boolean ok = true; |
1557 |
02 Nov 05 |
enell |
43 |
|
1557 |
02 Nov 05 |
enell |
44 |
public static void main(String[] args) |
1557 |
02 Nov 05 |
enell |
45 |
{ |
1557 |
02 Nov 05 |
enell |
46 |
TestUtil.checkArgs(args); |
1557 |
02 Nov 05 |
enell |
47 |
TestUtil.begin(); |
1557 |
02 Nov 05 |
enell |
48 |
test_all(); |
1557 |
02 Nov 05 |
enell |
49 |
TestUtil.stop(); |
1557 |
02 Nov 05 |
enell |
50 |
} |
1557 |
02 Nov 05 |
enell |
51 |
|
1557 |
02 Nov 05 |
enell |
52 |
static boolean test_all() |
1557 |
02 Nov 05 |
enell |
53 |
{ |
1557 |
02 Nov 05 |
enell |
54 |
write("++Testing plate import using plugin"); |
1557 |
02 Nov 05 |
enell |
55 |
int pluginDefinitionId = TestPluginDefinition.test_get("net.sf.basedb.plugins.PlateFlatFileImporter"); |
1557 |
02 Nov 05 |
enell |
// Test 96 well plate |
1557 |
02 Nov 05 |
enell |
// Create upload file and platetype |
3626 |
03 Aug 07 |
nicklas |
58 |
TestReporter.test_import_from_file("data/test.plate96.import.txt", "Plate\\tRow\\tColumn\\tCluster ID\\tClone ID\\tGene Symbol\\tBarcode", "\\t", 4, 5); |
3719 |
12 Sep 07 |
nicklas |
59 |
int fileId = TestFile.test_create("data/test.plate96.import.txt", false, false); |
1557 |
02 Nov 05 |
enell |
60 |
int plateGeometry = TestPlateGeometry.test_create(8, 12, false); |
1557 |
02 Nov 05 |
enell |
61 |
int plateTypeId = TestPlateType.test_create(plateGeometry, false); |
1557 |
02 Nov 05 |
enell |
62 |
|
1557 |
02 Nov 05 |
enell |
// Create plugin configuration and job |
1557 |
02 Nov 05 |
enell |
64 |
int pluginConfigurationId = test_create_configuration96(pluginDefinitionId); |
1557 |
02 Nov 05 |
enell |
65 |
TestPluginConfiguration.test_load(pluginConfigurationId); |
1557 |
02 Nov 05 |
enell |
66 |
int jobId = test_create_job(pluginConfigurationId, fileId, plateTypeId); |
1557 |
02 Nov 05 |
enell |
67 |
|
1557 |
02 Nov 05 |
enell |
// Execute job |
5319 |
20 Apr 10 |
nicklas |
69 |
ok &= TestJob.test_execute(jobId, false); |
1557 |
02 Nov 05 |
enell |
70 |
|
1557 |
02 Nov 05 |
enell |
// Test: list the result |
1557 |
02 Nov 05 |
enell |
72 |
TestPlate.write_header(); |
1557 |
02 Nov 05 |
enell |
73 |
TestPlate.test_list(-1); |
1557 |
02 Nov 05 |
enell |
74 |
|
1557 |
02 Nov 05 |
enell |
75 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
1557 |
02 Nov 05 |
enell |
76 |
|
1557 |
02 Nov 05 |
enell |
// Cleanup |
1557 |
02 Nov 05 |
enell |
78 |
TestJob.test_delete(jobId); |
1557 |
02 Nov 05 |
enell |
79 |
TestPluginConfiguration.test_delete(pluginConfigurationId); |
1568 |
04 Nov 05 |
enell |
80 |
TestPlate.test_delete_all(); |
1557 |
02 Nov 05 |
enell |
81 |
TestPlateType.test_delete(plateTypeId); |
1557 |
02 Nov 05 |
enell |
82 |
TestPlateGeometry.test_delete(plateGeometry); |
1557 |
02 Nov 05 |
enell |
83 |
TestReporter.test_delete(); |
1557 |
02 Nov 05 |
enell |
84 |
TestFile.test_delete(fileId); |
1557 |
02 Nov 05 |
enell |
85 |
|
1627 |
17 Nov 05 |
enell |
86 |
write("++Testing plate import using plugin "+(ok ? "OK" : "Failed")+"\n"); |
1557 |
02 Nov 05 |
enell |
87 |
return ok; |
1557 |
02 Nov 05 |
enell |
88 |
} |
1557 |
02 Nov 05 |
enell |
89 |
|
1557 |
02 Nov 05 |
enell |
90 |
static int test_create_configuration96(int pluginDefinitionId) |
1557 |
02 Nov 05 |
enell |
91 |
{ |
1557 |
02 Nov 05 |
enell |
92 |
if (pluginDefinitionId == 0 || !TestUtil.hasPermission(Permission.CREATE, Item.PLUGINCONFIGURATION)) return 0; |
1557 |
02 Nov 05 |
enell |
93 |
int id = 0; |
1557 |
02 Nov 05 |
enell |
94 |
DbControl dc = null; |
1557 |
02 Nov 05 |
enell |
95 |
try |
1557 |
02 Nov 05 |
enell |
96 |
{ |
1557 |
02 Nov 05 |
enell |
97 |
dc = TestUtil.getDbControl(); |
1557 |
02 Nov 05 |
enell |
98 |
|
1557 |
02 Nov 05 |
enell |
99 |
PluginDefinition pd = PluginDefinition.getById(dc, pluginDefinitionId); |
1557 |
02 Nov 05 |
enell |
100 |
PluginConfiguration pc = pd.newPluginConfiguration(); |
1557 |
02 Nov 05 |
enell |
101 |
pc.setName(pd.getName()); |
1557 |
02 Nov 05 |
enell |
102 |
|
1557 |
02 Nov 05 |
enell |
103 |
PluginConfigurationRequest request = pc.configure(); |
1557 |
02 Nov 05 |
enell |
104 |
|
1557 |
02 Nov 05 |
enell |
105 |
write_request_information(request.getRequestInformation()); |
1557 |
02 Nov 05 |
enell |
106 |
|
2203 |
28 Apr 06 |
nicklas |
107 |
request.setParameterValue("dataSplitterRegexp", "\\t"); |
1557 |
02 Nov 05 |
enell |
108 |
request.setParameterValue("dataHeaderRegexp", "Plate.*"); |
1557 |
02 Nov 05 |
enell |
109 |
|
2203 |
28 Apr 06 |
nicklas |
110 |
request.setParameterValue("nameColumnMapping", "\\Plate\\"); |
2203 |
28 Apr 06 |
nicklas |
111 |
request.setParameterValue("rowColumnMapping", "\\Row\\"); |
2203 |
28 Apr 06 |
nicklas |
112 |
request.setParameterValue("columnColumnMapping", "\\Column\\"); |
2203 |
28 Apr 06 |
nicklas |
113 |
request.setParameterValue("reporterColumnMapping", "\\Clone ID\\"); |
2203 |
28 Apr 06 |
nicklas |
114 |
request.setParameterValue("barcodeColumnMapping", "\\Barcode\\"); |
1557 |
02 Nov 05 |
enell |
115 |
|
1557 |
02 Nov 05 |
enell |
116 |
request.setParameterValue("minDataColumns", 7); |
1557 |
02 Nov 05 |
enell |
117 |
request.setParameterValue("maxDataColumns", 7); |
1557 |
02 Nov 05 |
enell |
118 |
|
1557 |
02 Nov 05 |
enell |
119 |
PluginResponse response = request.invoke(); |
1557 |
02 Nov 05 |
enell |
120 |
if (response.getStatus() == Response.Status.DONE) |
1557 |
02 Nov 05 |
enell |
121 |
{ |
1780 |
17 Jan 06 |
nicklas |
122 |
response.saveParameters(dc); |
1557 |
02 Nov 05 |
enell |
123 |
dc.saveItem(pc); |
1557 |
02 Nov 05 |
enell |
124 |
dc.commit(); |
1557 |
02 Nov 05 |
enell |
125 |
} |
1557 |
02 Nov 05 |
enell |
126 |
else |
1557 |
02 Nov 05 |
enell |
127 |
{ |
1622 |
16 Nov 05 |
nicklas |
128 |
throw new BaseException(response.getMessage(), response.getErrorList().get(0)); |
1557 |
02 Nov 05 |
enell |
129 |
} |
1557 |
02 Nov 05 |
enell |
130 |
id = pc.getId(); |
1557 |
02 Nov 05 |
enell |
131 |
write("--Create configuration for 96 plate import OK"); |
1557 |
02 Nov 05 |
enell |
132 |
} |
1557 |
02 Nov 05 |
enell |
133 |
catch (Throwable ex) |
1557 |
02 Nov 05 |
enell |
134 |
{ |
1557 |
02 Nov 05 |
enell |
135 |
write("--Create configuration for 96 plate import FAILED"); |
1557 |
02 Nov 05 |
enell |
136 |
ex.printStackTrace(); |
1557 |
02 Nov 05 |
enell |
137 |
ok = false; |
1557 |
02 Nov 05 |
enell |
138 |
} |
1557 |
02 Nov 05 |
enell |
139 |
finally |
1557 |
02 Nov 05 |
enell |
140 |
{ |
1557 |
02 Nov 05 |
enell |
141 |
if (dc != null) dc.close(); |
1557 |
02 Nov 05 |
enell |
142 |
} |
1557 |
02 Nov 05 |
enell |
143 |
return id; |
1557 |
02 Nov 05 |
enell |
144 |
} |
1557 |
02 Nov 05 |
enell |
145 |
|
1557 |
02 Nov 05 |
enell |
146 |
static int test_create_job(int pluginConfigurationId, int fileId, int plateTypeId) |
1557 |
02 Nov 05 |
enell |
147 |
{ |
1557 |
02 Nov 05 |
enell |
148 |
if (plateTypeId == 0 || pluginConfigurationId == 0 || fileId == 0 || !TestUtil.hasPermission(Permission.CREATE, Item.JOB)) return 0; |
1557 |
02 Nov 05 |
enell |
149 |
int id = 0; |
1557 |
02 Nov 05 |
enell |
150 |
DbControl dc = null; |
1557 |
02 Nov 05 |
enell |
151 |
try |
1557 |
02 Nov 05 |
enell |
152 |
{ |
1557 |
02 Nov 05 |
enell |
153 |
dc = TestUtil.getDbControl(); |
1557 |
02 Nov 05 |
enell |
154 |
|
1557 |
02 Nov 05 |
enell |
155 |
PluginConfiguration pc = PluginConfiguration.getById(dc, pluginConfigurationId); |
4254 |
28 Apr 08 |
nicklas |
156 |
Job j = pc.newJob(null); |
1557 |
02 Nov 05 |
enell |
157 |
j.setName(pc.getName()); |
1557 |
02 Nov 05 |
enell |
158 |
|
1789 |
18 Jan 06 |
nicklas |
159 |
PluginConfigurationRequest request = j.configure(null); |
1557 |
02 Nov 05 |
enell |
160 |
write_request_information(request.getRequestInformation()); |
1557 |
02 Nov 05 |
enell |
161 |
request.setParameterValue("file", File.getById(dc, fileId)); |
1557 |
02 Nov 05 |
enell |
162 |
request.setParameterValue("plateType", PlateType.getById(dc, plateTypeId)); |
1557 |
02 Nov 05 |
enell |
163 |
|
1557 |
02 Nov 05 |
enell |
164 |
PluginResponse response = request.invoke(); |
1557 |
02 Nov 05 |
enell |
165 |
if (response.getStatus() == Response.Status.DONE) |
1557 |
02 Nov 05 |
enell |
166 |
{ |
1780 |
17 Jan 06 |
nicklas |
167 |
response.saveParameters(dc); |
1557 |
02 Nov 05 |
enell |
168 |
dc.saveItem(j); |
1557 |
02 Nov 05 |
enell |
169 |
dc.commit(); |
1557 |
02 Nov 05 |
enell |
170 |
} |
1557 |
02 Nov 05 |
enell |
171 |
else |
1557 |
02 Nov 05 |
enell |
172 |
{ |
1622 |
16 Nov 05 |
nicklas |
173 |
throw new BaseException(response.getMessage(), response.getErrorList().get(0)); |
1557 |
02 Nov 05 |
enell |
174 |
} |
1557 |
02 Nov 05 |
enell |
175 |
id = j.getId(); |
1789 |
18 Jan 06 |
nicklas |
176 |
write("--Create job for plate import OK"); |
1557 |
02 Nov 05 |
enell |
177 |
} |
1557 |
02 Nov 05 |
enell |
178 |
catch (Throwable ex) |
1557 |
02 Nov 05 |
enell |
179 |
{ |
1789 |
18 Jan 06 |
nicklas |
180 |
write("--Create job for plate import FAILED"); |
1557 |
02 Nov 05 |
enell |
181 |
ex.printStackTrace(); |
1557 |
02 Nov 05 |
enell |
182 |
ok = false; |
1557 |
02 Nov 05 |
enell |
183 |
} |
1557 |
02 Nov 05 |
enell |
184 |
finally |
1557 |
02 Nov 05 |
enell |
185 |
{ |
1557 |
02 Nov 05 |
enell |
186 |
if (dc != null) dc.close(); |
1557 |
02 Nov 05 |
enell |
187 |
} |
1557 |
02 Nov 05 |
enell |
188 |
return id; |
1557 |
02 Nov 05 |
enell |
189 |
} |
1557 |
02 Nov 05 |
enell |
190 |
|
1557 |
02 Nov 05 |
enell |
191 |
static void write(String message) |
1557 |
02 Nov 05 |
enell |
192 |
{ |
1557 |
02 Nov 05 |
enell |
193 |
System.out.println(message); |
1557 |
02 Nov 05 |
enell |
194 |
} |
1557 |
02 Nov 05 |
enell |
195 |
|
1557 |
02 Nov 05 |
enell |
196 |
|
1557 |
02 Nov 05 |
enell |
197 |
static void write_request_information(RequestInformation ri) |
1557 |
02 Nov 05 |
enell |
198 |
{ |
1557 |
02 Nov 05 |
enell |
199 |
if (TestUtil.getSilent()) return; |
1557 |
02 Nov 05 |
enell |
200 |
|
1557 |
02 Nov 05 |
enell |
201 |
write("Request information for command: "+ri.getCommand()); |
1557 |
02 Nov 05 |
enell |
202 |
write("\tTitle:\t"+ri.getTitle()); |
1557 |
02 Nov 05 |
enell |
203 |
write("\tDescription:\t"+ri.getDescription()); |
6875 |
20 Apr 15 |
nicklas |
204 |
for (PluginParameter<?> pp : ri.getParameters()) |
1557 |
02 Nov 05 |
enell |
205 |
{ |
6875 |
20 Apr 15 |
nicklas |
206 |
ParameterType<?> pt = pp.getParameterType(); |
1557 |
02 Nov 05 |
enell |
207 |
System.out.println("\tParameter:\t"+pp.getName() + "\t" + pp.getLabel() + "\t" + pt ); |
1557 |
02 Nov 05 |
enell |
208 |
} |
1557 |
02 Nov 05 |
enell |
209 |
} |
1557 |
02 Nov 05 |
enell |
210 |
} |