Changeset 6206


Ignore:
Timestamp:
Apr 12, 2021, 12:52:13 PM (13 months ago)
Author:
Nicklas Nordborg
Message:

References #1295: Registration of specimen handled by external lab

Implemented some checks that are displayed as warnings when importing. For example, if a date is in the future or older than 1 year.

Location:
extensions/net.sf.basedb.reggie/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/resources/batch/import-external-specimen.js

    r6205 r6206  
    9999      html += '</td>';
    100100      html += '<td class="valid dottedleft">';
     101      var startNo = 1;
    101102      if (jsonFile && jsonFile.errors)
    102103      {
    103         html += '<div class="messagecontainer error"><ol>';
     104        html += '<div class="messagecontainer error"><ol start="'+startNo+'">';
    104105        for (var errNo = 0; errNo < jsonFile.errors.length; errNo++)
    105106        {
    106107          html += '<li>'+Strings.encodeTags(jsonFile.errors[errNo]);
    107108        }
    108         html += '</ol><div>';
    109       }
    110       else if (jsonFile && jsonFile.warnings)
    111       {
    112         html += '<div">'+Strings.encodeTags(jsonFile.warnings.join('<br>'))+'</div>';
     109        html += '</ol></div>';
     110        startNo += jsonFile.errors.length;
     111      }
     112      if (jsonFile && jsonFile.warnings)
     113      {
     114        html += '<div class="messagecontainer note"><ol start="'+startNo+'">';
     115        for (var warnNo = 0; warnNo < jsonFile.warnings.length; warnNo++)
     116        {
     117          html += '<li>'+Strings.encodeTags(jsonFile.warnings[warnNo]);
     118        }
     119        html += '</ol></div>';
     120        startNo += jsonFile.warnings.length;
    113121      }
    114122      html += '</td>';
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/cmd/DateValidator.java

    r6205 r6206  
    66
    77import net.sf.basedb.core.DbControl;
     8import net.sf.basedb.reggie.Reggie;
    89
    910
     
    1516*/
    1617public class DateValidator
    17   implements ValueValidator<String, Date>
     18  implements ValueValidator<String, Date>, Cloneable
    1819{
    1920  /**
     
    3637  private final DateFormat dateFormat;
    3738 
     39  private Date notAfter;
     40  private Date notBefore;
     41 
    3842  public DateValidator(String format)
    3943  {
     
    4246  }
    4347 
     48  /**
     49    Wrap this date validator with a validator that issue a warning
     50    if the date is in the future.
     51  */
     52  public DateValidator warnIfFuture()
     53  {
     54    DateValidator wrap;
     55    try
     56    {
     57      wrap = (DateValidator)this.clone();
     58      wrap.notAfter = new Date();
     59    }
     60    catch (CloneNotSupportedException e)
     61    {
     62      throw new UnsupportedOperationException("clone()");
     63    }
     64    return wrap;
     65  }
     66 
     67  /**
     68    Wrap this date validator with a validator that issue a warning
     69    if the date is in the future or older than the specified number of
     70    days.
     71  */
     72  public DateValidator warnIfFutureOrOlder(int numDays)
     73  {
     74    DateValidator wrap = warnIfFuture();
     75    wrap.notBefore = new Date(wrap.notAfter.getTime()-numDays*86400l*1000l);
     76    return wrap;
     77  }
     78 
     79  /**
     80    Wrap this date validator with a validator that issue a warning
     81    if the date is in the future or older than the specified date.
     82  */
     83  public DateValidator warnIfFutureOrOlder(Date oldDate)
     84  {
     85    DateValidator wrap = warnIfFuture();
     86    wrap.notBefore = oldDate;
     87    return wrap;
     88  }
     89 
    4490  @Override
    4591  public Date isValid(DbControl dc, String value, JsonSection section, String entryKey)
    4692  {
     93    Date result = null;
    4794    try
    4895    {
    49       return dateFormat.parse(value);
     96      result = dateFormat.parse(value);
    5097    }
    5198    catch (Exception ex)
     
    53100      section.addErrorMessage("Invalid date in JSON: "+entryKey+"="+value+" (expected format: "+format+")");
    54101    }
    55     return null;
     102    if (result != null)
     103    {
     104      if (notAfter != null && result.after(notAfter))
     105      {
     106        section.addWarningMessage("Future date in JSON: "+entryKey+"="+value);
     107      }
     108      if (notBefore != null && result.before(notBefore))
     109      {
     110        section.addWarningMessage("Old date in JSON: "+entryKey+"="+value+
     111          " (expected after "+Reggie.CONVERTER_DATE_TO_STRING_WITH_SEPARATOR.format(notBefore)+")");
     112      }
     113    }
     114    return result;
    56115  }
    57116 
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/cmd/IntValidator.java

    r6203 r6206  
    1212*/
    1313public class IntValidator
    14   implements ValueValidator<Object, Integer>
     14  implements ValueValidator<Object, Integer>, Cloneable
    1515{
    1616  /**
     
    3333  private List<Integer> allowed;
    3434 
     35  private Integer softMax;
     36  private Integer softMin;
     37 
    3538  /**
    3639    Allow all integers.
     
    4245    Allow all integers between min and max (inclusive).
    4346    Null values are allowed and mean no limit.
     47    Report either as error or warnings.
    4448  */
    4549  public IntValidator(Integer min, Integer max)
     
    5559  {
    5660    this.allowed = allowed;
     61  }
     62 
     63  /**
     64    Wrap this validator with a validator that create warnings
     65    if the value is below the softMin or above the softMax limits.
     66  */
     67  public IntValidator warnIf(Integer softMin, Integer softMax)
     68  {
     69    IntValidator wrap;
     70    try
     71    {
     72      wrap = (IntValidator)this.clone();
     73      wrap.softMax = softMax;
     74      wrap.softMin = softMin;
     75    }
     76    catch (CloneNotSupportedException e)
     77    {
     78      throw new UnsupportedOperationException("clone()");
     79    }
     80    return wrap;
    5781  }
    5882 
     
    97121      }
    98122    }
     123    if (result != null)
     124    {
     125      if (softMin != null && result < softMin)
     126      {
     127        section.addWarningMessage("Unexpected integer in JSON: "+entryKey+"="+value+" (expected >="+softMin+")");
     128      }
     129      if (softMax != null && result > softMax)
     130      {
     131        section.addWarningMessage("Unexpected integer in JSON: "+entryKey+"="+value+" (expected <="+softMax+")");
     132      }
     133    }
    99134    return result;
    100135  }
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/cmd/LibraryInfo.java

    r6205 r6206  
    6363      }
    6464     
    65       libDate = section.getRequiredEntry("Date", DateValidator.YYYY_MM_DD);
    66       libSize = section.getRequiredEntry("Library size", IntValidator.POSITIVE);
     65      libDate = section.getRequiredEntry("Date", DateValidator.YYYY_MM_DD.warnIfFutureOrOlder(365));
     66      libSize = section.getRequiredEntry("Library size", IntValidator.POSITIVE.warnIf(150, 400));
    6767      libMolarity = section.getRequiredEntry("Library molarity", FloatValidator.POSITIVE);
    6868      qubitConc = section.getRequiredEntry("Qubit concentration (ng/ul)", FloatValidator.POSITIVE);
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/cmd/LongValidator.java

    r6204 r6206  
    1111*/
    1212public class LongValidator
    13   implements ValueValidator<Object, Long>
     13  implements ValueValidator<Object, Long>, Cloneable
    1414{
    1515  /**
     
    2626  private Long minValue;
    2727  private List<Long> allowed;
     28  private Long softMax;
     29  private Long softMin;
    2830 
    2931  /**
     
    5052    this.allowed = allowed;
    5153  }
     54 
     55  /**
     56    Wrap this validator with a validator that create warnings
     57    if the value is below the softMin or above the softMax limits.
     58  */
     59  public LongValidator warnIf(Long softMin, Long softMax)
     60  {
     61    LongValidator wrap;
     62    try
     63    {
     64      wrap = (LongValidator)this.clone();
     65      wrap.softMax = softMax;
     66      wrap.softMin = softMin;
     67    }
     68    catch (CloneNotSupportedException e)
     69    {
     70      throw new UnsupportedOperationException("clone()");
     71    }
     72    return wrap;
     73  }
     74
    5275 
    5376  @Override
     
    91114      }
    92115    }
     116    if (result != null)
     117    {
     118      if (softMin != null && result < softMin)
     119      {
     120        section.addWarningMessage("Unexpected long in JSON: "+entryKey+"="+value+" (expected >="+softMin+")");
     121      }
     122      if (softMax != null && result > softMax)
     123      {
     124        section.addWarningMessage("Unexpected long in JSON: "+entryKey+"="+value+" (expected <="+softMax+")");
     125      }
     126    }
    93127    return result;
    94128  }
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/cmd/MergeInfo.java

    r6204 r6206  
    2020    if (merge != null)
    2121    {
    22       pfReads = merge.getRequiredEntry("PF_READS", LongValidator.POSITIVE);
     22      pfReads = merge.getRequiredEntry("PF_READS", LongValidator.POSITIVE.warnIf(10000000l, null)); // Warn if less than 10M reads
    2323    }
    2424    valid = merge != null && !merge.hasError();
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/cmd/PoolInfo.java

    r6205 r6206  
    4646        verifyUnusedBarcode(pool, libInfo.barcode, section);
    4747      }
    48       poolDate = section.getRequiredEntry("Date", DateValidator.YYYY_MM_DD);
     48      poolDate = section.getRequiredEntry("Date", DateValidator.YYYY_MM_DD.warnIfFutureOrOlder(365));
    4949      operator = section.getRequiredEntry("Operator");
    5050    }
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/cmd/SequencingRunInfo.java

    r6205 r6206  
    4949      position = section.getRequiredEntry("Position", PatternValidator.SEQUENCER_POSITION);
    5050      runNumber = section.getRequiredEntry("RunNumber", IntValidator.POSITIVE);
    51       startDate = section.getRequiredEntry("StartDate", DateValidator.YYMMDD);
    52       endDate = section.getRequiredEntry("EndDate", DateValidator.YYMMDD_HH_MM_SS);
     51      startDate = section.getRequiredEntry("StartDate", DateValidator.YYMMDD.warnIfFutureOrOlder(365));
     52      endDate = section.getRequiredEntry("EndDate", DateValidator.YYMMDD_HH_MM_SS.warnIfFutureOrOlder(startDate));
    5353      operator = section.getRequiredEntry("Operator");
    5454      if (flowCellInfo.flowCell != null)
Note: See TracChangeset for help on using the changeset viewer.