1783 |
18 Jan 06 |
enell |
1 |
import net.sf.basedb.core.BaseException; |
1783 |
18 Jan 06 |
enell |
2 |
import net.sf.basedb.core.DbControl; |
1783 |
18 Jan 06 |
enell |
3 |
import net.sf.basedb.core.File; |
1783 |
18 Jan 06 |
enell |
4 |
import net.sf.basedb.core.Item; |
1783 |
18 Jan 06 |
enell |
5 |
import net.sf.basedb.core.Job; |
1783 |
18 Jan 06 |
enell |
6 |
import net.sf.basedb.core.ParameterType; |
1783 |
18 Jan 06 |
enell |
7 |
import net.sf.basedb.core.Permission; |
1783 |
18 Jan 06 |
enell |
8 |
import net.sf.basedb.core.PluginConfiguration; |
1783 |
18 Jan 06 |
enell |
9 |
import net.sf.basedb.core.PluginConfigurationRequest; |
1783 |
18 Jan 06 |
enell |
10 |
import net.sf.basedb.core.PluginDefinition; |
1783 |
18 Jan 06 |
enell |
11 |
import net.sf.basedb.core.PluginParameter; |
1783 |
18 Jan 06 |
enell |
12 |
import net.sf.basedb.core.PluginResponse; |
1783 |
18 Jan 06 |
enell |
13 |
import net.sf.basedb.core.ReporterType; |
1783 |
18 Jan 06 |
enell |
14 |
import net.sf.basedb.core.RequestInformation; |
3596 |
24 Jul 07 |
nicklas |
15 |
import net.sf.basedb.core.plugin.GuiContext; |
1783 |
18 Jan 06 |
enell |
16 |
import net.sf.basedb.core.plugin.Response; |
1783 |
18 Jan 06 |
enell |
17 |
|
1256 |
06 Sep 05 |
nicklas |
18 |
/* |
1256 |
06 Sep 05 |
nicklas |
$Id$ |
1256 |
06 Sep 05 |
nicklas |
20 |
|
3675 |
16 Aug 07 |
jari |
Copyright (C) 2005 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 |
1256 |
06 Sep 05 |
nicklas |
24 |
|
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/ |
1256 |
06 Sep 05 |
nicklas |
27 |
|
1256 |
06 Sep 05 |
nicklas |
BASE is free software; you can redistribute it and/or |
1256 |
06 Sep 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 |
1256 |
06 Sep 05 |
nicklas |
of the License, or (at your option) any later version. |
1256 |
06 Sep 05 |
nicklas |
32 |
|
1256 |
06 Sep 05 |
nicklas |
BASE is distributed in the hope that it will be useful, |
1256 |
06 Sep 05 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1256 |
06 Sep 05 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1256 |
06 Sep 05 |
nicklas |
GNU General Public License for more details. |
1256 |
06 Sep 05 |
nicklas |
37 |
|
1256 |
06 Sep 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/>. |
1256 |
06 Sep 05 |
nicklas |
40 |
*/ |
1256 |
06 Sep 05 |
nicklas |
41 |
|
1256 |
06 Sep 05 |
nicklas |
42 |
public class TestReporterFlatFileImporter |
1256 |
06 Sep 05 |
nicklas |
43 |
{ |
1256 |
06 Sep 05 |
nicklas |
44 |
static boolean ok = true; |
1256 |
06 Sep 05 |
nicklas |
45 |
|
1256 |
06 Sep 05 |
nicklas |
46 |
public static void main(String[] args) |
1256 |
06 Sep 05 |
nicklas |
47 |
{ |
1256 |
06 Sep 05 |
nicklas |
48 |
TestUtil.checkArgs(args); |
1256 |
06 Sep 05 |
nicklas |
49 |
TestUtil.begin(); |
1256 |
06 Sep 05 |
nicklas |
50 |
test_all(); |
1256 |
06 Sep 05 |
nicklas |
51 |
TestUtil.stop(); |
1256 |
06 Sep 05 |
nicklas |
52 |
} |
1256 |
06 Sep 05 |
nicklas |
53 |
|
1256 |
06 Sep 05 |
nicklas |
54 |
static boolean test_all() |
1256 |
06 Sep 05 |
nicklas |
55 |
{ |
1265 |
06 Sep 05 |
nicklas |
56 |
write("++Testing reporter import using plugin"); |
1263 |
06 Sep 05 |
nicklas |
// Create reporter type and upload file |
1263 |
06 Sep 05 |
nicklas |
58 |
int reporterTypeId = TestReporterType.test_create(); |
3719 |
12 Sep 07 |
nicklas |
59 |
int fileId = TestFile.test_create("data/test.reporter.import.txt", false, false); |
1263 |
06 Sep 05 |
nicklas |
60 |
|
1263 |
06 Sep 05 |
nicklas |
// Create plugin configuration and job |
1256 |
06 Sep 05 |
nicklas |
62 |
int pluginDefinitionId = TestPluginDefinition.test_get("net.sf.basedb.plugins.ReporterFlatFileImporter"); |
1256 |
06 Sep 05 |
nicklas |
63 |
int pluginConfigurationId = test_create_configuration(pluginDefinitionId, reporterTypeId); |
1265 |
06 Sep 05 |
nicklas |
64 |
TestPluginConfiguration.test_load(pluginConfigurationId); |
3596 |
24 Jul 07 |
nicklas |
65 |
int jobId = test_create_job(pluginConfigurationId, fileId, "update"); |
1256 |
06 Sep 05 |
nicklas |
66 |
|
1256 |
06 Sep 05 |
nicklas |
// Execute job |
5319 |
20 Apr 10 |
nicklas |
68 |
ok &= TestJob.test_execute(jobId, false); |
1256 |
06 Sep 05 |
nicklas |
69 |
|
1256 |
06 Sep 05 |
nicklas |
// Test: list the result |
1293 |
08 Sep 05 |
nicklas |
71 |
TestReporter.write_header(); |
1256 |
06 Sep 05 |
nicklas |
72 |
TestReporter.test_list(-1); |
1529 |
27 Oct 05 |
nicklas |
73 |
|
1529 |
27 Oct 05 |
nicklas |
74 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
3596 |
24 Jul 07 |
nicklas |
75 |
int jobId2 = test_create_job(pluginConfigurationId, fileId, "delete"); |
5319 |
20 Apr 10 |
nicklas |
76 |
ok &= TestJob.test_execute(jobId2, false); |
3596 |
24 Jul 07 |
nicklas |
77 |
|
1258 |
06 Sep 05 |
nicklas |
78 |
TestJob.test_delete(jobId); |
3596 |
24 Jul 07 |
nicklas |
79 |
TestJob.test_delete(jobId2); |
1256 |
06 Sep 05 |
nicklas |
80 |
TestPluginConfiguration.test_delete(pluginConfigurationId); |
1256 |
06 Sep 05 |
nicklas |
81 |
TestFile.test_delete(fileId); |
1256 |
06 Sep 05 |
nicklas |
82 |
TestReporterType.test_delete(reporterTypeId); |
1256 |
06 Sep 05 |
nicklas |
83 |
|
1265 |
06 Sep 05 |
nicklas |
84 |
write("++Testing reporter import using plugin "+(ok ? "OK" : "Failed")+"\n"); |
1256 |
06 Sep 05 |
nicklas |
85 |
return ok; |
1256 |
06 Sep 05 |
nicklas |
86 |
} |
1256 |
06 Sep 05 |
nicklas |
87 |
|
1256 |
06 Sep 05 |
nicklas |
88 |
static int test_create_configuration(int pluginDefinitionId, int reporterTypeId) |
1256 |
06 Sep 05 |
nicklas |
89 |
{ |
1256 |
06 Sep 05 |
nicklas |
90 |
if (pluginDefinitionId == 0 || !TestUtil.hasPermission(Permission.CREATE, Item.PLUGINCONFIGURATION)) return 0; |
1256 |
06 Sep 05 |
nicklas |
91 |
int id = 0; |
1256 |
06 Sep 05 |
nicklas |
92 |
DbControl dc = null; |
1256 |
06 Sep 05 |
nicklas |
93 |
try |
1256 |
06 Sep 05 |
nicklas |
94 |
{ |
1256 |
06 Sep 05 |
nicklas |
95 |
dc = TestUtil.getDbControl(); |
1256 |
06 Sep 05 |
nicklas |
96 |
|
1256 |
06 Sep 05 |
nicklas |
97 |
PluginDefinition pd = PluginDefinition.getById(dc, pluginDefinitionId); |
1256 |
06 Sep 05 |
nicklas |
98 |
PluginConfiguration pc = pd.newPluginConfiguration(); |
1256 |
06 Sep 05 |
nicklas |
99 |
pc.setName(pd.getName()); |
1256 |
06 Sep 05 |
nicklas |
100 |
|
1376 |
22 Sep 05 |
nicklas |
101 |
PluginConfigurationRequest request = pc.configure(); |
1256 |
06 Sep 05 |
nicklas |
102 |
|
1256 |
06 Sep 05 |
nicklas |
103 |
write_request_information(request.getRequestInformation()); |
1256 |
06 Sep 05 |
nicklas |
104 |
|
2203 |
28 Apr 06 |
nicklas |
105 |
request.setParameterValue("dataSplitterRegexp", "\\t"); |
1256 |
06 Sep 05 |
nicklas |
106 |
request.setParameterValue("dataHeaderRegexp", "Reporter ID\\tCluster\\tGene sym.*"); |
2203 |
28 Apr 06 |
nicklas |
107 |
request.setParameterValue("reporterIdColumnMapping", "\\Reporter ID\\"); |
2203 |
28 Apr 06 |
nicklas |
108 |
request.setParameterValue("nameColumnMapping", "\\Reporter name\\"); |
2203 |
28 Apr 06 |
nicklas |
109 |
request.setParameterValue("symbolColumnMapping", "\\Gene sym.\\"); |
2203 |
28 Apr 06 |
nicklas |
110 |
request.setParameterValue("extendedColumnMapping.clusterId", "\\Cluster\\"); |
1265 |
06 Sep 05 |
nicklas |
111 |
request.setParameterValue("extendedColumnMapping.sequence", "\\5\\"); |
1265 |
06 Sep 05 |
nicklas |
112 |
request.setParameterValue("extendedColumnMapping.vector", "\\6\\"); |
1265 |
06 Sep 05 |
nicklas |
113 |
request.setParameterValue("extendedColumnMapping.tissue", "\\7\\"); |
1265 |
06 Sep 05 |
nicklas |
114 |
request.setParameterValue("extendedColumnMapping.library", "\\8\\"); |
1265 |
06 Sep 05 |
nicklas |
115 |
request.setParameterValue("extendedColumnMapping.accession", "\\9\\"); |
1265 |
06 Sep 05 |
nicklas |
116 |
request.setParameterValue("extendedColumnMapping.nid", "\\10\\"); |
1265 |
06 Sep 05 |
nicklas |
117 |
request.setParameterValue("extendedColumnMapping.chromosome", "\\11\\"); |
1265 |
06 Sep 05 |
nicklas |
118 |
request.setParameterValue("extendedColumnMapping.cytoband", "\\12\\"); |
1265 |
06 Sep 05 |
nicklas |
119 |
request.setParameterValue("extendedColumnMapping.markers", "\\13\\"); |
1265 |
06 Sep 05 |
nicklas |
120 |
request.setParameterValue("extendedColumnMapping.antibiotics", "\\14\\"); |
1265 |
06 Sep 05 |
nicklas |
121 |
request.setParameterValue("extendedColumnMapping.locusLink", "\\15\\"); |
1275 |
08 Sep 05 |
nicklas |
122 |
request.setParameterValue("minDataColumns", 20); |
1275 |
08 Sep 05 |
nicklas |
123 |
request.setParameterValue("maxDataColumns", 20); |
1256 |
06 Sep 05 |
nicklas |
124 |
if (reporterTypeId != 0) |
1256 |
06 Sep 05 |
nicklas |
125 |
{ |
1256 |
06 Sep 05 |
nicklas |
126 |
request.setParameterValue("reporterType", ReporterType.getById(dc, reporterTypeId)); |
1256 |
06 Sep 05 |
nicklas |
127 |
} |
1256 |
06 Sep 05 |
nicklas |
128 |
|
1256 |
06 Sep 05 |
nicklas |
129 |
PluginResponse response = request.invoke(); |
1256 |
06 Sep 05 |
nicklas |
130 |
if (response.getStatus() == Response.Status.DONE) |
1256 |
06 Sep 05 |
nicklas |
131 |
{ |
1779 |
17 Jan 06 |
nicklas |
132 |
response.saveParameters(dc); |
1256 |
06 Sep 05 |
nicklas |
133 |
dc.saveItem(pc); |
1256 |
06 Sep 05 |
nicklas |
134 |
dc.commit(); |
1256 |
06 Sep 05 |
nicklas |
135 |
} |
1256 |
06 Sep 05 |
nicklas |
136 |
else |
1256 |
06 Sep 05 |
nicklas |
137 |
{ |
1622 |
16 Nov 05 |
nicklas |
138 |
throw new BaseException(response.getMessage(), response.getErrorList().get(0)); |
1256 |
06 Sep 05 |
nicklas |
139 |
} |
1256 |
06 Sep 05 |
nicklas |
140 |
id = pc.getId(); |
1256 |
06 Sep 05 |
nicklas |
141 |
write("--Create configuration for reporter import OK"); |
1256 |
06 Sep 05 |
nicklas |
142 |
} |
1256 |
06 Sep 05 |
nicklas |
143 |
catch (Throwable ex) |
1256 |
06 Sep 05 |
nicklas |
144 |
{ |
1256 |
06 Sep 05 |
nicklas |
145 |
write("--Create configuration for reporter import FAILED"); |
1256 |
06 Sep 05 |
nicklas |
146 |
ex.printStackTrace(); |
1256 |
06 Sep 05 |
nicklas |
147 |
ok = false; |
1256 |
06 Sep 05 |
nicklas |
148 |
} |
1256 |
06 Sep 05 |
nicklas |
149 |
finally |
1256 |
06 Sep 05 |
nicklas |
150 |
{ |
1256 |
06 Sep 05 |
nicklas |
151 |
if (dc != null) dc.close(); |
1256 |
06 Sep 05 |
nicklas |
152 |
} |
1256 |
06 Sep 05 |
nicklas |
153 |
return id; |
1256 |
06 Sep 05 |
nicklas |
154 |
} |
1256 |
06 Sep 05 |
nicklas |
155 |
|
3596 |
24 Jul 07 |
nicklas |
156 |
static int test_create_job(int pluginConfigurationId, int fileId, String mode) |
1256 |
06 Sep 05 |
nicklas |
157 |
{ |
1256 |
06 Sep 05 |
nicklas |
158 |
if (pluginConfigurationId == 0 || fileId == 0 || !TestUtil.hasPermission(Permission.CREATE, Item.JOB)) return 0; |
1256 |
06 Sep 05 |
nicklas |
159 |
int id = 0; |
1256 |
06 Sep 05 |
nicklas |
160 |
DbControl dc = null; |
1256 |
06 Sep 05 |
nicklas |
161 |
try |
1256 |
06 Sep 05 |
nicklas |
162 |
{ |
1256 |
06 Sep 05 |
nicklas |
163 |
dc = TestUtil.getDbControl(); |
1256 |
06 Sep 05 |
nicklas |
164 |
|
1256 |
06 Sep 05 |
nicklas |
165 |
PluginConfiguration pc = PluginConfiguration.getById(dc, pluginConfigurationId); |
4254 |
28 Apr 08 |
nicklas |
166 |
Job j = pc.newJob(null); |
1256 |
06 Sep 05 |
nicklas |
167 |
j.setName(pc.getName()); |
1256 |
06 Sep 05 |
nicklas |
168 |
|
3596 |
24 Jul 07 |
nicklas |
169 |
PluginConfigurationRequest request = j.configure(new GuiContext(Item.REPORTER, GuiContext.Type.LIST)); |
1256 |
06 Sep 05 |
nicklas |
170 |
write_request_information(request.getRequestInformation()); |
6875 |
20 Apr 15 |
nicklas |
171 |
for (PluginParameter<?> pp : request.getRequestInformation().getParameters()) |
5241 |
10 Feb 10 |
nicklas |
172 |
{ |
5241 |
10 Feb 10 |
nicklas |
173 |
Object value = request.getCurrentParameterValue(pp.getName()); |
5241 |
10 Feb 10 |
nicklas |
174 |
if (value != null) request.setParameterValue(pp.getName(), value); |
5241 |
10 Feb 10 |
nicklas |
175 |
} |
1256 |
06 Sep 05 |
nicklas |
176 |
request.setParameterValue("file", File.getById(dc, fileId)); |
3596 |
24 Jul 07 |
nicklas |
177 |
request.setParameterValue("mode", mode); |
2751 |
20 Oct 06 |
nicklas |
178 |
request.setParameterValue("invalidUseOfNullError", "skip"); |
5241 |
10 Feb 10 |
nicklas |
179 |
|
1256 |
06 Sep 05 |
nicklas |
180 |
PluginResponse response = request.invoke(); |
1256 |
06 Sep 05 |
nicklas |
181 |
if (response.getStatus() == Response.Status.DONE) |
1256 |
06 Sep 05 |
nicklas |
182 |
{ |
1779 |
17 Jan 06 |
nicklas |
183 |
response.saveParameters(dc); |
1256 |
06 Sep 05 |
nicklas |
184 |
dc.saveItem(j); |
1256 |
06 Sep 05 |
nicklas |
185 |
dc.commit(); |
1256 |
06 Sep 05 |
nicklas |
186 |
} |
1256 |
06 Sep 05 |
nicklas |
187 |
else |
1256 |
06 Sep 05 |
nicklas |
188 |
{ |
1622 |
16 Nov 05 |
nicklas |
189 |
throw new BaseException(response.getMessage(), response.getErrorList().get(0)); |
1256 |
06 Sep 05 |
nicklas |
190 |
} |
1256 |
06 Sep 05 |
nicklas |
191 |
id = j.getId(); |
3596 |
24 Jul 07 |
nicklas |
192 |
write("--Create job for reporter import (mode="+mode+") OK"); |
1256 |
06 Sep 05 |
nicklas |
193 |
} |
1256 |
06 Sep 05 |
nicklas |
194 |
catch (Throwable ex) |
1256 |
06 Sep 05 |
nicklas |
195 |
{ |
3596 |
24 Jul 07 |
nicklas |
196 |
write("--Create job for reporter import (mode="+mode+") FAILED"); |
1256 |
06 Sep 05 |
nicklas |
197 |
ex.printStackTrace(); |
1256 |
06 Sep 05 |
nicklas |
198 |
ok = false; |
1256 |
06 Sep 05 |
nicklas |
199 |
} |
1256 |
06 Sep 05 |
nicklas |
200 |
finally |
1256 |
06 Sep 05 |
nicklas |
201 |
{ |
1256 |
06 Sep 05 |
nicklas |
202 |
if (dc != null) dc.close(); |
1256 |
06 Sep 05 |
nicklas |
203 |
} |
1256 |
06 Sep 05 |
nicklas |
204 |
return id; |
1256 |
06 Sep 05 |
nicklas |
205 |
} |
1256 |
06 Sep 05 |
nicklas |
206 |
|
1256 |
06 Sep 05 |
nicklas |
207 |
static void write(String message) |
1256 |
06 Sep 05 |
nicklas |
208 |
{ |
1256 |
06 Sep 05 |
nicklas |
209 |
System.out.println(message); |
1256 |
06 Sep 05 |
nicklas |
210 |
} |
1256 |
06 Sep 05 |
nicklas |
211 |
|
1256 |
06 Sep 05 |
nicklas |
212 |
|
1256 |
06 Sep 05 |
nicklas |
213 |
static void write_request_information(RequestInformation ri) |
1256 |
06 Sep 05 |
nicklas |
214 |
{ |
1256 |
06 Sep 05 |
nicklas |
215 |
if (TestUtil.getSilent()) return; |
1256 |
06 Sep 05 |
nicklas |
216 |
|
1265 |
06 Sep 05 |
nicklas |
217 |
write("Request information for command: "+ri.getCommand()); |
1265 |
06 Sep 05 |
nicklas |
218 |
write("\tTitle:\t"+ri.getTitle()); |
1265 |
06 Sep 05 |
nicklas |
219 |
write("\tDescription:\t"+ri.getDescription()); |
1783 |
18 Jan 06 |
enell |
220 |
for (PluginParameter<?> pp : ri.getParameters()) |
1256 |
06 Sep 05 |
nicklas |
221 |
{ |
6875 |
20 Apr 15 |
nicklas |
222 |
ParameterType<?> pt = pp.getParameterType(); |
1265 |
06 Sep 05 |
nicklas |
223 |
System.out.println("\tParameter:\t"+pp.getName() + "\t" + pp.getLabel() + "\t" + pt ); |
1256 |
06 Sep 05 |
nicklas |
224 |
} |
1256 |
06 Sep 05 |
nicklas |
225 |
} |
1256 |
06 Sep 05 |
nicklas |
226 |
} |
1256 |
06 Sep 05 |
nicklas |
227 |
|