Changeset 5709


Ignore:
Timestamp:
Aug 26, 2011, 1:26:09 PM (12 years ago)
Author:
Nicklas Nordborg
Message:

References #1597: Subtypes of items

Added link to item subtype from bioplate type which makes it possible to restrict/filter on the biomaterial subtype when selecting biomaterial for a plate. The "restriction" is in the gui only and is not checked by the core since it is possible to change the subtype of a biomaterial after it has been placed on a plate.

As a result of this the "Labeled extract reaction plate" is brought back to life again.

Also discovered that the bioplate event wizards should probably be able to utilize subtype information for some improvements. So there are still some things to fix before this ticket can be closed.

Location:
trunk
Files:
12 edited

Legend:

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

    r5641 r5709  
    237237 
    238238  /**
     239    Get the subtype that biomaterial items should have when placed
     240    on a plate with this bioplate type.
     241    @return A subtype or null if not important
     242    @since 3.0
     243  */
     244  public ItemSubtype getItemSubtype()
     245  {
     246    return getDbControl().getItem(ItemSubtype.class, getData().getItemSubtype());
     247  }
     248 
     249  /**
     250    Set the subtype that biomaterial items should have when placed on a
     251    plate with the bioplate type. A subtype can only be specified if
     252    a biomaterial type has been set and the given subtype must be compatible
     253    with the biomaterial type.
     254    @param subtype A subtype or null if the subtype is not important
     255    @since 3.0
     256  */
     257  public void setItemSubtype(ItemSubtype subtype)
     258  {
     259    checkPermission(Permission.WRITE);
     260   
     261    if (subtype == null)
     262    {
     263      getData().setItemSubtype(null);
     264    }
     265    else
     266    {
     267      Item bmType = getBioMaterialType();
     268      if (bmType == null)
     269      {
     270        throw new InvalidDataException("Can't set subtype when no biomaterial type has been set: " + this.getName());
     271      }
     272      if (bmType != subtype.getMainItemType())
     273      {
     274        throw new InvalidDataException("The subtype is not used for " + bmType.name() + ": " + subtype.getName());
     275      }
     276      subtype.checkPermission(Permission.USE);
     277      getData().setItemSubtype(subtype.getData());
     278    }
     279  }
     280 
     281  /**
    239282    Get the lock mode for wells located on plates of this plate type.
    240283    The lock mode determines if biomaterial may be changed in the
  • trunk/src/core/net/sf/basedb/core/Install.java

    r5699 r5709  
    646646      if (progress != null) progress.display((int)(progressStep*progress_factor), "--Creating bioplate types...");
    647647      BioPlateTypeData storagePlate = createBioPlateType("Storage plate", "A generic storage plate for all types of biomaterial.",
    648           null, BioWell.LockMode.UNLOCKED);
     648          null, null, BioWell.LockMode.UNLOCKED);
    649649      BioPlateTypeData sampleReactionPlate = createBioPlateType("Sample reaction plate", "A generic reaction plate for samples.",
    650           Item.SAMPLE, BioWell.LockMode.LOCKED_AFTER_ADD);
     650          Item.SAMPLE, null, BioWell.LockMode.LOCKED_AFTER_ADD);
    651651      BioPlateTypeData extractReactionPlate = createBioPlateType("Extract reaction plate", "A generic reaction plate for extracts.",
    652           Item.EXTRACT, BioWell.LockMode.LOCKED_AFTER_ADD);
    653      
     652          Item.EXTRACT, null, BioWell.LockMode.LOCKED_AFTER_ADD);
     653      BioPlateTypeData labeledExtractReactionPlate = createBioPlateType("Labeled extract reaction plate",
     654          "A generic reaction plate for labeled extracts.",
     655          Item.EXTRACT, labeledExtract, BioWell.LockMode.LOCKED_AFTER_ADD);
     656
    654657      BioPlateEventTypeData genericEvent = createBioPlateEventType("Generic", BioPlateEventType.GENERIC,
    655658          "An event that does something unspecified to the participating bioplates. Use the " +
     
    16691672  */
    16701673  private static BioPlateTypeData createBioPlateType(String name, String description,
    1671     Item biomaterialType, BioWell.LockMode lockedMode)
     1674    Item biomaterialType, ItemSubtypeData subtype, BioWell.LockMode lockedMode)
    16721675    throws BaseException
    16731676  {
     
    16871690      if (pt != null)
    16881691      {
     1692        if (pt.getItemSubtype() == null && subtype != null)
     1693        {
     1694          pt.setItemSubtype(subtype);
     1695        }
    16891696        log.info("createBioPlateType: EXISTS [name="+name+"]");
    16901697        HibernateUtil.commit(tx);
     
    16961703        pt.setDescription(description);
    16971704        pt.setBioMaterialType(biomaterialType == null ? null : biomaterialType.getValue());
     1705        pt.setItemSubtype(subtype);
    16981706        pt.setLockMode(lockedMode.getValue());
    16991707        HibernateUtil.saveData(session, pt);
  • trunk/src/core/net/sf/basedb/core/data/BioPlateTypeData.java

    r5456 r5709  
    101101  }
    102102
     103  private ItemSubtypeData subtype;
     104  /**
     105    Get the subtype of biomaterials that can be placed on plates of this type.
     106    @hibernate.many-to-one column="`subtype_id`" not-null="false" outer-join="false"
     107    @since 3.0
     108  */
     109  public ItemSubtypeData getItemSubtype()
     110  {
     111    return subtype;
     112  }
     113  public void setItemSubtype(ItemSubtypeData subtype)
     114  {
     115    this.subtype = subtype;
     116  }
     117 
    103118  private int lockMode;
    104119  /**
  • trunk/www/biomaterials/bioplates/list_bioplates.jsp

    r5708 r5709  
    3737  import="net.sf.basedb.core.Include"
    3838  import="net.sf.basedb.core.Type"
     39  import="net.sf.basedb.core.ItemSubtype"
    3940  import="net.sf.basedb.core.ItemResultIterator"
    4041  import="net.sf.basedb.core.ItemResultList"
     
    100101{
    101102  final ItemQuery<AnnotationType> annotationTypeQuery = Base.getAnnotationTypesQuery(itemType);
     103
     104  final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(null);
     105  subtypesQuery.restrict(
     106    Restrictions.in(
     107      Hql.property("itemType"),
     108      Expressions.integer(Item.SAMPLE.getValue()), Expressions.integer(Item.EXTRACT.getValue())
     109    ));
    102110 
    103111  final ItemQuery<PlateGeometry> geometryQuery = PlateGeometry.getQuery();
     
    322330        exportable="true"
    323331        enumeration="<%=bioMaterialTypes%>"
     332      />
     333      <tbl:columndef
     334        id="bioMaterialSubtype"
     335        property="bioPlateType.itemSubtype"
     336        sortproperty="bioPlateType.itemSubtype.name"
     337        exportproperty="bioPlateType.itemSubtype.name:string"
     338        datatype="int"
     339        enumeration="<%=Enumeration.fromItems(subtypesQuery.list(dc), "-any-")%>"
     340        title="Biomaterial subtype"
     341        sortable="true"
     342        filterable="true"
     343        exportable="true"
    324344      />
    325345      <tbl:columndef
     
    588608                  Integer i = bmType.getValue(dc, item);
    589609                  %><%=i == null ? "<i>- any -</i>" : Item.fromValue(i).toString() %></tbl:cell>
     610                <tbl:cell column="bioMaterialSubtype"><base:propertyvalue
     611                    item="<%=item%>"
     612                    property="bioPlateType.itemSubtype"
     613                    enableEditLink="<%=mode.hasEditLink()%>"
     614                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
     615                    nulltext="<i>- any -</i>"
     616                  /></tbl:cell>
    590617                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>               
    591618                <%
  • trunk/www/biomaterials/bioplates/wells/edit_biowell.jsp

    r5708 r5709  
    3131  import="net.sf.basedb.core.BioPlateType"
    3232  import="net.sf.basedb.core.BioWell"
     33  import="net.sf.basedb.core.ItemSubtype"
    3334  import="net.sf.basedb.core.MeasuredBioMaterial"
    3435  import="net.sf.basedb.core.Sample"
     
    6465  BioPlateType bioPlateType = bioPlate.getBioPlateType();
    6566  Item bioMaterialType = bioPlateType.getBioMaterialType();
     67  ItemSubtype bioMaterialSubType = bioPlateType.getItemSubtype();
    6668 
    6769  bioWell.checkPermission(Permission.WRITE);
     
    132134      }
    133135      url += '&resetTemporary=1&tmpfilter:STRING:bioWell='+escape('=');
     136      <%
     137      if (bioMaterialSubType != null)
     138      {
     139        %>
     140        url += '&tmpfilter:INT:itemSubtype=<%=bioMaterialSubType.getId()%>';
     141        <%
     142      }
     143      %>
    134144      Main.openPopup(url, 'Select'+type, 1000, 700);
    135145    }
     
    188198            {
    189199              Item currentBmType = currentBioMaterial == null ? null : currentBioMaterial.getType();
     200              String subtype = bioMaterialSubType != null ? " ("+HTML.encodeTags(bioMaterialSubType.getName()) + ")" : "";
    190201              %>
    191202              <option value="0">- none -
    192203              <option value="<%=Item.SAMPLE.name()%>"
    193                 <%=currentBmType == Item.SAMPLE || bioMaterialType == Item.SAMPLE ? "selected" : ""%>>Sample
     204                <%=currentBmType == Item.SAMPLE || bioMaterialType == Item.SAMPLE ? "selected" : ""%>>Sample<%=subtype %>
    194205              <option value="<%=Item.EXTRACT.name()%>"
    195                 <%=currentBmType == Item.EXTRACT || bioMaterialType == Item.EXTRACT ? "selected" : ""%>>Extract
     206                <%=currentBmType == Item.EXTRACT || bioMaterialType == Item.EXTRACT ? "selected" : ""%>>Extract<%=subtype %>
    196207              <%
    197208            }
  • trunk/www/biomaterials/bioplates/wells/list_biowells.jsp

    r5525 r5709  
    395395              BioWell item = biowells.next();
    396396              int itemId = item.getId();
     397              String coordinate = rowFormatter.format(item.getRow()) + columnFormatter.format(item.getColumn());
    397398              index++;
    398399              numListed++;
     
    429430                    name="<%=itemId%>"
    430431                    value="<%=itemId%>"
    431                     title="[<%=rowFormatter.format(item.getRow())%>,<%=columnFormatter.format(item.getColumn())%>]"
     432                    title="<%=coordinate%>"
    432433                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%>
    433434                  ></tbl:header>
     
    439440                    name="item_id"
    440441                    value="<%=itemId%>"
    441                     title="[<%=rowFormatter.format(item.getRow())%>,<%=columnFormatter.format(item.getColumn())%>]"
     442                    title="<%=coordinate%>"
    442443                    <%=selectedItemId == itemId ? "checked" : ""%>
    443444                  ></tbl:header>
  • trunk/www/biomaterials/bioplatetypes/edit_platetype.jsp

    r5708 r5709  
    3434  import="net.sf.basedb.core.BioPlateType"
    3535  import="net.sf.basedb.core.BioWell"
     36  import="net.sf.basedb.core.ItemSubtype"
    3637  import="net.sf.basedb.core.ItemQuery"
    3738  import="net.sf.basedb.core.ItemResultList"
    3839  import="net.sf.basedb.core.PermissionDeniedException"
    3940  import="net.sf.basedb.core.BaseException"
     41  import="net.sf.basedb.core.query.Expressions"
     42  import="net.sf.basedb.core.query.Restrictions"
    4043  import="net.sf.basedb.core.query.Orders"
    4144  import="net.sf.basedb.core.query.Hql"
     
    6871  BioPlateType bioPlateType = null;
    6972  BioWell.LockMode lockMode = BioWell.LockMode.UNLOCKED;
     73  boolean readCurrentSubtype = true;
     74  ItemSubtype currentSubtype = null;
     75  ItemQuery<ItemSubtype> subtypesQuery = null;
    7076 
    7177  if (itemId == 0)
     
    7581    int lm = Values.getInt(cc.getPropertyValue("lockMode"));
    7682    lockMode = BioWell.LockMode.fromValue(lm);
     83    subtypesQuery = Base.getSubtypesQuery(null);
     84    subtypesQuery.restrict(
     85        Restrictions.in(
     86          Hql.property("itemType"),
     87          Expressions.integer(Item.SAMPLE.getValue()), Expressions.integer(Item.EXTRACT.getValue())
     88        ));
    7789  }
    7890  else
     
    8395    cc.setObject("item", bioPlateType);
    8496    title = "Edit bioplate type -- " + HTML.encodeTags(bioPlateType.getName());
     97    try
     98    {
     99      currentSubtype = bioPlateType.getItemSubtype();
     100    }
     101    catch (PermissionDeniedException ex)
     102    {
     103      readCurrentSubtype = false;
     104    }
     105    if (bioPlateType.getBioMaterialType() != null)
     106    {
     107      subtypesQuery = Base.getSubtypesQuery(bioPlateType.getBioMaterialType());
     108    }
    85109  }
    86110  final String clazz = "class=\"text\"";
     
    88112  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), bioPlateType);
    89113  ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext);
     114
    90115  %>
    91116  <base:page type="popup" title="<%=title%>">
     
    126151        frm.name.focus();
    127152        frm.name.select();
     153        bioMaterialTypeOnChange();
    128154        <%
    129155      }
    130156      %>
     157    }
     158   
     159    var subtypeOptions = null;
     160    function bioMaterialTypeOnChange()
     161    {
     162      var frm = document.forms['bioPlateType'];
     163      if (subtypeOptions == null)
     164      {
     165        // Cache all options in the list
     166        subtypeOptions = new Array();
     167        for (var i = 1; i < frm.subtype_id.length; i++)
     168        {
     169          var opt = frm.subtype_id[i];
     170          subtypeOptions[subtypeOptions.length] = frm.subtype_id[i];
     171        }
     172      }
     173     
     174      var bmType = frm.bioMaterialType[frm.bioMaterialType.selectedIndex].value;
     175     
     176      frm.subtype_id.selectedIndex = 0;
     177      if (bmType == '')
     178      {
     179        frm.subtype_id.disabled = true;
     180      }
     181      else
     182      {
     183        frm.subtype_id.disabled = false;
     184        // Clean the list...
     185        frm.subtype_id.length = 1;
     186        // ...and re-populate from the cache
     187        for (var i = 0; i < subtypeOptions.length; i++)
     188        {
     189          if (subtypeOptions[i].attributes['bmtype'].value == bmType)
     190          {
     191            frm.subtype_id[frm.subtype_id.length] = subtypeOptions[i];
     192          }
     193        }
     194      }
    131195    }
    132196    </script>
     
    149213          size="40" maxlength="<%=BioPlateType.MAX_NAME_LENGTH%>"></td>
    150214      </tr>
     215      <tr valign=top>
     216        <td class="prompt">Biomaterial type</td>
     217        <%
     218        if (bioPlateType == null)
     219        {
     220          %>
     221            <td>
     222              <select name="bioMaterialType" class="required unchangeable" onchange="bioMaterialTypeOnChange()">
     223              <option value="">- any -
     224              <option value="<%=Item.SAMPLE.name()%>">Sample
     225              <option value="<%=Item.EXTRACT.name()%>">Extract
     226              </select>
     227            </td>
     228          <%
     229        }
     230        else
     231        {
     232          %>
     233          <td><%=bioPlateType.getBioMaterialType() == null ? "- any -" : bioPlateType.getBioMaterialType()%></td>
     234          <%
     235        }
     236        %>
     237      </tr>
    151238      <%
    152       if (bioPlateType == null)
     239      if (subtypesQuery != null)
    153240      {
    154241        %>
    155         <tr valign=top>
    156           <td class="prompt">Biomaterial type</td>
    157           <td>
    158             <select name="bioMaterialType" class="required unchangeable">
    159             <option value="">any
    160             <option value="<%=Item.SAMPLE.name()%>">Sample
    161             <option value="<%=Item.EXTRACT.name()%>">Extract
     242        <tr valign="top">
     243          <td class="prompt">Biomaterial subtype</td>
     244          <td colspan="2">
     245            <select name="subtype_id"
     246              <%=!readCurrentSubtype ? "disabled readonly class=\"disabled selectionlist\"" : "class=\"selectionlist\""%>
     247              onchange="subtypeOnChange()"
     248              >
     249            <%
     250            if (!readCurrentSubtype)
     251            {
     252              %>
     253              <option value="-1">- denied -
     254              <%
     255            }
     256            else
     257            {
     258              %>
     259              <option value="0">-any-
     260              <%
     261              int currentSubtypeId = currentSubtype == null ? 0 : currentSubtype.getId();
     262              for (ItemSubtype subtype : subtypesQuery.list(dc))
     263              {
     264                int id = subtype.getId();
     265                if (id != currentSubtypeId && subtype.isRemoved()) continue;
     266                %>
     267                <option value="<%=id == currentSubtypeId && bioPlateType != null ? -id : id%>"
     268                  <%=id == currentSubtypeId ? "selected" : ""%>
     269                  title="<%=HTML.encodeTags(subtype.getDescription()) %>"
     270                  bmtype="<%=subtype.getMainItemType().name() %>"
     271                  ><%=HTML.encodeTags(subtype.getName())%>
     272                <%
     273              }
     274            }
     275            %>
    162276            </select>
    163277          </td>
  • trunk/www/biomaterials/bioplatetypes/index.jsp

    r5590 r5709  
    3030  import="net.sf.basedb.core.BioPlateType"
    3131  import="net.sf.basedb.core.BioWell"
     32  import="net.sf.basedb.core.ItemSubtype"
    3233  import="net.sf.basedb.core.ItemQuery"
    3334  import="net.sf.basedb.core.ItemResultIterator"
     
    161162      plateType.setLockMode(BioWell.LockMode.valueOf(request.getParameter("lockMode")));
    162163     
     164      int subtypeId = Values.getInt(request.getParameter("subtype_id"), -1);
     165      ItemSubtype subtype = null;
     166      if (subtypeId >= 0) // < 0 = denied or unchanged
     167      {
     168        if (subtypeId > 0) subtype = ItemSubtype.getById(dc, subtypeId);
     169        plateType.setItemSubtype(subtype);
     170      }
     171     
    163172      // OnSave extensions
    164173      invoker.render(OnSaveRenderer.ON_SAVE);
  • trunk/www/biomaterials/bioplatetypes/list_platetypes.jsp

    r5708 r5709  
    3232  import="net.sf.basedb.core.Type"
    3333  import="net.sf.basedb.core.BioWell"
     34  import="net.sf.basedb.core.ItemSubtype"
    3435  import="net.sf.basedb.core.ItemResultIterator"
     36  import="net.sf.basedb.core.ItemQuery"
    3537  import="net.sf.basedb.core.ItemResultList"
    3638  import="net.sf.basedb.core.ItemContext"
     
    99101{
    100102  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
     103  final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(null);
     104  subtypesQuery.restrict(
     105    Restrictions.in(
     106      Hql.property("itemType"),
     107      Expressions.integer(Item.SAMPLE.getValue()), Expressions.integer(Item.EXTRACT.getValue())
     108    ));
    101109  try
    102110  {
     
    242250        exportable="true"
    243251        enumeration="<%=bioMaterialTypes%>"
     252      />
     253      <tbl:columndef
     254        id="itemSubtype"
     255        property="itemSubtype"
     256        sortproperty="itemSubtype.name"
     257        exportproperty="itemSubtype.name:string"
     258        datatype="int"
     259        enumeration="<%=Enumeration.fromItems(subtypesQuery.list(dc), "-none-")%>"
     260        title="Biomaterial subtype"
     261        sortable="true"
     262        filterable="true"
     263        exportable="true"
    244264      />
    245265      <tbl:columndef
     
    409429                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
    410430                <tbl:cell column="bioMaterialType"><%=item.getBioMaterialType() == null ? "<i>- any -</i>" : item.getBioMaterialType().toString() %></tbl:cell>
     431                <tbl:cell column="itemSubtype"><base:propertyvalue
     432                    item="<%=item%>"
     433                    property="itemSubtype"
     434                    enableEditLink="<%=mode.hasEditLink()%>"
     435                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
     436                  /></tbl:cell>
    411437                <tbl:cell column="lockMode"><%=item.getLockMode()%></tbl:cell>
    412438                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
  • trunk/www/biomaterials/bioplatetypes/view_platetype.jsp

    r5708 r5709  
    219219      </tr>
    220220      <tr>
     221        <td class="prompt">Biomaterial subtype</td>
     222        <td><base:propertyvalue item="<%=plateType%>" property="itemSubtype" nulltext="<i>- any -</i>"/></td>
     223      </tr>
     224      <tr>
    221225        <td class="prompt">Well lock mode</td>
    222226        <td><%=plateType.getLockMode()%></td>
  • trunk/www/biomaterials/extracts/edit_extract.jsp

    r5708 r5709  
    457457      }
    458458      url += '&resetTemporary=1&tmpfilter:INT:bioPlateType.lockMode=<><%=BioWell.LockMode.LOCKED_AFTER_CREATE.getValue()%>';
     459      // Restrict to plates that can holds extracts
     460      url += '&tmpfilter:INT:bioPlateType.bioMaterialType=|<%=itemType.getValue()%>';
     461      var subtypeId = ItemSubtype.getSubtypeId('extract');
     462      // Restrict to plates with the given subtype
     463      url += '&tmpfilter:INT:bioPlateType.itemSubtype='+(subtypeId ? '|' + subtypeId : '=');
    459464      url += '&tmpfilter:BOOLEAN:destroyed=false';
    460465      Main.openPopup(url, 'SelectBioplate', 1000, 700);
     
    493498        Forms.addListOption(list, 1, new Option());
    494499        list[1].value = '<%=currentBioWell.getId()*(extract == null ? 1 : -1)%>';
    495         list[1].text = '[<%=rowFormatter.format(currentBioWell.getRow())%>,<%=columnFormatter.format(currentBioWell.getColumn())%>]';
     500        list[1].text = '<%=rowFormatter.format(currentBioWell.getRow())%><%=columnFormatter.format(currentBioWell.getColumn())%>';
    496501        list.selectedIndex = 1;
    497502      <%
  • trunk/www/biomaterials/samples/edit_sample.jsp

    r5708 r5709  
    411411      }
    412412      url += '&resetTemporary=1&tmpfilter:INT:bioPlateType.lockMode=<><%=BioWell.LockMode.LOCKED_AFTER_CREATE.getValue()%>';
     413      // Restrict to plates that can holds samples
     414      url += '&tmpfilter:INT:bioPlateType.bioMaterialType=|<%=itemType.getValue()%>';
     415      var subtypeId = ItemSubtype.getSubtypeId('sample');
     416      // Restrict to plates with the given subtype
     417      url += '&tmpfilter:INT:bioPlateType.itemSubtype='+(subtypeId ? '|' + subtypeId : '=');
    413418      url += '&tmpfilter:BOOLEAN:destroyed=false';
    414419      Main.openPopup(url, 'SelectBioplate', 1000, 700);
     
    447452        Forms.addListOption(list, 1, new Option());
    448453        list[1].value = '<%=currentBioWell.getId()*(sample == null ? 1 : -1)%>';
    449         list[1].text = '[<%=rowFormatter.format(currentBioWell.getRow())%>,<%=columnFormatter.format(currentBioWell.getColumn())%>]';
     454        list[1].text = '<%=rowFormatter.format(currentBioWell.getRow())%><%=columnFormatter.format(currentBioWell.getColumn())%>';
    450455        list.selectedIndex = 1;
    451456      <%
Note: See TracChangeset for help on using the changeset viewer.