- Timestamp:
- Nov 28, 2007, 5:13:18 PM (14 years ago)
- Location:
- branches/uk_ac_ebi_Tab2MageImporter
- Files:
-
- 10 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/uk_ac_ebi_Tab2MageImporter/jsp/uk/ac/ebi/nugo/plugins/input.jsp
r486 r497 23 23 %> 24 24 25 25 <h2>Tab2MAGE Importer -- Experiment Configuration</h2> 26 26 27 27 <form action="index.jsp" method="get"> … … 115 115 name="parameter:pooling" value="no" checked="checked"></td> 116 116 </tr> 117 118 <tr> 119 <td align="center" colspan="2"> 120 <input type="submit" value="Continue" /> 121 </td> 122 </tr> 123 117 124 118 125 119 126 </table> 120 127 121 <p><input type="submit" value="Submit" />122 128 </form> 123 129 -
branches/uk_ac_ebi_Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/Tab2MageImporter.java
r486 r497 12 12 import java.util.LinkedList; 13 13 import java.util.List; 14 import java.util.Map; 14 15 import java.util.Set; 15 16 import java.util.zip.ZipEntry; … … 22 23 import net.sf.basedb.core.Experiment; 23 24 import net.sf.basedb.core.File; 24 import net.sf.basedb.core.FileParameterType;25 import net.sf.basedb.core.IntegerParameterType;26 25 import net.sf.basedb.core.Item; 27 26 import net.sf.basedb.core.Job; … … 32 31 import net.sf.basedb.core.RequestInformation; 33 32 import net.sf.basedb.core.StringParameterType; 33 import net.sf.basedb.core.User; 34 34 import net.sf.basedb.core.plugin.About; 35 35 import net.sf.basedb.core.plugin.AboutImpl; … … 41 41 import net.sf.basedb.core.plugin.Request; 42 42 import net.sf.basedb.core.plugin.Response; 43 import uk.ac.ebi.nugo.common.Helper; 44 import uk.ac.ebi.nugo.common.ZipUnpacker; 45 import uk.ac.ebi.nugo.plugins.tab2mageimport.ValidationConstants; 46 import uk.ac.ebi.nugo.plugins.tab2mageimport.io.AnnotationTypesWriter; 47 import uk.ac.ebi.nugo.plugins.tab2mageimport.io.Tab2MageDataImportFactory; 48 import uk.ac.ebi.nugo.plugins.tab2mageimport.io.Tab2MageExperimentWriter; 49 import uk.ac.ebi.nugo.plugins.tab2mageimport.io.Tab2MageWriterFactory; 50 import uk.ac.ebi.nugo.plugins.tab2mageimport.mail.Tab2MageEMessaging; 51 import uk.ac.ebi.nugo.plugins.tab2mageimport.validation.Tab2MageValidationFactory; 43 52 import uk.ac.ebi.nugo.plugins.util.tab2mage.Tab2MageHelper; 44 53 … … 52 61 public class Tab2MageImporter extends AbstractPlugin implements InteractivePlugin, AutoDetectingImporter 53 62 { 63 64 // =======================================================vars=================================== 65 54 66 // 55 67 private RequestInformation configureJob; … … 93 105 PluginParameter tissues; 94 106 PluginParameter pooling; 95 107 PluginParameter experimentName; 108 PluginParameter treatmentProtocol; 109 110 //holds the plugin/job config parameters 111 LinkedList<PluginParameter<?>> params; 96 112 97 113 private static final About about = new AboutImpl("Tab2Mage Importer", "This plugin is used to import raw data files and an experiment in the tab2mage format specfication. The tab2mage specification " + "is provided by the microarray informatics team at the EBI, Cambridge. The imported experiment can later be " + "exported by the corresponding tab2mage export plugin.", "1.0", "@Copyright 2007, The EBI NutriBase development team", "Dominic Oyeniran", "oyeniran@ebi.ac.uk", "http://www.ebi.ac.uk/~oyeniran"); … … 100 116 101 117 private static final Set<GuiContext> guiContexts = Collections.singleton(experimentItemGuiContext); 118 119 // =====================================================c'tor================================== 102 120 103 121 /** … … 107 125 public Tab2MageImporter() 108 126 { 109 } 127 initParams(); 128 } 129 130 131 // ================================================methods==================================== 132 133 134 private void initParams() 135 { 136 // first create the parameter types 137 StringParameterType stringPT = new StringParameterType(255, null, true); 138 139 // create the plugin parameter objects here 140 experimentName = new PluginParameter<String>("experimentName", "experimentName", "experimentName", stringPT); 141 treatmentProtocol = new PluginParameter<String>("treatmentProtocol", "treatmentProtocol", "treatmentProtocol", stringPT); 142 // zipFile = new PluginParameter<String>("zipFile", " Zip file", "Contains raw data files", stringPT); 143 platform = new PluginParameter<String>("platform", "Platform", "chip platform used", stringPT); 144 // organism = new PluginParameter<String>("organism", "Organism", "First string", stringPT); 145 // numDesigns = new PluginParameter<String>("numDesigns", "NumDesigns", "Second string", stringPT); 146 // dyeSwap = new PluginParameter<String>("dyeSwap", "dyeSwap", "dyeSwap", stringPT); 147 // refSample = new PluginParameter<String>("refSample","refSample","refSample", stringPT); 148 // numTreatments = new PluginParameter<String>("numTreatments","numTreatments","numTreatments", stringPT); 149 // expFactors = new PluginParameter<String>("expFactors","expFactors","expFactors",stringPT); 150 // numReplicates = new PluginParameter<String>("numReplicates","numReplicates","numReplicates", stringPT); 151 // tissues = new PluginParameter<String>("tissues","tissues","tissues", stringPT); 152 // pooling = new PluginParameter<String>("pooling","pooling","pooling",stringPT); 153 154 //add them all to a list 155 params = new LinkedList<PluginParameter<?>>(); 156 params.add(experimentName); 157 params.add(treatmentProtocol); 158 // params.add(zipFile); 159 params.add(platform); 160 // params.add(organism); 161 // params.add(numDesigns); 162 // params.add(dyeSwap); 163 // params.add(refSample); 164 // params.add(numTreatments); 165 // params.add(expFactors); 166 // params.add(numReplicates); 167 // params.add(tissues); 168 // params.add(pooling); 169 } 170 171 // ---------------------------------------------------------------------------------------------------------------------------------------------- 110 172 111 173 public void configure(GuiContext context, Request request, Response response) … … 117 179 try 118 180 { 119 if (command.equals(Request.COMMAND_CONFIGURE_PLUGIN)) 120 { 121 122 } 123 else if (command.equals(Request.COMMAND_CONFIGURE_JOB)) 181 if (command.equals(Request.COMMAND_CONFIGURE_JOB)) 124 182 { 125 183 //validation 126 // List<Throwable> errors = validateRequestParameters (getConfigureJobParameters().getParameters(), request); 127 // if (errors != null) 128 // { 129 // response.setError(errors.size() + " invalid parameters were found in the request",errors); 130 // return; 184 List<Throwable> errors = validateRequestParameters (params, request); 185 if (errors != null) 186 { 187 response.setError(errors.size() + " invalid parameters were found in the request",errors); 188 return; 189 } 131 190 132 191 //store the parameter values in the database 133 storeValue(job, request, zipFile); 134 storeValue(job, request, platform); 135 storeValue(job, request, organism); 136 storeValue(job, request, numDesigns); 137 storeValue(job, request, dyeSwap); 138 storeValue(job, request, refSample); 139 storeValue(job, request, numTreatments); 140 storeValue(job, request, expFactors); 141 storeValue(job, request, numReplicates); 142 storeValue(job, request, tissues); 143 storeValue(job, request, pooling); 144 145 // set the response as done 146 response.setDone("Job configuration complete", Job.ExecutionTime.SHORT); 192 for(PluginParameter<?> param : params) 193 { 194 storeValue(job, request, param); 195 } 196 197 //for speedy testing 198 //requires plugin to be set up so that immediate execution is allowed 199 response.setExecuteImmediately("Job configuration complete", Job.ExecutionTime.SHORT,true); 200 201 //set the response as done 202 //response.setDone("Job configuration complete", Job.ExecutionTime.SHORT); 147 203 148 204 //print out current values 205 System.out.println("current parameter values:"); 149 206 PluginConfigurationRequest pcRequest = (PluginConfigurationRequest) sc.getSessionSetting("plugin.configure.request"); 150 String zipFile = (String)pcRequest.getCurrentParameterValue("zipFile"); 151 String platform = (String) pcRequest.getCurrentParameterValue("platform"); 152 String organism = (String) pcRequest.getCurrentParameterValue("organism"); 153 String numDesigns = (String) pcRequest.getCurrentParameterValue("numDesigns"); 154 String dyeSwap = (String) pcRequest.getCurrentParameterValue("dyeSwap"); 155 String refSample = (String) pcRequest.getCurrentParameterValue("refSample"); 156 String numTreatments = (String) pcRequest.getCurrentParameterValue("numTreatments"); 157 String expFactors = (String) pcRequest.getCurrentParameterValue("expFactors"); 158 String numReplicates = (String) pcRequest.getCurrentParameterValue("numReplicates"); 159 String tissues = (String) pcRequest.getCurrentParameterValue("tissues"); 160 String pooling = (String) pcRequest.getCurrentParameterValue("pooling"); 161 162 System.out.println("zipFile = " + zipFile); 163 System.out.println("platform = " + platform); 164 System.out.println("numDesigns = " + numDesigns); 165 System.out.println("numTreatments = " + numTreatments); 166 System.out.println("numReplicates = " + numReplicates); 167 System.out.println("dyeSwap = " + dyeSwap); 168 System.out.println("organism = " + organism); 169 System.out.println("refSample = " + refSample); 170 System.out.println("expFactors = " + expFactors); 171 System.out.println("numReplicates = " + numReplicates); 172 System.out.println("tissues = " + tissues); 173 System.out.println("pooling = " + pooling); 174 207 for(PluginParameter<?> param : params) 208 { 209 String value = (String)pcRequest.getCurrentParameterValue(param.getName()); 210 System.out.println(param.getName() + " = " + value); 211 } 175 212 } 176 213 } … … 183 220 } 184 221 185 /* 186 * From the InteractivePlugin interface ------------------------------------------- 187 */ 222 // ---------------------------------------------------------------------------------------------------------------------------------------------- 223 188 224 /** 189 225 * Return a set containing the context:s [ARRAY DESIGN, LIST], … … 194 230 } 195 231 232 // ---------------------------------------------------------------------------------------------------------------------------------------------- 233 196 234 /** 197 235 * checks that the we are using the experiment object and that it is not null returns null if we are not working on an ITEM but a LIST … … 221 259 } 222 260 261 // ---------------------------------------------------------------------------------------------------------------------------------------------- 262 223 263 public RequestInformation getRequestInformation(GuiContext context, String command) throws BaseException 224 264 { … … 229 269 try 230 270 { 231 // first create the parameter types232 StringParameterType stringPT = new StringParameterType(255, null, true);233 234 // create the plugin parameter objects here235 zipFile = new PluginParameter<String>("zipFile", " Zip file", "Contains raw data files", stringPT);236 platform = new PluginParameter<String>("platform", "Platform", "chip platform used", stringPT);237 organism = new PluginParameter<String>("organism", "Organism", "First string", stringPT);238 numDesigns = new PluginParameter<String>("numDesigns", "NumDesigns", "Second string", stringPT);239 dyeSwap = new PluginParameter<String>("dyeSwap", "dyeSwap", "dyeSwap", stringPT);240 refSample = new PluginParameter<String>("refSample","refSample","refSample", stringPT);241 numTreatments = new PluginParameter<String>("numTreatments","numTreatments","numTreatments", stringPT);242 expFactors = new PluginParameter<String>("expFactors","expFactors","expFactors",stringPT);243 numReplicates = new PluginParameter<String>("numReplicates","numReplicates","numReplicates", stringPT);244 tissues = new PluginParameter<String>("tissues","tissues","tissues", stringPT);245 pooling = new PluginParameter<String>("pooling","pooling","pooling",stringPT);246 247 // add them all to our list248 List<PluginParameter<?>> parameters = new LinkedList<PluginParameter<?>>();249 parameters.add(zipFile);250 parameters.add(platform);251 parameters.add(organism);252 parameters.add(numDesigns);253 parameters.add(dyeSwap);254 parameters.add(refSample);255 parameters.add(numTreatments);256 parameters.add(expFactors);257 parameters.add(numReplicates);258 parameters.add(tissues);259 parameters.add(pooling);260 261 271 //the request information object provides the parameter list and the name of the custom input page to navigate to for 262 272 //the configuration of the plugin run 263 requestInformation = new RequestInformation(Request.COMMAND_CONFIGURE_JOB, null, null, param eters, "input.jsp");264 } 265 catch ( Throwablee)273 requestInformation = new RequestInformation(Request.COMMAND_CONFIGURE_JOB, null, null, params, "experiment.jsp"); 274 } 275 catch (Exception e) 266 276 { 267 277 e.printStackTrace(); … … 271 281 } 272 282 273 /* 274 * From the Plugin interface -------------------------------- 275 */ 283 // ---------------------------------------------------------------------------------------------------------------------------------------------- 284 276 285 public About getAbout() 277 286 { … … 279 288 } 280 289 290 // ---------------------------------------------------------------------------------------------------------------------------------------------- 291 281 292 public MainType getMainType() 282 293 { 283 294 return Plugin.MainType.IMPORT; 284 295 } 285 286 public void run(Request request, Response response, ProgressReporter progress) 287 { 288 // DbControl dc=null; 289 // String hostName=""; 290 // boolean validPlatform=false, validateImageFile, validTab2mageFile, validTab2mageFileName=false; 291 // boolean overwrite= false, validation = false; 292 // try 293 // { 294 // //who is using this plugin 295 // dc= sc.newDbControl(); 296 // User user= User.getById(dc, sc.getLoggedInUserId()); 297 298 // /* 299 // obtain all job parameters 300 // */ 301 // File file = (File) job.getValue("file"); 302 // file= File.getById(dc, file.getId()); 303 304 // String directoryName = (String)job.getValue("directory"); 305 306 // String tab2MageFileName= (String) job.getValue("tab2mageFileName"); 307 // hostName= (String) job.getValue("emailHost"); 308 309 // if ((Boolean)job.getValue("overwrite") != null) overwrite = (Boolean)job.getValue("overwrite"); 310 // if ((Boolean)job.getValue("validation") != null) validation = (Boolean)job.getValue("validation"); 311 312 // Experiment experiment= (Experiment)job.getValue("experiment"); 313 // experiment= Experiment.getById(dc,experiment.getId()); 314 // RawDataType rdt= experiment.getRawDataType(); // experiment platform 315 316 // String statusp=(String)job.getValue("statusPath"); 317 // File statusFile=Helper.processFilePath(user,overwrite, sc,statusp); 318 319 // /* 320 // FILE UNZIP MODULE: unzip the files into user specified directory 321 // */ 322 323 // ZipUnpacker importUnpacker = new ZipUnpacker(file, user, sc); 324 // importUnpacker.unpack(directoryName); 325 // Directory dir= importUnpacker.getUnzippedFilesDirectory(); // this may return the id of the unzipped file directory instead 326 // if (dir==null) 327 // { 328 // response.setError("IMPORT FAILS: The zip file cannot be unzipped. You may NOT have sufficient Disk Space or " + 329 // "Lack permission to read or use the Directory" ,Arrays.asList(new Throwable())); 330 // return; 331 // } 332 333 // // -- end of file unzip module 334 335 // /* 336 // VALIDATION MODULE 337 // */ 338 339 // if (dc == null || !dc.isConnected()|| dc.isClosed()) dc = sc.newDbControl(); 340 341 // // validate files supplied to platform 342 // validPlatform=Tab2MageHelper.validatePlatform(dir, dc, rdt); 343 // if (!validPlatform) 344 // { 345 // response.setError("IMPORT FAILS: Invalid File format: files supplied not appropriate for the experiment platform: [ " + rdt.getId() +" ]" ,Arrays.asList(new Throwable())); 346 // return; 347 // } 348 349 // // validate image file 350 // List<File> imageFiles=Tab2MageHelper.getImageFiles(dir, dc) ; 351 // if (!imageFiles.isEmpty()|| imageFiles==null) 352 // { 353 // validateImageFile= Tab2MageHelper.validateImages(imageFiles, rdt); 354 // if (!validateImageFile) 355 // { 356 // response.setError("IMPORT FAILS: Invalid Image File format: image files supplied not appropriate for the experiment platform: [ " + rdt.getId() +" ]" ,Arrays.asList(new 357 // Throwable())); 358 // return; 359 // } 360 // } 361 // // validate the tab2mage file (do initialisation here too) 362 363 // Tab2MageValidationFactory validator = new Tab2MageValidationFactory(tab2MageFileName, sc, dir, rdt.getId(), response, statusFile); 364 // validTab2mageFileName = validator.validateTab2MageFileName(); 365 // if (!validTab2mageFileName) 366 // { 367 // response.setError("IMPORT FAILS: The Tab2Mage filename provided as parameter on the GUI : [ " + tab2MageFileName+ " ] does not match that contained in the zip file" 368 // ,Arrays.asList(new Throwable())); 369 // return; 370 // } 371 372 // Map<ValidationConstants, Boolean> validations= validator.validateTab2MageFile(); 373 // StringBuffer failureMessage = new StringBuffer(); 374 // if (!validations.isEmpty()) 375 // { 376 // for (ValidationConstants key : validations.keySet()) 377 // { 378 // failureMessage.append(key.getKeyMessage()+";") ; 379 // } 380 // response.setError("IMPORT FAILS: Tab2Mage file validation is UNSUCCESSFUL. The ['"+ failureMessage.substring(0, failureMessage.length()-1)+ "'] Failed. " + 381 // "Check the Validation ReportFile ["+statusFile.getPath().toString()+"] on BASE File System for Details" ,Arrays.asList(new Throwable())); 382 // return; 383 // } 384 385 // // -- end of validation module 386 // if (validation) 387 // { 388 // Directory delDir =Directory.getById(dc, dir.getId()); 389 // response.setDone("Validation Successful. Check the Validation File [ "+statusFile.getPath().toString()+" ] for annotations warning. The unzipped directory " + 390 // "name [ "+delDir.getName()+" ] CANNOT be re-used as a parameter to re-run the tab2mage importer."); 391 // return; 392 // } 393 394 // /* 395 // TAB2MAGE FILE IMPORT MODULE. 396 // */ 397 // // create annotation types 398 // AnnotationTypesWriter atWriter= new AnnotationTypesWriter (sc, validator.getAtFile(),progress); 399 // boolean writtenAT =atWriter.write(); // note if this action failed the transaction is completely rolled back 400 // if (!writtenAT) 401 // { 402 // response.setError("IMPORT FAILS: Annotation Type was not written to the Database. Check Log error for details" ,Arrays.asList(new Throwable())); 403 // return; 404 // } 405 406 // // write protocols and hybs 407 // Tab2MageWriterFactory hibernateItemsWriter = new Tab2MageWriterFactory 408 // (sc,Tab2MageValidationFactory.getCatchedProtocol(), 409 // Tab2MageValidationFactory.getCatchedHybs(),rdt, 410 // validator.getSampleExtractMap(), 411 // validator.getBioSourceSampleMap(), 412 // validator.getExtractLabeledExtractMap()); 413 414 // // if the protocol type is not found, write it into the database. 415 // // alternative is to fail at validation instead of a warning, if the protocol type 416 // // provided in tab2mage file is not in Base2 database. 417 418 // hibernateItemsWriter.writeProtocolTypes(); 419 420 // boolean writtenHibItems = hibernateItemsWriter.write(); 421 // if (!writtenHibItems) 422 // { 423 // response.setError("IMPORT FAILS: Protocol and Hybridization items were not written to the Database. Check Log error for details" ,Arrays.asList(new Throwable())); 424 // return; 425 // } 426 427 // boolean writtenPoolItems = hibernateItemsWriter.writePooledMetaData(); 428 // if (!writtenPoolItems) 429 // { 430 // response.setError("IMPORT FAILS: Pooled items were not written to the Database. Check Log error for details" ,Arrays.asList(new Throwable())); 431 // return; 432 // } 433 // // -- end of Tab2Mage file import module 434 435 // /* 436 // RAW DATA IMPORT MODULE 437 438 // */ 439 440 // if (dc == null || !dc.isConnected()|| dc.isClosed()) dc = sc.newDbControl(); 441 442 // // get raw data files 443 // List<File> rawDataFiles= Tab2MageHelper.getRawDataFiles(dir, dc, rdt.getId(), tab2MageFileName); 444 445 // // do data import 446 // Tab2MageDataImportFactory dataImport = new Tab2MageDataImportFactory(sc,rdt.getId(),rawDataFiles, 447 // hibernateItemsWriter.getRbas(), progress); 448 // boolean writtenRawData = dataImport.importData(); 449 // if (!writtenRawData) 450 // { 451 // response.setError("IMPORT FAILS: Raw Data cannot not be written to the Database. Check Log error for details" ,Arrays.asList(new Throwable())); 452 // return; 453 // } 454 // // -- end of raw data import module 455 456 // /* 457 // EXPERIMENT CONFIGURATION AND LOADING MODULE 458 459 // */ 460 // //write experiment, attaching raw bio-assays 461 // Tab2MageExperimentWriter expWriter= new Tab2MageExperimentWriter(hibernateItemsWriter.getRbas(),sc, 462 // experiment,hibernateItemsWriter.getExpFactors(), 463 // validator.getTExperiment()); 464 // boolean writtenExp= expWriter.LoadExperiment(); 465 // // -- end of experiment configuration and loading module 466 467 // /* 468 // MESSAGING MODULE 469 // */ 470 // // send an email to the user on the success of the experiment (if email server name and email address are provided) 471 // if (hostName!= null && hostName.length()>=5) 472 // { 473 // if (!user.getEmail().equals("") && user.getEmail()!=null ) 474 // { 475 // Tab2MageEMessaging message= new Tab2MageEMessaging(writtenExp,"", user.getEmail(),tab2MageFileName, user.getName(), experiment.getName(),hostName ); 476 // message.sendEmail(); 477 // } 478 // } 479 // // -- end of messaging module 480 // dc.commit(); 481 // response.setDone("Import plugin ended successfully"); 482 // } 483 // catch(Throwable tr) 484 // { 485 // response.setError(tr.getMessage(), Arrays.asList(tr)); 486 // } 487 // finally 488 // { 489 // if (dc!=null) 490 // dc.close(); 491 // } 492 493 System.out.println("running Tab2MageImporter plugin (testing run method only)"); 494 response.setDone("Plugin ended successfully"); 495 } 496 497 /* 498 * From AutoDetectionImporter interface 499 */ 500 /** 501 * checks whether the zip file supplied by the user is actually a zip file. 502 */ 503 public boolean isImportable(InputStream in) throws BaseException 504 { 505 ZipInputStream zin = null; 506 try 507 { 508 zin = new ZipInputStream(in); 509 // if this is not a zip file, this will throw an exception: 510 ZipEntry zn = zin.getNextEntry(); 511 } 512 catch (Exception e) 513 { 514 return false; 515 } 516 finally 517 { 518 try 519 { 520 zin.close(); 521 } 522 catch (IOException ex) 523 { 524 throw new BaseException(ex); 525 } 526 } 527 return true; 528 } 296 297 // ---------------------------------------------------------------------------------------------------------------------------------------------- 529 298 530 299 public void doImport(InputStream in, ProgressReporter progress) throws BaseException 531 300 { 532 301 } 302 303 // ---------------------------------------------------------------------------------------------------------------------------------------------- 533 304 534 305 /** … … 555 326 } 556 327 } 557 } 328 329 330 // ---------------------------------------------------------------------------------------------------------------------------------------------- 331 332 /** 333 * checks whether the zip file supplied by the user is actually a zip file. 334 */ 335 public boolean isImportable(InputStream in) throws BaseException 336 { 337 ZipInputStream zin = null; 338 try 339 { 340 zin = new ZipInputStream(in); 341 // if this is not a zip file, this will throw an exception: 342 ZipEntry zn = zin.getNextEntry(); 343 } 344 catch (Exception e) 345 { 346 return false; 347 } 348 finally 349 { 350 try 351 { 352 zin.close(); 353 } 354 catch (IOException ex) 355 { 356 throw new BaseException(ex); 357 } 358 } 359 return true; 360 } 361 362 // ---------------------------------------------------------------------------------------------------------------------------------------------- 363 364 public void run(Request request, Response response, ProgressReporter progress) 365 { 366 System.out.println("running Tab2MageImporter plugin"); 367 response.setDone("Import plugin ended successfully"); 368 /* 369 370 DbControl dc=null; 371 String hostName=""; 372 boolean validPlatform=false, validateImageFile, validTab2mageFile, validTab2mageFileName=false; 373 boolean overwrite= false, validation = false; 374 try 375 { 376 //who is using this plugin 377 dc= sc.newDbControl(); 378 User user= User.getById(dc, sc.getLoggedInUserId()); 379 380 381 //obtain all job parameters 382 383 File file = (File) job.getValue("file"); 384 file= File.getById(dc, file.getId()); 385 386 String directoryName = (String)job.getValue("directory"); 387 388 String tab2MageFileName= (String) job.getValue("tab2mageFileName"); 389 hostName= (String) job.getValue("emailHost"); 390 391 if ((Boolean)job.getValue("overwrite") != null) overwrite = (Boolean)job.getValue("overwrite"); 392 if ((Boolean)job.getValue("validation") != null) validation = (Boolean)job.getValue("validation"); 393 394 Experiment experiment= (Experiment)job.getValue("experiment"); 395 experiment= Experiment.getById(dc,experiment.getId()); 396 RawDataType rdt= experiment.getRawDataType(); // experiment platform 397 398 String statusp=(String)job.getValue("statusPath"); 399 File statusFile=Helper.processFilePath(user,overwrite, sc,statusp); 400 401 //FILE UNZIP MODULE: unzip the files into user specified directory 402 403 ZipUnpacker importUnpacker = new ZipUnpacker(file, user, sc); 404 importUnpacker.unpack(directoryName); 405 Directory dir= importUnpacker.getUnzippedFilesDirectory(); // this may return the id of the unzipped file directory instead 406 if (dir==null) 407 { 408 response.setError("IMPORT FAILS: The zip file cannot be unzipped. You may NOT have sufficient Disk Space or " + 409 "Lack permission to read or use the Directory" ,Arrays.asList(new Throwable())); 410 return; 411 } 412 413 // -- end of file unzip module 414 415 /////////////////////////////////////////////////////////////////////////////////////////////////// 416 417 //now write the tab2mage file to the user's home dir on the server so it can be consumed by the plugin 418 //this takes all the inputs provided by the user on the custom interface (input.jsp) 419 //give the file a unique name so we don't get any conflicts 420 //use code from tab2mage exporter to do so 421 422 ///////////////////////////////////////////////////////////////////////////////////////////////// 423 424 425 426 //VALIDATION MODULE 427 428 429 if (dc == null || !dc.isConnected()|| dc.isClosed()) dc = sc.newDbControl(); 430 431 // validate files supplied to platform 432 validPlatform=Tab2MageHelper.validatePlatform(dir, dc, rdt); 433 if (!validPlatform) 434 { 435 response.setError("IMPORT FAILS: Invalid File format: files supplied not appropriate for the experiment platform: [ " + rdt.getId() +" ]" ,Arrays.asList(new Throwable())); 436 return; 437 } 438 439 // validate image file 440 List<File> imageFiles=Tab2MageHelper.getImageFiles(dir, dc) ; 441 if (!imageFiles.isEmpty()|| imageFiles==null) 442 { 443 validateImageFile= Tab2MageHelper.validateImages(imageFiles, rdt); 444 if (!validateImageFile) 445 { 446 response.setError("IMPORT FAILS: Invalid Image File format: image files supplied not appropriate for the experiment platform: [ " + rdt.getId() +" ]" ,Arrays.asList(new Throwable())); 447 return; 448 } 449 } 450 // validate the tab2mage file (do initialisation here too) 451 452 Tab2MageValidationFactory validator = new Tab2MageValidationFactory(tab2MageFileName, sc, dir, rdt.getId(), response, statusFile); 453 validTab2mageFileName = validator.validateTab2MageFileName(); 454 if (!validTab2mageFileName) 455 { 456 response.setError("IMPORT FAILS: The Tab2Mage filename provided as parameter on the GUI : [ " + tab2MageFileName+ " ] does not match that contained in the zip file" ,Arrays.asList(new Throwable())); 457 return; 458 } 459 460 Map<ValidationConstants, Boolean> validations= validator.validateTab2MageFile(); 461 StringBuffer failureMessage = new StringBuffer(); 462 if (!validations.isEmpty()) 463 { 464 for (ValidationConstants key : validations.keySet()) 465 { 466 failureMessage.append(key.getKeyMessage()+";") ; 467 } 468 response.setError("IMPORT FAILS: Tab2Mage file validation is UNSUCCESSFUL. The ['"+ failureMessage.substring(0, failureMessage.length()-1)+ "'] Failed. " + 469 "Check the Validation ReportFile ["+statusFile.getPath().toString()+"] on BASE File System for Details" ,Arrays.asList(new Throwable())); 470 return; 471 } 472 473 // -- end of validation module 474 if (validation) 475 { 476 Directory delDir =Directory.getById(dc, dir.getId()); 477 response.setDone("Validation Successful. Check the Validation File [ "+statusFile.getPath().toString()+" ] for annotations warning. The unzipped directory " + 478 "name [ "+delDir.getName()+" ] CANNOT be re-used as a parameter to re-run the tab2mage importer."); 479 return; 480 } 481 482 483 //TAB2MAGE FILE IMPORT MODULE. 484 485 // create annotation types 486 AnnotationTypesWriter atWriter= new AnnotationTypesWriter (sc, validator.getAtFile(),progress); 487 boolean writtenAT =atWriter.write(); // note if this action failed the transaction is completely rolled back 488 if (!writtenAT) 489 { 490 response.setError("IMPORT FAILS: Annotation Type was not written to the Database. Check Log error for details" ,Arrays.asList(new Throwable())); 491 return; 492 } 493 494 // write protocols and hybs 495 Tab2MageWriterFactory hibernateItemsWriter = new Tab2MageWriterFactory 496 (sc,Tab2MageValidationFactory.getCatchedProtocol(), 497 Tab2MageValidationFactory.getCatchedHybs(),rdt, 498 validator.getSampleExtractMap(), 499 validator.getBioSourceSampleMap(), 500 validator.getExtractLabeledExtractMap()); 501 502 // if the protocol type is not found, write it into the database. 503 // alternative is to fail at validation instead of a warning, if the protocol type 504 // provided in tab2mage file is not in Base2 database. 505 506 hibernateItemsWriter.writeProtocolTypes(); 507 508 boolean writtenHibItems = hibernateItemsWriter.write(); 509 if (!writtenHibItems) 510 { 511 response.setError("IMPORT FAILS: Protocol and Hybridization items were not written to the Database. Check Log error for details" ,Arrays.asList(new Throwable())); 512 return; 513 } 514 515 boolean writtenPoolItems = hibernateItemsWriter.writePooledMetaData(); 516 if (!writtenPoolItems) 517 { 518 response.setError("IMPORT FAILS: Pooled items were not written to the Database. Check Log error for details" ,Arrays.asList(new Throwable())); 519 return; 520 } 521 // -- end of Tab2Mage file import module 522 523 524 //RAW DATA IMPORT MODULE 525 526 527 if (dc == null || !dc.isConnected()|| dc.isClosed()) dc = sc.newDbControl(); 528 529 // get raw data files 530 List<File> rawDataFiles= Tab2MageHelper.getRawDataFiles(dir, dc, rdt.getId(), tab2MageFileName); 531 532 // do data import 533 Tab2MageDataImportFactory dataImport = new Tab2MageDataImportFactory(sc,rdt.getId(),rawDataFiles, 534 hibernateItemsWriter.getRbas(), progress); 535 boolean writtenRawData = dataImport.importData(); 536 if (!writtenRawData) 537 { 538 response.setError("IMPORT FAILS: Raw Data cannot not be written to the Database. Check Log error for details" ,Arrays.asList(new Throwable())); 539 return; 540 } 541 // -- end of raw data import module 542 543 544 //EXPERIMENT CONFIGURATION AND LOADING MODULE 545 546 //write experiment, attaching raw bio-assays 547 Tab2MageExperimentWriter expWriter= new Tab2MageExperimentWriter(hibernateItemsWriter.getRbas(),sc, 548 experiment,hibernateItemsWriter.getExpFactors(), 549 validator.getTExperiment()); 550 boolean writtenExp= expWriter.LoadExperiment(); 551 // -- end of experiment configuration and loading module 552 553 //MESSAGING MODULE 554 555 // send an email to the user on the success of the experiment (if email server name and email address are provided) 556 if (hostName!= null && hostName.length()>=5) 557 { 558 if (!user.getEmail().equals("") && user.getEmail()!=null ) 559 { 560 Tab2MageEMessaging message= new Tab2MageEMessaging(writtenExp,"", user.getEmail(),tab2MageFileName, user.getName(), experiment.getName(),hostName ); 561 message.sendEmail(); 562 } 563 } 564 // -- end of messaging module 565 566 dc.commit(); 567 response.setDone("Import plugin ended successfully"); 568 } 569 catch(Throwable tr) 570 { 571 response.setError(tr.getMessage(), Arrays.asList(tr)); 572 } 573 finally 574 { 575 if (dc!=null) 576 dc.close(); 577 } 578 579 */ 580 581 } 582 583 584 // ---------------------------------------------------------------------------------------------------------------------------------------------- 585 586 }//end class
Note: See TracChangeset
for help on using the changeset viewer.