Changeset 460


Ignore:
Timestamp:
Oct 31, 2007, 6:19:59 PM (14 years ago)
Author:
dominic
Message:

commit file for the latest version of the tab2mage importer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/Tab2MageImporter.java

    r417 r460  
    1212import java.util.Collections;
    1313import java.util.List;
     14import java.util.Map;
    1415import java.util.Set;
    1516import java.util.zip.ZipEntry;
     
    1718
    1819import net.sf.basedb.core.BaseException;
     20import net.sf.basedb.core.BooleanParameterType;
    1921import net.sf.basedb.core.DbControl;
    2022import net.sf.basedb.core.Directory;
     
    2426import net.sf.basedb.core.Item;
    2527import net.sf.basedb.core.ItemParameterType;
     28import net.sf.basedb.core.Path;
     29import net.sf.basedb.core.PathParameterType;
    2630import net.sf.basedb.core.PluginParameter;
    2731import net.sf.basedb.core.ProgressReporter;
     
    3943import net.sf.basedb.core.plugin.Request;
    4044import net.sf.basedb.core.plugin.Response;
     45import uk.ac.ebi.nugo.common.Helper;
    4146import uk.ac.ebi.nugo.common.ZipUnpacker;
     47import uk.ac.ebi.nugo.plugins.tab2mageimport.ValidationConstants;
    4248import uk.ac.ebi.nugo.plugins.tab2mageimport.io.AnnotationTypesWriter;
    4349import uk.ac.ebi.nugo.plugins.tab2mageimport.io.Tab2MageDataImportFactory;
     
    7177  private PluginParameter<String> emailHostParameter;
    7278 
     79  // validation file parameter
     80  private PluginParameter<String> statusPathParameter;
     81 
     82  // boolean overwrite parameter type
     83  private BooleanParameterType overwriteType= new BooleanParameterType(false, false);;
     84 
     85  // overwrite parameter
     86  private PluginParameter<Boolean> overWriteParameter;
     87
     88  //  validation mode parameter
     89  private PluginParameter<Boolean> validationParameter;
     90 
    7391  private static final About about =
    7492    new AboutImpl
     
    123141          "The experiment to import to", 
    124142          new ItemParameterType<Experiment>(Experiment.class, null,true,1,null));
     143     
     144      statusPathParameter = new PluginParameter<String>(
     145          "statusPath",
     146          "Save Validation Report As",
     147          "Please specify the file name where the plugin should store causes for failure and errors during validation",
     148          new PathParameterType(Path.Type.FILE, Helper.getUserDefaultDirectory(sc)+"/validationreport.txt", true));
    125149           
     150       overWriteParameter = new PluginParameter<Boolean>(
     151           "overwrite",
     152           "Overwrite",
     153           "Overwrite existing validation file?",
     154           overwriteType);
     155       
     156       validationParameter = new PluginParameter<Boolean>(
     157           "validation",
     158           "Run Validation Only",
     159           "Set parameter to TRUE to run the plugin in VALIDATION MODE ONLY.",
     160           overwriteType);
     161       
    126162      List<PluginParameter<?>> parameters = new ArrayList<PluginParameter<?>>();
    127163      parameters.add(fileParameter);
     
    129165      parameters.add(emailHostParameter);
    130166      parameters.add(experimentParameter);
     167      parameters.add(statusPathParameter);
     168      parameters.add(overWriteParameter);
     169      parameters.add(validationParameter);
    131170     
    132171      configureJob = new RequestInformation
     
    134173          Request.COMMAND_CONFIGURE_JOB,
    135174          "Tab2Mage importer options",
    136           "Set the zip file path and the paramters required to import raw data files and tab2mage experiment meta data.",
     175          "Set the zip file path and the parameters required to import raw data files and tab2mage experiment meta data." +
     176          "To run the Validation Mode Please set 'Run Validation' to TRUE. ",
    137177          parameters
    138178      );
     
    158198        storeValue(job, request, emailHostParameter);
    159199        storeValue(job, request, experimentParameter);
     200        storeValue(job, request, statusPathParameter);
     201        storeValue(job, request, overWriteParameter);
     202        storeValue(job, request, validationParameter);
    160203        response.setDone("The job configuration is complete");
    161204      }
     
    236279    DbControl dc=null;
    237280    String hostName="";
    238     boolean validPlatform=false, validateImageFile=false;
    239     boolean validTab2mageFile=false;
     281    boolean validPlatform=false, validateImageFile, validTab2mageFile, validTab2mageFileName=false;
     282    boolean overwrite= false, validation = false;
    240283    try
    241284    {
     
    254297      hostName= (String) job.getValue("emailHost");
    255298     
     299      if ((Boolean)job.getValue("overwrite") != null) overwrite = (Boolean)job.getValue("overwrite");
     300      if ((Boolean)job.getValue("validation") != null)  validation = (Boolean)job.getValue("validation");
     301     
     302     
    256303      Experiment experiment= (Experiment)job.getValue("experiment");
    257304      experiment= Experiment.getById(dc,experiment.getId());
    258305      RawDataType rdt= experiment.getRawDataType(); // experiment platform
    259            
    260       /*
    261         create the roll back object here for testing
    262        */
     306     
     307      String statusp=(String)job.getValue("statusPath");
     308      File statusFile=Helper.processFilePath(user,overwrite, sc,statusp);
     309         
    263310      //RollBack rollback = new RollBack(sc);
    264311     
     
    266313        FILE UNZIP MODULE: unzip the files into user directory
    267314       */
     315   
    268316      ZipUnpacker importUnpacker = new ZipUnpacker(file, user, sc);
    269317      importUnpacker.unpack();
     
    271319      if (dir==null)
    272320      {
    273         response.setError("IMPORT FAILS: The directory containing the unzipped files could not be found. You may NOT have sufficient Disk Space" ,Arrays.asList(new Throwable()));
    274         return;
    275       }
    276      
     321        response.setError("IMPORT FAILS: The directory containing the unzipped files could not be found. You may NOT have sufficient Disk Space or " +
     322            "Lack Permission to read the Directory" ,Arrays.asList(new Throwable()));
     323        return;
     324      }
     325         
    277326      // -- end of file unzip module
    278327     
     
    280329        VALIDATION MODULE
    281330       */
    282         //[ DC MESSAGE : if the manager dc is no longer available creates a new one.  It should be]
    283       if (dc == null || !dc.isConnected()) dc = sc.newDbControl();
     331       
     332      if (dc == null || !dc.isConnected()|| dc.isClosed()) dc = sc.newDbControl();
    284333     
    285334        // validate files supplied to platform
     
    302351        }
    303352      }
    304      
    305353        // validate the tab2mage file (do initialisation here too)
    306       Tab2MageValidationFactory validator = new Tab2MageValidationFactory(tab2MageFileName, sc, dir, rdt.getId());
    307       validTab2mageFile=validator.getValidated();
    308       if (!validTab2mageFile)
    309       {
    310         response.setError("IMPORT FAILS: The tab2mage file supplied is not compliant with the tab2mage specification" ,Arrays.asList(new Throwable()));
    311         return;
    312       }
     354     
     355      Tab2MageValidationFactory validator = new Tab2MageValidationFactory(tab2MageFileName, sc, dir, rdt.getId(), response, statusFile);
     356      validTab2mageFileName = validator.validateTab2MageFileName();
     357      if (!validTab2mageFileName)
     358      {
     359        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()));
     360        return;
     361      }
     362     
     363      Map<ValidationConstants, Boolean> validations= validator.validateTab2MageFile();
     364      StringBuffer failureMessage = new StringBuffer();
     365      if (!validations.isEmpty())
     366      {
     367        for (ValidationConstants key : validations.keySet())
     368        {
     369          failureMessage.append(key.getKeyMessage()+";")  ;
     370        }
     371        response.setError("IMPORT FAILS: Tab2Mage file validation is UNSUCCESSFUL. The ['"+ failureMessage.substring(0, failureMessage.length()-1)+ "'] Failed. " +
     372            "Check the Validation ReportFile ["+statusFile.getPath().toString()+"] on BASE File System for Details" ,Arrays.asList(new Throwable()));
     373        return;
     374      }
     375     
    313376      // -- end of validation module
     377      if (validation)
     378      {
     379        Directory delDir =Directory.getById(dc, dir.getId());
     380        delDir.setRemoved(true);
     381        dc.commit();
     382        response.setDone("Validation Successful. Check the Validation File ["+statusFile.getPath().toString()+"] for annotations warning. The unzipped diretory " +
     383            "has been marked for DELETION. PLEASE remove it from the BASE file system " +
     384            "and trash can and re-run the importer.");
     385        return;
     386      }
    314387     
    315388      /*
     
    331404                          (sc,Tab2MageValidationFactory.getCatchedProtocol(),
    332405                            Tab2MageValidationFactory.getCatchedHybs(),rdt,
    333                             Tab2MageValidationFactory.getSampleExtractMap(),
    334                             Tab2MageValidationFactory.getBioSourceSampleMap(),
    335                             Tab2MageValidationFactory.getExtractLabeledExtractMap());
    336      
    337         // if the protocol type is not found, write it into the database.
    338         // alternative is to fail at validation instead of a warning, if the protocol type
    339         // provided in tab2mage file is not in Base2 database. May may have to rework this.
     406                            validator.getSampleExtractMap(),
     407                            validator.getBioSourceSampleMap(),
     408                            validator.getExtractLabeledExtractMap());
    340409     
    341410      hibernateItemsWriter.writeProtocolTypes();
     
    360429       
    361430       */
    362         //[ DC MESSAGE : if the manager dc is no longer available creates a new one.  It should be]
    363431      if (dc == null || !dc.isConnected()|| dc.isClosed()) dc = sc.newDbControl();
    364432     
     
    401469      }
    402470      // -- end of messaging module
    403      
     471      dc.commit();
    404472      response.setDone("Import plugin ended successfully");
    405473    }
     
    412480      if (dc!=null)
    413481        dc.close();
    414       // get all the temp. files created at: Base2Tab2MageReader and deleted them
    415       // delete the tempAt folder containing the annotation type tem file too
    416482    }
    417483  }
Note: See TracChangeset for help on using the changeset viewer.