Changeset 2168 for trunk/src/examples


Ignore:
Timestamp:
Apr 20, 2006, 8:33:36 AM (16 years ago)
Author:
Nicklas Nordborg
Message:

Made ExampleImporter? an AutoDetectingImporter?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/examples/plugins/src/net/sf/basedb/exampleplugins/ExampleImporter.java

    r2154 r2168  
    3737import net.sf.basedb.core.plugin.AboutImpl;
    3838import net.sf.basedb.core.plugin.AbstractPlugin;
     39import net.sf.basedb.core.plugin.AutoDetectingImporter;
    3940import net.sf.basedb.core.plugin.InteractivePlugin;
    4041import net.sf.basedb.core.plugin.GuiContext;
     
    4344import net.sf.basedb.core.plugin.Response;
    4445
     46import java.io.InputStream;
    4547import java.util.ArrayList;
    4648import java.util.Arrays;
     
    6264public class ExampleImporter
    6365  extends AbstractPlugin
    64   implements InteractivePlugin
     66  implements InteractivePlugin, AutoDetectingImporter
    6567{
    6668
     
    131133    try
    132134    {
     135      // Get the parameters from the job configuration
    133136      boolean updateExisting = (Boolean)job.getValue("updateExisting");
    134137      File f = (File)job.getValue("file");
     138     
     139      // Open the file an import it
    135140      f = File.getById(dc, f.getId());
    136       /*
    137          Pseudo code
    138         Parse file, for each found sample:
    139         String name = ...
    140         String externalId = ...
    141         boolean isNew = false;
    142         Sample s = getByExternalId(externalId);
    143         if (s == null)
    144         {
    145           s = Sample.getNew(dc);
    146           dc.saveItem(s);
    147           isNew = true;
    148         }
    149         if (updateExisting || isNew)
    150         {
    151           s.setName(name);
    152           s.setExternalId(externalId);
    153           ...
    154         }
    155       */
     141      InputStream in = f.getDownloadStream(0);
     142      doImport(in, progress);
     143      in.close();
     144     
    156145      // Commit the work
    157146      dc.commit();
     
    249238
    250239
     240  /*
     241    From the AutoDetectingImporter interface
     242    -------------------------------------------
     243  */
     244  /**
     245    Always true, since we accept all files.
     246  */
     247  public boolean isImportable(InputStream in)
     248    throws BaseException
     249  {
     250    return true;
     251  }
     252  /**
     253    We don't do anything in this method.
     254  */
     255  public void doImport(InputStream in, ProgressReporter progress)
     256    throws BaseException
     257  {
     258    /*
     259       Pseudo code:
     260      Parse input stream, for each found sample:
     261      String name = ...
     262      String externalId = ...
     263      boolean isNew = false;
     264      Sample s = getByExternalId(externalId);
     265      if (s == null)
     266      {
     267        s = Sample.getNew(dc);
     268        dc.saveItem(s);
     269        isNew = true;
     270      }
     271      if (updateExisting || isNew)
     272      {
     273        s.setName(name);
     274        s.setExternalId(externalId);
     275        ...
     276      }
     277    */
     278  }
     279  // -------------------------------------------
     280
    251281  private RequestInformation getConfigureJob(GuiContext context)
    252282  {
Note: See TracChangeset for help on using the changeset viewer.