226 |
09 Jan 07 |
mbayer |
1 |
/* |
226 |
09 Jan 07 |
mbayer |
Copyright (C) Authors contributing to this file. |
226 |
09 Jan 07 |
mbayer |
3 |
|
226 |
09 Jan 07 |
mbayer |
This program is free software; you can redistribute it and/or modify |
226 |
09 Jan 07 |
mbayer |
it under the terms of the GNU General Public License as published by |
226 |
09 Jan 07 |
mbayer |
the Free Software Foundation; either version 2 of the License, or |
226 |
09 Jan 07 |
mbayer |
(at your option) any later version. |
226 |
09 Jan 07 |
mbayer |
8 |
|
226 |
09 Jan 07 |
mbayer |
This program is distributed in the hope that it will be useful, |
226 |
09 Jan 07 |
mbayer |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
226 |
09 Jan 07 |
mbayer |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
226 |
09 Jan 07 |
mbayer |
GNU General Public License for more details. |
226 |
09 Jan 07 |
mbayer |
13 |
|
226 |
09 Jan 07 |
mbayer |
You should have received a copy of the GNU General Public License along |
226 |
09 Jan 07 |
mbayer |
with this program; if not, write to the Free Software Foundation, Inc., |
226 |
09 Jan 07 |
mbayer |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
226 |
09 Jan 07 |
mbayer |
17 |
|
226 |
09 Jan 07 |
mbayer |
See also http://www.gnu.org/licenses/gpl.txt. |
226 |
09 Jan 07 |
mbayer |
19 |
*/ |
226 |
09 Jan 07 |
mbayer |
20 |
package sbrn.base; |
226 |
09 Jan 07 |
mbayer |
21 |
|
226 |
09 Jan 07 |
mbayer |
22 |
import net.sf.basedb.core.BaseException; |
226 |
09 Jan 07 |
mbayer |
23 |
import net.sf.basedb.core.BooleanParameterType; |
226 |
09 Jan 07 |
mbayer |
24 |
import net.sf.basedb.core.DbControl; |
226 |
09 Jan 07 |
mbayer |
25 |
import net.sf.basedb.core.Experiment; |
226 |
09 Jan 07 |
mbayer |
26 |
import net.sf.basedb.core.File; |
226 |
09 Jan 07 |
mbayer |
27 |
import net.sf.basedb.core.FileParameterType; |
226 |
09 Jan 07 |
mbayer |
28 |
import net.sf.basedb.core.Item; |
226 |
09 Jan 07 |
mbayer |
29 |
import net.sf.basedb.core.ItemParameterType; |
226 |
09 Jan 07 |
mbayer |
30 |
import net.sf.basedb.core.Job; |
226 |
09 Jan 07 |
mbayer |
31 |
import net.sf.basedb.core.PluginParameter; |
226 |
09 Jan 07 |
mbayer |
32 |
import net.sf.basedb.core.ProgressReporter; |
226 |
09 Jan 07 |
mbayer |
33 |
import net.sf.basedb.core.RawBioAssay; |
226 |
09 Jan 07 |
mbayer |
34 |
import net.sf.basedb.core.RequestInformation; |
226 |
09 Jan 07 |
mbayer |
35 |
import net.sf.basedb.core.plugin.About; |
226 |
09 Jan 07 |
mbayer |
36 |
import net.sf.basedb.core.plugin.AboutImpl; |
226 |
09 Jan 07 |
mbayer |
37 |
import net.sf.basedb.core.plugin.AbstractPlugin; |
226 |
09 Jan 07 |
mbayer |
38 |
import net.sf.basedb.core.plugin.AutoDetectingImporter; |
226 |
09 Jan 07 |
mbayer |
39 |
import net.sf.basedb.core.plugin.GuiContext; |
226 |
09 Jan 07 |
mbayer |
40 |
import net.sf.basedb.core.plugin.InteractivePlugin; |
226 |
09 Jan 07 |
mbayer |
41 |
import net.sf.basedb.core.plugin.Plugin; |
226 |
09 Jan 07 |
mbayer |
42 |
import net.sf.basedb.core.plugin.Request; |
226 |
09 Jan 07 |
mbayer |
43 |
import net.sf.basedb.core.plugin.Response; |
226 |
09 Jan 07 |
mbayer |
44 |
|
226 |
09 Jan 07 |
mbayer |
45 |
import java.io.InputStream; |
226 |
09 Jan 07 |
mbayer |
46 |
import java.util.ArrayList; |
226 |
09 Jan 07 |
mbayer |
47 |
import java.util.Arrays; |
226 |
09 Jan 07 |
mbayer |
48 |
import java.util.Collections; |
226 |
09 Jan 07 |
mbayer |
49 |
import java.util.List; |
226 |
09 Jan 07 |
mbayer |
50 |
import java.util.Set; |
226 |
09 Jan 07 |
mbayer |
51 |
import java.util.zip.ZipEntry; |
226 |
09 Jan 07 |
mbayer |
52 |
import java.util.zip.ZipInputStream; |
226 |
09 Jan 07 |
mbayer |
53 |
|
226 |
09 Jan 07 |
mbayer |
54 |
/** |
226 |
09 Jan 07 |
mbayer |
This plugin imports a batch of individual data files into an experiment chosen by the user. It is set up to be invoked |
226 |
09 Jan 07 |
mbayer |
from the detail view of a single Experiment where an import tab lets the user select a zip file that contains all the |
226 |
09 Jan 07 |
mbayer |
data files. On invocation it proceeds to create a new subdirectory in the user's raw data directory -- this subdirectory |
226 |
09 Jan 07 |
mbayer |
is named after the zip file minus the extension plus a timestamp in the format ddMMyy_hhmmss. The zip file is |
226 |
09 Jan 07 |
mbayer |
unzipped into this directory. For each file in the directory, a single RawBioAssay object is then created, and once |
226 |
09 Jan 07 |
mbayer |
all the data files have been processed in this way, the RawBioAssay objects just created are attached to the Experiment |
226 |
09 Jan 07 |
mbayer |
where the import is run from. |
226 |
09 Jan 07 |
mbayer |
62 |
|
226 |
09 Jan 07 |
mbayer |
It is assumed that all the data files are of the same data type and all adhere strictly to the same format -- the import |
226 |
09 Jan 07 |
mbayer |
will fail otherwise. It is also assumed that a suitable import config for the data exists. |
226 |
09 Jan 07 |
mbayer |
65 |
|
226 |
09 Jan 07 |
mbayer |
This is an initial prototype and does not support annotation features or creation of any other items. |
226 |
09 Jan 07 |
mbayer |
67 |
|
226 |
09 Jan 07 |
mbayer |
@author Micha Bayer - Plant Bioinformatics Group, Scottish Crop Research Institute |
226 |
09 Jan 07 |
mbayer |
email: sbrn@scri.ac.uk, web http://www.scri.ac.uk |
226 |
09 Jan 07 |
mbayer |
70 |
*/ |
226 |
09 Jan 07 |
mbayer |
71 |
public class BatchDataImporter extends AbstractPlugin implements InteractivePlugin, AutoDetectingImporter |
226 |
09 Jan 07 |
mbayer |
72 |
{ |
226 |
09 Jan 07 |
mbayer |
73 |
|
226 |
09 Jan 07 |
mbayer |
// ========================================variables=================================== |
226 |
09 Jan 07 |
mbayer |
75 |
|
226 |
09 Jan 07 |
mbayer |
//current version |
226 |
09 Jan 07 |
mbayer |
77 |
private static final String version = "0.1"; |
226 |
09 Jan 07 |
mbayer |
78 |
|
226 |
09 Jan 07 |
mbayer |
//the context that this plugin will be invoked from |
226 |
09 Jan 07 |
mbayer |
//currently set to provide the user with an "import" tab when they view a single experiment's details |
226 |
09 Jan 07 |
mbayer |
81 |
private static final Set<GuiContext> guiContexts = Collections.singleton(new GuiContext(Item.EXPERIMENT, |
226 |
09 Jan 07 |
mbayer |
82 |
GuiContext.Type.ITEM)); |
226 |
09 Jan 07 |
mbayer |
83 |
|
226 |
09 Jan 07 |
mbayer |
// The complete request information |
226 |
09 Jan 07 |
mbayer |
85 |
private RequestInformation configureJob; |
226 |
09 Jan 07 |
mbayer |
86 |
|
226 |
09 Jan 07 |
mbayer |
// The parameter that asks for a file to import from |
226 |
09 Jan 07 |
mbayer |
88 |
private PluginParameter<File> fileParameter; |
226 |
09 Jan 07 |
mbayer |
89 |
|
226 |
09 Jan 07 |
mbayer |
// The parameter that asks if existing items should be updated or not |
226 |
09 Jan 07 |
mbayer |
91 |
private PluginParameter<Boolean> updateExistingParameter; |
226 |
09 Jan 07 |
mbayer |
92 |
|
226 |
09 Jan 07 |
mbayer |
//dbcontrol object |
226 |
09 Jan 07 |
mbayer |
94 |
private DbControl dc; |
226 |
09 Jan 07 |
mbayer |
95 |
|
226 |
09 Jan 07 |
mbayer |
//this is info about the plugin that is visible on the Definitions page |
226 |
09 Jan 07 |
mbayer |
97 |
private static final About about = new AboutImpl("Batch Data Importer", |
226 |
09 Jan 07 |
mbayer |
98 |
"Imports batches of data files into BASE, creating a single RawbioAssay for each file", |
226 |
09 Jan 07 |
mbayer |
99 |
version, |
226 |
09 Jan 07 |
mbayer |
100 |
"2006, Scottish Crop Research Institute", |
226 |
09 Jan 07 |
mbayer |
101 |
"Micha Bayer", |
226 |
09 Jan 07 |
mbayer |
102 |
"mbayer@scri.ac.uk", |
226 |
09 Jan 07 |
mbayer |
103 |
"http://www.scri.ac.uk" |
226 |
09 Jan 07 |
mbayer |
104 |
); |
226 |
09 Jan 07 |
mbayer |
105 |
|
226 |
09 Jan 07 |
mbayer |
//the Experiment item we want to attach the data to, packaged as a parameter to the plugin |
226 |
09 Jan 07 |
mbayer |
107 |
private PluginParameter<Experiment> experimentParameter; |
226 |
09 Jan 07 |
mbayer |
108 |
|
226 |
09 Jan 07 |
mbayer |
//the Experiment item we want to attach the data to |
226 |
09 Jan 07 |
mbayer |
110 |
private Experiment experiment; |
226 |
09 Jan 07 |
mbayer |
111 |
|
226 |
09 Jan 07 |
mbayer |
// ========================================methods=================================== |
226 |
09 Jan 07 |
mbayer |
113 |
|
226 |
09 Jan 07 |
mbayer |
114 |
/** |
226 |
09 Jan 07 |
mbayer |
Called when the plugin is to execute. This is where the actual import is initiated from. The class |
226 |
09 Jan 07 |
mbayer |
that actually does most of the work is BatchDataImport.java. |
226 |
09 Jan 07 |
mbayer |
117 |
*/ |
226 |
09 Jan 07 |
mbayer |
118 |
public void run(Request request, Response response, ProgressReporter progress) |
226 |
09 Jan 07 |
mbayer |
119 |
{ |
226 |
09 Jan 07 |
mbayer |
// Open a connection to the database |
226 |
09 Jan 07 |
mbayer |
// sc is set by init() method |
226 |
09 Jan 07 |
mbayer |
122 |
dc = sc.newDbControl(); |
226 |
09 Jan 07 |
mbayer |
123 |
try |
226 |
09 Jan 07 |
mbayer |
124 |
{ |
226 |
09 Jan 07 |
mbayer |
//get the Experiment object that this import pertains to |
226 |
09 Jan 07 |
mbayer |
126 |
experiment = (Experiment)job.getValue("experiment"); |
226 |
09 Jan 07 |
mbayer |
127 |
dc.reattachItem(experiment); |
226 |
09 Jan 07 |
mbayer |
128 |
System.out.println("experiment: " + experiment); |
226 |
09 Jan 07 |
mbayer |
129 |
|
226 |
09 Jan 07 |
mbayer |
//get the file selected by the user |
226 |
09 Jan 07 |
mbayer |
131 |
File file = (File) job.getValue("file"); |
226 |
09 Jan 07 |
mbayer |
132 |
file = File.getById(dc, file.getId()); |
226 |
09 Jan 07 |
mbayer |
133 |
System.out.println("file selected: " + file.getName()); |
226 |
09 Jan 07 |
mbayer |
134 |
|
226 |
09 Jan 07 |
mbayer |
//do the import |
226 |
09 Jan 07 |
mbayer |
136 |
BatchDataImport batchDataImport = new BatchDataImport(sc,file,experiment,progress); |
226 |
09 Jan 07 |
mbayer |
137 |
boolean importSuccess = batchDataImport.importData(); |
226 |
09 Jan 07 |
mbayer |
138 |
|
230 |
14 Feb 07 |
mbayer |
//set the success message if appropriate |
226 |
09 Jan 07 |
mbayer |
140 |
if(importSuccess) |
226 |
09 Jan 07 |
mbayer |
141 |
response.setDone("Plugin ended successfully"); |
230 |
14 Feb 07 |
mbayer |
142 |
|
226 |
09 Jan 07 |
mbayer |
143 |
} |
226 |
09 Jan 07 |
mbayer |
144 |
catch (Throwable t) |
226 |
09 Jan 07 |
mbayer |
145 |
{ |
230 |
14 Feb 07 |
mbayer |
// All exceptions must be caught and sent back |
226 |
09 Jan 07 |
mbayer |
// using the response object |
226 |
09 Jan 07 |
mbayer |
148 |
response.setError(t.getMessage(), Arrays.asList(t)); |
230 |
14 Feb 07 |
mbayer |
149 |
response.setDone("Plugin failed: " + t.getMessage()); |
226 |
09 Jan 07 |
mbayer |
150 |
} |
226 |
09 Jan 07 |
mbayer |
151 |
finally |
226 |
09 Jan 07 |
mbayer |
152 |
{ |
230 |
14 Feb 07 |
mbayer |
153 |
|
226 |
09 Jan 07 |
mbayer |
// IMPORTANT!!! Make sure opened connections are closed |
226 |
09 Jan 07 |
mbayer |
155 |
if (dc != null) |
226 |
09 Jan 07 |
mbayer |
156 |
dc.close(); |
226 |
09 Jan 07 |
mbayer |
157 |
} |
226 |
09 Jan 07 |
mbayer |
158 |
} |
226 |
09 Jan 07 |
mbayer |
159 |
|
226 |
09 Jan 07 |
mbayer |
160 |
|
226 |
09 Jan 07 |
mbayer |
161 |
// ------------------------------------------------------------------------------------------------------------------------------------------ |
226 |
09 Jan 07 |
mbayer |
162 |
|
226 |
09 Jan 07 |
mbayer |
163 |
/** |
226 |
09 Jan 07 |
mbayer |
Checks whether a file is importable. In our case this consists of getting a zip inputstream to the file in question |
226 |
09 Jan 07 |
mbayer |
and trying to read from it. |
226 |
09 Jan 07 |
mbayer |
@param InputStream in - the input stream from the (zip) file the user specified for import |
226 |
09 Jan 07 |
mbayer |
@return boolean -- false if the file is not a zip file |
226 |
09 Jan 07 |
mbayer |
168 |
*/ |
226 |
09 Jan 07 |
mbayer |
169 |
public boolean isImportable(InputStream in) throws BaseException |
226 |
09 Jan 07 |
mbayer |
170 |
{ |
226 |
09 Jan 07 |
mbayer |
171 |
try |
226 |
09 Jan 07 |
mbayer |
172 |
{ |
226 |
09 Jan 07 |
mbayer |
173 |
System.out.println("====================================="); |
226 |
09 Jan 07 |
mbayer |
174 |
System.out.println("===========NEW BATCH IMPORT ========="); |
226 |
09 Jan 07 |
mbayer |
175 |
System.out.println("====================================="); |
226 |
09 Jan 07 |
mbayer |
176 |
|
226 |
09 Jan 07 |
mbayer |
//check whether the file is actually a zip file |
226 |
09 Jan 07 |
mbayer |
178 |
ZipInputStream zin = new ZipInputStream(in); |
226 |
09 Jan 07 |
mbayer |
//if this is not a zip file, this will throw an exception: |
226 |
09 Jan 07 |
mbayer |
180 |
ZipEntry zn = zin.getNextEntry(); |
226 |
09 Jan 07 |
mbayer |
181 |
System.out.println("zn =" + zn.getName()); |
226 |
09 Jan 07 |
mbayer |
182 |
} |
226 |
09 Jan 07 |
mbayer |
183 |
catch (Exception e) |
226 |
09 Jan 07 |
mbayer |
184 |
{ |
226 |
09 Jan 07 |
mbayer |
// TODO Auto-generated catch block |
226 |
09 Jan 07 |
mbayer |
186 |
System.out.println("file is not a zip file"); |
226 |
09 Jan 07 |
mbayer |
187 |
e.printStackTrace(); |
226 |
09 Jan 07 |
mbayer |
188 |
return false; |
226 |
09 Jan 07 |
mbayer |
189 |
} |
226 |
09 Jan 07 |
mbayer |
190 |
|
226 |
09 Jan 07 |
mbayer |
191 |
return true; |
226 |
09 Jan 07 |
mbayer |
192 |
} |
226 |
09 Jan 07 |
mbayer |
193 |
|
226 |
09 Jan 07 |
mbayer |
194 |
// ------------------------------------------------------------------------------------------------------------------------------------------ |
226 |
09 Jan 07 |
mbayer |
195 |
|
226 |
09 Jan 07 |
mbayer |
196 |
/** |
226 |
09 Jan 07 |
mbayer |
Indicates whether the plugin can be configured by means of PluginConfigurations; false in our case because |
226 |
09 Jan 07 |
mbayer |
all this plugin ever does is to import zip files in the same way. The actual data import is handled by actual |
226 |
09 Jan 07 |
mbayer |
PluginConfigurations that need to pre-exist before the import but these are autodetected by the code in the |
226 |
09 Jan 07 |
mbayer |
PluginConfigDetector class. |
226 |
09 Jan 07 |
mbayer |
201 |
*/ |
226 |
09 Jan 07 |
mbayer |
202 |
public boolean supportsConfigurations() |
226 |
09 Jan 07 |
mbayer |
203 |
{ |
226 |
09 Jan 07 |
mbayer |
204 |
return false; |
226 |
09 Jan 07 |
mbayer |
205 |
} |
226 |
09 Jan 07 |
mbayer |
206 |
|
226 |
09 Jan 07 |
mbayer |
207 |
// ------------------------------------------------------------------------------------------------------------------------------------------ |
226 |
09 Jan 07 |
mbayer |
208 |
|
226 |
09 Jan 07 |
mbayer |
209 |
/** |
226 |
09 Jan 07 |
mbayer |
Returns information about where the plugin should be plugged in - in our case the Experiment view page. |
226 |
09 Jan 07 |
mbayer |
211 |
*/ |
226 |
09 Jan 07 |
mbayer |
212 |
public Set<GuiContext> getGuiContexts() |
226 |
09 Jan 07 |
mbayer |
213 |
{ |
226 |
09 Jan 07 |
mbayer |
214 |
return guiContexts; |
226 |
09 Jan 07 |
mbayer |
215 |
} |
226 |
09 Jan 07 |
mbayer |
216 |
|
226 |
09 Jan 07 |
mbayer |
217 |
// ------------------------------------------------------------------------------------------------------------------------------------------ |
226 |
09 Jan 07 |
mbayer |
218 |
|
226 |
09 Jan 07 |
mbayer |
219 |
/** |
226 |
09 Jan 07 |
mbayer |
Currently not used -- required if the plugin needs interactive configuration by the user |
226 |
09 Jan 07 |
mbayer |
221 |
*/ |
226 |
09 Jan 07 |
mbayer |
222 |
public String isInContext(GuiContext context, Object item) |
226 |
09 Jan 07 |
mbayer |
223 |
{ |
226 |
09 Jan 07 |
mbayer |
224 |
return null; |
226 |
09 Jan 07 |
mbayer |
225 |
} |
226 |
09 Jan 07 |
mbayer |
226 |
|
226 |
09 Jan 07 |
mbayer |
227 |
// ------------------------------------------------------------------------------------------------------------------------------------------ |
226 |
09 Jan 07 |
mbayer |
228 |
|
226 |
09 Jan 07 |
mbayer |
229 |
/** |
226 |
09 Jan 07 |
mbayer |
Returns info on parameters the user needs to enter before using the plugin. |
226 |
09 Jan 07 |
mbayer |
231 |
*/ |
226 |
09 Jan 07 |
mbayer |
232 |
public RequestInformation getRequestInformation(GuiContext context, String command) throws BaseException |
226 |
09 Jan 07 |
mbayer |
233 |
{ |
226 |
09 Jan 07 |
mbayer |
234 |
RequestInformation requestInformation = null; |
226 |
09 Jan 07 |
mbayer |
235 |
if (command.equals(Request.COMMAND_CONFIGURE_JOB)) |
226 |
09 Jan 07 |
mbayer |
236 |
{ |
226 |
09 Jan 07 |
mbayer |
237 |
requestInformation = getConfigureJob(); |
226 |
09 Jan 07 |
mbayer |
238 |
} |
226 |
09 Jan 07 |
mbayer |
239 |
return requestInformation; |
226 |
09 Jan 07 |
mbayer |
240 |
} |
226 |
09 Jan 07 |
mbayer |
241 |
|
226 |
09 Jan 07 |
mbayer |
242 |
// ------------------------------------------------------------------------------------------------------------------------------------------ |
226 |
09 Jan 07 |
mbayer |
243 |
|
226 |
09 Jan 07 |
mbayer |
244 |
/** |
226 |
09 Jan 07 |
mbayer |
Get (and build) the request information for starting a job. |
226 |
09 Jan 07 |
mbayer |
246 |
*/ |
226 |
09 Jan 07 |
mbayer |
247 |
private RequestInformation getConfigureJob() |
226 |
09 Jan 07 |
mbayer |
248 |
{ |
226 |
09 Jan 07 |
mbayer |
249 |
if (configureJob == null) |
226 |
09 Jan 07 |
mbayer |
250 |
{ |
226 |
09 Jan 07 |
mbayer |
251 |
fileParameter = new PluginParameter<File>("file", "File", "The zip file to import the data from", |
226 |
09 Jan 07 |
mbayer |
252 |
new FileParameterType(null, true, 1)); |
226 |
09 Jan 07 |
mbayer |
253 |
|
226 |
09 Jan 07 |
mbayer |
254 |
updateExistingParameter = new PluginParameter<Boolean>("updateExisting", |
226 |
09 Jan 07 |
mbayer |
255 |
"Update existing items", |
226 |
09 Jan 07 |
mbayer |
256 |
"If this option is selected, already existing items will be updated " + |
226 |
09 Jan 07 |
mbayer |
257 |
" with the information in the file. If this option isn't selected " + |
226 |
09 Jan 07 |
mbayer |
258 |
" existing items are left untouched.", |
226 |
09 Jan 07 |
mbayer |
259 |
new BooleanParameterType(false, true)); |
226 |
09 Jan 07 |
mbayer |
260 |
|
226 |
09 Jan 07 |
mbayer |
// Parameter for getting the current raw bioassay |
226 |
09 Jan 07 |
mbayer |
262 |
ItemParameterType<Experiment> experimentType = new ItemParameterType<Experiment>(Experiment.class, null, true, 1, null); |
226 |
09 Jan 07 |
mbayer |
263 |
experimentParameter = new PluginParameter<Experiment> |
226 |
09 Jan 07 |
mbayer |
264 |
( |
226 |
09 Jan 07 |
mbayer |
265 |
"experiment", |
226 |
09 Jan 07 |
mbayer |
266 |
"Experiment", |
226 |
09 Jan 07 |
mbayer |
267 |
"The experiment for importing the raw data into", |
226 |
09 Jan 07 |
mbayer |
268 |
experimentType |
226 |
09 Jan 07 |
mbayer |
269 |
); |
226 |
09 Jan 07 |
mbayer |
270 |
|
226 |
09 Jan 07 |
mbayer |
271 |
List<PluginParameter<?>> parameters = new ArrayList<PluginParameter<?>>(2); |
226 |
09 Jan 07 |
mbayer |
272 |
parameters.add(fileParameter); |
226 |
09 Jan 07 |
mbayer |
273 |
parameters.add(experimentParameter); |
226 |
09 Jan 07 |
mbayer |
274 |
|
226 |
09 Jan 07 |
mbayer |
275 |
configureJob = new RequestInformation(Request.COMMAND_CONFIGURE_JOB, |
226 |
09 Jan 07 |
mbayer |
276 |
"Select a file to import items from", "TODO - description", parameters); |
226 |
09 Jan 07 |
mbayer |
277 |
} |
226 |
09 Jan 07 |
mbayer |
278 |
return configureJob; |
226 |
09 Jan 07 |
mbayer |
279 |
} |
226 |
09 Jan 07 |
mbayer |
280 |
|
226 |
09 Jan 07 |
mbayer |
281 |
// ------------------------------------------------------------------------------------------------------------------------------------------ |
226 |
09 Jan 07 |
mbayer |
282 |
|
226 |
09 Jan 07 |
mbayer |
283 |
/** |
226 |
09 Jan 07 |
mbayer |
Sends parameter values entered by the user for processing by the plugin. |
226 |
09 Jan 07 |
mbayer |
Typically the plugin should validate that the parameter values are |
226 |
09 Jan 07 |
mbayer |
correct and then store them in the database. |
226 |
09 Jan 07 |
mbayer |
287 |
*/ |
226 |
09 Jan 07 |
mbayer |
288 |
public void configure(GuiContext context, Request request, Response response) |
226 |
09 Jan 07 |
mbayer |
289 |
{ |
226 |
09 Jan 07 |
mbayer |
//set the current GUI context so we can use it elsewhere |
226 |
09 Jan 07 |
mbayer |
291 |
|
226 |
09 Jan 07 |
mbayer |
292 |
|
226 |
09 Jan 07 |
mbayer |
293 |
String command = request.getCommand(); |
226 |
09 Jan 07 |
mbayer |
294 |
try |
226 |
09 Jan 07 |
mbayer |
295 |
{ |
226 |
09 Jan 07 |
mbayer |
296 |
if (command.equals(Request.COMMAND_CONFIGURE_PLUGIN)) |
226 |
09 Jan 07 |
mbayer |
297 |
{ |
226 |
09 Jan 07 |
mbayer |
// TODO |
226 |
09 Jan 07 |
mbayer |
299 |
} |
226 |
09 Jan 07 |
mbayer |
300 |
else if (command.equals(Request.COMMAND_CONFIGURE_JOB)) |
226 |
09 Jan 07 |
mbayer |
301 |
{ |
226 |
09 Jan 07 |
mbayer |
// Validate user input |
226 |
09 Jan 07 |
mbayer |
303 |
List<Throwable> errors = validateRequestParameters(getConfigureJob().getParameters(), request); |
226 |
09 Jan 07 |
mbayer |
304 |
if (errors != null) |
226 |
09 Jan 07 |
mbayer |
305 |
{ |
226 |
09 Jan 07 |
mbayer |
306 |
response.setError(errors.size() + " invalid parameter(s) were found in the request", errors); |
226 |
09 Jan 07 |
mbayer |
307 |
return; |
226 |
09 Jan 07 |
mbayer |
308 |
} |
226 |
09 Jan 07 |
mbayer |
309 |
|
226 |
09 Jan 07 |
mbayer |
// Store user input |
226 |
09 Jan 07 |
mbayer |
311 |
storeValue(job, request, fileParameter); |
226 |
09 Jan 07 |
mbayer |
312 |
storeValue(job, request, updateExistingParameter); |
226 |
09 Jan 07 |
mbayer |
313 |
storeValue(job, request, experimentParameter); |
226 |
09 Jan 07 |
mbayer |
314 |
|
226 |
09 Jan 07 |
mbayer |
// We are happy and done |
226 |
09 Jan 07 |
mbayer |
316 |
response.setDone("Job configuration complete", Job.ExecutionTime.SHORT); |
226 |
09 Jan 07 |
mbayer |
317 |
} |
226 |
09 Jan 07 |
mbayer |
318 |
} |
226 |
09 Jan 07 |
mbayer |
319 |
catch (Throwable ex) |
226 |
09 Jan 07 |
mbayer |
320 |
{ |
226 |
09 Jan 07 |
mbayer |
321 |
response.setError(ex.getMessage(), Arrays.asList(ex)); |
226 |
09 Jan 07 |
mbayer |
322 |
} |
226 |
09 Jan 07 |
mbayer |
323 |
} |
226 |
09 Jan 07 |
mbayer |
324 |
|
226 |
09 Jan 07 |
mbayer |
325 |
// ------------------------------------------------------------------------------------------------------------------------------------------ |
226 |
09 Jan 07 |
mbayer |
326 |
|
226 |
09 Jan 07 |
mbayer |
327 |
/** |
226 |
09 Jan 07 |
mbayer |
Required by the AutoDetectingImporter interface -- not sure why we actually need it since it never seems to be called |
226 |
09 Jan 07 |
mbayer |
329 |
*/ |
226 |
09 Jan 07 |
mbayer |
330 |
public void doImport(InputStream in, ProgressReporter progress) throws BaseException |
226 |
09 Jan 07 |
mbayer |
331 |
{ |
226 |
09 Jan 07 |
mbayer |
332 |
|
226 |
09 Jan 07 |
mbayer |
333 |
} |
226 |
09 Jan 07 |
mbayer |
334 |
// ------------------------------------------------------------------------------------------------------------------------------------------ |
226 |
09 Jan 07 |
mbayer |
335 |
/** |
226 |
09 Jan 07 |
mbayer |
Returns some info about the plugin |
226 |
09 Jan 07 |
mbayer |
337 |
*/ |
226 |
09 Jan 07 |
mbayer |
338 |
public About getAbout() |
226 |
09 Jan 07 |
mbayer |
339 |
{ |
226 |
09 Jan 07 |
mbayer |
340 |
return about; |
226 |
09 Jan 07 |
mbayer |
341 |
} |
226 |
09 Jan 07 |
mbayer |
342 |
|
226 |
09 Jan 07 |
mbayer |
343 |
// ------------------------------------------------------------------------------------------------------------------------------------------ |
226 |
09 Jan 07 |
mbayer |
344 |
|
226 |
09 Jan 07 |
mbayer |
345 |
/** |
226 |
09 Jan 07 |
mbayer |
The main type is the kind of job the plugin is configured to do -- in our case it's importing stuff. |
226 |
09 Jan 07 |
mbayer |
347 |
*/ |
226 |
09 Jan 07 |
mbayer |
348 |
public Plugin.MainType getMainType() |
226 |
09 Jan 07 |
mbayer |
349 |
{ |
226 |
09 Jan 07 |
mbayer |
350 |
return Plugin.MainType.IMPORT; |
226 |
09 Jan 07 |
mbayer |
351 |
} |
226 |
09 Jan 07 |
mbayer |
352 |
|
226 |
09 Jan 07 |
mbayer |
353 |
// ------------------------------------------------------------------------------------------------------------------------------------------ |
226 |
09 Jan 07 |
mbayer |
354 |
|
226 |
09 Jan 07 |
mbayer |
355 |
|
226 |
09 Jan 07 |
mbayer |
356 |
}//end class |