Changeset 5241


Ignore:
Timestamp:
Feb 10, 2010, 3:25:56 PM (13 years ago)
Author:
Nicklas Nordborg
Message:

References #1446: Use the core "Reporter importer" without a file format configuration

This should fix the issue, though I have not yet tested it with the web client. I'll also keep this ticket open until the Illumina importer ticket has been fixed: http://baseplugins.thep.lu.se/ticket/257

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/src/docbook/appendix/incompatible.xml

    r5204 r5241  
    6464    </para>
    6565   
     66    <bridgehead>
     67      ReporterFlatFileImporter store file parser settings as job parameters
     68    </bridgehead>
     69    <para>
     70      This change was introduced since it should be possible to run the plug-in
     71      without a configuration. Existing code that uses this plug-in outside the
     72      web client, may fail due to not setting required parameter values as job
     73      parameters.
     74    </para>
    6675  </sect1>
    6776 
  • trunk/src/core/net/sf/basedb/core/plugin/AbstractPlugin.java

    r4889 r5241  
    319319 
    320320  /**
     321    Get the value for a job or configuration parameter. This method first
     322    checks the job parameters. If there is no value it will check the
     323    configuration parameters.
     324    @param name The name of the parameter
     325    @return The parameter value, or null
     326    @since 2.15
     327  */
     328  protected Object getJobOrConfigurationValue(String name)
     329  {
     330    Object value = null;
     331    if (job != null) value = job.getValue(name);
     332    if (value == null && configuration != null) value = configuration.getValue(name);
     333    return value;
     334  }
     335 
     336  /**
     337    Clone a plug-in parameter and set the default value to the value that is
     338    already stored in the job or configuration parameters.
     339    @param pp The parameter to clone
     340    @return The cloned parameter
     341    @since 2.15
     342  */
     343  @SuppressWarnings("unchecked")
     344  protected <T> PluginParameter<T> cloneParameterWithDefaultValue(PluginParameter<T> pp)
     345  {
     346    T defaultValue = (T)getJobOrConfigurationValue(pp.getName());
     347    PluginParameter<T> clone = new PluginParameter<T>(
     348        pp.getName(),
     349        pp.getLabel(),
     350        pp.getDescription(),
     351        defaultValue,
     352        pp.getParameterType());
     353    return clone;
     354  }
     355 
     356  /**
    321357    Check if the current thread has been interrupted and throw
    322358    a SignalException if it has. Subclasses that use the {@link ThreadSignalHandler}
     
    434470    logger.flush();
    435471  }
     472 
     473 
    436474}
  • trunk/src/plugins/core/net/sf/basedb/plugins/AbstractFlatFileImporter.java

    r5218 r5241  
    962962    Create and initialise a flat file parser by setting all regular expressions
    963963    and other options. This implementation gets all parameters from the
    964     {@link #configuration} settings. If a subclass doesn't store the parameters
    965     there it must override this method and initialise the parser. Note that
     964    {@link #job} or {@link #configuration} settings. If a subclass doesn't store the
     965    parameters there it must override this method and initialise the parser. Note that
    966966    this method is called once for each file returned by the
    967967    {@link #getFileIterator()} and that a new parser is needed for each file.
     
    973973  {
    974974    FlatFileParser ffp = new FlatFileParser();
    975     if (configuration != null)
    976     {
    977       ffp.setSectionRegexp(getPattern(sectionRegexpParameter.getName()));
    978       ffp.setHeaderRegexp(getPattern(headerRegexpParameter.getName()));
    979       ffp.setDataHeaderRegexp(getPattern(dataHeaderRegexpParameter.getName()));
    980       ffp.setDataSplitterRegexp(getPattern(dataSplitterRegexpParameter.getName()));
    981       Boolean trimQuotes = (Boolean)configuration.getValue(trimQuotesParameter.getName());
    982       if (trimQuotes != null) ffp.setTrimQuotes(trimQuotes);
    983       ffp.setIgnoreRegexp(getPattern(ignoreRegexpParameter.getName()));
    984       ffp.setDataFooterRegexp(getPattern(dataFooterRegexpParameter.getName()));
    985       ffp.setMinDataColumns(IntegerUtil.getInt((Integer)configuration.getValue(minDataColumnsParameter.getName())));
    986       ffp.setMaxDataColumns(IntegerUtil.getInt((Integer)configuration.getValue(maxDataColumnsParameter.getName())));
    987     }
     975
     976    ffp.setSectionRegexp(getPattern(sectionRegexpParameter.getName()));
     977    ffp.setHeaderRegexp(getPattern(headerRegexpParameter.getName()));
     978    ffp.setDataHeaderRegexp(getPattern(dataHeaderRegexpParameter.getName()));
     979    ffp.setDataSplitterRegexp(getPattern(dataSplitterRegexpParameter.getName()));
     980    Boolean trimQuotes = (Boolean)getJobOrConfigurationValue(trimQuotesParameter.getName());
     981    if (trimQuotes != null) ffp.setTrimQuotes(trimQuotes);
     982    ffp.setIgnoreRegexp(getPattern(ignoreRegexpParameter.getName()));
     983    ffp.setDataFooterRegexp(getPattern(dataFooterRegexpParameter.getName()));
     984    ffp.setMinDataColumns(IntegerUtil.getInt((Integer)getJobOrConfigurationValue(minDataColumnsParameter.getName())));
     985    ffp.setMaxDataColumns(IntegerUtil.getInt((Integer)getJobOrConfigurationValue(maxDataColumnsParameter.getName())));
    988986    return ffp;
    989987  }
     
    10061004  protected String getCharset()
    10071005  {
    1008     String charset = null;
    1009     if (job != null)
    1010     {
    1011       charset = (String)job.getValue(Parameters.CHARSET_PARAMETER);
    1012     }
    1013     if (charset == null && configuration != null)
    1014     {
    1015       charset = (String)configuration.getValue(Parameters.CHARSET_PARAMETER);
    1016     }
     1006    String charset = (String)getJobOrConfigurationValue(Parameters.CHARSET_PARAMETER);
    10171007    if (charset == null && job != null)
    10181008    {
     
    10501040  protected String getDecimalSeparator()
    10511041  {
    1052     String ds = null;
    1053     if (job != null) ds = (String)job.getValue(Parameters.DECIMAL_SEPARATOR_PARAMETER);
    1054     if (ds == null && configuration != null)
    1055     {
    1056       ds = (String)configuration.getValue(Parameters.DECIMAL_SEPARATOR_PARAMETER);
    1057     }
    1058     return ds;
     1042    return (String)getJobOrConfigurationValue(Parameters.DECIMAL_SEPARATOR_PARAMETER);
    10591043  }
    10601044 
     
    11381122    throws BaseException
    11391123  {
    1140     String regexp = (String)configuration.getValue(name);
     1124    String regexp = (String)getJobOrConfigurationValue(name);
    11411125    return regexp != null ? Pattern.compile(regexp) : null;
    11421126  }
  • trunk/src/plugins/core/net/sf/basedb/plugins/ReporterFlatFileImporter.java

    r4985 r5241  
    3131import net.sf.basedb.core.ItemInUseException;
    3232import net.sf.basedb.core.Permission;
     33import net.sf.basedb.core.PermissionDeniedException;
    3334import net.sf.basedb.core.ReporterList;
    3435import net.sf.basedb.core.RequestInformation;
     
    210211  public boolean requiresConfiguration()
    211212  {
    212     return true;
     213    return false;
    213214  }
    214215  /**
     
    353354        }
    354355        storeValue(job, request, fileParameter);
     356        storeValue(job, request, ri.getParameter("mode"));
     357       
     358        // Parser settings
     359        storeValue(job, request, headerRegexpParameter);
     360        storeValue(job, request, dataHeaderRegexpParameter);
     361        storeValue(job, request, dataSplitterRegexpParameter);
     362        storeValue(job, request, trimQuotesParameter);
     363        storeValue(job, request, ignoreRegexpParameter);
     364        storeValue(job, request, dataFooterRegexpParameter);
     365        storeValue(job, request, minDataColumnsParameter);
     366        storeValue(job, request, maxDataColumnsParameter);
    355367        storeValue(job, request, ri.getParameter(Parameters.CHARSET_PARAMETER));
    356368        storeValue(job, request, ri.getParameter(Parameters.DECIMAL_SEPARATOR_PARAMETER));
    357         storeValue(job, request, ri.getParameter("mode"));
     369       
     370        // Column mappings
     371        storeValue(job, request, complexMappings);
     372        boolean allowComplex = "allow".equals(request.getParameterValue(complexMappings.getName()));
     373        for (PluginParameter<String> pp : getAllColumnMappings())
     374        {
     375          String mapExpression = (String)request.getParameterValue(pp.getName());
     376          checkColumnMapping(mapExpression, allowComplex, pp.getLabel());
     377          storeValue(job, pp, mapExpression);
     378        }
    358379       
    359380        // Error handling parameters
     
    470491    // Mapper that always return null
    471492    Mapper nullMapper = new ConstantMapper((String)null);
    472     idMapper = getMapper(ffp, (String)configuration.getValue("reporterIdColumnMapping"),
     493    idMapper = getMapper(ffp, (String)job.getValue("reporterIdColumnMapping"),
    473494      cropStrings ? ReporterData.MAX_EXTERNAL_ID_LENGTH : null, nullMapper);
    474495    if (!deleteMode)
    475496    {
    476       nameMapper = getMapper(ffp, (String)configuration.getValue("nameColumnMapping"),
     497      nameMapper = getMapper(ffp, (String)job.getValue("nameColumnMapping"),
    477498        cropStrings ? ReporterData.MAX_NAME_LENGTH : null, null);
    478       symbolMapper = getMapper(ffp, (String)configuration.getValue("symbolColumnMapping"),
     499      symbolMapper = getMapper(ffp, (String)job.getValue("symbolColumnMapping"),
    479500        cropStrings ? ReporterData.MAX_SYMBOL_LENGTH : null, null);
    480       descriptionMapper = getMapper(ffp, (String)configuration.getValue("descriptionColumnMapping"),
     501      descriptionMapper = getMapper(ffp, (String)job.getValue("descriptionColumnMapping"),
    481502        cropStrings ? ReporterData.MAX_DESCRIPTION_LENGTH : null, null);
    482       reporterTypeMapper = getMapper(ffp, (String)configuration.getValue("reporterTypeColumnMapping"),
     503      reporterTypeMapper = getMapper(ffp, (String)job.getValue("reporterTypeColumnMapping"),
    483504        cropStrings ? ReporterType.MAX_NAME_LENGTH : null, null);
    484       scoreMapper = getMapper(ffp, (String)configuration.getValue("scoreColumnMapping"), null, null);
     505      scoreMapper = getMapper(ffp, (String)job.getValue("scoreColumnMapping"), null, null);
    485506     
    486507      reporterTypes = new HashMap<String, ReporterType>();
     
    492513        {
    493514          String name = "extendedColumnMapping." + ep.getName();
    494           Mapper m = getMapper(ffp, (String)configuration.getValue(name),
     515          Mapper m = getMapper(ffp, (String)job.getValue(name),
    495516            cropStrings && ep.getLength() > 0 ? ep.getLength() : null, null);
    496517          if (m != null) extendedMappers.put(ep, m);
     
    810831     
    811832      parameters.add(modeParameter);
     833     
     834      // Parser regular expressions
     835      parameters.add(parserSection);
     836      parameters.add(cloneParameterWithDefaultValue(headerRegexpParameter));
     837      parameters.add(cloneParameterWithDefaultValue(dataHeaderRegexpParameter));
     838      parameters.add(cloneParameterWithDefaultValue(dataSplitterRegexpParameter));
     839      parameters.add(cloneParameterWithDefaultValue(trimQuotesParameter));
     840      parameters.add(cloneParameterWithDefaultValue(ignoreRegexpParameter));
     841      parameters.add(cloneParameterWithDefaultValue(dataFooterRegexpParameter));
     842      parameters.add(cloneParameterWithDefaultValue(minDataColumnsParameter));
     843      parameters.add(cloneParameterWithDefaultValue(maxDataColumnsParameter));
    812844      parameters.add(Parameters.charsetParameter(null, null,
    813845          (String)configuration.getValue(Parameters.CHARSET_PARAMETER)));
    814846      parameters.add(Parameters.decimalSeparatorParameter(null, null,
    815847          (String)configuration.getValue(Parameters.DECIMAL_SEPARATOR_PARAMETER)));
     848
     849      // Column mappings
     850      parameters.add(mappingSection);
     851      parameters.add(complexMappings);
     852      parameters.addAll(getAllColumnMappings());
    816853     
    817854      parameters.add(errorSection);
  • trunk/src/plugins/core/net/sf/basedb/plugins/util/Parameters.java

    r4521 r5241  
    443443  }
    444444 
     445  /**
     446    Clone a plug-in parameter but give it a different default value.
     447   
     448    @param pp The plug-in parameter to clone
     449    @param defaultValue The new default value
     450    @return The cloned plug-in parameter
     451    @since 2.15
     452  */
     453  public static <T> PluginParameter<T> cloneParameter(PluginParameter<T> pp, T defaultValue)
     454  {
     455    PluginParameter<T> clone = new PluginParameter<T>(
     456        pp.getName(),
     457        pp.getLabel(),
     458        pp.getDescription(),
     459        defaultValue,
     460        pp.getParameterType());
     461    return clone;
     462  }
     463 
    445464}
  • trunk/src/test/TestReporterFlatFileImporter.java

    r4889 r5241  
    171171      PluginConfigurationRequest request = j.configure(new GuiContext(Item.REPORTER, GuiContext.Type.LIST));
    172172      write_request_information(request.getRequestInformation());
     173      for (PluginParameter pp : request.getRequestInformation().getParameters())
     174      {
     175        Object value = request.getCurrentParameterValue(pp.getName());
     176        if (value != null) request.setParameterValue(pp.getName(), value);
     177      }
    173178      request.setParameterValue("file", File.getById(dc, fileId));
    174179      request.setParameterValue("mode", mode);
    175180      request.setParameterValue("invalidUseOfNullError", "skip");
     181     
    176182      PluginResponse response = request.invoke();
    177183      if (response.getStatus() == Response.Status.DONE)
Note: See TracChangeset for help on using the changeset viewer.