Changeset 5899


Ignore:
Timestamp:
Dec 6, 2011, 9:17:37 AM (10 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1642: Add support for column mapping that selects a project default item in batch item importers

Use =default() as column mapping to assign the project default value to all items, or
=default(col('foo')) to use the value from column 'foo' if it is not empty and the project default value otherwise.

Location:
trunk
Files:
1 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/src/docbook/user/import_data.xml

    r5798 r5899  
    821821                  constant string (eg. no backslash '\' character).
    822822                </para>
     823               
     824                <tip>
     825                  <title>Project default items</title>
     826                  <para>
     827                    When creating new items some properties (eg. protocol, software,
     828                    hardware, etc.) are assigned default values from the currently
     829                    active project if no mapping has been specified for that property.
     830                    It is also possible to access project default values when a
     831                    a mapping is used. Use <code>=default()</code> as a mapping expression
     832                    to set the property to the project default value or
     833                    <code>=default(col('foo'))</code> to use the value from column
     834                    <code>foo</code> if it is not empty and the project default otherwise.
     835                    Do not forget to enable the <code>Complex column mappings</code>
     836                    option.
     837                  </para>
     838                </tip>
    823839              </listitem>
    824840            </varlistentry>
  • trunk/src/core/net/sf/basedb/util/parser/ColFunction.java

    r5769 r5899  
    145145      else
    146146      {
    147         value = data.get(column);
     147        value = column < data.columns() ? data.get(column) : null;
    148148      }
    149149    }
  • trunk/src/core/net/sf/basedb/util/parser/FlatFileParser.java

    r5689 r5899  
    4747import net.sf.basedb.core.signal.ThreadSignalHandler;
    4848import net.sf.basedb.util.InputStreamTracker;
     49import net.sf.basedb.util.jep.JepFunction;
    4950
    5051/**
     
    949950  }
    950951 
     952  public Mapper getMapper(String expression, JepFunction... functions)
     953  {
     954    return getMapper(expression, numberFormat, useNullIfException, functions);
     955  }
     956 
    951957  /**
    952958    Get a mapper using the default number format.
     
    969975  }
    970976 
     977  /**
     978    @see #getMapper(String, NumberFormat, boolean, JepFunction...)
     979    @since 2.4
     980  */
     981  public Mapper getMapper(String expression, NumberFormat numberFormat, boolean nullIfException)
     982  {
     983    return getMapper(expression, numberFormat, nullIfException, (JepFunction[])null);
     984  }
     985
    971986  /**
    972987    Create a mapper object that maps an expression string to a value.
     
    9971012    @param nullIfException TRUE to return a null value instead of throwing
    9981013      an exception when a value can't be parsed.
     1014    @param functions Optional array with Jep functions that should be
     1015      included in the parser
    9991016    @return A mapper object
    1000     @since 2.4
    1001   */
    1002   public Mapper getMapper(String expression, NumberFormat numberFormat, boolean nullIfException)
     1017    @since 3.1
     1018  */
     1019  public Mapper getMapper(String expression, NumberFormat numberFormat, boolean nullIfException, JepFunction... functions)
    10031020  {
    10041021    Mapper mapper = null;
     
    10091026    else if (expression.startsWith("="))
    10101027    {
    1011       mapper = new JepMapper(expression.substring(1), columnHeaders, numberFormat, ignoreNonExistingColumns);
     1028      mapper = new JepMapper(expression.substring(1), columnHeaders, numberFormat, ignoreNonExistingColumns, functions);
    10121029      if (nullIfException) mapper = new NullIfExceptionMapper(mapper);
    10131030    }
  • trunk/src/core/net/sf/basedb/util/parser/JepMapper.java

    r5773 r5899  
    2727
    2828import net.sf.basedb.util.jep.Jep;
     29import net.sf.basedb.util.jep.JepFunction;
    2930import net.sf.basedb.util.jep.LeftFunction;
    3031import net.sf.basedb.util.parser.FlatFileParser.Data;
     
    7879
    7980  public JepMapper(String expression, List<String> columnHeaders, NumberFormat numberFormat,
    80     boolean ignoreNonExistingColumns)
     81      boolean ignoreNonExistingColumns)
     82  {
     83    this(expression, columnHeaders, numberFormat, ignoreNonExistingColumns, (JepFunction[])null);
     84  }
     85
     86  /**
     87 
     88    @since 3.1
     89  */
     90  public JepMapper(String expression, List<String> columnHeaders, NumberFormat numberFormat,
     91    boolean ignoreNonExistingColumns, JepFunction... functions)
    8192  {
    8293    this.expression = expression;
     
    90101    // Replace: \ColumnName\ with: col('ColumnName')
    91102    expression = expression.replaceAll("\\\\([^\\\\]*)\\\\", "col('$1')");
    92     this.parser = Jep.newJep(expression, colFunction, lineNoFunction, dataNoFunction, new LeftFunction());
     103   
     104    JepFunction[] extraFunctions = new JepFunction[4 + (functions == null ? 0 : functions.length)];
     105    extraFunctions[0] = colFunction;
     106    extraFunctions[1] = lineNoFunction;
     107    extraFunctions[2] = dataNoFunction;
     108    extraFunctions[3] = new LeftFunction();
     109    if (functions != null)
     110    {
     111      System.arraycopy(functions, 0, extraFunctions, 4, functions.length);
     112    }
     113    this.parser = Jep.newJep(expression, extraFunctions);
    93114  }
    94115 
  • trunk/src/plugins/core/net/sf/basedb/plugins/AbstractFlatFileImporter.java

    r5590 r5899  
    5959import net.sf.basedb.util.error.ErrorHandler;
    6060import net.sf.basedb.util.error.SimpleErrorHandler;
     61import net.sf.basedb.util.jep.JepFunction;
    6162import net.sf.basedb.util.parser.CropStringMapper;
     63import net.sf.basedb.util.parser.DefaultItemFunction;
    6264import net.sf.basedb.util.parser.FlatFileParser;
    6365import net.sf.basedb.util.parser.JepMapper;
     
    11241126      {
    11251127        throw new InvalidDataException("Invalid expression for column '" +
    1126             name + "': " + mapExpression + " (" + t.getMessage() + ")");
     1128            name + "': " + mapExpression + " (" + t.getMessage() + ")", t);
    11271129      }
    11281130    }
     
    11311133      try
    11321134      {
    1133         new JepMapper(mapExpression.substring(1), new ArrayList<String>(), null);
     1135        new JepMapper(mapExpression.substring(1), new ArrayList<String>(), null, false,
     1136          new DefaultItemFunction(null, null, null));
    11341137      }
    11351138      catch (Throwable t)
    11361139      {
    11371140        throw new InvalidDataException("Invalid expression for column '" +
    1138             name + "': " + mapExpression + " (" + t.getMessage() + ")");
     1141            name + "': " + mapExpression + " (" + t.getMessage() + ")", t);
    11391142      }
    11401143    }
     
    11421145  }
    11431146 
     1147  /**
     1148    @see #getMapper(FlatFileParser, String, Integer, Mapper, JepFunction...)
     1149  */
     1150  protected Mapper getMapper(FlatFileParser ffp, String mapExpression, Integer maxStringLength, Mapper defaultMapper)
     1151  {
     1152    return getMapper(ffp, mapExpression, maxStringLength, defaultMapper, (JepFunction[])null);
     1153  }
     1154
    11441155  /**
    11451156    Get a mapper for the specified flat file parser. This method
     
    11541165    @param maxStringLength The maximum allowed string length or null to allow any length
    11551166    @param defaultMapper The mapper to return if the map expression is null
     1167    @param functions Additional JEP functions that should be included in the parser
     1168      in case the map expression is a JEP expression
    11561169    @return A mapper, or null if the map expression and default mapper is null
    1157   */
    1158   protected Mapper getMapper(FlatFileParser ffp, String mapExpression, Integer maxStringLength, Mapper defaultMapper)
     1170    @since 3.1
     1171  */
     1172  protected Mapper getMapper(FlatFileParser ffp, String mapExpression, Integer maxStringLength,
     1173    Mapper defaultMapper, JepFunction... functions)
    11591174  {
    11601175    Mapper mapper = defaultMapper;
    11611176    if (mapExpression != null)
    11621177    {
    1163       mapper = ffp.getMapper(mapExpression);
     1178      mapper = ffp.getMapper(mapExpression, functions);
    11641179      if (maxStringLength != null && maxStringLength > 0) mapper = new CropStringMapper(mapper, maxStringLength);
    11651180    }
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/AbstractItemImporter.java

    r5719 r5899  
    5454import net.sf.basedb.core.Hardware;
    5555import net.sf.basedb.core.ItemParameterType;
     56import net.sf.basedb.core.Nameable;
    5657import net.sf.basedb.core.PhysicalBioAssay;
    5758import net.sf.basedb.core.Include;
     
    111112import net.sf.basedb.util.formatter.DateFormatter;
    112113import net.sf.basedb.util.parser.ConfigureByExample;
     114import net.sf.basedb.util.parser.DefaultItemFunction;
    113115import net.sf.basedb.util.parser.FlatFileParser;
    114116import net.sf.basedb.util.parser.Mapper;
     
    469471  */
    470472  private DbControl dc;
     473  private Project activeProject;
    471474  private FlatFileParser ffp;
    472475  private DateFormatter dateFormatter;
     
    576579  {
    577580    this.dc = sc.newDbControl();
     581    if (sc.getActiveProjectId() != 0)
     582    {
     583      activeProject = Project.getById(dc, sc.getActiveProjectId());
     584    }
    578585   
    579586    // Mapper to get name or external ID
     
    10711078  }
    10721079  // ---------------------------------------
     1080 
     1081  /**
     1082    Create a {@link DefaultItemFunction} for the given item type.
     1083    The currently active project (if any) is used.
     1084    @param itemType The type of items the function should look for
     1085    @since 3.1
     1086  */
     1087  protected <T extends Nameable> DefaultItemFunction<T> getDefaultItemFunction(Item itemType)
     1088  {
     1089    DefaultItemFunction<T> fun = new DefaultItemFunction<T>(dc, activeProject, itemType);
     1090    return fun;
     1091  }
     1092   
    10731093 
    10741094  /**
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/ArrayBatchImporter.java

    r5630 r5899  
    3737import net.sf.basedb.core.SystemItems;
    3838import net.sf.basedb.core.plugin.GuiContext;
     39import net.sf.basedb.util.parser.DefaultItemFunction;
    3940import net.sf.basedb.util.parser.FlatFileParser;
    4041import net.sf.basedb.util.parser.Mapper;
     
    9798  private Mapper descriptionMapper;
    9899  private Mapper protocolMapper;
     100  private DefaultItemFunction<Protocol> defaultProtocolFunction;
    99101  private Mapper hardwareMapper;
     102  private DefaultItemFunction<Hardware> defaultHardwareFunction;
    100103  private Mapper arrayDesignMapper;
    101104 
     
    147150    descriptionMapper = getMapper(ffp, (String)job.getValue("descriptionColumnMapping"),
    148151        cropStrings ? ArrayBatch.MAX_DESCRIPTION_LENGTH : null, null);
    149     protocolMapper = getMapper(ffp, (String)job.getValue("protocolColumnMapping"), null, null);
    150     hardwareMapper = getMapper(ffp, (String)job.getValue("hardwareColumnMapping"), null, null);
     152    defaultProtocolFunction = getDefaultItemFunction(Item.PROTOCOL);
     153    protocolMapper = getMapper(ffp, (String)job.getValue("protocolColumnMapping"), null, null, defaultProtocolFunction);
     154    defaultHardwareFunction = getDefaultItemFunction(Item.HARDWARE);
     155    hardwareMapper = getMapper(ffp, (String)job.getValue("hardwareColumnMapping"), null, null, defaultHardwareFunction);
    151156    arrayDesignMapper = getMapper(ffp, (String)job.getValue("arrayDesignColumnMapping"), null, null);
    152157  }
     
    173178    if (protocolMapper != null)
    174179    {
     180      ItemSubtype type = ItemSubtype.getById(dc, SystemItems.getId(Protocol.PRINTING));
     181      defaultProtocolFunction.setCurrentSubtype(type);
    175182      String nameOrId = protocolMapper.getValue(data);
    176       ItemSubtype type = ItemSubtype.getById(dc, SystemItems.getId(Protocol.PRINTING));
    177183      Protocol protocol = findProtocol(dc, FallbackIdMethod.NAME_OR_EXTERNALID_OR_ID, nameOrId, type);
    178184      if (nameOrId == null || protocol != null) batch.setProtocol(protocol);
     
    180186    if (hardwareMapper != null)
    181187    {
     188      ItemSubtype type = ItemSubtype.getById(dc, SystemItems.getId(Hardware.PRINT_ROBOT));
     189      defaultHardwareFunction.setCurrentSubtype(type);
    182190      String nameOrId = hardwareMapper.getValue(data);
    183       ItemSubtype type = ItemSubtype.getById(dc, SystemItems.getId(Hardware.PRINT_ROBOT));
    184191      Hardware robot = findHardware(dc, FallbackIdMethod.NAME_OR_ID, nameOrId, type);
    185192      if (nameOrId == null || robot != null) batch.setPrintRobot(robot);
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/ArrayDesignImporter.java

    r5719 r5899  
    3939import net.sf.basedb.core.PluginParameter;
    4040import net.sf.basedb.core.plugin.GuiContext;
     41import net.sf.basedb.util.parser.DefaultItemFunction;
    4142import net.sf.basedb.util.parser.FlatFileParser;
    4243import net.sf.basedb.util.parser.Mapper;
     
    133134  private Mapper numArraysMapper;
    134135  private Mapper platformMapper;
     136  private DefaultItemFunction<Platform> defaultPlatformFunction;
    135137  private Mapper variantMapper;
     138  private DefaultItemFunction<PlatformVariant> defaultVariantFunction;
    136139  private Mapper fileTypeMapper;
    137140  private Mapper fileMapper;
     
    206209        cropStrings ? ArrayDesign.MAX_DESCRIPTION_LENGTH : null, null);
    207210    numArraysMapper = getMapper(ffp, (String)job.getValue("numArraysColumnMapping"), null, null);
    208     platformMapper = getMapper(ffp, (String)job.getValue("platformColumnMapping"), null, null);
    209     variantMapper = getMapper(ffp, (String)job.getValue("variantColumnMapping"), null, null);
     211    defaultPlatformFunction = getDefaultItemFunction(Item.PLATFORM);
     212    platformMapper = getMapper(ffp, (String)job.getValue("platformColumnMapping"), null, null, defaultPlatformFunction);
     213    defaultVariantFunction = getDefaultItemFunction(Item.PLATFORMVARIANT);
     214    variantMapper = getMapper(ffp, (String)job.getValue("variantColumnMapping"), null, null, defaultVariantFunction);
    210215    fileTypeMapper = getMapper(ffp, (String)job.getValue("fileTypeColumnMapping"), null, null);
    211216    fileMapper = getMapper(ffp, (String)job.getValue("fileColumnMapping"), null, null);
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/BioPlateImporter.java

    r5641 r5899  
    3838import net.sf.basedb.core.SystemItems;
    3939import net.sf.basedb.core.plugin.GuiContext;
     40import net.sf.basedb.util.parser.DefaultItemFunction;
    4041import net.sf.basedb.util.parser.FlatFileParser;
    4142import net.sf.basedb.util.parser.Mapper;
     
    122123  private Mapper plateGeometryMapper;
    123124  private Mapper hardwareMapper;
     125  private DefaultItemFunction<Hardware> defaultHardwareFunction;
    124126  private Mapper barcodeMapper;
    125127 
     
    176178    bioPlateTypeMapper = getMapper(ffp, (String)job.getValue("bioPlateTypeColumnMapping"), null, null);
    177179    plateGeometryMapper = getMapper(ffp, (String)job.getValue("plateGeometryColumnMapping"), null, null);
    178     hardwareMapper = getMapper(ffp, (String)job.getValue("hardwareColumnMapping"), null, null);
     180    defaultHardwareFunction = getDefaultItemFunction(Item.HARDWARE);
     181    hardwareMapper = getMapper(ffp, (String)job.getValue("hardwareColumnMapping"), null, null, defaultHardwareFunction);
    179182    barcodeMapper = getMapper(ffp, (String)job.getValue("barcodeColumnMapping"),
    180183        cropStrings ? ArraySlide.MAX_BARCODE_LENGTH : null, null);
     
    208211    if (hardwareMapper != null)
    209212    {
     213      ItemSubtype type = ItemSubtype.getById(dc, SystemItems.getId(Hardware.FREEZER));
     214      defaultHardwareFunction.setCurrentSubtype(type);
    210215      String nameOrId = hardwareMapper.getValue(data);
    211       ItemSubtype type = ItemSubtype.getById(dc, SystemItems.getId(Hardware.FREEZER));
    212216      Hardware freezer = findHardware(dc, FallbackIdMethod.NAME_OR_ID, nameOrId, type);
    213217      if (nameOrId == null || freezer != null) plate.setFreezer(freezer);
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/DerivedBioAssayImporter.java

    r5785 r5899  
    3939import net.sf.basedb.core.Software;
    4040import net.sf.basedb.core.plugin.GuiContext;
     41import net.sf.basedb.util.parser.DefaultItemFunction;
    4142import net.sf.basedb.util.parser.FlatFileParser;
    4243import net.sf.basedb.util.parser.Mapper;
     
    168169  private Mapper descriptionMapper;
    169170  private Mapper protocolMapper;
     171  private DefaultItemFunction<Protocol> defaultProtocolFunction;
    170172  private Mapper hardwareMapper;
     173  private DefaultItemFunction<Hardware> defaultHardwareFunction;
    171174  private Mapper softwareMapper;
     175  private DefaultItemFunction<Software> defaultSoftwareFunction;
    172176  private Mapper parentTypeMapper;
    173177  private Mapper parentMapper;
     
    256260    parentMapper = getMapper(ffp, (String)job.getValue("parentColumnMapping"), null, null);
    257261    extractMapper = getMapper(ffp, (String)job.getValue("extractColumnMapping"), null, null);
    258     protocolMapper = getMapper(ffp, (String)job.getValue("protocolColumnMapping"), null, null);
    259     hardwareMapper = getMapper(ffp, (String)job.getValue("hardwareColumnMapping"), null, null);
    260     softwareMapper = getMapper(ffp, (String)job.getValue("softwareColumnMapping"), null, null);
     262    defaultProtocolFunction = getDefaultItemFunction(Item.PROTOCOL);
     263    protocolMapper = getMapper(ffp, (String)job.getValue("protocolColumnMapping"), null, null, defaultProtocolFunction);
     264    defaultHardwareFunction = getDefaultItemFunction(Item.HARDWARE);
     265    hardwareMapper = getMapper(ffp, (String)job.getValue("hardwareColumnMapping"), null, null, defaultHardwareFunction);
     266    defaultSoftwareFunction = getDefaultItemFunction(Item.SOFTWARE);
     267    softwareMapper = getMapper(ffp, (String)job.getValue("softwareColumnMapping"), null, null, defaultSoftwareFunction);
    261268    fileTypeMapper = getMapper(ffp, (String)job.getValue("fileTypeColumnMapping"), null, null);
    262269    fileMapper = getMapper(ffp, (String)job.getValue("fileColumnMapping"), null, null);
     
    350357    if (protocolMapper != null)
    351358    {
     359      ItemSubtype type = ItemSubtype.getRelatedSubtype(dc, bioAssay, Item.PROTOCOL, 0);
     360      defaultProtocolFunction.setCurrentSubtype(type);
    352361      String nameOrId = protocolMapper.getValue(data);
    353       ItemSubtype type = ItemSubtype.getRelatedSubtype(dc, bioAssay, Item.PROTOCOL, 0);
    354362      Protocol protocol = findProtocol(dc, FallbackIdMethod.NAME_OR_EXTERNALID_OR_ID, nameOrId, type);
    355363      if (nameOrId == null || protocol != null) bioAssay.setProtocol(protocol);
     
    357365    if (hardwareMapper != null)
    358366    {
     367      ItemSubtype type = ItemSubtype.getRelatedSubtype(dc, bioAssay, Item.HARDWARE, 0);
     368      defaultHardwareFunction.setCurrentSubtype(type);
    359369      String nameOrId = hardwareMapper.getValue(data);
    360       ItemSubtype type = ItemSubtype.getRelatedSubtype(dc, bioAssay, Item.HARDWARE, 0);
    361370      Hardware hardware = findHardware(dc, FallbackIdMethod.NAME_OR_ID, nameOrId, type);
    362371      if (nameOrId == null || hardware != null) bioAssay.setHardware(hardware);
     
    364373    if (softwareMapper != null)
    365374    {
     375      ItemSubtype type = ItemSubtype.getRelatedSubtype(dc, bioAssay, Item.SOFTWARE, 0);
     376      defaultSoftwareFunction.setCurrentSubtype(type);
    366377      String nameOrId = softwareMapper.getValue(data);
    367       ItemSubtype type = ItemSubtype.getRelatedSubtype(dc, bioAssay, Item.SOFTWARE, 0);
    368378      Software software = findSoftware(dc, FallbackIdMethod.NAME_OR_ID, nameOrId, type);
    369379      if (nameOrId == null || software != null) bioAssay.setSoftware(software);
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/ExtractImporter.java

    r5667 r5899  
    4141import net.sf.basedb.core.Tag;
    4242import net.sf.basedb.core.plugin.GuiContext;
     43import net.sf.basedb.util.parser.DefaultItemFunction;
    4344import net.sf.basedb.util.parser.FlatFileParser;
    4445import net.sf.basedb.util.parser.Mapper;
     
    9596  private Mapper createdMapper;
    9697  private Mapper protocolMapper;
     98  private DefaultItemFunction<Protocol> defaultPrototolFunction;
    9799  private Mapper parentTypeMapper;
    98100  private Mapper parentMapper;
     
    172174    originalQuantityMapper = getMapper(ffp, (String)job.getValue("originalQuantityColumnMapping"), null, null);
    173175    createdMapper = getMapper(ffp, (String)job.getValue("createdColumnMapping"), null, null);
    174     protocolMapper = getMapper(ffp, (String)job.getValue("protocolColumnMapping"), null, null);
     176    defaultPrototolFunction = getDefaultItemFunction(Item.PROTOCOL);
     177    protocolMapper = getMapper(ffp, (String)job.getValue("protocolColumnMapping"), null, null, defaultPrototolFunction);
    175178    parentTypeMapper = getMapper(ffp, (String)job.getValue("parentTypeColumnMapping"), null, null);
    176179    parentMapper = getMapper(ffp, (String)job.getValue("parentColumnMapping"), null, null);
     
    210213    if (protocolMapper != null)
    211214    {
     215      ItemSubtype type = ItemSubtype.getRelatedSubtype(dc, extract, Item.PROTOCOL, SystemItems.getId(Protocol.EXTRACTION));
     216      if (defaultPrototolFunction != null) defaultPrototolFunction.setCurrentSubtype(type);
    212217      String nameOrId = protocolMapper.getValue(data);
    213       ItemSubtype type = ItemSubtype.getRelatedSubtype(dc, extract, Item.PROTOCOL, SystemItems.getId(Protocol.EXTRACTION));
    214218      Protocol protocol = findProtocol(dc, FallbackIdMethod.NAME_OR_EXTERNALID_OR_ID, nameOrId, type);
    215219      if (nameOrId == null || protocol != null) creationEvent.setProtocol(protocol);
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/PhysicalBioAssayImporter.java

    r5832 r5899  
    4444import net.sf.basedb.core.StringParameterType;
    4545import net.sf.basedb.core.plugin.GuiContext;
     46import net.sf.basedb.util.parser.DefaultItemFunction;
    4647import net.sf.basedb.util.parser.FlatFileParser;
    4748import net.sf.basedb.util.parser.Mapper;
     
    140141  private Mapper createdMapper;
    141142  private Mapper protocolMapper;
     143  private DefaultItemFunction<Protocol> defaultProtocolFunction;
    142144  private Mapper hardwareMapper;
     145  private DefaultItemFunction<Hardware> defaultHardwareFunction;
    143146  private Mapper parentMapper;
    144147  private Mapper usedQuantityMapper;
     
    216219    sizeMapper = getMapper(ffp, (String)job.getValue("sizeColumnMapping"), null, null);
    217220    createdMapper = getMapper(ffp, (String)job.getValue("createdColumnMapping"), null, null);
    218     protocolMapper = getMapper(ffp, (String)job.getValue("protocolColumnMapping"), null, null);
    219     hardwareMapper = getMapper(ffp, (String)job.getValue("hardwareColumnMapping"), null, null);
     221    defaultProtocolFunction = getDefaultItemFunction(Item.PROTOCOL);
     222    protocolMapper = getMapper(ffp, (String)job.getValue("protocolColumnMapping"), null, null, defaultProtocolFunction);
     223    defaultHardwareFunction = getDefaultItemFunction(Item.HARDWARE);
     224    hardwareMapper = getMapper(ffp, (String)job.getValue("hardwareColumnMapping"), null, null, defaultHardwareFunction);
    220225    parentMapper = getMapper(ffp, (String)job.getValue("parentColumnMapping"), null, null);
    221226    usedQuantityMapper = getMapper(ffp, (String)job.getValue("usedQuantityColumnMapping"), null, null);
     
    244249    if (protocolMapper != null)
    245250    {
     251      ItemSubtype type = ItemSubtype.getRelatedSubtype(dc, pba, Item.PROTOCOL, 0);
     252      defaultProtocolFunction.setCurrentSubtype(type);
    246253      String nameOrId = protocolMapper.getValue(data);
    247       ItemSubtype type = ItemSubtype.getRelatedSubtype(dc, pba, Item.PROTOCOL, 0);
    248254      Protocol protocol = findProtocol(dc, FallbackIdMethod.NAME_OR_EXTERNALID_OR_ID, nameOrId, type);
    249255      if (nameOrId == null || protocol != null) creationEvent.setProtocol(protocol);
     
    251257    if (hardwareMapper != null)
    252258    {
     259      ItemSubtype type = ItemSubtype.getRelatedSubtype(dc, pba, Item.HARDWARE, 0);
     260      defaultHardwareFunction.setCurrentSubtype(type);
    253261      String nameOrId = hardwareMapper.getValue(data);
    254       ItemSubtype type = ItemSubtype.getRelatedSubtype(dc, pba, Item.HARDWARE, 0);
    255262      Hardware hardware = findHardware(dc, FallbackIdMethod.NAME_OR_ID, nameOrId, type);
    256263      if (nameOrId == null || hardware != null) creationEvent.setHardware(hardware);
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/RawBioAssayImporter.java

    r5719 r5899  
    4747import net.sf.basedb.core.SystemItems;
    4848import net.sf.basedb.core.plugin.GuiContext;
     49import net.sf.basedb.util.parser.DefaultItemFunction;
    4950import net.sf.basedb.util.parser.FlatFileParser;
    5051import net.sf.basedb.util.parser.Mapper;
     
    184185  private Mapper descriptionMapper;
    185186  private Mapper protocolMapper;
     187  private DefaultItemFunction<Protocol> defaultProtocolFunction;
    186188  private Mapper softwareMapper;
     189  private DefaultItemFunction<Software> defaultSoftwareFunction;
    187190  private Mapper bioAssayMapper;
    188191  private Mapper extractMapper;
    189192  private Mapper arrayDesignMapper;
     193  private DefaultItemFunction<ArrayDesign> defaultArrayDesignFunction;
    190194  private Mapper platformMapper;
    191195  private Mapper variantMapper;
     
    267271    descriptionMapper = getMapper(ffp, (String)job.getValue("descriptionColumnMapping"),
    268272        cropStrings ? RawBioAssay.MAX_DESCRIPTION_LENGTH : null, null);
    269     protocolMapper = getMapper(ffp, (String)job.getValue("protocolColumnMapping"), null, null);
    270     softwareMapper = getMapper(ffp, (String)job.getValue("softwareColumnMapping"), null, null);
     273    defaultProtocolFunction = getDefaultItemFunction(Item.PROTOCOL);
     274    protocolMapper = getMapper(ffp, (String)job.getValue("protocolColumnMapping"), null, null, defaultProtocolFunction);
     275    defaultSoftwareFunction = getDefaultItemFunction(Item.SOFTWARE);
     276    softwareMapper = getMapper(ffp, (String)job.getValue("softwareColumnMapping"), null, null, defaultSoftwareFunction);
    271277    bioAssayMapper = getMapper(ffp, (String)job.getValue("bioAssayColumnMapping"), null, null);
    272278    extractMapper = getMapper(ffp, (String)job.getValue("extractColumnMapping"), null, null);
    273     arrayDesignMapper = getMapper(ffp, (String)job.getValue("arrayDesignColumnMapping"), null, null);
     279    defaultArrayDesignFunction = getDefaultItemFunction(Item.ARRAYDESIGN);
     280    arrayDesignMapper = getMapper(ffp, (String)job.getValue("arrayDesignColumnMapping"), null, null, defaultArrayDesignFunction);
    274281    platformMapper = getMapper(ffp, (String)job.getValue("platformColumnMapping"), null, null);
    275282    variantMapper = getMapper(ffp, (String)job.getValue("variantColumnMapping"), null, null);
     
    423430    if (protocolMapper != null)
    424431    {
     432      ItemSubtype type = ItemSubtype.getById(dc, SystemItems.getId(Protocol.FEATURE_EXTRACTION));
     433      defaultProtocolFunction.setCurrentSubtype(type);
    425434      String nameOrId = protocolMapper.getValue(data);
    426       ItemSubtype type = ItemSubtype.getById(dc, SystemItems.getId(Protocol.FEATURE_EXTRACTION));
    427435      Protocol protocol = findProtocol(dc, FallbackIdMethod.NAME_OR_EXTERNALID_OR_ID, nameOrId, type);
    428436      if (nameOrId == null || protocol != null) rba.setProtocol(protocol);
     
    430438    if (softwareMapper != null)
    431439    {
     440      ItemSubtype type = ItemSubtype.getById(dc, SystemItems.getId(Software.FEATURE_EXTRACTION));
     441      defaultSoftwareFunction.setCurrentSubtype(type);
    432442      String nameOrId = softwareMapper.getValue(data);
    433       ItemSubtype type = ItemSubtype.getById(dc, SystemItems.getId(Software.FEATURE_EXTRACTION));
    434443      Software software = findSoftware(dc, FallbackIdMethod.NAME_OR_ID, nameOrId, type);
    435444      if (nameOrId == null || software != null) rba.setSoftware(software);
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/SampleImporter.java

    r5667 r5899  
    3939import net.sf.basedb.core.SystemItems;
    4040import net.sf.basedb.core.plugin.GuiContext;
     41import net.sf.basedb.util.parser.DefaultItemFunction;
    4142import net.sf.basedb.util.parser.FlatFileParser;
    4243import net.sf.basedb.util.parser.Mapper;
     
    193194  private Mapper createdMapper;
    194195  private Mapper protocolMapper;
     196  private DefaultItemFunction<Protocol> defaultPrototolFunction;
    195197  private Mapper parentTypeMapper;
    196198  private Mapper parentMapper;
     
    268270    originalQuantityMapper = getMapper(ffp, (String)job.getValue("originalQuantityColumnMapping"), null, null);
    269271    createdMapper = getMapper(ffp, (String)job.getValue("createdColumnMapping"), null, null);
    270     protocolMapper = getMapper(ffp, (String)job.getValue("protocolColumnMapping"), null, null);
     272    defaultPrototolFunction = getDefaultItemFunction(Item.PROTOCOL);
     273    protocolMapper = getMapper(ffp, (String)job.getValue("protocolColumnMapping"), null, null, defaultPrototolFunction);
    271274    parentTypeMapper = getMapper(ffp, (String)job.getValue("parentTypeColumnMapping"), null, null);
    272275    parentMapper = getMapper(ffp, (String)job.getValue("parentColumnMapping"), null, null);
     
    297300    if (protocolMapper != null)
    298301    {
     302      ItemSubtype type = ItemSubtype.getRelatedSubtype(dc, sample, Item.PROTOCOL, SystemItems.getId(Protocol.SAMPLING));
     303      if (defaultPrototolFunction != null) defaultPrototolFunction.setCurrentSubtype(type);
    299304      String nameOrId = protocolMapper.getValue(data);
    300       ItemSubtype type = ItemSubtype.getRelatedSubtype(dc, sample, Item.PROTOCOL, SystemItems.getId(Protocol.SAMPLING));
    301305      Protocol protocol = findProtocol(dc, FallbackIdMethod.NAME_OR_EXTERNALID_OR_ID, nameOrId, type);
    302306      if (nameOrId == null || protocol != null) creationEvent.setProtocol(protocol);
  • trunk/src/test/TestItemImporter.java

    r5696 r5899  
    5959    write("++Testing item import using plugin");
    6060   
     61    // Project
     62    int projectId = TestProject.test_create("Default project", false);
     63    TestProject.test_activate_project(projectId, null);
     64   
    6165    // Create referenced items
    6266    int samplingProtocolId = TestProtocol.test_create(SystemItems.getId(Protocol.SAMPLING), "Sampling", false);
     67    int defaultSamplingProtocolId =  TestProtocol.test_create(SystemItems.getId(Protocol.SAMPLING), "Sampling.def", false);
    6368    int extractionProtocolId = TestProtocol.test_create(SystemItems.getId(Protocol.EXTRACTION), "Extraction", false);
    6469    int labelingProtocolId = TestProtocol.test_create(SystemItems.getId(Protocol.LABELING), "Labeling", false);
     
    7782    int childScanId = TestItemSubtype.test_create(Item.DERIVEDBIOASSAY, "ChildScan", SystemItems.getId(DerivedBioAssay.SCAN));
    7883   
     84    TestProject.test_defaultItem(projectId, Item.PROTOCOL, defaultSamplingProtocolId);
     85    TestProject.test_defaultItem(projectId, Item.PROTOCOL, hybProtocolId);
     86    TestProject.test_defaultItem(projectId, Item.HARDWARE, hybStationId);
     87   
    7988    // Import bioplates
    8089    int bioPlateFileId = TestFile.test_create("data/test.batchimport.bioplates.txt", false, false);
     
    230239    TestHardware.test_delete(robotId);
    231240    TestProtocol.test_delete(samplingProtocolId);
     241    TestProtocol.test_delete(defaultSamplingProtocolId);
    232242    TestProtocol.test_delete(extractionProtocolId);
    233243    TestProtocol.test_delete(labelingProtocolId);
     
    242252    TestPlatform.test_delete_variant(variantId);
    243253    TestItemSubtype.test_delete(childScanId);
     254    TestProject.test_delete(projectId);
    244255
    245256    write("++Testing item import using plugin "+(ok ? "OK" : "Failed")+"\n");
     
    340351    request.setParameterValue("nameColumnMapping", "\\Name\\");
    341352    request.setParameterValue("descriptionColumnMapping", "\\Description\\");
     353    request.setParameterValue("complexExpressions", "allow");
    342354    if (itemType == Item.BIOPLATE)
    343355    {
     
    350362    {
    351363      request.setParameterValue("externalIdColumnMapping", "\\External ID\\");
    352       request.setParameterValue("protocolColumnMapping", "\\Protocol\\");
     364      request.setParameterValue("protocolColumnMapping", "=default(col('Protocol'))");
    353365      request.setParameterValue("createdColumnMapping", "\\Created\\");
    354366      request.setParameterValue("originalQuantityColumnMapping", "\\Original quantity\\");
     
    367379      request.setParameterValue("subtypeColumnMapping", "Hybridization");
    368380      request.setParameterValue("sizeColumnMapping", "\\Size\\");
    369       request.setParameterValue("protocolColumnMapping", "\\Protocol\\");
    370       request.setParameterValue("hardwareColumnMapping", "\\Hardware\\");
     381      request.setParameterValue("protocolColumnMapping", "=default(col('Protocol'))");
     382      request.setParameterValue("hardwareColumnMapping", "=default()");
    371383      request.setParameterValue("createdColumnMapping", "\\Created\\");
    372384      request.setParameterValue("parentColumnMapping", "\\Parent\\");
Note: See TracChangeset for help on using the changeset viewer.