Changeset 2162


Ignore:
Timestamp:
Apr 12, 2006, 5:35:16 PM (17 years ago)
Author:
Johan Enell
Message:

It reads the configuration file but it doesnt store tha values

Location:
trunk/src/core/net/sf/basedb/plugins
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/plugins/AbstractFlatFileImporter.java

    r2080 r2162  
    352352      {
    353353        if (progress != null) progress.display(5, "Parsing headers...");
     354        FlatFileParser.LineType result = ffp.parseHeaders();
     355        if (result == FlatFileParser.LineType.UNKNOWN) return;
    354356        FlatFileParser.Line section = ffp.nextSection();
    355357        if (section != null)
     
    357359          handleSection(section);
    358360        }
    359         FlatFileParser.LineType result = ffp.parseHeaders();
    360         if (result == FlatFileParser.LineType.UNKNOWN) return;
    361361        for (int i = 0; i < ffp.getLineCount(); i++)
    362362        {
  • trunk/src/core/net/sf/basedb/plugins/Base1PluginExecuter.java

    r2140 r2162  
    5656  implements InteractivePlugin
    5757{
    58   private static final String NO_FILE_CONFIGURATION = "no_file_configuration";
    59  
    6058  /**
    6159     Plugin description
     
    7573  private RequestInformation configureJob;
    7674
     75  private RequestInformation configureFile;
     76
    7777  private RequestInformation configurePlugin;
    7878 
     
    9797    "File",
    9898    "The file to import the data from",
    99     new FileParameterType(null, false, 1)
     99    new FileParameterType(null, true, 1)
    100100  );
    101101 
     
    158158  private static final PluginParameter<String> usedFieldsParameter = new PluginParameter<String>
    159159  (
    160     "usedfields",
     160    "usedFields",
    161161    "Fields",
    162162    "A tab separeted sting of field namnes. A field is a value from the bioassay, the rawdata or feature",
     
    171171    new ItemParameterType<BioAssaySet>(BioAssaySet.class, null, true, 1, null)
    172172  );
     173
     174
     175  private static final String ACCEPT_FILE_PARAMETERS = "accept";
    173176
    174177  public Base1PluginExecuter()
     
    199202      requestInformation = configurePlugin;
    200203    }
     204   
     205    else if (command.equals(ACCEPT_FILE_PARAMETERS))
     206    {
     207      requestInformation = configureFile;
     208    }
    201209    else if (command.equals(Request.COMMAND_CONFIGURE_JOB))
    202210    {
     
    215223      {
    216224        File f = (File) request.getParameterValue(fileParameter.getName());
    217         if (f != null)
    218         {
    219           FlatFileParser ffp = getInitializedFlatFileParser();
    220           ffp.setInputStream(f.getDownloadStream(0));
    221          
    222           FlatFileParser.Line section = ffp.nextSection();
    223           if (!ffp.getLine(0).equals("BASEfile"))
     225        FlatFileParser ffp = getInitializedFlatFileParser();
     226        ffp.setInputStream(f.getDownloadStream(0));
     227
     228        FlatFileParser.LineType result = ffp.parseHeaders();
     229        if (result == FlatFileParser.LineType.UNKNOWN) return;
     230        if (!ffp.getLine(0).line().equals("BASEfile"))
     231        {
     232          throw new InvalidDataException("File '" + f + "' is not a valid basefile. First line ("+ffp.getLine(0).line()+") must be BASEfile.");
     233        }
     234
     235        FlatFileParser.Line section = ffp.nextSection();
     236        while (section != null && !section.name().equals("plugin"))
     237        {
     238          section = ffp.nextSection();
     239        }
     240        if (section == null)
     241        {
     242          throw new InvalidDataException("File '" + f + "' is not a valid plugin configuration. cannt find the plugin section.");
     243        }
     244
     245        configuration.setValue(versionNumberParameter.getName(), versionNumberParameter.getParameterType(),
     246          ffp.getHeader(versionNumberParameter.getName()));
     247        configuration.setValue(execNameParameter.getName(), execNameParameter.getParameterType(), ffp.getHeader(execNameParameter.getName()));
     248        configuration.setValue(geneAveragesParameter.getName(), geneAveragesParameter.getParameterType(),
     249          new Boolean(ffp.getHeader(geneAveragesParameter.getName())));
     250        configuration.setValue(serialFormatParameter.getName(), serialFormatParameter.getParameterType(),
     251          new Boolean(ffp.getHeader(serialFormatParameter.getName())));
     252        configuration.setValue(leaveStdinParameter.getName(), leaveStdinParameter.getParameterType(),
     253          new Boolean(ffp.getHeader(leaveStdinParameter.getName())));
     254        configuration.setValue(leaveStdoutParameter.getName(), leaveStdoutParameter.getParameterType(),
     255          new Boolean(ffp.getHeader(leaveStdoutParameter.getName())));
     256        configuration.setValue(leaveStdoutParameter.getName(), leaveStdoutParameter.getParameterType(),
     257          new Boolean(ffp.getHeader(leaveStdoutParameter.getName())));
     258        configuration.setValue(usedColumnsParameter.getName(), usedColumnsParameter.getParameterType(), ffp.getHeader(usedColumnsParameter.getName()));
     259        configuration.setValue(usedFieldsParameter.getName(), usedFieldsParameter.getParameterType(), ffp.getHeader(usedFieldsParameter.getName()));
     260
     261        System.out.println(ffp.getHeader(usedFieldsParameter.getName()));
     262       
     263        ffp.parseHeaders();
     264        List<String> columns = Arrays.asList(ffp.getHeader("columns").split("\\t"));
     265        int valueTypeCol = columns.indexOf("valueType");
     266        int nameCol = columns.indexOf("name");
     267        int commonNameCol = columns.indexOf("commonName");
     268        int optionsCol = columns.indexOf("options");
     269        int defaultValueCol = columns.indexOf("defaultValue");
     270        int enumOptionsCol = columns.indexOf("enumOptions");
     271        int removedCol = columns.indexOf("removed");
     272
     273        while (ffp.hasMoreData())
     274        {
     275          FlatFileParser.Data dataline = ffp.nextData();
     276          if (!Boolean.valueOf(dataline.get(removedCol)))
    224277          {
    225             throw new InvalidDataException("File '"+f+"' is not a valid basefile. First line must be BASEfile.");
    226           }
    227          
    228           while (section != null && !section.name().equals("plugin"))
    229           {
    230             section = ffp.nextSection();
    231           }
    232           if (section == null)
    233           {
    234             throw new InvalidDataException("File '"+f+"' is not a valid plugin configuration. cannt find the plugin section.");
    235           }
    236          
    237           configuration.setValue(versionNumberParameter.getName(), versionNumberParameter.getParameterType(), ffp.getHeader(versionNumberParameter.getName()));
    238           configuration.setValue(execNameParameter.getName(), execNameParameter.getParameterType(), ffp.getHeader(execNameParameter.getName()));
    239           configuration.setValue(geneAveragesParameter.getName(), geneAveragesParameter.getParameterType(), new Boolean(ffp.getHeader(geneAveragesParameter.getName())));
    240           configuration.setValue(serialFormatParameter.getName(), serialFormatParameter.getParameterType(), new Boolean(ffp.getHeader(serialFormatParameter.getName())));
    241           configuration.setValue(leaveStdinParameter.getName(), leaveStdinParameter.getParameterType(), new Boolean(ffp.getHeader(leaveStdinParameter.getName())));
    242           configuration.setValue(leaveStdoutParameter.getName(), leaveStdoutParameter.getParameterType(), new Boolean(ffp.getHeader(leaveStdoutParameter.getName())));
    243           configuration.setValue(leaveStdoutParameter.getName(), leaveStdoutParameter.getParameterType(), new Boolean(ffp.getHeader(leaveStdoutParameter.getName())));
    244           configuration.setValue(usedColumnsParameter.getName(), usedColumnsParameter.getParameterType(), ffp.getHeader(usedColumnsParameter.getName()));
    245           configuration.setValue(usedFieldsParameter.getName(), usedFieldsParameter.getParameterType(), ffp.getHeader(usedFieldsParameter.getName()));
    246          
    247           List<String> columns = Arrays.asList(ffp.getHeader("columns").split("\\t"));
    248           int valueTypeCol = columns.indexOf("valueType");
    249           int nameCol = columns.indexOf("name");
    250           int commonNameCol = columns.indexOf("commonName");
    251           int optionsCol = columns.indexOf("options");
    252           int defaultValueCol = columns.indexOf("defaultValue");
    253           int enumOptionsCol = columns.indexOf("enumOptions");
    254           int removedCol = columns.indexOf("removed");
    255          
    256           while (ffp.hasMoreData())
    257           {
    258             FlatFileParser.Data dataline = ffp.nextData();
    259             if (!Boolean.valueOf(dataline.get(removedCol)))
     278            String name = dataline.get(nameCol);
     279            String commonName = dataline.get(commonNameCol);
     280            String options = dataline.get(optionsCol);
     281            String defaultValue = dataline.get(defaultValueCol);
     282            String enumOptions = dataline.get(enumOptionsCol);
     283
     284            PluginParameter<?> parameter = null;
     285            switch (dataline.get(valueTypeCol).charAt(0))
    260286            {
    261               String name = dataline.get(nameCol);
    262               String commonName = dataline.get(commonNameCol);
    263               String options = dataline.get(optionsCol);
    264               String defaultValue = dataline.get(defaultValueCol);
    265               String[] enumOptions = dataline.get(enumOptionsCol).split("\\\\t");
    266              
    267               PluginParameter<?> parameter = null;
    268               switch (dataline.get(valueTypeCol).charAt(0))
    269               {
    270                 //String parameter
    271                 case 't':
     287              //String parameter
     288              case 't':
     289              {
     290                StringParameterType type = new StringParameterType(null, defaultValue, true, 1, new Integer(options), 1, null);
     291                parameter = new PluginParameter<String>(name, commonName, "", type);
     292                jobParameters.add(parameter);
     293                break;
     294              }
     295              //Integer parameter
     296              case 'i':
     297              {
     298                Integer defValue = defaultValue == null ? null : new Integer(defaultValue);
     299                IntegerParameterType type = new IntegerParameterType(null, null, defValue, true, 1, new Integer(options), 1, null);
     300                parameter = new PluginParameter<Integer>(name, commonName, "", type);
     301                jobParameters.add(parameter);
     302                break;
     303              }
     304              //Float parameter
     305              case 'f':
     306              {
     307                Float defValue = defaultValue == null ? null : new Float(defaultValue);
     308                FloatParameterType type = new FloatParameterType(null, null, defValue, true, 1, new Integer(options), 1, null);
     309                parameter = new PluginParameter<Float>(name, commonName, "", type);
     310                jobParameters.add(parameter);
     311                break;
     312              }
     313              //TextField parameter
     314              case 'a':
     315              {
     316                String[] wh = options.split(",");
     317                StringParameterType type = new StringParameterType(null, defaultValue, true, 1, new Integer(wh[0]), wh.length > 1 ? new Integer(wh[1]) : 1, null);
     318                parameter = new PluginParameter<String>(name, commonName, "", type);
     319                jobParameters.add(parameter);
     320                break;
     321              }
     322              //Annotation parameter
     323              case 'n':
     324              {
     325                // TODO
     326                break;
     327              }
     328              //HiddenString parameter
     329              case 'h':
     330              {
     331                StringParameterType type = new StringParameterType(null, defaultValue, true, 1, new Integer(options), 1, null);
     332                parameter = new PluginParameter<String>(name, commonName, "", type);
     333                hiddenParameters.add(parameter);
     334                break;
     335              }
     336              //Enum Parameter
     337              case 'e':
     338              {
     339                Map<String, String> enums = new HashMap<String, String>();
     340                String[] enumOptionsSplit = enumOptions.split("\\\\t");
     341                for (int i = 0; i < enumOptionsSplit.length; i += 2)
    272342                {
    273                   StringParameterType type = new StringParameterType(null, defaultValue, true, 1, new Integer(options), 1, null);
    274                   parameter = new PluginParameter<String>(name, commonName, "", type);
    275                   jobParameters.add(parameter);
    276                   break;
     343                  enums.put(enumOptionsSplit[i], enumOptionsSplit[i + 1]);
    277344                }
    278                 //Integer parameter
    279                 case 'i':
    280                 {
    281                   IntegerParameterType type = new IntegerParameterType(null, null, new Integer(defaultValue), true, 1, new Integer(options), 1, null);
    282                   parameter = new PluginParameter<Integer>(name, commonName, "", type);
    283                   jobParameters.add(parameter);
    284                   break;
    285                 }
    286                 //Float parameter
    287                 case 'f':
    288                 {
    289                   FloatParameterType type = new FloatParameterType(null, null, new Float(defaultValue), true, 1, new Integer(options), 1, null);
    290                   parameter = new PluginParameter<Float>(name, commonName, "", type);
    291                   jobParameters.add(parameter);
    292                   break;
    293                 }
    294                 //TextField parameter
    295                 case 'a':
    296                 {
    297                   String[] wh = options.split(",");
    298                   StringParameterType type = new StringParameterType(null, defaultValue, true, 1, new Integer(wh[0]), wh.length > 1?new Integer(wh[1]):1, null);
    299                   parameter = new PluginParameter<String>(name, commonName, "", type);
    300                   jobParameters.add(parameter);
    301                   break;
    302                 }
    303                 //Annotation parameter
    304                 case 'n':
    305                 {
    306                   // TODO
    307                   break;
    308                 }
    309                 //HiddenString parameter
    310                 case 'h':
    311                 {
    312                   StringParameterType type = new StringParameterType(null, defaultValue, true, 1, new Integer(options), 1, null);
    313                   parameter = new PluginParameter<String>(name, commonName, "", type);
    314                   hiddenParameters.add(parameter);
    315                   break;
    316                 }
    317                 //Enum Parameter
    318                 case 'e':
    319                 {
    320                   Map<String, String> enums = new HashMap<String, String>();
    321                   for (int i = 0; i < enumOptions.length; i += 2)
    322                   {
    323                     enums.put(enumOptions[i], enumOptions[i+1]);
    324                   }
    325                   StringParameterType type = new StringParameterType(null, defaultValue, true, enums.size(), new Integer(options), 1, new ArrayList<String>(enums.keySet()));
    326                   parameter = new PluginParameter<String>(name, commonName, "", type);
    327                   jobParameters.add(parameter);
    328                   break;
    329                 }
     345                StringParameterType type = new StringParameterType(null, defaultValue, true, enums.size(), new Integer(options), 1, new ArrayList<String>(enums.keySet()));
     346                parameter = new PluginParameter<String>(name, commonName, "", type);
     347                jobParameters.add(parameter);
     348                break;
    330349              }
    331350            }
    332351          }
    333          
    334           response.setDone("Plugin configuration with file complete");
    335         }
    336         else
    337         {
    338           response.setContinue(NO_FILE_CONFIGURATION);
    339         }
     352        }
     353        response.setContinue(ACCEPT_FILE_PARAMETERS);
    340354      }
    341       else if (command.equals(NO_FILE_CONFIGURATION))
     355      else if (command.equals(ACCEPT_FILE_PARAMETERS))
    342356      {
    343         //TODO
    344         response.setError("Plugin configuration without file not implemented", null);
     357
     358        response.setContinue("Plugin configuration with file complete");
    345359      }
    346360      else if (command.equals(Request.COMMAND_CONFIGURE_JOB))
     
    360374    catch (Throwable ex)
    361375    {
     376      ex.printStackTrace();
    362377      response.setError(ex.getMessage(), Arrays.asList(ex));
    363378    }
     
    368383  public MainType getMainType()
    369384  {
    370     // TODO Auto-generated method stub
    371     return null;
     385    return MainType.ANALYZE;
    372386  }
    373387
     
    389403    super.init(sc, configuration, job);
    390404   
     405    List<PluginParameter<?>> parameters = new ArrayList<PluginParameter<?>>();
     406    parameters.add(bioAssaySetParameter);
     407    parameters.addAll(jobParameters);
     408    configureJob = new RequestInformation
     409    (
     410      Request.COMMAND_CONFIGURE_JOB,
     411      "Configure job",
     412      "Set the parameters needed for this plugin.",
     413      parameters
     414    );
    391415   
    392   }
    393 
     416    parameters = new ArrayList<PluginParameter<?>>();
     417    parameters.add(fileParameter);
     418    configurePlugin = new RequestInformation
     419    (
     420      Request.COMMAND_CONFIGURE_PLUGIN,
     421      "Configure plugin",
     422      "The configuration file from base1",
     423      parameters
     424    );
     425  }
    394426 
    395427  private FlatFileParser getInitializedFlatFileParser()
     
    397429  {
    398430    FlatFileParser ffp = new FlatFileParser();
    399     ffp.setSectionRegexp(Pattern.compile("section (.*)^"));
    400     ffp.setHeaderRegexp(Pattern.compile("(.*)\\t(.*)"));
     431    ffp.setSectionRegexp(Pattern.compile("section\\t(.*)"));
     432    ffp.setHeaderRegexp(Pattern.compile("(.*?)\\t(.*)"));
    401433    ffp.setDataHeaderRegexp(Pattern.compile("%"));
    402434    ffp.setDataSplitterRegexp(Pattern.compile("\\t"));
Note: See TracChangeset for help on using the changeset viewer.