1793 |
19 Jan 06 |
enell |
1 |
import java.util.Arrays; |
1793 |
19 Jan 06 |
enell |
2 |
|
1793 |
19 Jan 06 |
enell |
3 |
import net.sf.basedb.core.ArrayDesign; |
1793 |
19 Jan 06 |
enell |
4 |
import net.sf.basedb.core.BaseException; |
1793 |
19 Jan 06 |
enell |
5 |
import net.sf.basedb.core.DbControl; |
1793 |
19 Jan 06 |
enell |
6 |
import net.sf.basedb.core.File; |
1793 |
19 Jan 06 |
enell |
7 |
import net.sf.basedb.core.Item; |
1793 |
19 Jan 06 |
enell |
8 |
import net.sf.basedb.core.Job; |
1793 |
19 Jan 06 |
enell |
9 |
import net.sf.basedb.core.ParameterType; |
1793 |
19 Jan 06 |
enell |
10 |
import net.sf.basedb.core.Permission; |
3820 |
12 Oct 07 |
nicklas |
11 |
import net.sf.basedb.core.Platform; |
1793 |
19 Jan 06 |
enell |
12 |
import net.sf.basedb.core.PluginConfigurationRequest; |
1793 |
19 Jan 06 |
enell |
13 |
import net.sf.basedb.core.PluginDefinition; |
1793 |
19 Jan 06 |
enell |
14 |
import net.sf.basedb.core.PluginParameter; |
1793 |
19 Jan 06 |
enell |
15 |
import net.sf.basedb.core.PluginResponse; |
1793 |
19 Jan 06 |
enell |
16 |
import net.sf.basedb.core.RequestInformation; |
1793 |
19 Jan 06 |
enell |
17 |
import net.sf.basedb.core.plugin.Response; |
1793 |
19 Jan 06 |
enell |
18 |
|
1793 |
19 Jan 06 |
enell |
19 |
/* |
1793 |
19 Jan 06 |
enell |
$Id$ |
1793 |
19 Jan 06 |
enell |
21 |
|
4889 |
06 Apr 09 |
nicklas |
Copyright (C) 2006 Johan Enell, Jari Häkkinen, Nicklas Nordborg |
1793 |
19 Jan 06 |
enell |
23 |
|
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/ |
1793 |
19 Jan 06 |
enell |
26 |
|
1793 |
19 Jan 06 |
enell |
BASE is free software; you can redistribute it and/or |
1793 |
19 Jan 06 |
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 |
1793 |
19 Jan 06 |
enell |
of the License, or (at your option) any later version. |
1793 |
19 Jan 06 |
enell |
31 |
|
1793 |
19 Jan 06 |
enell |
BASE is distributed in the hope that it will be useful, |
1793 |
19 Jan 06 |
enell |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1793 |
19 Jan 06 |
enell |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1793 |
19 Jan 06 |
enell |
GNU General Public License for more details. |
1793 |
19 Jan 06 |
enell |
36 |
|
1793 |
19 Jan 06 |
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/>. |
1793 |
19 Jan 06 |
enell |
39 |
*/ |
1793 |
19 Jan 06 |
enell |
40 |
|
1793 |
19 Jan 06 |
enell |
41 |
/** |
1793 |
19 Jan 06 |
enell |
42 |
|
1793 |
19 Jan 06 |
enell |
@base.modified $Date$ |
1793 |
19 Jan 06 |
enell |
@author Enell |
1793 |
19 Jan 06 |
enell |
@version 2.0 |
1793 |
19 Jan 06 |
enell |
46 |
*/ |
1793 |
19 Jan 06 |
enell |
47 |
public class TestPrintMapFlatFileImporter |
1793 |
19 Jan 06 |
enell |
48 |
{ |
1793 |
19 Jan 06 |
enell |
49 |
static boolean ok = true; |
1793 |
19 Jan 06 |
enell |
50 |
|
1793 |
19 Jan 06 |
enell |
51 |
public static void main(String[] args) |
1793 |
19 Jan 06 |
enell |
52 |
{ |
1793 |
19 Jan 06 |
enell |
53 |
TestUtil.checkArgs(args); |
1793 |
19 Jan 06 |
enell |
54 |
TestUtil.begin(); |
1793 |
19 Jan 06 |
enell |
55 |
test_all(); |
1793 |
19 Jan 06 |
enell |
56 |
TestUtil.stop(); |
1793 |
19 Jan 06 |
enell |
57 |
} |
1793 |
19 Jan 06 |
enell |
58 |
|
1793 |
19 Jan 06 |
enell |
59 |
static boolean test_all() |
1793 |
19 Jan 06 |
enell |
60 |
{ |
1793 |
19 Jan 06 |
enell |
61 |
write("++Testing print map import using plugin"); |
1793 |
19 Jan 06 |
enell |
62 |
|
4239 |
22 Apr 08 |
nicklas |
// Import reporters |
4239 |
22 Apr 08 |
nicklas |
64 |
TestReporter.test_import_from_file("data/test.rawdata.import.txt", "\"Block\"\\t\"Column\"\\t\"Row\"\\t\"Name\"\\t\"ID\".*", "\\t", 4, 3); |
4239 |
22 Apr 08 |
nicklas |
65 |
|
1793 |
19 Jan 06 |
enell |
// Create ArrayDesign needed for print map import |
3820 |
12 Oct 07 |
nicklas |
67 |
int arrayDesignId = TestArrayDesign.test_create(Platform.GENERIC, false); |
1793 |
19 Jan 06 |
enell |
68 |
int plateGeometryId = TestPlateGeometry.test_create(16, 24, false); |
1793 |
19 Jan 06 |
enell |
69 |
int plateTypeId = TestPlateType.test_create(plateGeometryId, false); |
4239 |
22 Apr 08 |
nicklas |
70 |
int plate384 = TestPlate.test_create(plateTypeId, true); |
1793 |
19 Jan 06 |
enell |
71 |
int[] plates = new int[4]; |
1793 |
19 Jan 06 |
enell |
72 |
Arrays.fill(plates, plate384); |
1793 |
19 Jan 06 |
enell |
73 |
TestArrayDesign.test_add_plates(arrayDesignId, plates); |
2512 |
10 Aug 06 |
nicklas |
74 |
TestArrayDesign.test_list_plates(arrayDesignId, 4); |
1793 |
19 Jan 06 |
enell |
75 |
|
2512 |
10 Aug 06 |
nicklas |
// Print map import |
3719 |
12 Sep 07 |
nicklas |
77 |
int fileId = TestFile.test_create("data/test.parse.printmap.tam", false, false); |
1793 |
19 Jan 06 |
enell |
78 |
int printMapPluginDefinitionId = TestPluginDefinition.test_get("net.sf.basedb.plugins.PrintMapFlatFileImporter"); |
2512 |
10 Aug 06 |
nicklas |
79 |
int jobId = test_create_job_printmap(printMapPluginDefinitionId, fileId, arrayDesignId); |
1793 |
19 Jan 06 |
enell |
80 |
|
1793 |
19 Jan 06 |
enell |
// Execute job |
5319 |
20 Apr 10 |
nicklas |
82 |
ok &= TestJob.test_execute(jobId, false); |
1793 |
19 Jan 06 |
enell |
83 |
|
1793 |
19 Jan 06 |
enell |
// Print result |
1793 |
19 Jan 06 |
enell |
85 |
TestArrayDesign.write_feature_header(); |
1793 |
19 Jan 06 |
enell |
86 |
TestArrayDesign.test_list_features(arrayDesignId, -1); |
1793 |
19 Jan 06 |
enell |
87 |
|
1793 |
19 Jan 06 |
enell |
88 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
1793 |
19 Jan 06 |
enell |
89 |
|
4257 |
29 Apr 08 |
nicklas |
90 |
TestArrayDesign.test_delete(arrayDesignId); |
1793 |
19 Jan 06 |
enell |
91 |
TestJob.test_delete(jobId); |
1793 |
19 Jan 06 |
enell |
92 |
TestPlate.test_delete(plate384); |
1793 |
19 Jan 06 |
enell |
93 |
TestPlateType.test_delete(plateTypeId); |
1793 |
19 Jan 06 |
enell |
94 |
TestPlateGeometry.test_delete(plateGeometryId); |
1793 |
19 Jan 06 |
enell |
95 |
TestReporter.test_delete(); |
1793 |
19 Jan 06 |
enell |
96 |
TestFile.test_delete(fileId); |
1793 |
19 Jan 06 |
enell |
97 |
|
1793 |
19 Jan 06 |
enell |
98 |
write("++Testing print map import using plugin "+(ok ? "OK" : "Failed")+"\n"); |
1793 |
19 Jan 06 |
enell |
99 |
return ok; |
1793 |
19 Jan 06 |
enell |
100 |
} |
1793 |
19 Jan 06 |
enell |
101 |
|
1793 |
19 Jan 06 |
enell |
102 |
|
4239 |
22 Apr 08 |
nicklas |
103 |
static int test_create_job_printmap(int pluginDefinitionId, int fileId, int arrayDesignId) |
1793 |
19 Jan 06 |
enell |
104 |
{ |
2512 |
10 Aug 06 |
nicklas |
105 |
if (pluginDefinitionId == 0 || fileId == 0 || arrayDesignId == 0 || !TestUtil.hasPermission(Permission.CREATE, Item.JOB)) return 0; |
1793 |
19 Jan 06 |
enell |
106 |
int id = 0; |
1793 |
19 Jan 06 |
enell |
107 |
DbControl dc = null; |
1793 |
19 Jan 06 |
enell |
108 |
try |
1793 |
19 Jan 06 |
enell |
109 |
{ |
1793 |
19 Jan 06 |
enell |
110 |
dc = TestUtil.getDbControl(); |
1793 |
19 Jan 06 |
enell |
111 |
|
2512 |
10 Aug 06 |
nicklas |
112 |
PluginDefinition pd = PluginDefinition.getById(dc, pluginDefinitionId); |
4254 |
28 Apr 08 |
nicklas |
113 |
Job j = Job.getNew(dc, pd, null, null); |
2512 |
10 Aug 06 |
nicklas |
114 |
j.setName(pd.getName()); |
1793 |
19 Jan 06 |
enell |
115 |
|
1793 |
19 Jan 06 |
enell |
116 |
PluginConfigurationRequest request = j.configure(null); |
1793 |
19 Jan 06 |
enell |
117 |
write_request_information(request.getRequestInformation()); |
1793 |
19 Jan 06 |
enell |
118 |
request.setParameterValue("file", File.getById(dc, fileId)); |
1793 |
19 Jan 06 |
enell |
119 |
request.setParameterValue("arrayDesign", ArrayDesign.getById(dc, arrayDesignId)); |
1793 |
19 Jan 06 |
enell |
120 |
|
1793 |
19 Jan 06 |
enell |
121 |
PluginResponse response = request.invoke(); |
1793 |
19 Jan 06 |
enell |
122 |
if (response.getStatus() == Response.Status.DONE) |
1793 |
19 Jan 06 |
enell |
123 |
{ |
1793 |
19 Jan 06 |
enell |
124 |
response.saveParameters(dc); |
1793 |
19 Jan 06 |
enell |
125 |
dc.saveItem(j); |
1793 |
19 Jan 06 |
enell |
126 |
dc.commit(); |
1793 |
19 Jan 06 |
enell |
127 |
} |
1793 |
19 Jan 06 |
enell |
128 |
else |
1793 |
19 Jan 06 |
enell |
129 |
{ |
1793 |
19 Jan 06 |
enell |
130 |
throw new BaseException(response.getMessage(), response.getErrorList().get(0)); |
1793 |
19 Jan 06 |
enell |
131 |
} |
1793 |
19 Jan 06 |
enell |
132 |
id = j.getId(); |
1793 |
19 Jan 06 |
enell |
133 |
write("--Create job for print map import OK"); |
1793 |
19 Jan 06 |
enell |
134 |
} |
1793 |
19 Jan 06 |
enell |
135 |
catch (Throwable ex) |
1793 |
19 Jan 06 |
enell |
136 |
{ |
1793 |
19 Jan 06 |
enell |
137 |
write("--Create job for print map import FAILED"); |
1793 |
19 Jan 06 |
enell |
138 |
ex.printStackTrace(); |
1793 |
19 Jan 06 |
enell |
139 |
ok = false; |
1793 |
19 Jan 06 |
enell |
140 |
} |
1793 |
19 Jan 06 |
enell |
141 |
finally |
1793 |
19 Jan 06 |
enell |
142 |
{ |
1793 |
19 Jan 06 |
enell |
143 |
if (dc != null) dc.close(); |
1793 |
19 Jan 06 |
enell |
144 |
} |
1793 |
19 Jan 06 |
enell |
145 |
return id; |
1793 |
19 Jan 06 |
enell |
146 |
} |
1793 |
19 Jan 06 |
enell |
147 |
|
1793 |
19 Jan 06 |
enell |
148 |
static void write(String message) |
1793 |
19 Jan 06 |
enell |
149 |
{ |
1793 |
19 Jan 06 |
enell |
150 |
System.out.println(message); |
1793 |
19 Jan 06 |
enell |
151 |
} |
1793 |
19 Jan 06 |
enell |
152 |
|
1793 |
19 Jan 06 |
enell |
153 |
static void write_request_information(RequestInformation ri) |
1793 |
19 Jan 06 |
enell |
154 |
{ |
1793 |
19 Jan 06 |
enell |
155 |
if (TestUtil.getSilent()) return; |
1793 |
19 Jan 06 |
enell |
156 |
|
1793 |
19 Jan 06 |
enell |
157 |
write("Request information for command: "+ri.getCommand()); |
1793 |
19 Jan 06 |
enell |
158 |
write("\tTitle:\t"+ri.getTitle()); |
1793 |
19 Jan 06 |
enell |
159 |
write("\tDescription:\t"+ri.getDescription()); |
2188 |
25 Apr 06 |
nicklas |
160 |
if (ri.getParameters() != null) |
1793 |
19 Jan 06 |
enell |
161 |
{ |
2188 |
25 Apr 06 |
nicklas |
162 |
for (PluginParameter<?> pp : ri.getParameters()) |
2188 |
25 Apr 06 |
nicklas |
163 |
{ |
6875 |
20 Apr 15 |
nicklas |
164 |
ParameterType<?> pt = pp.getParameterType(); |
2188 |
25 Apr 06 |
nicklas |
165 |
write("\tParameter:\t"+pp.getName() + "\t" + pp.getLabel() + "\t" + pt ); |
2188 |
25 Apr 06 |
nicklas |
166 |
} |
1793 |
19 Jan 06 |
enell |
167 |
} |
1793 |
19 Jan 06 |
enell |
168 |
} |
1793 |
19 Jan 06 |
enell |
169 |
} |