Changeset 5781


Ignore:
Timestamp:
Dec 11, 2019, 12:34:23 PM (2 years ago)
Author:
Nicklas Nordborg
Message:

References #1209: Add support for storing TMA specimen

Added support for using either "Name" or "External ID" to reference existing cases.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/TMASpecimenImporter.java

    r5779 r5781  
    2222import net.sf.basedb.core.Sample;
    2323import net.sf.basedb.core.StringParameterType;
    24 import net.sf.basedb.core.Type;
    2524import net.sf.basedb.core.plugin.GuiContext;
    2625import net.sf.basedb.core.plugin.InteractivePlugin;
     
    2928import net.sf.basedb.core.plugin.Request;
    3029import net.sf.basedb.core.plugin.Response;
    31 import net.sf.basedb.core.query.Expressions;
    32 import net.sf.basedb.core.query.Hql;
    33 import net.sf.basedb.core.query.Restrictions;
    3430import net.sf.basedb.plugins.AbstractFlatFileImporter;
     31import net.sf.basedb.plugins.batchimport.IdMethod;
     32import net.sf.basedb.plugins.batchimport.PropertyIdMethod;
    3533import net.sf.basedb.plugins.util.Parameters;
    3634import net.sf.basedb.reggie.Reggie;
     
    3937import net.sf.basedb.reggie.dao.ReggieItem;
    4038import net.sf.basedb.reggie.dao.Subtype;
     39import net.sf.basedb.util.Enumeration;
    4140import net.sf.basedb.util.parser.ConfigureByExample;
    4241import net.sf.basedb.util.parser.FlatFileParser;
     
    6564  private static final PluginParameter<String> caseColumnMapping = new PluginParameter<String>(
    6665      "caseColumnMapping",
    67       "Case",
    68       "Mapping that picks the name of the Case from the data columns. This " +
     66      "Case ID",
     67      "Mapping that picks the name or external id for the Case from the data columns. This " +
    6968      "parameter is required. " +
    70       "Example: \\Case\\",
     69      "Example: \\Case ID\\",
    7170      requiredColumnMapping
    7271      );
     
    156155  // ------------------------------------
    157156
     157  protected IdMethod[] getIdMethods()
     158  {
     159    return new IdMethod[] { PropertyIdMethod.NAME, PropertyIdMethod.EXTERNAL_ID };
     160  }
     161 
     162  /**
     163    Get the id method to use for finding cases. This implementation
     164    searches the methods returned by {@link #getIdMethods()}
     165  */
     166  protected IdMethod getIdMethod(String method)
     167  {
     168    for (IdMethod im : getIdMethods())
     169    {
     170      if (im.getMethod().equals(method))
     171      {
     172        return im;
     173      }
     174    }
     175    return PropertyIdMethod.NAME;
     176  }
     177 
    158178  @Override
    159179  public RequestInformation getRequestInformation(GuiContext context, String command)
     
    199219          return;
    200220        }
     221       
     222        // Check that a mapping has been provided for the selected idMethod
     223        IdMethod idMethod = getIdMethod((String)request.getParameterValue("idMethod"));
     224        if (idMethod == null)
     225        {
     226          response.setError("Unknown method for item identification: " +
     227              request.getParameterValue("idMethod"), null);
     228          return;
     229        }
    201230
    202231        // Check the mapping expressions
     
    208237        storeValue(wrapper, request, ri.getParameter(Parameters.LOGFILE_PARAMETER));
    209238        storeValue(wrapper, request, excelSheetParameter);
     239        storeValue(wrapper, request, ri.getParameter("idMethod"));
    210240
    211241        storeValue(wrapper, request, dataHeaderRegexpParameter);
     
    245275  private DbControl dc;
    246276  private FlatFileParser ffp;
     277  private IdMethod idMethod;
    247278  private ItemQuery<Sample> caseQuery;
    248279  private Mapper caseMapper;
     
    262293    this.dc = sc.newDbControl();
    263294    this.dryRun = job.getJob().isDryRun();
     295    this.idMethod = getIdMethod(job.getValue("idMethod"));
    264296    this.caseQuery = Sample.getQuery();
    265297    Subtype.CASE.addFilter(dc, caseQuery);
    266298    caseQuery.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
    267     caseQuery.restrict(Restrictions.eq(Hql.property("name"), Expressions.parameter("caseName")));
     299    idMethod.prepareQuery(dc, caseQuery);
    268300    if (ffp.getExcelSheet() != null)
    269301    {
     
    275307  protected void beginData()
    276308  {
    277     caseMapper = NotNullMapper.wrap("Case name is null", getMapper(ffp, job.getValue("caseColumnMapping"), null, null));
     309    caseMapper = NotNullMapper.wrap("Case ID is null", getMapper(ffp, job.getValue("caseColumnMapping"), null, null));
    278310    tmaBlockMapper = NotNullMapper.wrap("TMABlock is null", getMapper(ffp, job.getValue("tmaBlockColumnMapping"), null, null));
    279311    tmaBlockPosMapper = NotNullMapper.wrap("TMABlockPos is null", getMapper(ffp, job.getValue("tmaBlockPosColumnMapping"), null, null));
     
    287319    throws BaseException
    288320  {
    289     String caseName = caseMapper.getString(data);
    290     caseQuery.setParameter("caseName", caseName, Type.STRING);
    291     List<Sample> cases = caseQuery.list(dc);
     321    String caseId = caseMapper.getString(data);
     322    List<Sample> cases = idMethod.find(dc, caseQuery, caseId);
    292323    if (cases.size() > 1)
    293324    {
    294       throw new InvalidDataException("Found " + cases.size() + " cases with the same name (" + caseName + ").");
     325      throw new InvalidDataException("Found " + cases.size() + " cases [" + idMethod + "=" + caseId + "]");
    295326    }
    296327    else if (cases.size() == 0)
    297328    {
    298       throw new ItemNotFoundException("Case[name=" + caseName + "]");
     329      throw new ItemNotFoundException("Case[" + idMethod + "=" + caseId + "]");
    299330    }
    300331
     
    380411        parameters.add(Parameters.dryRunParameter(null, null, null));
    381412       
     413        Enumeration<String, String> idMethods = new Enumeration<String, String>();
     414        idMethods.add(null, null);
     415        idMethods.add(PropertyIdMethod.NAME.getMethod(), PropertyIdMethod.NAME.getTitle());
     416        idMethods.add(PropertyIdMethod.EXTERNAL_ID.getMethod(), PropertyIdMethod.EXTERNAL_ID.getTitle());
     417        PluginParameter<String> idMethodParameter = new PluginParameter<String>(
     418          "idMethod",
     419          "Case identification method",
     420          "The method to use for finding existing cases. The plug-in can use either the " +
     421          "SCAN-B ID or the Release ID.",
     422          new StringParameterType(null, null, true, 1, 0, 0, idMethods)
     423        );
     424        parameters.add(idMethodParameter);
     425
     426       
    382427        // Parser regular expressions
    383428        parameters.add(parserSection);
Note: See TracChangeset for help on using the changeset viewer.