Changeset 5755


Ignore:
Timestamp:
Nov 25, 2019, 9:40:49 AM (3 years ago)
Author:
Nicklas Nordborg
Message:

References #1202: Add check for duplicate barcode template in the MIPs library registration

Other MIPs plates that has not yet been pooled are now loaded in the MIPs library registration so that a warning message can be displayed if the same barcode template is selected more than once. It is still possible to register but it requires the extra "checkbox verification" step.

Location:
extensions/net.sf.basedb.reggie/branches/4.24-stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/branches/4.24-stable/resources/mipsprep/lib_registration.js

    r5754 r5755  
    137137      var tmp = templates[i];
    138138      var option = new Option(tmp.name, tmp.id);
     139      option.template = tmp;
    139140      frm.barcodeTemplate[frm.barcodeTemplate.length] = option;
    140141    }
     
    147148   
    148149    Wizard.setInputStatus('barcodeTemplate');
     150    Wizard.hideGoNextConfirmation();
    149151    barcodeTemplateIsValid = false;
    150152   
     
    164166   
    165167    barcodeTemplateIsValid = true;
    166     Wizard.setInputStatus('barcodeTemplate', 'valid');
     168
     169    var template = frm.barcodeTemplate[frm.barcodeTemplate.selectedIndex].template;
     170    if (template.otherPlates && template.otherPlates.length > 0)
     171    {
     172      var msg = 'This template is also used by ' + Strings.encodeTags(template.otherPlates[0].name);
     173      if (template.otherPlates.length > 1)
     174      {
     175        msg += ' and '+(template.otherPlates.length-1)+' more plate(s)';
     176      }
     177      Wizard.setInputStatus('barcodeTemplate', 'warning', msg);
     178      Wizard.showGoNextConfirmation(true, 'Verify registration of plate with duplicate barcode template');
     179    }
     180    else
     181    {
     182      Wizard.setInputStatus('barcodeTemplate', 'valid');
     183    }
    167184  }
    168185 
  • extensions/net.sf.basedb.reggie/branches/4.24-stable/src/net/sf/basedb/reggie/query/AnyToAnyRestriction.java

    r3051 r5755  
    22
    33import java.util.Collection;
     4import java.util.Collections;
    45
    56import net.sf.basedb.core.DbControl;
    67import net.sf.basedb.core.Item;
    78import net.sf.basedb.core.Type;
     9import net.sf.basedb.core.query.Expressions;
     10import net.sf.basedb.core.query.Hql;
    811import net.sf.basedb.core.query.Query;
    912import net.sf.basedb.core.query.QueryElement;
    1013import net.sf.basedb.core.query.Restriction;
     14import net.sf.basedb.core.query.Restrictions;
    1115import net.sf.basedb.util.EqualsHelper;
    1216
     
    2933  public static AnyToAnyRestriction exists(String linkName, Item linkedTo)
    3034  {
    31     return new AnyToAnyRestriction(linkName, linkedTo, true);
     35    Restriction link = linkedTo == null ? null :
     36      Restrictions.eq(Hql.property("at", "toType"), Expressions.integer(linkedTo.getValue()));
     37    return new AnyToAnyRestriction(linkName, link, true);
    3238  }
     39
     40  /**
     41    Create a restriction that restrict a query to return
     42    items that has a linked item with the given link name.
     43    An optional restriction can be used to limit the query
     44    to on the linked item (use "at" as prefix in the HQL).
     45    @since 4.24.1
     46  */
     47  public static AnyToAnyRestriction exists(String linkName, Restriction restriction)
     48  {
     49    return new AnyToAnyRestriction(linkName, restriction, true);
     50  }
     51
    3352 
    3453  /**
     
    3958  public static AnyToAnyRestriction missing(String linkName, Item linkedTo)
    4059  {
    41     return new AnyToAnyRestriction(linkName, linkedTo, false);
     60    Restriction link = linkedTo == null ? null :
     61        Restrictions.eq(Hql.property("at", "toType"), Expressions.integer(linkedTo.getValue()));
     62    return new AnyToAnyRestriction(linkName, link, false);
    4263  }
    4364 
    4465  private final String parameterName;
    45   private final String subQuery;
     66  private final Restriction linkRestriction;
    4667  private final String linkName;
    4768  private final boolean hasLink;
    4869 
    49   private AnyToAnyRestriction(String linkName, Item linkedTo, boolean hasLink)
     70  private AnyToAnyRestriction(String linkName, Restriction linkRestriction, boolean hasLink)
    5071  {
    5172    this.linkName = linkName;
    5273    this.hasLink = hasLink;
    5374    this.parameterName = "LN" + System.identityHashCode(this);
    54     StringBuilder sb = new StringBuilder();
    55     sb.append("(SELECT at.fromId FROM AnyToAnyData at WHERE at.name = :");
    56     sb.append(parameterName);
    57     if (linkedTo != null)
    58     {
    59       sb.append(" AND at.toType=").append(linkedTo.getValue());
    60     }
    61     sb.append(")");
    62     this.subQuery = sb.toString();
     75    this.linkRestriction = linkRestriction;
    6376  }
    6477 
     
    6780  {
    6881    query.setParameter(parameterName, linkName, Type.STRING);
    69     return query.getRootAlias() + (hasLink ? ".id = ANY" : ".id <> ALL") + subQuery;
     82    return query.getRootAlias() + (hasLink ? ".id = ANY" : ".id <> ALL") + getSubQuery(query, dc);
    7083  }
    7184
     
    7386  public Collection<? extends QueryElement> getChildren()
    7487  {
    75     return null;
     88    return linkRestriction != null ? Collections.singleton(linkRestriction) : null;
    7689  }
    7790
     91  private String getSubQuery(Query query, DbControl dc)
     92  {
     93    StringBuilder sb = new StringBuilder();
     94    sb.append("(SELECT at.fromId FROM AnyToAnyData at WHERE at.name = :");
     95    sb.append(parameterName);
     96    if (linkRestriction != null)
     97    {
     98      if (query == null)
     99      {
     100        sb.append(" AND ").append(linkRestriction.toString());
     101      }
     102      else
     103      {
     104        sb.append(" AND ").append(linkRestriction.toQl(query, dc));
     105      }
     106    }
     107    sb.append(")");
     108    return sb.toString();
     109  }
    78110 
    79111  @Override
    80112  public String toString()
    81113  {
    82     return (hasLink ? "id = ANY" : "id <> ALL") + subQuery;
     114    return (hasLink ? "id = ANY" : "id <> ALL") + getSubQuery(null, null);
    83115  }
    84116 
  • extensions/net.sf.basedb.reggie/branches/4.24-stable/src/net/sf/basedb/reggie/servlet/MipsServlet.java

    r5603 r5755  
    6565import net.sf.basedb.reggie.plugins.AliquotImporter;
    6666import net.sf.basedb.reggie.plugins.AliquotImporter.AliquotPlate;
     67import net.sf.basedb.reggie.query.AnyToAnyRestriction;
    6768import net.sf.basedb.util.EqualsHelper;
    6869import net.sf.basedb.util.FileUtil;
     
    348349        query.order(Orders.asc(Hql.property("name")));
    349350       
     351        // Find other MIPs plates with a given template that has not yet been pooled
     352        // We use this information to display a warning if registering more than one plate with
     353        // the same barcode template since that is typically a mistake
     354        ItemQuery<BioPlate> unpooledQuery = BioPlate.getQuery();
     355        unpooledQuery.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
     356        // Only MIPs plates that are not destroyed
     357        BioplateType.MIPS.addFilter(dc, unpooledQuery, true);
     358        // Must have a PLATE_PROCESS_RESULT=Success annotation
     359        unpooledQuery.join(Annotations.innerJoin(null, Annotationtype.PLATE_PROCESS_RESULT.load(dc), "ppr"));
     360        unpooledQuery.restrict(Restrictions.eq(Hql.alias("ppr"), Expressions.string(ReactionPlate.PROCESS_SUCCESSFUL)));
     361        // Must NOT have a PoolDate annotation
     362        unpooledQuery.join(Annotations.leftJoin(null, Annotationtype.POOL_DATE.load(dc), "pd"));
     363        unpooledQuery.restrict(Restrictions.eq(Hql.alias("pd"), null));
     364        // Filter on BarcodeTemplate link
     365        unpooledQuery.restrict(AnyToAnyRestriction.exists("BarcodeTemplate",
     366          Restrictions.eq(Hql.property("at", "toId"), Hql.entityParameter("template", Item.BIOPLATE))));
     367        unpooledQuery.order(Orders.asc(Hql.property("name")));
     368       
    350369        List<BioPlate> result = query.list(dc);
    351370        JSONArray jsonPlates = new JSONArray();
     
    359378          jsonPlate.put("comments", plate.getDescription());
    360379          jsonPlates.add(jsonPlate);
     380         
     381          JSONArray jsonUnpooled = new JSONArray();
     382          unpooledQuery.setEntityParameter("template", plate);
     383          for (BioPlate unpooled : unpooledQuery.list(dc))
     384          {
     385            JSONObject jsonUP = new JSONObject();
     386            jsonUP.put("id", unpooled.getId());
     387            jsonUP.put("name", unpooled.getName());
     388            jsonUnpooled.add(jsonUP);
     389          }
     390          jsonPlate.put("otherPlates", jsonUnpooled);
     391         
    361392        }
    362393        json.put("templates", jsonPlates);
Note: See TracChangeset for help on using the changeset viewer.