2.17.2: 2011-06-17

net.sf.basedb.plugins.batchimport
Class SampleImporter

java.lang.Object
  extended by net.sf.basedb.core.plugin.AbstractPlugin
      extended by net.sf.basedb.plugins.AbstractFlatFileImporter
          extended by net.sf.basedb.plugins.batchimport.AbstractItemImporter<Sample>
              extended by net.sf.basedb.plugins.batchimport.SampleImporter
All Implemented Interfaces:
AutoDetectingImporter, InteractivePlugin, Plugin, SignalTarget, ConfigureByExample

public class SampleImporter
extends AbstractItemImporter<Sample>

Plug-in for importing sample items in a batch. The plug-in can create new items and updated existing items.

Version:
2.8
Author:
nicklas
Last modified
$Date: 2010-10-26 10:51:19 +0200 (Tue, 26 Oct 2010) $

Nested Class Summary
 
Nested classes/interfaces inherited from interface net.sf.basedb.core.plugin.Plugin
Plugin.MainType
 
Field Summary
private static About about
           
protected static PluginParameter<String> bioPlateColumnMapping
          Column mapping parameter for the bioplate
private  Mapper bioPlateMapper
           
protected static PluginParameter<String> bioWellColColumnMapping
          Column mapping parameter for the biowell's column
private  Mapper bioWellColMapper
           
protected static PluginParameter<String> bioWellRowColumnMapping
          Column mapping parameter for the biowell's row
private  Mapper bioWellRowMapper
           
protected static PluginParameter<String> createdColumnMapping
          Column mapping parameter for the sample creation date.
private  Mapper createdMapper
           
private  Mapper descriptionMapper
           
private  Mapper externalIdMapper
           
private static Set<GuiContext> guiContexts
           
private  Mapper nameMapper
           
protected static PluginParameter<String> originalQuantityColumnMapping
          Column mapping parameter for the original quantity.
private  Mapper originalQuantityMapper
           
protected static PluginParameter<String> parentColumnMapping
          Column mapping parameter for the parent (biosource OR pooled sample)
private  Mapper parentMapper
           
protected static PluginParameter<String> pooledColumnMapping
          Column mapping parameter for the pooled property.
private  Mapper pooledMapper
           
private  Mapper protocolMapper
           
protected static PluginParameter<String> usedQuantityColumnMapping
          Column mapping parameter for the used quantity from the parent.
private  Mapper usedQuantityMapper
           
 
Fields inherited from class net.sf.basedb.plugins.batchimport.AbstractItemImporter
defaultsSection, descriptionColumnMapping, externalIdColumnMapping, identificationSection, internalIdColumnMapping, nameColumnMapping, optionalColumnMapping, permissionTemplateColumnMapping, protocolColumnMapping, requiredColumnMapping
 
Fields inherited from class net.sf.basedb.plugins.AbstractFlatFileImporter
CHARSET, charsetType, complexMappings, dataFooterRegexpParameter, dataHeaderRegexpParameter, dataSplitterRegexpParameter, DECIMAL_SEPARATOR, decimalSeparatorType, defaultErrorParameter, errorSection, fileParameter, fileType, headerRegexpParameter, ignoreRegexpParameter, invalidUseOfNullErrorParameter, mappingSection, maxDataColumnsParameter, minDataColumnsParameter, numberFormatErrorParameter, numberOutOfRangeErrorParameter, numDataColumnsType, optionalRegexpType, parserSection, requiredRegexpType, sectionRegexpParameter, stringTooLongErrorParameter, trimQuotesParameter
 
Fields inherited from class net.sf.basedb.core.plugin.AbstractPlugin
annotationSection, configuration, COPY_ANNOTATIONS, job, OVERWRITE_ANNOTATIONS, sc
 
Constructor Summary
SampleImporter()
           
 
Method Summary
protected  void addMoreColumnMappingParameters(List<PluginParameter<?>> parameters)
          Adds column mappings for name, externalId, description, protocol, creation date, original quantity, pooled, parent and used quantity from parent.
protected  void createColumnMappers(FlatFileParser ffp, boolean cropStrings)
          Create mappers that can be used to extract data values from the file that is currently being parsed by the ffp FlatFileParser.
protected  Sample createItem(DbControl dc, FlatFileParser.Data data)
          Create a new item and populate it with data from the current line.
protected  ItemQuery<Sample> createItemQuery()
          Calls Sample.getQuery().
 About getAbout()
          Get information about the plugin, such as name, version, authors, etc.
 Set<GuiContext> getGuiContexts()
          Get a set containing all items that the plugin handles.
protected  IdMethod[] getIdMethods()
          Useable methods are: PropertyIdMethod.NAME PropertyIdMethod.EXTERNAL_ID InternalIdMethod.INTERNAL_ID FallbackIdMethod.NAME_OR_ID
protected  void updateItem(DbControl dc, Sample sample, FlatFileParser.Data data)
          Update an item with data from the current line.
protected  void updateMultiLineItem(DbControl dc, Sample sample, FlatFileParser.Data data, int multiLineNum)
          If the sample is pooled, add the parent sample.
 
Methods inherited from class net.sf.basedb.plugins.batchimport.AbstractItemImporter
addMoreErrorParameters, addMoreJobParameters, addMoreParsingParameters, begin, beginData, configure, doneWithItem, end, findArrayBatch, findArrayDesign, findArraySlide, findBioPlate, findBioPlateType, findBioSource, findBioWell, findDataFileType, findExtract, findFeatureExtractionSoftware, findFreezer, findHybridization, findHybridizationStation, findImage, findLabel, findLabeledExtract, findPermissionTemplate, findPlateGeometry, findPlatform, findPrintRobot, findProtocol, findProtocol, findRawDataType, findReferencedItem, findSample, findScan, findScanner, findVariant, getConfigureOptionsParameters, getConfigureParserParameters, getIdMethod, getInitializedFlatFileParser, getInitializedFlatFileParser, getProjectDefaultPlatform, getProjectDefaultRawDataType, getProjectDefaultVariant, getRequestInformation, getSuccessMessage, handleData, initReferenceQuery, isInContext, parseDate, requiresConfiguration, setUpErrorHandling, supportsConfigurations, updatePermissions
 
Methods inherited from class net.sf.basedb.plugins.AbstractFlatFileImporter
addErrorHandler, checkColumnMapping, checkColumnMapping, continueWithNextFileAfterError, doImport, finish, getCharset, getCharset, getCharsetParameter, getDecimalSeparator, getDecimalSeparatorParameter, getErrorHandler, getErrorOption, getFileIterator, getMainType, getMapper, getNumberFormat, getNumBytes, getPrimaryLocationFilter, getProgress, getSignalHandler, getTotalFileSize, handleHeader, handleSection, isImportable, isImportable, log, log, log, log, run, start, wrapInputStream
 
Methods inherited from class net.sf.basedb.core.plugin.AbstractPlugin
checkInterrupted, cloneParameterWithDefaultValue, closeLogFile, createLogFile, done, getCopyAnnotationsParmeter, getCurrentConfiguration, getCurrentJob, getJobOrConfigurationValue, getOverwriteAnnotationsParameters, getPermissions, init, log, log, storeValue, storeValue, storeValues, validateRequestParameters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.basedb.core.plugin.Plugin
done, getMainType, getPermissions, init, run
 

Field Detail

guiContexts

private static final Set<GuiContext> guiContexts

createdColumnMapping

protected static final PluginParameter<String> createdColumnMapping
Column mapping parameter for the sample creation date.


originalQuantityColumnMapping

protected static final PluginParameter<String> originalQuantityColumnMapping
Column mapping parameter for the original quantity.


pooledColumnMapping

protected static final PluginParameter<String> pooledColumnMapping
Column mapping parameter for the pooled property.


parentColumnMapping

protected static final PluginParameter<String> parentColumnMapping
Column mapping parameter for the parent (biosource OR pooled sample)


usedQuantityColumnMapping

protected static final PluginParameter<String> usedQuantityColumnMapping
Column mapping parameter for the used quantity from the parent.


bioPlateColumnMapping

protected static final PluginParameter<String> bioPlateColumnMapping
Column mapping parameter for the bioplate


bioWellRowColumnMapping

protected static final PluginParameter<String> bioWellRowColumnMapping
Column mapping parameter for the biowell's row


bioWellColColumnMapping

protected static final PluginParameter<String> bioWellColColumnMapping
Column mapping parameter for the biowell's column


about

private static final About about

nameMapper

private Mapper nameMapper

descriptionMapper

private Mapper descriptionMapper

externalIdMapper

private Mapper externalIdMapper

originalQuantityMapper

private Mapper originalQuantityMapper

createdMapper

private Mapper createdMapper

protocolMapper

private Mapper protocolMapper

pooledMapper

private Mapper pooledMapper

parentMapper

private Mapper parentMapper

usedQuantityMapper

private Mapper usedQuantityMapper

bioPlateMapper

private Mapper bioPlateMapper

bioWellRowMapper

private Mapper bioWellRowMapper

bioWellColMapper

private Mapper bioWellColMapper
Constructor Detail

SampleImporter

public SampleImporter()
Method Detail

getAbout

public About getAbout()
Description copied from interface: Plugin
Get information about the plugin, such as name, version, authors, etc.

Returns:
An About object

getGuiContexts

public Set<GuiContext> getGuiContexts()
Description copied from interface: InteractivePlugin
Get a set containing all items that the plugin handles. Ie. if the plugin imports reporters, return a set containing Item.REPORTER. This information is used by client applications to put the plugin in the proper place in the user interface.

Returns:
A Set containing Item:s, or null if the plugin is not concerned about items

getIdMethods

protected IdMethod[] getIdMethods()
Useable methods are:

Overrides:
getIdMethods in class AbstractItemImporter<Sample>

addMoreColumnMappingParameters

protected void addMoreColumnMappingParameters(List<PluginParameter<?>> parameters)
Adds column mappings for name, externalId, description, protocol, creation date, original quantity, pooled, parent and used quantity from parent.

Overrides:
addMoreColumnMappingParameters in class AbstractItemImporter<Sample>
Parameters:
parameters - The list of parameters to add the column mapping parameters to

createItemQuery

protected ItemQuery<Sample> createItemQuery()
Calls Sample.getQuery().

Specified by:
createItemQuery in class AbstractItemImporter<Sample>
Returns:
A query

createColumnMappers

protected void createColumnMappers(FlatFileParser ffp,
                                   boolean cropStrings)
Description copied from class: AbstractItemImporter
Create mappers that can be used to extract data values from the file that is currently being parsed by the ffp FlatFileParser. This method is called during initialisation of the plug-in when the FlatFileParser.parseHeaders() has successfully found the start of data. Use the AbstractFlatFileImporter.getMapper(FlatFileParser, String, Integer, Mapper) to create column mappers. Example:
nameMapper = getMapper(ffp, job.getValue("nameColumnMapping"), 
   cropStrings ? Nameable.MAX_NAME_LENGTH : null, null);

Overrides:
createColumnMappers in class AbstractItemImporter<Sample>
Parameters:
ffp - The parser that is parsing the data file
cropStrings - If strings that are too long to fit in the database should be cropped or not (=generate an error)

createItem

protected Sample createItem(DbControl dc,
                            FlatFileParser.Data data)
Description copied from class: AbstractItemImporter
Create a new item and populate it with data from the current line. Do not call DbControl.saveItem(BasicItem). This is done automatically by the core implementation.
BioSource bs = BioSource.getNew(dc);
// Set properties; see example on updateItem method
return bs;

If the current data line doesn't have data for all required properties, this method should throw an InvalidUseOfNullException exception.

This method is called during import when current item can be found and if the user has selected to create missing item.

Specified by:
createItem in class AbstractItemImporter<Sample>
Parameters:
dc - The DbControl to use for database access
data - The current data line
Returns:
A new item

updateItem

protected void updateItem(DbControl dc,
                          Sample sample,
                          FlatFileParser.Data data)
Description copied from class: AbstractItemImporter
Update an item with data from the current line. Example:
if (nameMapper != null) item.setName(nameMapper.getValue(data));
if (descriptionMapper != null) item.setDescription(descriptionMapper.getValue(data));
...
This method is called during import to update an existing item.

Specified by:
updateItem in class AbstractItemImporter<Sample>
Parameters:
dc - The DbControl to use for database access
sample - The item to update
data - The current data line

updateMultiLineItem

protected void updateMultiLineItem(DbControl dc,
                                   Sample sample,
                                   FlatFileParser.Data data,
                                   int multiLineNum)
If the sample is pooled, add the parent sample.

Overrides:
updateMultiLineItem in class AbstractItemImporter<Sample>
Parameters:
dc - The DbControl to use for database access
sample - The item to update
data - The current data line
multiLineNum - The number of the multi-line entry, starting with 1 for the first multi-line

2.17.2: 2011-06-17