5270 |
15 Mar 10 |
nicklas |
1 |
/* |
5270 |
15 Mar 10 |
nicklas |
$Id$ |
5270 |
15 Mar 10 |
nicklas |
3 |
|
5270 |
15 Mar 10 |
nicklas |
Copyright (C) 2010 Nicklas Nordborg |
5270 |
15 Mar 10 |
nicklas |
5 |
|
5270 |
15 Mar 10 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
5270 |
15 Mar 10 |
nicklas |
Available at http://base.thep.lu.se/ |
5270 |
15 Mar 10 |
nicklas |
8 |
|
5270 |
15 Mar 10 |
nicklas |
BASE is free software; you can redistribute it and/or modify it |
5270 |
15 Mar 10 |
nicklas |
under the terms of the GNU General Public License as published by |
5270 |
15 Mar 10 |
nicklas |
the Free Software Foundation; either version 3 of the License, or |
5270 |
15 Mar 10 |
nicklas |
(at your option) any later version. |
5270 |
15 Mar 10 |
nicklas |
13 |
|
5270 |
15 Mar 10 |
nicklas |
BASE is distributed in the hope that it will be useful, but |
5270 |
15 Mar 10 |
nicklas |
WITHOUT ANY WARRANTY; without even the implied warranty of |
5270 |
15 Mar 10 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
5270 |
15 Mar 10 |
nicklas |
General Public License for more details. |
5270 |
15 Mar 10 |
nicklas |
18 |
|
5270 |
15 Mar 10 |
nicklas |
You should have received a copy of the GNU General Public License |
5270 |
15 Mar 10 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5270 |
15 Mar 10 |
nicklas |
21 |
*/ |
5270 |
15 Mar 10 |
nicklas |
22 |
import net.sf.basedb.core.BaseException; |
5270 |
15 Mar 10 |
nicklas |
23 |
import net.sf.basedb.core.BioAssaySet; |
5270 |
15 Mar 10 |
nicklas |
24 |
import net.sf.basedb.core.DbControl; |
5270 |
15 Mar 10 |
nicklas |
25 |
import net.sf.basedb.core.Experiment; |
5270 |
15 Mar 10 |
nicklas |
26 |
import net.sf.basedb.core.Item; |
5270 |
15 Mar 10 |
nicklas |
27 |
import net.sf.basedb.core.Job; |
5270 |
15 Mar 10 |
nicklas |
28 |
import net.sf.basedb.core.Permission; |
5270 |
15 Mar 10 |
nicklas |
29 |
import net.sf.basedb.core.PluginConfiguration; |
5270 |
15 Mar 10 |
nicklas |
30 |
import net.sf.basedb.core.PluginConfigurationRequest; |
5270 |
15 Mar 10 |
nicklas |
31 |
import net.sf.basedb.core.PluginDefinition; |
5270 |
15 Mar 10 |
nicklas |
32 |
import net.sf.basedb.core.PluginResponse; |
5270 |
15 Mar 10 |
nicklas |
33 |
import net.sf.basedb.core.plugin.Response; |
5270 |
15 Mar 10 |
nicklas |
34 |
import net.sf.basedb.plugins.executor.ExternalProgramExecutor; |
5271 |
15 Mar 10 |
nicklas |
35 |
import net.sf.basedb.plugins.util.Parameters; |
5270 |
15 Mar 10 |
nicklas |
36 |
|
5270 |
15 Mar 10 |
nicklas |
37 |
|
5270 |
15 Mar 10 |
nicklas |
38 |
public class TestExternalProgramExecutor |
5270 |
15 Mar 10 |
nicklas |
39 |
{ |
5270 |
15 Mar 10 |
nicklas |
40 |
static boolean ok = true; |
5270 |
15 Mar 10 |
nicklas |
41 |
public static void main(String[] args) |
5270 |
15 Mar 10 |
nicklas |
42 |
{ |
5270 |
15 Mar 10 |
nicklas |
43 |
TestUtil.checkArgs(args); |
5270 |
15 Mar 10 |
nicklas |
44 |
TestUtil.begin(); |
5270 |
15 Mar 10 |
nicklas |
45 |
ok = test_all(); |
5270 |
15 Mar 10 |
nicklas |
46 |
TestUtil.stop(); |
5270 |
15 Mar 10 |
nicklas |
47 |
} |
5270 |
15 Mar 10 |
nicklas |
48 |
|
5270 |
15 Mar 10 |
nicklas |
49 |
static boolean test_all() |
5270 |
15 Mar 10 |
nicklas |
50 |
{ |
5270 |
15 Mar 10 |
nicklas |
51 |
boolean wasSetup = TestAnalyzeUtil.setupExperiment(); |
5270 |
15 Mar 10 |
nicklas |
52 |
write("++Testing External program executor"); |
5270 |
15 Mar 10 |
nicklas |
53 |
|
5270 |
15 Mar 10 |
nicklas |
54 |
try |
5270 |
15 Mar 10 |
nicklas |
55 |
{ |
5270 |
15 Mar 10 |
nicklas |
56 |
int experimentId = TestAnalyzeUtil.getItemId("experiment.genepix"); |
5270 |
15 Mar 10 |
nicklas |
57 |
int rootBasId = TestAnalyzeUtil.getItemId("bioassayset.root"); |
5384 |
13 Aug 10 |
nicklas |
58 |
int cloneId = TestAnalyzeUtil.clone_bioassay_set(rootBasId, "External executor clone"); |
5384 |
13 Aug 10 |
nicklas |
59 |
if (experimentId == 0 || rootBasId == 0 || cloneId == 0) |
5270 |
15 Mar 10 |
nicklas |
60 |
{ |
5270 |
15 Mar 10 |
nicklas |
61 |
ok = false; |
5270 |
15 Mar 10 |
nicklas |
62 |
write("Test experiment was not setup correctly."); |
5270 |
15 Mar 10 |
nicklas |
63 |
return ok; |
5270 |
15 Mar 10 |
nicklas |
64 |
} |
5270 |
15 Mar 10 |
nicklas |
65 |
|
5285 |
24 Mar 10 |
nicklas |
66 |
int directoryId = TestDirectory.test_create(true, "External program executor"); |
5270 |
15 Mar 10 |
nicklas |
67 |
int pluginDefinitionId = TestPluginDefinition.test_get("net.sf.basedb.plugins.executor.ExternalProgramExecutor"); |
5270 |
15 Mar 10 |
nicklas |
68 |
int bfsExporter = TestPluginDefinition.test_get("net.sf.basedb.plugins.executor.BfsExporterSupport"); |
5270 |
15 Mar 10 |
nicklas |
69 |
int bfsImporter = TestPluginDefinition.test_get("net.sf.basedb.plugins.executor.BfsImporterSupport"); |
5375 |
03 Aug 10 |
nicklas |
70 |
int baseFileExporter = TestPluginDefinition.test_get("net.sf.basedb.plugins.executor.BaseFileExporterSupport"); |
5375 |
03 Aug 10 |
nicklas |
71 |
int baseFileImporter = TestPluginDefinition.test_get("net.sf.basedb.plugins.executor.BaseFileImporterSupport"); |
5378 |
03 Aug 10 |
nicklas |
72 |
int fileOnlyImporter = TestPluginDefinition.test_get("net.sf.basedb.plugins.executor.FileOnlyImporterSupport"); |
5375 |
03 Aug 10 |
nicklas |
73 |
|
5285 |
24 Mar 10 |
nicklas |
74 |
String program = TestUtil.isWindows() ? "executeclass.bat" : "executeclass.sh"; |
5375 |
03 Aug 10 |
nicklas |
// If this parameter is TRUE temporary files are not deleted by the test program |
5375 |
03 Aug 10 |
nicklas |
76 |
TestJob.Parameter debugMode = |
5378 |
03 Aug 10 |
nicklas |
77 |
new TestJob.Parameter(ExternalProgramExecutor.PARAMETER_DEBUG_MODE, false); |
5375 |
03 Aug 10 |
nicklas |
78 |
|
5375 |
03 Aug 10 |
nicklas |
// ********* BFS tests ************ |
5277 |
22 Mar 10 |
nicklas |
80 |
TestJob.Parameter reporterFields = new TestJob.Parameter( |
5381 |
05 Aug 10 |
nicklas |
81 |
ExternalProgramExecutor.NAMESPACE_EXPORTER + ".reporterFields", "=property(\"Name\")"); |
5277 |
22 Mar 10 |
nicklas |
82 |
TestJob.Parameter assayFields = new TestJob.Parameter( |
5381 |
05 Aug 10 |
nicklas |
83 |
ExternalProgramExecutor.NAMESPACE_EXPORTER + ".assayFields", "=property(\"Name\")"); |
5277 |
22 Mar 10 |
nicklas |
84 |
TestJob.Parameter spotFields = new TestJob.Parameter( |
5381 |
05 Aug 10 |
nicklas |
85 |
ExternalProgramExecutor.NAMESPACE_EXPORTER + ".spotFields", "=jep(\"ch(1)\", \"Ch 1\", \"int\")\n=jep(\"ch(2)\", \"Ch 2\", \"int\")"); |
5285 |
24 Mar 10 |
nicklas |
86 |
TestJob.Parameter enableExtraFiles = new TestJob.Parameter( |
5285 |
24 Mar 10 |
nicklas |
87 |
ExternalProgramExecutor.NAMESPACE_IMPORTER + ".extraFiles", true); |
5285 |
24 Mar 10 |
nicklas |
88 |
|
5270 |
15 Mar 10 |
nicklas |
89 |
int cloneBFS = test_create_configuration(pluginDefinitionId, "BFS copy", |
5375 |
03 Aug 10 |
nicklas |
90 |
program, "CopyStdin2Stdout", bfsExporter, bfsImporter, |
5375 |
03 Aug 10 |
nicklas |
91 |
debugMode, reporterFields, spotFields, assayFields); |
5270 |
15 Mar 10 |
nicklas |
92 |
int errorBFS = test_create_configuration(pluginDefinitionId, "BFS error", |
5375 |
03 Aug 10 |
nicklas |
93 |
program, "CopyStdin2Stdout error", bfsExporter, bfsImporter, |
5375 |
03 Aug 10 |
nicklas |
94 |
debugMode, reporterFields, spotFields, assayFields); |
5285 |
24 Mar 10 |
nicklas |
95 |
int extraFileBFS = test_create_configuration(pluginDefinitionId, "BFS extra", |
5285 |
24 Mar 10 |
nicklas |
96 |
program, "BfsExtraFileGenerator", bfsExporter, bfsImporter, |
5375 |
03 Aug 10 |
nicklas |
97 |
debugMode, reporterFields, spotFields, assayFields, enableExtraFiles); |
5285 |
24 Mar 10 |
nicklas |
98 |
int extraFileNoSdataBFS = test_create_configuration(pluginDefinitionId, "BFS extra (no sdata)", |
5285 |
24 Mar 10 |
nicklas |
99 |
program, "BfsExtraFileGenerator nosdata", bfsExporter, bfsImporter, |
5375 |
03 Aug 10 |
nicklas |
100 |
debugMode, reporterFields, spotFields, assayFields, enableExtraFiles); |
5270 |
15 Mar 10 |
nicklas |
101 |
|
5270 |
15 Mar 10 |
nicklas |
// Clone bioassay set |
5375 |
03 Aug 10 |
nicklas |
103 |
int copyBfsJob = test_create_job(cloneBFS, experimentId, cloneId, debugMode, |
5375 |
03 Aug 10 |
nicklas |
104 |
new TestJob.Parameter(Parameters.CHILD_NAME, "Cloned from parent (BFS)")); |
5285 |
24 Mar 10 |
nicklas |
// Simulate an error |
5375 |
03 Aug 10 |
nicklas |
106 |
int errorBfsJob = test_create_job(errorBFS, experimentId, cloneId, debugMode, |
5375 |
03 Aug 10 |
nicklas |
107 |
new TestJob.Parameter(Parameters.CHILD_NAME, "Should really not be created (BFS)")); |
5285 |
24 Mar 10 |
nicklas |
// Add extra files to the result |
5375 |
03 Aug 10 |
nicklas |
109 |
int extraFilesBfsJob = test_create_job(extraFileBFS, experimentId, cloneId, debugMode, |
5375 |
03 Aug 10 |
nicklas |
110 |
new TestJob.Parameter(Parameters.CHILD_NAME, "Extra files+sdata (BFS)"), |
5285 |
24 Mar 10 |
nicklas |
111 |
new TestJob.Parameter(ExternalProgramExecutor.NAMESPACE_IMPORTER + ".extraFilesDirectory", |
5375 |
03 Aug 10 |
nicklas |
112 |
"/External program executor/bfs-1")); |
5285 |
24 Mar 10 |
nicklas |
// Result with only extra files |
5375 |
03 Aug 10 |
nicklas |
114 |
int extraFilesNoSdataBfsJob = test_create_job(extraFileNoSdataBFS, experimentId, cloneId, debugMode, |
5375 |
03 Aug 10 |
nicklas |
115 |
new TestJob.Parameter(Parameters.CHILD_NAME, "Extra files (no sdata) (BFS)"), |
5285 |
24 Mar 10 |
nicklas |
116 |
new TestJob.Parameter(ExternalProgramExecutor.NAMESPACE_IMPORTER + ".extraFilesDirectory", |
5375 |
03 Aug 10 |
nicklas |
117 |
"/External program executor/bfs-2")); |
5270 |
15 Mar 10 |
nicklas |
118 |
|
5375 |
03 Aug 10 |
nicklas |
119 |
ok &= TestJob.test_execute(copyBfsJob, false); |
5375 |
03 Aug 10 |
nicklas |
120 |
ok &= TestJob.test_execute(errorBfsJob, true); |
5375 |
03 Aug 10 |
nicklas |
121 |
ok &= TestJob.test_execute(extraFilesBfsJob, false); |
5375 |
03 Aug 10 |
nicklas |
122 |
ok &= TestJob.test_execute(extraFilesNoSdataBfsJob, false); |
5375 |
03 Aug 10 |
nicklas |
123 |
|
5375 |
03 Aug 10 |
nicklas |
// ********* BASEFile tests ************ |
5375 |
03 Aug 10 |
nicklas |
125 |
reporterFields = new TestJob.Parameter( |
5375 |
03 Aug 10 |
nicklas |
126 |
ExternalProgramExecutor.NAMESPACE_EXPORTER + ".reporterFields", "Position\nInternal id\nName"); |
5381 |
05 Aug 10 |
nicklas |
127 |
int cloneBaseFile = test_create_configuration(pluginDefinitionId, "BASEfile copy", |
5375 |
03 Aug 10 |
nicklas |
128 |
program, "CopyStdin2Stdout", baseFileExporter, baseFileImporter, |
5375 |
03 Aug 10 |
nicklas |
129 |
debugMode, reporterFields, spotFields); |
5381 |
05 Aug 10 |
nicklas |
130 |
int errorBaseFile = test_create_configuration(pluginDefinitionId, "BASEfile error", |
5375 |
03 Aug 10 |
nicklas |
131 |
program, "CopyStdin2Stdout error", baseFileExporter, baseFileImporter, |
5375 |
03 Aug 10 |
nicklas |
132 |
debugMode, reporterFields, spotFields); |
5381 |
05 Aug 10 |
nicklas |
133 |
int extraBaseFile = test_create_configuration(pluginDefinitionId, "BASEfile extra-files", |
5375 |
03 Aug 10 |
nicklas |
134 |
program, "CopyStdin2Stdout extra", baseFileExporter, baseFileImporter, |
5375 |
03 Aug 10 |
nicklas |
135 |
debugMode, reporterFields, spotFields, enableExtraFiles); |
5270 |
15 Mar 10 |
nicklas |
136 |
|
5375 |
03 Aug 10 |
nicklas |
// Clone bioassay set |
5375 |
03 Aug 10 |
nicklas |
138 |
int copyBaseFileJob = test_create_job(cloneBaseFile, experimentId, cloneId, debugMode, |
5381 |
05 Aug 10 |
nicklas |
139 |
new TestJob.Parameter(Parameters.CHILD_NAME, "Cloned from parent (BASEfile)")); |
5375 |
03 Aug 10 |
nicklas |
// Simulate an error |
5375 |
03 Aug 10 |
nicklas |
141 |
int errorBaseFileJob = test_create_job(errorBaseFile, experimentId, cloneId, debugMode, |
5381 |
05 Aug 10 |
nicklas |
142 |
new TestJob.Parameter(Parameters.CHILD_NAME, "Should really not be created (BASEfile)")); |
5375 |
03 Aug 10 |
nicklas |
// Add extra files to the result |
5375 |
03 Aug 10 |
nicklas |
144 |
int extraBaseFileJob = test_create_job(extraBaseFile, experimentId, cloneId, debugMode, |
5375 |
03 Aug 10 |
nicklas |
145 |
new TestJob.Parameter(Parameters.CHILD_NAME, "Extra files (BASEFile)"), |
5375 |
03 Aug 10 |
nicklas |
146 |
new TestJob.Parameter(ExternalProgramExecutor.NAMESPACE_IMPORTER + ".extraFilesDirectory", |
5375 |
03 Aug 10 |
nicklas |
147 |
"/External program executor/basefile-1")); |
5375 |
03 Aug 10 |
nicklas |
148 |
|
5375 |
03 Aug 10 |
nicklas |
149 |
ok &= TestJob.test_execute(copyBaseFileJob, false); |
5375 |
03 Aug 10 |
nicklas |
150 |
ok &= TestJob.test_execute(errorBaseFileJob, true); |
5375 |
03 Aug 10 |
nicklas |
151 |
ok &= TestJob.test_execute(extraBaseFileJob, false); |
5375 |
03 Aug 10 |
nicklas |
152 |
|
5378 |
03 Aug 10 |
nicklas |
// ********* File-only tests ************ |
5378 |
03 Aug 10 |
nicklas |
154 |
int cloneFileOnly = test_create_configuration(pluginDefinitionId, "File-only importer", |
5378 |
03 Aug 10 |
nicklas |
155 |
program, "BfsExtraFileGenerator", bfsExporter, fileOnlyImporter, |
5378 |
03 Aug 10 |
nicklas |
156 |
debugMode, reporterFields, spotFields, assayFields); |
5378 |
03 Aug 10 |
nicklas |
157 |
int cloneFileOnlyJob = test_create_job(cloneFileOnly, experimentId, cloneId, debugMode, |
5378 |
03 Aug 10 |
nicklas |
158 |
new TestJob.Parameter(Parameters.CHILD_NAME, "File-only importer"), |
5378 |
03 Aug 10 |
nicklas |
159 |
new TestJob.Parameter(ExternalProgramExecutor.NAMESPACE_IMPORTER + ".extraFilesDirectory", |
5378 |
03 Aug 10 |
nicklas |
160 |
"/External program executor/fileonly-1")); |
5378 |
03 Aug 10 |
nicklas |
161 |
ok &= TestJob.test_execute(cloneFileOnlyJob, false); |
5378 |
03 Aug 10 |
nicklas |
162 |
|
5270 |
15 Mar 10 |
nicklas |
163 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
5270 |
15 Mar 10 |
nicklas |
164 |
|
5270 |
15 Mar 10 |
nicklas |
// Cleanup |
5270 |
15 Mar 10 |
nicklas |
166 |
TestAnalyzeUtil.test_delete_bioassayset(cloneId); |
5375 |
03 Aug 10 |
nicklas |
167 |
TestJob.test_delete(copyBfsJob); |
5375 |
03 Aug 10 |
nicklas |
168 |
TestJob.test_delete(errorBfsJob); |
5375 |
03 Aug 10 |
nicklas |
169 |
TestJob.test_delete(extraFilesBfsJob); |
5375 |
03 Aug 10 |
nicklas |
170 |
TestJob.test_delete(extraFilesNoSdataBfsJob); |
5375 |
03 Aug 10 |
nicklas |
171 |
TestJob.test_delete(copyBaseFileJob); |
5375 |
03 Aug 10 |
nicklas |
172 |
TestJob.test_delete(errorBaseFileJob); |
5375 |
03 Aug 10 |
nicklas |
173 |
TestJob.test_delete(extraBaseFileJob); |
5378 |
03 Aug 10 |
nicklas |
174 |
TestJob.test_delete(cloneFileOnlyJob); |
5285 |
24 Mar 10 |
nicklas |
175 |
|
5270 |
15 Mar 10 |
nicklas |
176 |
TestPluginConfiguration.test_delete(cloneBFS); |
5270 |
15 Mar 10 |
nicklas |
177 |
TestPluginConfiguration.test_delete(errorBFS); |
5285 |
24 Mar 10 |
nicklas |
178 |
TestPluginConfiguration.test_delete(extraFileBFS); |
5285 |
24 Mar 10 |
nicklas |
179 |
TestPluginConfiguration.test_delete(extraFileNoSdataBFS); |
5375 |
03 Aug 10 |
nicklas |
180 |
TestPluginConfiguration.test_delete(cloneBaseFile); |
5375 |
03 Aug 10 |
nicklas |
181 |
TestPluginConfiguration.test_delete(errorBaseFile); |
5375 |
03 Aug 10 |
nicklas |
182 |
TestPluginConfiguration.test_delete(extraBaseFile); |
5378 |
03 Aug 10 |
nicklas |
183 |
TestPluginConfiguration.test_delete(cloneFileOnly); |
5285 |
24 Mar 10 |
nicklas |
184 |
|
5285 |
24 Mar 10 |
nicklas |
185 |
TestDirectory.test_delete(directoryId, true); |
5270 |
15 Mar 10 |
nicklas |
186 |
} |
5270 |
15 Mar 10 |
nicklas |
187 |
finally |
5270 |
15 Mar 10 |
nicklas |
188 |
{ |
5270 |
15 Mar 10 |
nicklas |
189 |
if (wasSetup) TestAnalyzeUtil.cleanupExperiment(); |
5270 |
15 Mar 10 |
nicklas |
190 |
write("++Testing External program executor "+(ok ? "OK" : "Failed")+"\n"); |
5270 |
15 Mar 10 |
nicklas |
191 |
} |
5270 |
15 Mar 10 |
nicklas |
192 |
return ok; |
5270 |
15 Mar 10 |
nicklas |
193 |
} |
5270 |
15 Mar 10 |
nicklas |
194 |
|
5270 |
15 Mar 10 |
nicklas |
195 |
|
5270 |
15 Mar 10 |
nicklas |
196 |
static void write(String message) |
5270 |
15 Mar 10 |
nicklas |
197 |
{ |
5270 |
15 Mar 10 |
nicklas |
198 |
System.out.println(message); |
5270 |
15 Mar 10 |
nicklas |
199 |
} |
5270 |
15 Mar 10 |
nicklas |
200 |
|
5270 |
15 Mar 10 |
nicklas |
201 |
|
5270 |
15 Mar 10 |
nicklas |
202 |
static int test_create_configuration(int pluginDefinitionId, String name, |
5283 |
24 Mar 10 |
nicklas |
203 |
String program, String cmdLine, |
5270 |
15 Mar 10 |
nicklas |
204 |
int exporterPlugin, int importerPlugin, TestJob.Parameter... parameters) |
5270 |
15 Mar 10 |
nicklas |
205 |
{ |
5270 |
15 Mar 10 |
nicklas |
206 |
if (pluginDefinitionId == 0 || !TestUtil.hasPermission(Permission.CREATE, Item.PLUGINCONFIGURATION)) return 0; |
5270 |
15 Mar 10 |
nicklas |
207 |
int id = 0; |
5270 |
15 Mar 10 |
nicklas |
208 |
DbControl dc = null; |
5270 |
15 Mar 10 |
nicklas |
209 |
try |
5270 |
15 Mar 10 |
nicklas |
210 |
{ |
5270 |
15 Mar 10 |
nicklas |
211 |
dc = TestUtil.getDbControl(); |
5270 |
15 Mar 10 |
nicklas |
212 |
|
5270 |
15 Mar 10 |
nicklas |
213 |
PluginDefinition plugin = PluginDefinition.getById(dc, pluginDefinitionId); |
5270 |
15 Mar 10 |
nicklas |
214 |
PluginDefinition exporter = PluginDefinition.getById(dc, exporterPlugin); |
5270 |
15 Mar 10 |
nicklas |
215 |
PluginDefinition importer = PluginDefinition.getById(dc, importerPlugin); |
5270 |
15 Mar 10 |
nicklas |
216 |
|
5270 |
15 Mar 10 |
nicklas |
217 |
PluginConfiguration config = plugin.newPluginConfiguration(); |
5270 |
15 Mar 10 |
nicklas |
218 |
config.setName(name); |
5270 |
15 Mar 10 |
nicklas |
219 |
|
5270 |
15 Mar 10 |
nicklas |
220 |
PluginConfigurationRequest request = config.configure(); |
5270 |
15 Mar 10 |
nicklas |
221 |
TestJob.write_request_information(request.getRequestInformation()); |
5270 |
15 Mar 10 |
nicklas |
222 |
TestJob.setRequestParameterValues(request, parameters); |
5270 |
15 Mar 10 |
nicklas |
223 |
request.setParameterValue(ExternalProgramExecutor.PARAMETER_EXTERNAL_PATH, |
5270 |
15 Mar 10 |
nicklas |
224 |
new java.io.File("").getAbsolutePath()+java.io.File.separator + program); |
5283 |
24 Mar 10 |
nicklas |
225 |
request.setParameterValue(ExternalProgramExecutor.PARAMETER_EXTERNAL_CMDLINE, |
5283 |
24 Mar 10 |
nicklas |
226 |
cmdLine); |
5270 |
15 Mar 10 |
nicklas |
227 |
request.setParameterValue(ExternalProgramExecutor.PARAMETER_EXPORTER_CLASS, |
5270 |
15 Mar 10 |
nicklas |
228 |
exporter.getClassName()); |
5270 |
15 Mar 10 |
nicklas |
229 |
request.setParameterValue(ExternalProgramExecutor.PARAMETER_IMPORTER_CLASS, |
5270 |
15 Mar 10 |
nicklas |
230 |
importer.getClassName()); |
5270 |
15 Mar 10 |
nicklas |
231 |
|
5270 |
15 Mar 10 |
nicklas |
232 |
PluginResponse response = request.invoke(); |
5270 |
15 Mar 10 |
nicklas |
233 |
if (response.getStatus() == Response.Status.ERROR) |
5270 |
15 Mar 10 |
nicklas |
234 |
{ |
5270 |
15 Mar 10 |
nicklas |
235 |
throw new BaseException(response.getMessage(), response.getErrorList().get(0)); |
5270 |
15 Mar 10 |
nicklas |
236 |
} |
5270 |
15 Mar 10 |
nicklas |
237 |
else if (response.getStatus() != Response.Status.CONTINUE) |
5270 |
15 Mar 10 |
nicklas |
238 |
{ |
5270 |
15 Mar 10 |
nicklas |
239 |
throw new BaseException(response.getStatus() + ": " + response.getMessage()); |
5270 |
15 Mar 10 |
nicklas |
240 |
} |
5270 |
15 Mar 10 |
nicklas |
241 |
|
5270 |
15 Mar 10 |
nicklas |
// Second step: configure exporter/importer |
5270 |
15 Mar 10 |
nicklas |
243 |
request = response.getNextRequest(); |
5270 |
15 Mar 10 |
nicklas |
244 |
TestJob.write_request_information(request.getRequestInformation()); |
5270 |
15 Mar 10 |
nicklas |
245 |
TestJob.setRequestParameterValues(request, parameters); |
5270 |
15 Mar 10 |
nicklas |
246 |
response = request.invoke(); |
5270 |
15 Mar 10 |
nicklas |
247 |
|
5270 |
15 Mar 10 |
nicklas |
248 |
if (response.getStatus() == Response.Status.ERROR) |
5270 |
15 Mar 10 |
nicklas |
249 |
{ |
5270 |
15 Mar 10 |
nicklas |
250 |
throw new BaseException(response.getMessage(), response.getErrorList().get(0)); |
5270 |
15 Mar 10 |
nicklas |
251 |
} |
5270 |
15 Mar 10 |
nicklas |
252 |
else if (response.getStatus() != Response.Status.CONTINUE) |
5270 |
15 Mar 10 |
nicklas |
253 |
{ |
5270 |
15 Mar 10 |
nicklas |
254 |
throw new BaseException(response.getStatus() + ": " + response.getMessage()); |
5270 |
15 Mar 10 |
nicklas |
255 |
} |
5270 |
15 Mar 10 |
nicklas |
256 |
|
5270 |
15 Mar 10 |
nicklas |
// Third step: program parameters |
5270 |
15 Mar 10 |
nicklas |
258 |
request = response.getNextRequest(); |
5270 |
15 Mar 10 |
nicklas |
259 |
TestJob.write_request_information(request.getRequestInformation()); |
5270 |
15 Mar 10 |
nicklas |
260 |
TestJob.setRequestParameterValues(request); |
5270 |
15 Mar 10 |
nicklas |
261 |
response = request.invoke(); |
5270 |
15 Mar 10 |
nicklas |
262 |
|
5270 |
15 Mar 10 |
nicklas |
263 |
if (response.getStatus() == Response.Status.DONE) |
5270 |
15 Mar 10 |
nicklas |
264 |
{ |
5270 |
15 Mar 10 |
nicklas |
265 |
response.saveParameters(dc); |
5270 |
15 Mar 10 |
nicklas |
266 |
dc.saveItem(config); |
5270 |
15 Mar 10 |
nicklas |
267 |
dc.commit(); |
5270 |
15 Mar 10 |
nicklas |
268 |
} |
5270 |
15 Mar 10 |
nicklas |
269 |
else |
5270 |
15 Mar 10 |
nicklas |
270 |
{ |
5270 |
15 Mar 10 |
nicklas |
271 |
throw new BaseException(response.getMessage(), response.getErrorList().get(0)); |
5270 |
15 Mar 10 |
nicklas |
272 |
} |
5270 |
15 Mar 10 |
nicklas |
273 |
id = config.getId(); |
5270 |
15 Mar 10 |
nicklas |
274 |
write("--Create configuration for External program executor OK"); |
5270 |
15 Mar 10 |
nicklas |
275 |
} |
5270 |
15 Mar 10 |
nicklas |
276 |
catch (Throwable ex) |
5270 |
15 Mar 10 |
nicklas |
277 |
{ |
5270 |
15 Mar 10 |
nicklas |
278 |
write("--Create configuration for External program executor FAILED"); |
5270 |
15 Mar 10 |
nicklas |
279 |
ex.printStackTrace(); |
5270 |
15 Mar 10 |
nicklas |
280 |
ok = false; |
5270 |
15 Mar 10 |
nicklas |
281 |
} |
5270 |
15 Mar 10 |
nicklas |
282 |
finally |
5270 |
15 Mar 10 |
nicklas |
283 |
{ |
5270 |
15 Mar 10 |
nicklas |
284 |
if (dc != null) dc.close(); |
5270 |
15 Mar 10 |
nicklas |
285 |
} |
5270 |
15 Mar 10 |
nicklas |
286 |
return id; |
5270 |
15 Mar 10 |
nicklas |
287 |
} |
5270 |
15 Mar 10 |
nicklas |
288 |
|
5270 |
15 Mar 10 |
nicklas |
289 |
static int test_create_job(int pluginConfigurationId, int experimentId, int bioAssaySetId, |
5270 |
15 Mar 10 |
nicklas |
290 |
TestJob.Parameter... parameters) |
5270 |
15 Mar 10 |
nicklas |
291 |
{ |
5384 |
13 Aug 10 |
nicklas |
292 |
if (pluginConfigurationId == 0 || experimentId == 0 || bioAssaySetId == 0 |
5384 |
13 Aug 10 |
nicklas |
293 |
|| !TestUtil.hasPermission(Permission.CREATE, Item.JOB)) return 0; |
5270 |
15 Mar 10 |
nicklas |
294 |
int id = 0; |
5270 |
15 Mar 10 |
nicklas |
295 |
DbControl dc = null; |
5270 |
15 Mar 10 |
nicklas |
296 |
try |
5270 |
15 Mar 10 |
nicklas |
297 |
{ |
5270 |
15 Mar 10 |
nicklas |
298 |
dc = TestUtil.getDbControl(); |
5270 |
15 Mar 10 |
nicklas |
299 |
|
5270 |
15 Mar 10 |
nicklas |
300 |
Experiment e = Experiment.getById(dc, experimentId); |
5270 |
15 Mar 10 |
nicklas |
301 |
BioAssaySet bioAssaySet = BioAssaySet.getById(dc, bioAssaySetId); |
5270 |
15 Mar 10 |
nicklas |
302 |
dc.getSessionControl().getCurrentContext(Item.EXPERIMENT).setId(experimentId); |
5270 |
15 Mar 10 |
nicklas |
303 |
dc.getSessionControl().getCurrentContext(Item.BIOASSAYSET).setId(bioAssaySetId); |
5270 |
15 Mar 10 |
nicklas |
304 |
PluginConfiguration pc = PluginConfiguration.getById(dc, pluginConfigurationId); |
5270 |
15 Mar 10 |
nicklas |
305 |
Job j = pc.newJob(e); |
5270 |
15 Mar 10 |
nicklas |
306 |
j.setName(pc.getName()); |
5270 |
15 Mar 10 |
nicklas |
307 |
|
5270 |
15 Mar 10 |
nicklas |
308 |
PluginConfigurationRequest request = j.configure(null); |
5270 |
15 Mar 10 |
nicklas |
309 |
|
5270 |
15 Mar 10 |
nicklas |
// First, set default values |
5270 |
15 Mar 10 |
nicklas |
311 |
TestJob.setRequestParameterValues(request); |
5270 |
15 Mar 10 |
nicklas |
312 |
|
5270 |
15 Mar 10 |
nicklas |
// Then, set values from method call |
5270 |
15 Mar 10 |
nicklas |
314 |
if (parameters != null) |
5270 |
15 Mar 10 |
nicklas |
315 |
{ |
5270 |
15 Mar 10 |
nicklas |
316 |
for (TestJob.Parameter p : parameters) |
5270 |
15 Mar 10 |
nicklas |
317 |
{ |
5270 |
15 Mar 10 |
nicklas |
318 |
request.setParameterValue(p.name, p.value); |
5270 |
15 Mar 10 |
nicklas |
319 |
} |
5270 |
15 Mar 10 |
nicklas |
320 |
} |
5270 |
15 Mar 10 |
nicklas |
321 |
|
5270 |
15 Mar 10 |
nicklas |
// At last, some well-known parameters |
5270 |
15 Mar 10 |
nicklas |
323 |
request.setParameterValue("source", bioAssaySet); |
5270 |
15 Mar 10 |
nicklas |
324 |
TestJob.write_request_information(request.getRequestInformation()); |
5270 |
15 Mar 10 |
nicklas |
325 |
|
5270 |
15 Mar 10 |
nicklas |
326 |
PluginResponse response = request.invoke(); |
5270 |
15 Mar 10 |
nicklas |
327 |
if (response.getStatus() == Response.Status.DONE) |
5270 |
15 Mar 10 |
nicklas |
328 |
{ |
5270 |
15 Mar 10 |
nicklas |
329 |
response.saveParameters(dc); |
5270 |
15 Mar 10 |
nicklas |
330 |
dc.saveItem(j); |
5270 |
15 Mar 10 |
nicklas |
331 |
dc.commit(); |
5270 |
15 Mar 10 |
nicklas |
332 |
} |
5270 |
15 Mar 10 |
nicklas |
333 |
else |
5270 |
15 Mar 10 |
nicklas |
334 |
{ |
5270 |
15 Mar 10 |
nicklas |
335 |
throw new BaseException(response.getMessage(), response.getErrorList().get(0)); |
5270 |
15 Mar 10 |
nicklas |
336 |
} |
5270 |
15 Mar 10 |
nicklas |
337 |
id = j.getId(); |
5270 |
15 Mar 10 |
nicklas |
338 |
write("--Create job for External program executor OK"); |
5270 |
15 Mar 10 |
nicklas |
339 |
} |
5270 |
15 Mar 10 |
nicklas |
340 |
catch (Throwable ex) |
5270 |
15 Mar 10 |
nicklas |
341 |
{ |
5270 |
15 Mar 10 |
nicklas |
342 |
write("--Create job for External program executor FAILED"); |
5270 |
15 Mar 10 |
nicklas |
343 |
ex.printStackTrace(); |
5270 |
15 Mar 10 |
nicklas |
344 |
ok = false; |
5270 |
15 Mar 10 |
nicklas |
345 |
} |
5270 |
15 Mar 10 |
nicklas |
346 |
finally |
5270 |
15 Mar 10 |
nicklas |
347 |
{ |
5270 |
15 Mar 10 |
nicklas |
348 |
if (dc != null) dc.close(); |
5270 |
15 Mar 10 |
nicklas |
349 |
} |
5270 |
15 Mar 10 |
nicklas |
350 |
return id; |
5270 |
15 Mar 10 |
nicklas |
351 |
} |
5270 |
15 Mar 10 |
nicklas |
352 |
|
5270 |
15 Mar 10 |
nicklas |
353 |
|
5270 |
15 Mar 10 |
nicklas |
354 |
} |