Changeset 5535


Ignore:
Timestamp:
Dec 21, 2010, 11:31:46 AM (12 years ago)
Author:
Nicklas Nordborg
Message:

References #1564: Move biomaterial on plates

Manual mapping and saving should now work.

Location:
trunk
Files:
1 added
7 edited

Legend:

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

    r5357 r5535  
    4040{
    4141
     42  /**
     43    Get a biomaterial item when you know the id. This method can return any
     44    of the subclasses of {@link BioMaterial}. Eg. {@link BioSource},
     45    {@link Sample}, {@link Extract} or {@link LabeledExtract}.
     46   
     47    @param dc The <code>DbControl</code> which will be used for
     48      permission checking and database access.
     49    @param id The id of the item to load
     50    @return The <code>Sample</code> item
     51    @throws ItemNotFoundException If an item with the specified
     52      id is not found
     53    @throws PermissionDeniedException If the logged in user doesn't
     54      have read permission to the item
     55    @throws BaseException If there is another error
     56    @since 2.17
     57  */
     58  public static BioMaterial getById(DbControl dc, int id)
     59  {
     60    BioMaterial bm = dc.loadItemByDataClass(BioMaterial.class, BioMaterialData.class, id);
     61    if (bm == null) throw new ItemNotFoundException("BioMaterial[id="+id+"]");
     62    return bm;
     63  }
     64 
    4265  BioMaterial(D bioMaterialData)
    4366  {
  • trunk/src/core/net/sf/basedb/core/DbControl.java

    r5358 r5535  
    730730    throws PermissionDeniedException, BaseException
    731731  {
     732    Class<? extends BasicData> dataClass = Item.fromItemClass(itemClass).getDataClass();
     733    return loadItemByDataClass(itemClass, dataClass, id);
     734  }
     735 
     736  /**
     737    Load an item from the database when you know the id. If the item
     738    has already been loaded the item in the cache will be used.
     739
     740    @param itemClass The item class for the object
     741    @param dataClass The actual data class for the object which must be compatible
     742      with the item class
     743    @param id The id of the object
     744    @return An object of the <code>itemClass</code> class
     745    @since 2.17
     746  */
     747  <I extends BasicItem, D extends BasicData> I loadItemByDataClass(Class<I> itemClass, Class<D> dataClass, int id)
     748    throws PermissionDeniedException, BaseException
     749  {
    732750    if (isClosed()) throw new ConnectionClosedException();
    733751    sc.updateLastAccess();
    734     // Find out which data class to use for the specified item class
    735     Class<? extends BasicData> dataClass = Item.fromItemClass(itemClass).getDataClass();
    736752    BasicData data = HibernateUtil.loadData(hSession, dataClass, id);
    737753    return getItem(itemClass, data);
    738754  }
     755 
    739756
    740757  /**
  • trunk/www/biomaterials/bioplates/ajax.jsp

    r5528 r5535  
    6767      aw.ajaxPrintEntry("well.column", well.getColumn());
    6868      aw.ajaxPrintEntry("well.can-add", well.canAddBioMaterial() ? "1" : "0");
     69      aw.ajaxPrintEntry("well.can-clear", well.canClearBioMaterial() ? "1" : "0");
    6970      if (!well.isEmpty())
    7071      {
  • trunk/www/biomaterials/bioplates/index.jsp

    r5532 r5535  
    317317  else if ("MoveBioMaterial".equals(cmd))
    318318  {
    319     redirect = "../wizards/move_biomaterial.jsp?ID="+ID+"&plate_id=" + itemId;
     319    redirect = "../wizards/move_biomaterial.jsp?ID="+ID+"&sourceplate_id=" + itemId;
    320320  }
    321321  else
  • trunk/www/biomaterials/wizards/index.jsp

    r5529 r5535  
    2424<%@ page pageEncoding="UTF-8" session="false"
    2525  import="net.sf.basedb.core.SessionControl"
     26  import="net.sf.basedb.core.BioMaterial"
    2627  import="net.sf.basedb.core.BioMaterialEvent"
    2728  import="net.sf.basedb.core.BioPlate"
     
    122123    message = "Placed " + numPlaced + " items on plate " + plate.getName();
    123124  }
     125  else if ("MoveBioMaterial".equals(cmd))
     126  {
     127    dc = sc.newDbControl();
     128    ItemContext cc = sc.getCurrentContext(Item.BIOPLATEEVENT, BioPlateEventType.MOVE);
     129    final int maxRecent = Base.getMaxRecent(sc);
     130
     131    BioPlate sourcePlate = BioPlate.getById(dc, Values.getInt(request.getParameter("sourceplate_id")));
     132    BioPlate destPlate = BioPlate.getById(dc, Values.getInt(request.getParameter("destplate_id")));
     133    int rows = Values.getInt(request.getParameter("rows"));
     134    int columns = Values.getInt(request.getParameter("columns"));
     135   
     136    BioPlateEventType moveBioMaterial = BioPlateEventType.getById(dc, BioPlateEventType.MOVE);
     137    BioPlateEvent event = BioPlateEvent.getNew(dc, moveBioMaterial);
     138    BioPlateEventParticipant destination = event.addParticipant(destPlate, "destination", 1);
     139    BioPlateEventParticipant source = event.addParticipant(sourcePlate, "source", 1);
     140   
     141    event.setName(Values.getStringOrNull(request.getParameter("name")));
     142    event.setDescription(Values.getStringOrNull(request.getParameter("description")));
     143    Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
     144    event.setEventDate(dateFormatter.parseString(Values.getStringOrNull(request.getParameter("event_date"))));
     145    int protocolId = Values.getInt(request.getParameter("protocol_id"));
     146    if (protocolId > 0)
     147    {
     148      Protocol pt = Protocol.getById(dc, protocolId);
     149      event.setProtocol(pt);
     150      cc.setRecent(pt, maxRecent);
     151    }
     152    int hardwareId = Values.getInt(request.getParameter("hardware_id"));
     153    if (hardwareId > 0)
     154    {
     155      Hardware hw = Hardware.getById(dc, hardwareId);
     156      event.setHardware(hw);
     157      cc.setRecent(hw, maxRecent);
     158    }
     159    dc.saveItem(event);
     160   
     161    int numMoved = 0;
     162    for (int row = 0; row < rows; ++row)
     163    {
     164      for (int column = 0; column < columns; ++column)
     165      {
     166        int bioMaterialId = Values.getInt(request.getParameter("well." + row + "." + column));
     167        if (bioMaterialId > 0)
     168        {
     169          MeasuredBioMaterial bioMaterial = (MeasuredBioMaterial)BioMaterial.getById(dc, bioMaterialId);
     170          BioWell well = destPlate.getBioWell(row, column);
     171          bioMaterial.setBioWell(well);
     172          BioMaterialEvent bmEvent = bioMaterial.newEvent(destination);
     173          bmEvent.setComment("Well: " + well.getCoordinate());
     174          dc.saveItem(bmEvent);
     175          numMoved++;
     176        }
     177      }
     178    }
     179   
     180    dc.commit();
     181    message = "Moved " + numMoved + " items to plate " + destPlate.getName();
     182  }
    124183  else
    125184  {
  • trunk/www/biomaterials/wizards/move_biomaterial.jsp

    r5532 r5535  
    2222  @author Nicklas
    2323--%>
     24<%@page import="net.sf.basedb.core.BioPlateEventType"%>
    2425<%@ page pageEncoding="UTF-8" session="false"
    2526  import="net.sf.basedb.core.BioPlate"
     
    5152final String ID = sc.getId();
    5253final float scale = Base.getScale(sc);
    53 final int plateId = Values.getInt(request.getParameter("plate_id"));
    54 final ItemContext cc = Base.getAndSetCurrentContext(sc, Item.BIOPLATEEVENT, null, null);
     54final int sourcePlateId = Values.getInt(request.getParameter("sourceplate_id"));
     55final ItemContext cc = sc.getCurrentContext(Item.BIOPLATEEVENT, BioPlateEventType.MOVE);
    5556final DbControl dc = sc.newDbControl();
    5657try
    5758{
    58   BioPlate plate = BioPlate.getById(dc, plateId);
     59  BioPlate sourcePlate = BioPlate.getById(dc, sourcePlateId);
    5960 
    6061  // Load recently used items
    61   List<Hardware> recentHardware = (List<Hardware>)cc.getRecent(dc, Item.HARDWARE, "move-biomaterial");
    62   List<Protocol> recentProtocols = (List<Protocol>)cc.getRecent(dc, Item.PROTOCOL, "move-biomaterial");
     62  List<Hardware> recentHardware = (List<Hardware>)cc.getRecent(dc, Item.HARDWARE);
     63  List<Protocol> recentProtocols = (List<Protocol>)cc.getRecent(dc, Item.PROTOCOL);
    6364 
    6465  Item itemType = Item.SAMPLE;
     
    9495      pen = new jsPen();
    9596      selectedPen = new jsPen(new jsColor('445577'), 2);
    96       setBioPlateCallback(<%=plateId%>, '<%=HTML.javaScriptEncode(plate.getName())%>', true);
     97      setBioPlateCallback(<%=sourcePlateId%>, '<%=HTML.javaScriptEncode(sourcePlate.getName())%>', true);
    9798    }
    9899
     
    244245      var url = '../bioplates/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setBioPlateCallback';
    245246      url += '&resetTemporary=1&tmpfilter:INT:bioPlateType.bioMaterialType=|<%=itemType.getValue()%>'
     247      url += '&exclude='+sourcePlate.id;
    246248      Main.openPopup(url, 'SelectBioPlate', 1000, 700);
    247249    }
     
    249251    function setBioPlateCallback(bioPlateId, name, isSourcePlate)
    250252    {
     253      if (!isSourcePlate && bioPlateId == sourcePlate.id)
     254      {
     255        alert('It is not possible to use the same plate as both source and destination plate.');
     256        return;
     257      }
     258     
    251259      var request = Ajax.getXmlHttpRequest();
    252260      var url = '../bioplates/ajax.jsp?ID=<%=ID%>&cmd=GetFullPlateInfo&item_id=' + bioPlateId;
     
    282290        var col = parseInt(wellInfo['well.column']);
    283291        var well = plate.getWell(row, col);
    284         well.locked = wellInfo['bm.id'] || wellInfo['well.can-add'] == '0';
     292        well.id = wellInfo['bm.id'];
    285293        well.name = wellInfo['bm.name'];
     294        well.locked = isSourcePlate ? !wellInfo['well.can-clear'] : !wellInfo['well.can-add'];
    286295      }
    287296     
     
    305314          var onmouseout = '';
    306315          var title = '';
    307           if (well.locked)
     316          if (well.id)
    308317          {
    309             if (isSourcePlate)
     318            if (isSourcePlate && !well.locked)
    310319            {
    311320              cls += ' filled editable';
     
    351360        destPlate = plate;
    352361      }
    353       //Main.show('toolbar.mappings');
    354362    }
    355363   
     
    359367    function doMoveBioMaterial()
    360368    {
    361       if (!plate)
    362       {
    363         alert('No plate has been selected');
     369      if (!destPlate)
     370      {
     371        alert('No destination plate has been selected');
    364372        return;
    365373      }
     
    372380      }
    373381     
    374       frm.plate_id.value = plate.id;
    375       frm.rows.value = plate.rows;
    376       frm.columns.value = plate.columns;
     382      frm.destplate_id.value = destPlate.id;
     383      frm.rows.value = destPlate.rows;
     384      frm.columns.value = destPlate.columns;
    377385     
    378386      var numMapped = 0;
    379       for (var row = 0; row < plate.rows; row++)
    380       {
    381         for (var column = 0; column < plate.columns; column++)
     387      for (var row = 0; row < destPlate.rows; row++)
     388      {
     389        for (var column = 0; column < destPlate.columns; column++)
    382390        {
    383           var well = plate.getWell(row, column);
     391          var well = destPlate.getWell(row, column);
    384392         
    385           if (well.mappedItem)
     393          if (well.mappedWell)
    386394          {
    387             Forms.createHidden(frm, 'well.' + row + '.' + column, well.mappedItem.id);
     395            Forms.createHidden(frm, 'well.' + row + '.' + column, well.mappedWell.id);
    388396            numMapped++;
    389397          }
     
    393401      if (numMapped == 0)
    394402      {
    395         alert('No biomaterial has been mapped to wells');
     403        alert('No wells have been mapped.');
    396404        return;
    397405      }
     
    470478      <input type="hidden" name="ID" value="<%=ID%>">
    471479      <input type="hidden" name="cmd" value="MoveBioMaterial">
    472       <input type="hidden" name="plate_id" value="<%=plateId%>">
    473      
     480      <input type="hidden" name="sourceplate_id" value="<%=sourcePlateId%>">
     481      <input type="hidden" name="destplate_id" value="">
     482      <input type="hidden" name="rows" value="">
     483      <input type="hidden" name="columns" value="">
    474484
    475485      <table cellspacing="0" border="0" width="100%">
  • trunk/www/include/styles/plate.css

    r5533 r5535  
    9090}
    9191
     92.well.filled.mapped {
     93  background-image: url('../../images/well_move.png') !important;
     94}
     95
    9296.well.filled.locked {
    9397  background-image: url('../../images/info_locked.png') !important;
Note: See TracChangeset for help on using the changeset viewer.