Changeset 7849


Ignore:
Timestamp:
Oct 13, 2020, 2:31:34 PM (14 months ago)
Author:
Nicklas Nordborg
Message:

References #2223: Implement batch importer for any-to-any links

First version is now implemented.

Location:
trunk/src
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/Metadata.java

    r6898 r7849  
    7070  private static Set<Item> subtypableItems;
    7171  private static Set<Item> listableItems;
     72  private static Set<Item> nameableItems;
    7273
    7374  private static boolean isInitialised = false;
     
    8485    subtypableItems = Collections.unmodifiableSet(getImplementingItems(Subtypable.class));
    8586    listableItems = Collections.unmodifiableSet(getImplementingItems(Listable.class));
     87    nameableItems = Collections.unmodifiableSet(getImplementingItems(Nameable.class));
    8688    isInitialised = true;
    8789  }
     
    101103    subtypableItems = null;
    102104    listableItems = null;
     105    nameableItems = null;
    103106  }
    104107
     
    193196  {
    194197    return listableItems;
     198  }
     199 
     200  /**
     201    Get a set containing all {@link Nameable} item types.
     202    The set cannot be modified.
     203    @since 3.17
     204  */
     205  public static Set<Item> getNameableItems()
     206  {
     207    return nameableItems;
    195208  }
    196209 
  • trunk/src/plugins/core/core-plugins.xml

    r7747 r7849  
    444444    </settings>
    445445  </plugin-definition>
     446 
     447  <plugin-definition id="AnyToAnyImporter">
     448    <about>
     449      <name>Any-to-any importer</name>
     450      <description>
     451        This plugin is used to batch manage any-to-any links between items.
     452      </description>
     453    </about>
     454    <plugin-class>net.sf.basedb.plugins.batchimport.AnyToAnyImporter</plugin-class>
     455    <settings>
     456      <property name="everyone-use">1</property>
     457    </settings>
     458  </plugin-definition>
    446459
    447460  <plugin-definition id="IlluminaRawDataImporter">
  • trunk/src/plugins/core/net/sf/basedb/plugins/AbstractFlatFileImporter.java

    r7668 r7849  
    4646import net.sf.basedb.core.plugin.AutoDetectingImporter;
    4747import net.sf.basedb.core.plugin.ImportInputStream;
     48import net.sf.basedb.core.plugin.ParameterValues;
     49import net.sf.basedb.core.plugin.ParameterValuesWrapper;
    4850import net.sf.basedb.core.plugin.Request;
    4951import net.sf.basedb.core.plugin.Response;
     
    962964 
    963965  /**
     966    Get an initialized parser that is configured by job or configuration
     967    values.
     968  */
     969  protected FlatFileParser getInitializedFlatFileParser()
     970    throws BaseException
     971  {
     972    return getInitializedFlatFileParser(null);
     973  }
     974 
     975  /**
    964976    Create and initialise a flat file parser by setting all regular expressions
    965977    and other options. This implementation gets all parameters from the
     
    968980    this method is called once for each file returned by the
    969981    {@link #getFileIterator()} and that a new parser is needed for each file.
     982    @param parameters ParameterValues implementation to pick options from
    970983    @return An intialised flat file parser
    971   */
    972   protected FlatFileParser getInitializedFlatFileParser()
     984    @since 3.17
     985  */
     986  protected FlatFileParser getInitializedFlatFileParser(ParameterValues parameters)
    973987    throws BaseException
    974988  {
     989    if (parameters == null) parameters = new ParameterValuesWrapper(null, job, configuration, true);
     990
    975991    FlatFileParser ffp = new FlatFileParser();
    976992
    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)getJobOrConfigurationValue(trimQuotesParameter.getName());
     993    ffp.setSectionRegexp(getPattern(parameters, sectionRegexpParameter.getName()));
     994    ffp.setHeaderRegexp(getPattern(parameters, headerRegexpParameter.getName()));
     995    ffp.setDataHeaderRegexp(getPattern(parameters, dataHeaderRegexpParameter.getName()));
     996    ffp.setDataSplitterRegexp(getPattern(parameters, dataSplitterRegexpParameter.getName()));
     997    Boolean trimQuotes = parameters.getValue(trimQuotesParameter.getName());
    982998    if (trimQuotes != null) ffp.setTrimQuotes(trimQuotes);
    983     ffp.setIgnoreRegexp(getPattern(ignoreRegexpParameter.getName()));
    984     ffp.setDataFooterRegexp(getPattern(dataFooterRegexpParameter.getName()));
    985     ffp.setMinDataColumns(IntegerUtil.getInt((Integer)getJobOrConfigurationValue(minDataColumnsParameter.getName())));
    986     ffp.setMaxDataColumns(IntegerUtil.getInt((Integer)getJobOrConfigurationValue(maxDataColumnsParameter.getName())));
     999    ffp.setIgnoreRegexp(getPattern(parameters, ignoreRegexpParameter.getName()));
     1000    ffp.setDataFooterRegexp(getPattern(parameters, dataFooterRegexpParameter.getName()));
     1001    ffp.setMinDataColumns(IntegerUtil.getInt((Integer)parameters.getValue(minDataColumnsParameter.getName())));
     1002    ffp.setMaxDataColumns(IntegerUtil.getInt((Integer)parameters.getValue(maxDataColumnsParameter.getName())));
    9871003   
    9881004    ffp.setDefaultNumberFormat(getNumberFormat());
     
    9901006    ffp.setDefaultTimestampFormat(getTimestampFormatter("yyyy-MM-dd HH:mm:ss"));
    9911007
    992     ffp.setExcelSheet((String)getJobOrConfigurationValue(excelSheetParameter.getName()));
     1008    ffp.setExcelSheet(parameters.getValue(excelSheetParameter.getName()));
    9931009    return ffp;
    9941010  }
     
    10991115  }
    11001116 
     1117  protected Pattern getPattern(ParameterValues parameters, String name)
     1118    throws BaseException
     1119  {
     1120    String regexp = (String)parameters.getValue(name);
     1121    return regexp != null ? Pattern.compile(regexp) : null;
     1122  }
     1123
    11011124  /**
    11021125    Check if a column mapping is a valid mapping expression and
  • trunk/src/plugins/core/net/sf/basedb/plugins/AnnotationFlatFileImporter.java

    r7703 r7849  
    3838import java.util.Set;
    3939import java.util.TreeMap;
    40 import java.util.regex.Pattern;
    4140
    4241import net.sf.basedb.core.Annotatable;
     
    5150import net.sf.basedb.core.File;
    5251import net.sf.basedb.core.Include;
    53 import net.sf.basedb.core.IntegerUtil;
    5452import net.sf.basedb.core.Item;
    5553import net.sf.basedb.core.ItemContext;
     
    978976  private RequestInformation configureImport;
    979977 
    980   private Pattern getPattern(ParameterValues parameters, String name)
    981     throws BaseException
    982   {
    983     String regexp = (String)parameters.getValue(name);
    984     return regexp != null ? Pattern.compile(regexp) : null;
    985   }
    986  
    987   protected FlatFileParser getInitializedFlatFileParser(ParameterValues parameters)
    988     throws BaseException
    989   {
    990     FlatFileParser ffp = new FlatFileParser();
    991     ffp.setDataHeaderRegexp(getPattern(parameters, dataHeaderRegexpParameter.getName()));
    992     ffp.setDataSplitterRegexp(getPattern(parameters, dataSplitterRegexpParameter.getName()));
    993     Boolean trimQuotes = (Boolean)parameters.getValue(trimQuotesParameter.getName());
    994     if (trimQuotes != null) ffp.setTrimQuotes(trimQuotes);
    995     ffp.setIgnoreRegexp(getPattern(parameters, ignoreRegexpParameter.getName()));
    996     ffp.setDataFooterRegexp(getPattern(parameters, dataFooterRegexpParameter.getName()));
    997     ffp.setMinDataColumns(IntegerUtil.getInt((Integer)parameters.getValue(minDataColumnsParameter.getName())));
    998     ffp.setMaxDataColumns(IntegerUtil.getInt((Integer)parameters.getValue(maxDataColumnsParameter.getName())));
    999     ffp.setExcelSheet(parameters.getValue(excelSheetParameter.getName()));
    1000     return ffp;
    1001   }
    1002  
    1003978  /**
    1004979    If the current context is the "Members" tab for an item list we load
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/AbstractItemImporter.java

    r7747 r7849  
    3232import java.util.Map;
    3333import java.util.Set;
    34 import java.util.regex.Pattern;
    3534
    3635import net.sf.basedb.core.AnnotationTypeCategory;
     
    5958import net.sf.basedb.core.PhysicalBioAssay;
    6059import net.sf.basedb.core.Include;
    61 import net.sf.basedb.core.IntegerUtil;
    6260import net.sf.basedb.core.InvalidUseOfNullException;
    6361import net.sf.basedb.core.Item;
     
    24302428  private RequestInformation configureOptions;
    24312429
    2432   private Pattern getPattern(ParameterValues parameters, String name)
    2433     throws BaseException
    2434   {
    2435     String regexp = (String)parameters.getValue(name);
    2436     return regexp != null ? Pattern.compile(regexp) : null;
    2437   }
    2438  
    2439   protected FlatFileParser getInitializedFlatFileParser(ParameterValues parameters)
    2440     throws BaseException
    2441   {
    2442     FlatFileParser ffp = new FlatFileParser();
    2443     ffp.setDataHeaderRegexp(getPattern(parameters, dataHeaderRegexpParameter.getName()));
    2444     ffp.setDataSplitterRegexp(getPattern(parameters, dataSplitterRegexpParameter.getName()));
    2445     Boolean trimQuotes = (Boolean)parameters.getValue(trimQuotesParameter.getName());
    2446     if (trimQuotes != null) ffp.setTrimQuotes(trimQuotes);
    2447     ffp.setIgnoreRegexp(getPattern(parameters, ignoreRegexpParameter.getName()));
    2448     ffp.setDataFooterRegexp(getPattern(parameters, dataFooterRegexpParameter.getName()));
    2449     ffp.setMinDataColumns(IntegerUtil.getInt((Integer)parameters.getValue(minDataColumnsParameter.getName())));
    2450     ffp.setMaxDataColumns(IntegerUtil.getInt((Integer)parameters.getValue(maxDataColumnsParameter.getName())));
    2451    
    2452     ffp.setExcelSheet(parameters.getValue(excelSheetParameter.getName()));
    2453    
    2454     return ffp;
    2455   }
    2456  
    24572430  /**
    24582431    If the current context is the "Members" tab for an item list we load
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/FileImporter.java

    r7666 r7849  
    107107  public FileImporter()
    108108  {
    109     this.pathIdMethod = new PathIdMethod();
     109    this.pathIdMethod = PathIdMethod.ROOT; // Temporary until we know the rootPath
    110110    this.pathToDirectory = new HashMap<String, Directory>();
    111111  }
     
    147147  }
    148148 
     149  /**
     150    We need to initialize the PathIdMethod when this is called.
     151  */
     152  @Override
     153  protected IdMethod getIdMethod(DbControl dc, String method)
     154  {
     155    if (dc != null && job.getValue("root") != null)
     156    {
     157      pathIdMethod = new PathIdMethod(getRootPath(dc));
     158    }
     159    return super.getIdMethod(dc, method);
     160  }
     161
    149162  @Override
    150163  protected Item getItemForSubtypes()
     
    268281      Directory d = Directory.getById(dc, ((Directory)job.getValue("root")).getId());
    269282      rootPath = d.getPath().toString();
    270       pathIdMethod.rootPath = rootPath;
    271283    }
    272284    return rootPath;
     
    297309  }
    298310 
    299   public class PathIdMethod
     311  public static class PathIdMethod
    300312    implements IdMethod
    301313  {
    302 
    303     private String rootPath;
     314 
     315    public static final PathIdMethod ROOT = new PathIdMethod("/");
     316   
     317    public static FallbackIdMethod PATH_OR_ID = new FallbackIdMethod("pathOrId", "Path or Internal ID", ROOT);
     318   
     319    private final String rootPath;
     320   
     321    public PathIdMethod(String rootPath)
     322    {
     323      this.rootPath = rootPath;
     324    }
    304325   
    305326    @Override
     
    347368    public <I extends BasicItem> List<I> find(DbControl dc, ItemQuery<I> query, String identifier)
    348369    {
    349       Path filePath = new Path(resolvePath(identifier, getRootPath(dc)), Path.Type.FILE);
     370      Path filePath = new Path(resolvePath(identifier, rootPath), Path.Type.FILE);
    350371      try
    351372      {
     
    360381      }
    361382    }
    362    
    363   }
     383    /*
     384      From the Object class
     385      ---------------------
     386    */
     387    @Override
     388    public String toString()
     389    {
     390      return getTitle();
     391    }
     392    // --------------------------
     393 
     394  }
     395 
    364396}
Note: See TracChangeset for help on using the changeset viewer.