Changeset 4921


Ignore:
Timestamp:
May 4, 2009, 4:38:55 PM (13 years ago)
Author:
Martin Svensson
Message:

References #1303 The batch scan importer should now be able to import images for each scan. The functionallity has not been fully tested yet. There is also some documentation left to do.

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

Legend:

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

    r4891 r4921  
    4949import net.sf.basedb.core.HardwareType;
    5050import net.sf.basedb.core.Hybridization;
     51import net.sf.basedb.core.Image;
    5152import net.sf.basedb.core.Include;
    5253import net.sf.basedb.core.IntegerUtil;
     
    14621463  }
    14631464 
     1465  private ItemQuery<Image> imageQuery;
     1466  /**
     1467   * 
     1468      @param dc
     1469      @param idMethod
     1470      @param scan
     1471      @param identifier
     1472      @return
     1473      @since 2.12
     1474   */
     1475  protected Image findImage(DbControl dc, IdMethod idMethod, Scan scan, String identifier)
     1476  {
     1477    if (identifier == null) return null;
     1478    if (imageQuery == null)
     1479    {
     1480      imageQuery = initReferenceQuery(dc, idMethod, scan.getImages());
     1481    }
     1482    return findReferencedItem(dc, idMethod, imageQuery, identifier, false);
     1483  }
     1484 
    14641485  private ItemQuery<ArrayDesign> designQuery;
    14651486  /**
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/ScanImporter.java

    r4551 r4921  
    2222package net.sf.basedb.plugins.batchimport;
    2323
    24 import java.util.Collections;
    25 import java.util.List;
    26 import java.util.Set;
    27 
     24import net.sf.basedb.core.BaseException;
    2825import net.sf.basedb.core.DbControl;
     26import net.sf.basedb.core.File;
    2927import net.sf.basedb.core.Hardware;
    3028import net.sf.basedb.core.Hybridization;
     29import net.sf.basedb.core.Image;
    3130import net.sf.basedb.core.Item;
    3231import net.sf.basedb.core.ItemQuery;
     32import net.sf.basedb.core.Path;
    3333import net.sf.basedb.core.PluginParameter;
    3434import net.sf.basedb.core.Protocol;
     
    4040import net.sf.basedb.core.plugin.AboutImpl;
    4141import net.sf.basedb.core.plugin.GuiContext;
     42import net.sf.basedb.core.query.Hql;
     43import net.sf.basedb.core.query.Restrictions;
    4244import net.sf.basedb.util.parser.FlatFileParser;
    4345import net.sf.basedb.util.parser.Mapper;
     46
     47import java.util.Collections;
     48import java.util.List;
     49import java.util.Set;
    4450
    4551/**
     
    9197      );
    9298 
     99  protected static final PluginParameter<String> imageFileColumnMapping = new PluginParameter<String>(
     100      "fileColumnMapping",
     101      "Image file",
     102      "Mapping that picks the path of a image file from the columns. " +
     103      "The path can be an absolute path (starting with /) or relative " +
     104      "to the 'Data directory' parameter." +
     105      "The plug-in tries to find an existing image with the given file path and that belongs to current scan. "+
     106      "Example: \\Image file\\",
     107      optionalColumnMapping
     108      );
     109 
     110  protected static final PluginParameter<String> imageColumnMapping = new PluginParameter<String>(
     111      "imageColumnMapping",
     112      "Image",
     113      "Mapping that picks the name the image from the data columns. " +     
     114      "Example: \\Image\\",
     115      optionalColumnMapping
     116      );
     117 
     118  protected static final PluginParameter<String> imageFormatColumnMapping = new PluginParameter<String>(
     119      "imageFormatColumnMapping",
     120      "Image format",
     121      "Mapping that picks the format of the given image from the data columns. " +
     122      "The plug-in tries to parse the given format into one of the supported in BASE. " +
     123      "The image will get format 'unknown' if this isn't succeded."+
     124      "Example: \\Image format\\",
     125      optionalColumnMapping
     126      );
     127 
     128  protected static final PluginParameter<String> imagePreviewColumnMapping = new PluginParameter<String>(
     129      "imagePreviewColumnMapping",
     130      "Image preview",
     131      "Mapping that picks the preview flag of the given image from the data columns. " +
     132      "Example: \\Image preview\\",
     133      optionalColumnMapping
     134      );
     135 
     136  protected static final PluginParameter<String> imageDescriptionColumnMapping = new PluginParameter<String>(
     137      "imageDescriptionColumnMapping",
     138      "Image description",
     139      "Mapping that picks the description of the given image from the data columns. " +
     140      "Example: \\Image description\\",
     141      optionalColumnMapping
     142      );
     143
     144 
    93145  public ScanImporter()
    94146  {}
     
    126178  private Mapper hardwareMapper;
    127179  private Mapper hybridizationMapper;
     180  private Mapper imageFileMapper;
     181  private Mapper imageMapper;
     182  private Mapper imageFormatMapper;
     183  private Mapper imagePreviewMapper;
     184  private Mapper imageDescriptionMapper;
     185  private String imagesDirectory;
    128186 
    129187  /**
     
    143201 
    144202  /**
    145     Adds column mappings for name, externalId, description,
    146     protocol, creation date, original quantity, pooled, parent
    147     and used quantity from parent.
     203    Adds column mappings for name, internalId, description,
     204    hybridization, protocol, hardware, image-file, image-name,
     205    image-format and image-description.
    148206  */
    149207  @Override
     
    156214    parameters.add(protocolColumnMapping);
    157215    parameters.add(hardwareColumnMapping);
     216    parameters.add(imageFileColumnMapping);
     217    parameters.add(imageColumnMapping);
     218    parameters.add(imageFormatColumnMapping);
     219    parameters.add(imagePreviewColumnMapping);
     220    parameters.add(imageDescriptionColumnMapping);
    158221  }
    159222 
     
    177240    hardwareMapper = getMapper(ffp, (String)job.getValue("hardwareColumnMapping"), null, null);
    178241    hybridizationMapper = getMapper(ffp, (String)job.getValue("hybridizationColumnMapping"), null, null);
     242    imageFileMapper = getMapper(ffp, (String)job.getValue("imageFileColumnMapping"), null, null);
     243    imageMapper = getMapper(ffp, (String)job.getValue("imageColumnMapping"), null, null);
     244    imageFormatMapper = getMapper(ffp, (String)job.getValue("imageFormatColumnMapping"), null, null);
     245    imagePreviewMapper = getMapper(ffp, (String)job.getValue("imagePreviewColumnMapping"), null, null);
     246    imageDescriptionMapper = getMapper(ffp, (String)job.getValue("imageDescriptionColumnMapping"), null, null);
     247    imagesDirectory = (String)job.getValue("imagesDirectory");
     248    if (imagesDirectory != null && !imagesDirectory.startsWith("/"))
     249    {
     250      imagesDirectory += "/";
     251    }
    179252  }
    180253 
     
    220293      if (nameOrId == null || scanner != null) scan.setScanner(scanner);
    221294    }
     295   
     296    updateMultiLineItem(dc, scan, data, 0);
     297  }
     298 
     299  @Override
     300  protected void updateMultiLineItem(DbControl dc, Scan scan, FlatFileParser.Data data, int multiLineNum)
     301  {
     302    ItemQuery<Image> imageQuery = scan.getImages();
     303    Image image = null;
     304    File imageFile = null;
     305   
     306    // Get the imagefile
     307    if (imageFileMapper != null)
     308    {
     309      String filePath = imageFileMapper.getValue(data);
     310      if (!filePath.startsWith("/") && imagesDirectory != null)
     311      {
     312        filePath = imagesDirectory + filePath;
     313      }
     314      imageFile = File.getByPath(dc, new Path(filePath, Path.Type.FILE), false);     
     315    }
     316   
     317    // Get image by name or id and check image file.
     318    if (imageMapper != null)
     319    {
     320      String nameOrId = imageMapper.getValue(data);
     321      image = findImage(dc, FallbackIdMethod.NAME_OR_ID, scan, nameOrId);
     322
     323      if (image != null && imageFile != null)
     324      {
     325        if (image.getFile() == null) image.setFile(imageFile);
     326        else image = null;
     327      }
     328    }   
     329   
     330    // Create new image if no one could be found with the given name (and file).
     331    if (image == null)
     332    {
     333      image = scan.newImage();
     334      image.setFile(imageFile);
     335      image.setName(scan.getName() + "." + (imageFile != null ? imageFile.getName() : "i" + scan.countImages()));
     336    }   
     337   
     338    // Update the image's properties   
     339    if (imageDescriptionMapper != null) image.setDescription(imageDescriptionMapper.getValue(data));
     340    if (imageFormatMapper != null) image.setFormat(Image.Format.valueOf(imageFormatMapper.getValue(data)));
     341    if (imagePreviewMapper != null) image.setPreview(Boolean.getBoolean(imagePreviewMapper.getValue(data)));     
     342   
    222343  }
    223344  // ------------------------------------
Note: See TracChangeset for help on using the changeset viewer.