Changeset 5777


Ignore:
Timestamp:
Dec 6, 2019, 9:50:41 AM (2 years ago)
Author:
Nicklas Nordborg
Message:

References #1209: Add support for storing TMA specimen

First version of a TMA importer plug-in. It is very similar to existing batch importers in BASE, but can only be used in "create" mode. So far, the only required column is a case name. If the case exists a new TMASpecimen child item is created. The name and external id of the new item is auto-generated.

Location:
extensions/net.sf.basedb.reggie/trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/META-INF/extensions.xml

    r5743 r5777  
    137137    </settings>
    138138  </plugin-definition>
     139  <plugin-definition id="TMASpecimenImporter">
     140    <about>
     141      <name>TMA Specimen importer</name>
     142      <description>
     143        Plug-in for importing TMA specimen.
     144      </description>
     145    </about>
     146    <plugin-class>net.sf.basedb.reggie.plugins.TMASpecimenImporter</plugin-class>
     147    <settings>
     148      <property name="everyone-use">0</property>
     149    </settings>
     150  </plugin-definition>
    139151  <!--
    140152  <plugin-definition id="SingleSamplePredictorPlugin">
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/dao/Case.java

    r5320 r5777  
    294294  }
    295295 
     296  /**
     297    Find the next name to give a TMA specimen child item. This assumes that
     298    all child items are using the naming convention. foo.tma, foo.tma2, and
     299    so on. NOTE! The first child item have no number!
     300    @return The next unused name
     301    @since 4.25
     302  */
     303  public String getNextTMASpecimenName(DbControl dc)
     304  {
     305    Sample c = getItem();
     306    ItemQuery<Sample> query = c.getChildSamples();
     307    Subtype.TMA_SPECIMEN.addFilter(dc, query);
     308    query.setIncludes(Include.ALL);
     309    return getNextChildItemName(dc, query, Subtype.TMA_SPECIMEN.getItemSuffix(), true);
     310  }
     311
    296312}
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/dao/ReggieItem.java

    r5694 r5777  
    77import java.util.List;
    88import java.util.Map;
     9import java.util.regex.Matcher;
     10import java.util.regex.Pattern;
    911
    1012import org.json.simple.JSONObject;
     
    562564 
    563565  /**
     566    Generate the next auto-generated external ID based on one that was previously
     567    generated and reserved. The previous ID is one that is generated by either this
     568    method or {@link ##getNextExternalId(DbControl, ItemQuery, String)}.
     569    @since 4.25
     570  */
     571  public static String getNextExternalId(DbControl dc, String previousId)
     572  {
     573    Pattern p = Pattern.compile("(\\D+)(\\d+)");
     574   
     575    Matcher m = p.matcher(previousId);
     576    if (!m.matches()) throw new InvalidDataException("Previous ID doens't match pattern \\w+\\d+: " + previousId);
     577
     578    String prefix = m.group(1);
     579    String baseNumber = m.group(2);
     580   
     581    int nextIndex = Values.getInt(baseNumber) + 1;
     582   
     583    int numDigitsInName = baseNumber.length();
     584    int numIterations = 0;
     585    // This will hold the generated names
     586    String nextExternalId;
     587    while (true)
     588    {
     589      nextExternalId = prefix + MD5.leftPad(Integer.toString(nextIndex), '0', numDigitsInName);   
     590      if (RESERVED_NAMES.reserve(dc, nextExternalId))
     591      {
     592        RESERVED_NAMES.releaseIfTransactionFails(dc, nextExternalId);
     593        break;
     594      }
     595      nextIndex++;
     596      numIterations++;
     597      if (numIterations == 100)
     598      {
     599        throw new RuntimeException("Failed to generate an external ID for '" + prefix +
     600          "' after 100 tries. Last tested value was '" + nextExternalId + "'.");
     601      }
     602    }
     603   
     604    return nextExternalId;
     605  }
     606
     607 
     608  /**
    564609    @since 4.19
    565610    @see #ensureNonExistingItem(DbControl, Item, String, String)
Note: See TracChangeset for help on using the changeset viewer.