Changeset 5456


Ignore:
Timestamp:
Oct 28, 2010, 2:12:26 PM (12 years ago)
Author:
Nicklas Nordborg
Message:

References #1532: Add bioplate type to bioplates

Added BioPlateType?.getLockMode() and Well.getOriginalBioMaterial() link. Extended test programs to makes sure locking is working as expected. Changes to the gui are not yet complete. The JSPs compiles but locking options are not considered.

Location:
trunk
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/common-queries.xml

    r5454 r5456  
    38213821  </query>
    38223822
     3823  <query id="CLEAR_ORIGINAL_BIOMATERIAL_ON_BIOWELLS" type="HQL">
     3824    <sql>
     3825      UPDATE BioWellData bw
     3826      SET bw.originalBioMaterial = null
     3827      WHERE bw.originalBioMaterial = :bioMaterial
     3828    </sql>
     3829    <description>
     3830      An HQL update-query that for a given biomaterial clears the
     3831      link on all biowells were it is set as the original biomaterial.
     3832    </description>
     3833  </query>
     3834
    38233835</predefined-queries>
  • trunk/src/core/net/sf/basedb/core/BioPlate.java

    r5454 r5456  
    158158  /**
    159159    Check if there are any <code>MeasuredBioMaterial</code> on
    160     this plate or if this plate has any child plates (note that
    161     child events may exists but they are automatically deleted)
     160    this plate.
    162161   */
    163162  @Override
  • trunk/src/core/net/sf/basedb/core/BioPlateType.java

    r5452 r5456  
    238238 
    239239  /**
    240     A flag indicating if plates with this type have locked wells or not.
    241     If the wells are locked it is not possible to change the biomaterial
    242     in them.
    243     @return TRUE if the wells should be locked, FALSE otherwise
    244   */
    245   public boolean getLockedWells()
    246   {
    247     return getData().getLockedWells();
    248   }
    249   /**
    250     Set the flag to lock/unlock wells on the plates of this type.
    251   */
    252   public void setLockedWells(boolean lockedWells)
    253   {
    254     checkPermission(Permission.WRITE);
    255     getData().setLockedWells(lockedWells);
     240    Get the lock mode for wells located on plates of this plate type.
     241    The lock mode determines if biomaterial may be changed in the
     242    well.
     243   
     244    @return A lock mode
     245  */
     246  public BioWell.LockMode getLockMode()
     247  {
     248    return BioWell.LockMode.fromValue(getData().getLockMode());
     249  }
     250  /**
     251    Set the lock mode for wells on plates of this plate type.
     252    @param lockMode A lock mode, null is not allowed
     253  */
     254  public void setLockMode(BioWell.LockMode lockMode)
     255  {
     256    checkPermission(Permission.WRITE);
     257    if (lockMode == null) throw new InvalidUseOfNullException("lockMode");
     258    getData().setLockMode(lockMode.getValue());
    256259  }
    257260 
  • trunk/src/core/net/sf/basedb/core/BioWell.java

    r5348 r5456  
    2323
    2424import net.sf.basedb.core.data.BioWellData;
     25import net.sf.basedb.core.data.MeasuredBioMaterialData;
    2526import net.sf.basedb.core.data.SharedData;
    2627import net.sf.basedb.core.query.Hql;
     
    2829import net.sf.basedb.util.Coordinate;
    2930
     31import java.util.HashMap;
     32import java.util.Map;
    3033import java.util.Set;
    3134
     
    208211 
    209212  /**
    210     Is this well locked or not? A well is locked if there is biomaterial in it and
    211     the plate type has locked wells.
     213    If the original biomaterial in this well has been moved to
     214    another plate (eg. for final storage in a freezer). This property
     215    is only defined for well with lock mode={@link LockMode#LOCKED_AFTER_MOVE}.
     216    @return TRUE if the original biomaterial has been moved
    212217    @since 2.16
    213     @see BioPlateType#getLockedWells()
    214   */
    215   public boolean isLocked()
    216   {
    217     return getData().getBioPlate().getBioPlateType().getLockedWells() && getData().getBioMaterial() != null;
    218   }
     218  */
     219  public boolean hasBeenMoved()
     220  {
     221    return getData().getBioMaterial() == null && getData().getOriginalBioMaterial() != null;
     222  }
     223 
     224  /**
     225    Get the original biomaterial that was placed in this biowell. This
     226    property is only defined for well with lock mode={@link LockMode#LOCKED_AFTER_MOVE}
     227    after the biomaterial has been moved.
     228   
     229    @return The original biomaterial
     230    @since 2.16
     231  */
     232  public MeasuredBioMaterial getOriginalBioMaterial()
     233  {
     234    return getDbControl().getItem(MeasuredBioMaterial.class, getData().getOriginalBioMaterial());
     235  }
     236 
     237  /**
     238    The lock mode for a well is determined by the plate's bio
     239    plate type. See {@link BioPlateType#getLockMode()}. The lock-mode
     240    is used to determine if the well can be assigned to a biomaterial
     241    or not.
     242 
     243    @since 2.16
     244  */
     245  public enum LockMode
     246  {
     247    /**
     248      The well is not locked. It is possible to change the biomaterial
     249      any number of times.
     250    */
     251    UNLOCKED(0)
     252    {
     253      /**
     254        @return Always true
     255      */
     256      @Override
     257      boolean canClear(BioWellData well)
     258      {
     259        return true;
     260      }
     261      /**
     262        @return Always true
     263      */
     264      @Override
     265      boolean canAdd(BioWellData well)
     266      {
     267        return true;
     268      }
     269    },
     270   
     271    /**
     272      It is allowed to add biomaterial once to the well. It can not be replaced
     273      by a new biomaterial but it is possible to clear it. The original biomaterial
     274      is then saved in the {@link BioWell#getOriginalBioMaterial()}.
     275    */
     276    LOCKED_AFTER_MOVE(1)
     277    {
     278      /**
     279        @return Always true
     280      */
     281      @Override
     282      boolean canClear(BioWellData well)
     283      {
     284        return true;
     285      }
     286      /**
     287        Can only add if there is no original biomaterial.
     288      */
     289      @Override
     290      boolean canAdd(BioWellData well)
     291      {
     292        return well.getOriginalBioMaterial() == null;
     293      }
     294      /**
     295        This lockmode will save the original biomaterial in
     296        {@link BioWell#getOriginalBioMaterial()} when it is cleared.
     297        After that, it is not possible to add biomaterial to the well again.
     298      */
     299      @Override
     300      void onClear(BioWellData well, MeasuredBioMaterialData biomaterial)
     301      {
     302        well.setOriginalBioMaterial(biomaterial);
     303      }
     304    },
     305   
     306    /**
     307      It is allowed to add biomaterial once to the well. It can't be replaced
     308      by a new biomaterial and it is not possible to clear it. It is possible to
     309      add biomaterial to empty wells at any time.
     310    */
     311    LOCKED_AFTER_ADD(2)
     312    {
     313      /**
     314        @return Always false
     315      */
     316      @Override
     317      boolean canClear(BioWellData well)
     318      {
     319        return false;
     320      }
     321      /**
     322        @return Always true
     323      */
     324      @Override
     325      boolean canAdd(BioWellData well)
     326      {
     327        return true;
     328      }
     329    },
     330
     331    /**
     332      It is allowed to add biomaterial once to the well, but it most be done
     333      at the same time the plate is creted. Once the transaction has been
     334      committed to the database, all wells become locked.
     335    */
     336    LOCKED_AFTER_CREATE(3)
     337    {
     338      /**
     339        @return Always false
     340      */
     341      @Override
     342      boolean canClear(BioWellData well)
     343      {
     344        return false;
     345      }
     346      /**
     347        Can only add to unsaved items.
     348      */
     349      @Override
     350      boolean canAdd(BioWellData well)
     351      {
     352        return well.getId() == 0;
     353      }
     354    };   
     355   
     356    /**
     357      Maps an integer to a lock mode.
     358    */
     359    private static final Map<Integer, LockMode> valueMapping = new HashMap<Integer, LockMode>();
     360   
     361    static
     362    {
     363      for (LockMode lockMode : LockMode.values())
     364      {
     365        LockMode lm = valueMapping.put(lockMode.getValue(), lockMode);
     366        assert lm == null : "Another lock mode with the value "+lockMode.getValue()+" already exists";
     367      }
     368    }
     369   
     370    /**
     371      The integer value of this lock mode.
     372    */
     373    private final int value;
     374   
     375    private LockMode(int value)
     376    {
     377      this.value = value;
     378    }
     379   
     380    /**
     381      Get the integer value that is used when storing a lock mode to the database.
     382      @return The integer value for this lock mode
     383    */
     384    public int getValue()
     385    {
     386      return value;
     387    }
     388
     389    /**
     390      Get the <code>Lock mode</code> object when you know the integer code.
     391     
     392      @param value The integer value
     393      @return The location for the integer value
     394    */
     395    public static LockMode fromValue(int value)
     396    {
     397      LockMode lockMode = valueMapping.get(value);
     398      assert lockMode != null : "lockMode == null for value "+value;
     399      return lockMode;
     400    }
     401
     402    /**
     403      Is it allowed to clear a well that already has biomaterial in it? If
     404      this method is called with an empty well as parameter the result
     405      is undefined.
     406      @param well The biowell, which should already have biomaterial in it
     407    */
     408    public boolean canClear(BioWell well)
     409    {
     410      return canClear(well.getData());
     411    }
     412   
     413    abstract boolean canClear(BioWellData well);
     414   
     415    /**
     416      Called when a well is cleared from an existing biomaterial. The
     417      default implementation of this method does nothing, but it may be
     418      overriden by some lock modes.
     419     
     420      @param well The well that is cleared
     421      @param biomaterial The biomaterial that is currently located on the well
     422    */
     423    void onClear(BioWellData well, MeasuredBioMaterialData biomaterial)
     424    {}
     425
     426    /**
     427      Is it allowed to add biomaterial to the (empty) well? If this
     428      method is called with a non-empty well as parameter the result
     429      is undefined.
     430      @param well An empty biowell
     431    */
     432    public boolean canAdd(BioWell well)
     433    {
     434      return canAdd(well.getData());
     435    }
     436   
     437    abstract boolean canAdd(BioWellData well);
     438
     439    /**
     440      Called when biomaterial is added to a well. The
     441      default implementation of this method does nothing, but it may be
     442      overriden by some lock modes.
     443     
     444      @param well The well the biomaterial is added to
     445      @param biomaterial The biomaterial that is going to be added to the well
     446    */
     447    void onAdd(BioWellData well, MeasuredBioMaterialData biomaterial)
     448    {}
     449   
     450  }
     451 
    219452}
  • trunk/src/core/net/sf/basedb/core/Install.java

    r5454 r5456  
    583583      progressStep++;
    584584      if (progress != null) progress.display((int)(progressStep*progress_factor), "--Creating bioplate types...");
    585       BioPlateTypeData storagePlate = createBioPlateType("Storage plate", "A generic storage plate for all types of biomaterial.", null, false);
    586       BioPlateTypeData sampleReactionPlate = createBioPlateType("Sample reaction plate", "A generic reaction plate for samples.", Item.SAMPLE, true);
    587       BioPlateTypeData extractReactionPlate = createBioPlateType("Extract reaction plate", "A generic reaction plate for extracts.", Item.EXTRACT, true);
     585      BioPlateTypeData storagePlate = createBioPlateType("Storage plate", "A generic storage plate for all types of biomaterial.",
     586          null, BioWell.LockMode.UNLOCKED);
     587      BioPlateTypeData sampleReactionPlate = createBioPlateType("Sample reaction plate", "A generic reaction plate for samples.",
     588          Item.SAMPLE, BioWell.LockMode.LOCKED_AFTER_ADD);
     589      BioPlateTypeData extractReactionPlate = createBioPlateType("Extract reaction plate", "A generic reaction plate for extracts.",
     590          Item.EXTRACT, BioWell.LockMode.LOCKED_AFTER_ADD);
    588591      BioPlateTypeData labeledExtractReactionPlate =
    589         createBioPlateType("Labeled extract reaction plate", "A generic reaction plate for labeled extracts.", Item.LABELEDEXTRACT, true);
     592        createBioPlateType("Labeled extract reaction plate", "A generic reaction plate for labeled extracts.",
     593            Item.LABELEDEXTRACT, BioWell.LockMode.LOCKED_AFTER_ADD);
    590594     
    591595      // Labels
     
    17881792  */
    17891793  private static BioPlateTypeData createBioPlateType(String name, String description,
    1790     Item biomaterialType, boolean lockedWells)
     1794    Item biomaterialType, BioWell.LockMode lockedMode)
    17911795    throws BaseException
    17921796  {
     
    18151819        pt.setDescription(description);
    18161820        pt.setBioMaterialType(biomaterialType == null ? null : biomaterialType.getValue());
    1817         pt.setLockedWells(lockedWells);
     1821        pt.setLockMode(lockedMode.getValue());
    18181822        HibernateUtil.saveData(session, pt);
    18191823        HibernateUtil.commit(tx);
  • trunk/src/core/net/sf/basedb/core/MeasuredBioMaterial.java

    r5452 r5456  
    132132    {
    133133      getCreationEvent().clearSources();
     134      org.hibernate.Query query = HibernateUtil.getPredefinedQuery(getDbControl().getHibernateSession(),
     135          "CLEAR_ORIGINAL_BIOMATERIAL_ON_BIOWELLS");
     136      /*
     137        UPDATE BioWellData bw
     138        SET bw.originalBioMaterial = null
     139        WHERE bw.originalBioMaterial = :bioMaterial
     140      */
     141      query.setEntity("bioMaterial", getData());
     142      query.executeUpdate();
    134143    }
    135144  }
     
    344353 
    345354  /**
    346     Sets the <code>BioWell</code> where this biomaterial is located. This
    347     method also updates the plate event associated with the creation event
    348     of this biomaterial, if the new well is located on a plate which was
    349     created by an event.
     355    Sets the <code>BioWell</code> where this biomaterial is located.
    350356   
    351357      @param well The <code>BioWell</code> to set.
     
    362368  {
    363369    checkPermission(Permission.WRITE);
    364     BioWellData currentWell = getData().getBioWell();
     370    MeasuredBioMaterialData myData = getData();
     371    BioWellData currentWell = myData.getBioWell();
    365372    BioWellData newWell = well != null ? well.getData() : null;
    366373    if (EqualsHelper.equals(currentWell, newWell)) return; // early exit if no change
    367374   
    368375    // Check if current biowell is locked
    369     if (currentWell != null)
     376    if (currentWell != null && currentWell.getId() != 0)
    370377    {
    371378      BioPlateData currentPlate = currentWell.getBioPlate();
    372       if (currentPlate.getBioPlateType().getLockedWells())
     379      BioWell.LockMode lockMode = BioWell.LockMode.fromValue(currentPlate.getBioPlateType().getLockMode());
     380     
     381      if (!lockMode.canClear(currentWell))
    373382      {
    374383        throw new PermissionDeniedException(Permission.WRITE, this +
    375             ". Wells on plate '" + currentPlate.getName() + "'' are locked.");
    376       }
     384            ". Well on plate '" + currentPlate.getName() + "'' is locked: " + currentWell);
     385      }
     386      lockMode.onClear(currentWell, myData);
    377387    }
    378388   
     
    397407          Item.fromValue(biomaterialType));
    398408      }
     409      // Check that the lock mode allows adding biomaterial to the well
     410      BioWell.LockMode lockMode = BioWell.LockMode.fromValue(newPlateType.getLockMode());
     411      if (!lockMode.canAdd(newWell))
     412      {
     413        throw new PermissionDeniedException(Permission.WRITE, this +
     414            ". Well on plate '" + newPlate.getName() + "'' is locked: " + well);
     415      }
     416      lockMode.onAdd(newWell, myData);
    399417    }
    400418    if (currentWell != null) currentWell.setBioMaterial(null);
    401     if (newWell != null) newWell.setBioMaterial(getData());
    402     getData().setBioWell(newWell);
     419    if (newWell != null) newWell.setBioMaterial(myData);
     420    myData.setBioWell(newWell);
    403421  }
    404422 
  • trunk/src/core/net/sf/basedb/core/Update.java

    r5454 r5456  
    4141import net.sf.basedb.core.data.BioPlateData;
    4242import net.sf.basedb.core.data.BioPlateTypeData;
     43import net.sf.basedb.core.data.BioWellData;
    4344import net.sf.basedb.core.data.ChangeHistoryData;
    4445import net.sf.basedb.core.data.ChangeHistoryDetailData;
     
    882883    <td>80</td>
    883884    <td>
    884       Added {@link BioPlateTypeData}.
     885      Added {@link BioPlateTypeData}, {@link BioWellData#getOriginalBioMaterial()}.
    885886      All existing bio plates are assigned "Storage plate" as their
    886887      plate type.
  • trunk/src/core/net/sf/basedb/core/data/BioPlateTypeData.java

    r5389 r5456  
    101101  }
    102102
    103   private boolean lockedWells;
     103  private int lockMode;
    104104  /**
    105     If bioplates that uses this type must have locked wells or not.
    106     @hibernate.property column="`locked_wells`" type="boolean" not-null="true"
     105    A flag indicating if plates with this type have locked wells or not.
     106    0 = not locked; 1 = locked-after-move; 2 = locked-after-add; 3=locked-after-create
     107    @hibernate.property column="`lock_mode`" type="int" not-null="true"
    107108  */
    108   public boolean getLockedWells()
     109  public int getLockMode()
    109110  {
    110     return lockedWells;
     111    return lockMode;
    111112  }
    112   public void setLockedWells(boolean lockedWells)
     113  public void setLockMode(int lockMode)
    113114  {
    114     this.lockedWells = lockedWells;
     115    this.lockMode = lockMode;
    115116  }
    116117 
  • trunk/src/core/net/sf/basedb/core/data/BioWellData.java

    r5119 r5456  
    8080  }
    8181 
     82  private MeasuredBioMaterialData originalBioMaterial;
     83  /**
     84    The {@link MeasuredBioMaterialData} used in this well.
     85    @since 2.16
     86    @hibernate.many-to-one column="`original_biomaterial_id`" not-null="false" outer-join="false"
     87  */
     88  public MeasuredBioMaterialData getOriginalBioMaterial()
     89  {
     90    return originalBioMaterial;
     91  }
     92  public void setOriginalBioMaterial(MeasuredBioMaterialData originalBioMaterial)
     93  {
     94    this.originalBioMaterial = originalBioMaterial;
     95  }
     96 
    8297  private MeasuredBioMaterialData bioMaterial;
    8398  /**
  • trunk/src/test/TestBioPlate.java

    r5452 r5456  
    7171    write_header();
    7272   
    73     int sampleId = TestSample.test_create(0, "Sample A", true);
     73    int sampleId = TestSample.test_create(0, "Sample A.1", true);
     74    int sample2Id = TestSample.test_create(0, "Sample A.2", true);
     75    int sample3Id = TestSample.test_create(0, "Sample A.3", true);
    7476    int extractId = TestExtract.test_create(sampleId, true);
    7577    int labelId = TestLabel.test_create(true);
     
    8385    // Standard tests: create, load, list
    8486    int plateGeometryId = TestPlateGeometry.test_create(8, 12, false);
    85     int bioPlateTypeId = TestBioPlateType.test_create("Test for bioplate", null, false);
     87    int bioPlateTypeId = TestBioPlateType.test_create("Test for bioplate", null, BioWell.LockMode.UNLOCKED);
     88    int addOnlyTypeId = TestBioPlateType.test_create("Add-only plate type", null, BioWell.LockMode.LOCKED_AFTER_ADD);
     89    int moveTypeId = TestBioPlateType.test_create("Move plate type", null, BioWell.LockMode.LOCKED_AFTER_MOVE);
    8690    int id = test_create("Test BioPlate", plateGeometryId, bioPlateTypeId, freezerId, true);
     91    int id2 = test_create("Add-only plate", plateGeometryId, addOnlyTypeId, 0, false);
     92    int id3 = test_create("Move plate", plateGeometryId, moveTypeId, 0, false);
    8793    test_load(id);
    8894    test_list(-1);
    8995   
    90     // Wells
    91     test_set_well(id, 0, 0, Item.SAMPLE, sampleId);
    92     test_set_well(id, 0, 1, Item.EXTRACT, extractId);
     96    // Wells -- unlocked plate
     97    boolean FAIL = true;
     98    test_set_well(id, 0, 0, Item.SAMPLE, sampleId, !FAIL);
     99    test_set_well(id, 0, 1, Item.EXTRACT, extractId, !FAIL);
    93100    test_list_wells(id, 2);
     101    test_clear_well(id, 0, 0, !FAIL);
     102    test_clear_well(id, 0, 1, !FAIL);
     103    test_list_wells(id, 0);
     104   
     105    // Wells -- add-only plate
     106    test_set_well(id2, 0, 0, Item.SAMPLE, sample2Id, !FAIL);
     107    test_clear_well(id2, 0, 0, FAIL);
     108    test_set_well(id2, 0, 0, Item.SAMPLE, sample3Id, FAIL);
     109   
     110    // Wells -- locked-after-move plate
     111    test_set_well(id3, 0, 0, Item.SAMPLE, sample3Id, !FAIL);
     112    test_clear_well(id3, 0, 0, !FAIL);
     113    test_list_wells(id3, 0);
     114    test_list_original_biomaterial(id3, 1);
     115    test_set_well(id3, 0, 0, Item.SAMPLE, sample3Id, FAIL);
    94116   
    95117    if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter();
     
    99121    TestExtract.test_delete(extractId);
    100122    TestSample.test_delete(sampleId);
     123    TestSample.test_delete(sample2Id);
     124    TestSample.test_delete(sample3Id);
    101125    test_delete(id);
     126    test_delete(id2);
     127    test_delete(id3);
     128   
    102129    TestPlateGeometry.test_delete(plateGeometryId);
    103130    TestBioPlateType.test_delete(bioPlateTypeId);
     131    TestBioPlateType.test_delete(addOnlyTypeId);
     132    TestBioPlateType.test_delete(moveTypeId);
    104133    TestHardware.test_delete(freezerId);
    105134    TestProtocol.test_delete(protocolId);
     
    283312  {
    284313    if (!TestUtil.getSilent()) System.out.println(i+":\t"+well.getId()+"\t["+well.getRow()+
    285         ","+well.getColumn()+"]\t"+well.getBioMaterial());
    286   }
    287 
    288  
    289   static int test_set_well(int bioPlateId, int row, int column, Item bioMaterialType, int bioMaterialId)
     314        ","+well.getColumn()+"]\t"+well.getBioMaterial()+"\t"+well.getOriginalBioMaterial());
     315  }
     316
     317 
     318  static int test_set_well(int bioPlateId, int row, int column, Item bioMaterialType, int bioMaterialId, boolean shouldFail)
    290319  {
    291320    if (bioPlateId == 0 || bioMaterialId == 0)
     
    297326    try
    298327    {
    299       dc = TestUtil.getDbControl();
    300       BioPlate plate = BioPlate.getById(dc, bioPlateId);
    301       MeasuredBioMaterial bm = (MeasuredBioMaterial)bioMaterialType.getById(dc, bioMaterialId);
    302       BioWell well = plate.getBioWell(row, column);
    303       bm.setBioWell(well);
    304       dc.commit();
    305       wellId = well.getId();
    306       write("--Set well " + plate + "[" + row + "," + column + "] OK");
     328      Throwable t = null;
     329      BioPlate plate = null;
     330      try
     331      {
     332        dc = TestUtil.getDbControl();
     333        plate = BioPlate.getById(dc, bioPlateId);
     334        MeasuredBioMaterial bm = (MeasuredBioMaterial)bioMaterialType.getById(dc, bioMaterialId);
     335        BioWell well = plate.getBioWell(row, column);
     336        bm.setBioWell(well);
     337        dc.commit();
     338        wellId = well.getId();
     339      }
     340      catch (Throwable t1)
     341      {
     342        t = t1;
     343      }
     344      if (shouldFail)
     345      {
     346        if (t == null) throw new RuntimeException("Well shuld be locked");
     347        write("--Set well " + plate + "[" + row + "," + column + "] OK (well was locked)");
     348      }
     349      else
     350      {
     351        if (t != null) throw t;
     352        write("--Set well " + plate + "[" + row + "," + column + "] OK");
     353      }
    307354    }
    308355    catch (Throwable ex)
     
    318365    return wellId;
    319366  }
     367 
     368 
     369  static void test_clear_well(int bioPlateId, int row, int column, boolean shouldFail)
     370  {
     371    if (bioPlateId == 0) return;
     372    int wellId = 0;
     373    DbControl dc = null;
     374    try
     375    {
     376      Throwable t = null;
     377      BioPlate plate = null;
     378      try
     379      {
     380        dc = TestUtil.getDbControl();
     381        plate = BioPlate.getById(dc, bioPlateId);
     382        BioWell well = plate.getBioWell(row, column);
     383        well.getBioMaterial().setBioWell(null);
     384        dc.commit();
     385      }
     386      catch (Throwable t1)
     387      {
     388        t = t1;
     389      }
     390      if (shouldFail)
     391      {
     392        if (t == null) throw new RuntimeException("Well shuld be locked");
     393        write("--Clear well " + plate + "[" + row + "," + column + "] OK (well was locked)");
     394      }
     395      else
     396      {
     397        if (t != null) throw t;
     398        write("--Clear well " + plate + "[" + row + "," + column + "] OK");
     399      }
     400    }
     401    catch (Throwable ex)
     402    {
     403      write("--Clear well BioPlate[id=" + bioPlateId + "][" + row + "," + column + "] FAILED");
     404      ex.printStackTrace();
     405      ok = false;
     406    }
     407    finally
     408    {
     409      if (dc != null) dc.close();
     410    }
     411  }
     412
    320413 
    321414  static void test_list_wells(int bioPlateId, int expectedResults)
     
    356449    }
    357450  }
    358  
     451
     452  static void test_list_original_biomaterial(int bioPlateId, int expectedResults)
     453  {
     454    if (bioPlateId == 0) return;
     455    DbControl dc = null;
     456    try
     457    {
     458      dc = TestUtil.getDbControl();
     459      BioPlate plate = BioPlate.getById(dc, bioPlateId);
     460      ItemResultList<BioWell> wells = plate.getBioWells().list(dc);
     461      int numWells = 0;
     462      for (int i = 0; i<wells.size(); i++)
     463      {
     464        BioWell well = wells.get(i);
     465        if (well.getOriginalBioMaterial() != null)
     466        {
     467          write_item(i, well);
     468          numWells++;
     469        }
     470      }
     471      if (expectedResults >=0 && expectedResults != numWells)
     472      {
     473        throw new BaseException("Expected " + expectedResults + " results, " +
     474            "not " + numWells);
     475      }
     476      write ("--List wells with original biomaterial OK (" + numWells +")");
     477    }
     478    catch (Throwable ex)
     479    {
     480      write("--List wells with original biomaterial FAILED");
     481      ex.printStackTrace();
     482      ok = false;
     483    }
     484    finally
     485    {
     486      if (dc != null) dc.close();
     487    }
     488  }
     489
    359490 
    360491  static List<Integer> test_fill(int bioPlateId, Item itemType, String rootName, int labelId)
  • trunk/src/test/TestBioPlateType.java

    r5340 r5456  
    44import net.sf.basedb.core.BaseException;
    55import net.sf.basedb.core.BioPlateType;
     6import net.sf.basedb.core.BioWell;
    67import net.sf.basedb.core.DbControl;
    78import net.sf.basedb.core.Item;
     
    4950    write_header();
    5051    // Standard tests: create, load, list
    51     int id = test_create("Free for all", null, false);
    52     int id2 = test_create("Locked samples", Item.SAMPLE, true);
     52    int id = test_create("Free for all", null, BioWell.LockMode.UNLOCKED);
     53    int id2 = test_create("Locked samples", Item.SAMPLE, BioWell.LockMode.LOCKED_AFTER_ADD);
     54    int id3 = test_create("Moveable samples", Item.SAMPLE, BioWell.LockMode.LOCKED_AFTER_MOVE);
    5355    test_load(id);
    5456    test_list(-1);
     
    5860    test_delete(id);
    5961    test_delete(id2);
     62    test_delete(id3);
    6063    write("++Testing bioplate types "+(ok ? "OK" : "Failed")+"\n");
    6164    return ok;
    6265  }
    6366
    64   static int test_create(String name, Item bioMaterialType, boolean lockedWells)
     67  static int test_create(String name, Item bioMaterialType, BioWell.LockMode lockMode)
    6568  {
    6669    if (!TestUtil.hasPermission(Permission.CREATE, Item.BIOPLATETYPE)) return 0;
     
    7477      pt.setDescription("Added at "+new Date());
    7578      pt.setBioMaterialType(bioMaterialType);
    76       pt.setLockedWells(lockedWells);
     79      pt.setLockMode(lockMode);
    7780      dc.saveItem(pt);
    7881      dc.commit();
     
    181184    if (!TestUtil.getSilent())
    182185    {
    183       System.out.println("   \tID \tName      \tDescription\tBiomaterial type\tLocked wells");
     186      System.out.println("   \tID \tName      \tDescription\tBiomaterial type\tLock mode");
    184187      System.out.println("-- \t-- \t--------- \t-----------\t----------------\t------------");
    185188    }
     
    189192  {
    190193    if (!TestUtil.getSilent()) System.out.println(i+":\t"+pt.getId()+"\t"+pt.getName()+"\t"+pt.getDescription()+
    191       "\t"+pt.getBioMaterialType()+"\t"+pt.getLockedWells());
     194      "\t"+pt.getBioMaterialType()+"\t"+pt.getLockMode());
    192195  }
    193196  static void write(String message)
  • trunk/src/test/net/sf/basedb/test/roles/PowerUserTest.java

    r5260 r5456  
    3232import net.sf.basedb.core.ArraySlide;
    3333import net.sf.basedb.core.BioPlateType;
     34import net.sf.basedb.core.BioWell;
    3435import net.sf.basedb.core.DataFileType;
    3536import net.sf.basedb.core.DbControl;
     
    7879  <li>Create annotation types: {@link #createAnnotationType(DbControl, String, Type, Unit, Object[], Item[])}
    7980  <li>Create plate type: {@link #createPlateType(DbControl, String, int, int)}
    80   <li>Create bioplate type: {@link #createBioPlateType(DbControl, String, Item, boolean)}
     81  <li>Create bioplate type: {@link #createBioPlateType(DbControl, String, Item, BioWell.LockMode)}
    8182  <li>Create file formats for import:
    8283  <li>Import plates:
     
    154155     
    155156      PlateType plateType = createPlateType(dc, "Plate type A", 16, 24);
    156       BioPlateType bioPlateType = createBioPlateType(dc, "Bioplate type A", null, false);
     157      BioPlateType bioPlateType = createBioPlateType(dc, "Bioplate type A", null, BioWell.LockMode.UNLOCKED);
    157158     
    158159      PluginConfiguration platesImporter = PluginUtil.createPluginConfiguration(dc, "Plates for project A",
     
    395396    Create a bioplate type.
    396397  */
    397   public static BioPlateType createBioPlateType(DbControl dc, String name, Item bioMaterialType, boolean lockedWells)
     398  public static BioPlateType createBioPlateType(DbControl dc, String name, Item bioMaterialType, BioWell.LockMode lockMode)
    398399  {
    399400    TestUtil.write("--Creating bioplate type: " + name + "\n");
     
    402403    pt.setName(name);
    403404    pt.setBioMaterialType(bioMaterialType);
    404     pt.setLockedWells(lockedWells);
     405    pt.setLockMode(lockMode);
    405406    dc.saveItem(pt);
    406407    return pt;
  • trunk/www/biomaterials/bioplates/view_bioplate.jsp

    r5454 r5456  
    152152      location.href = 'wells/index.jsp?ID=<%=ID%>&bioplate_id=<%=itemId%>';
    153153    }
    154     function viewEvents()
    155     {
    156       location.href = 'events/index.jsp?ID=<%=ID%>&cmd=List&bioplate_id=<%=itemId%>';
    157     }
    158154    function switchTab(tabControlId, tabId)
    159155    {
     
    161157      {
    162158        location.href = 'index.jsp?ID=<%=ID%>&cmd=ViewItem&item_id=<%=itemId%>&tab='+tabId;
    163       }
    164       else if (tabId == 'events')
    165       {
    166         viewEvents();
    167159      }
    168160      else if (tabId == 'wells')
     
    407399            BioWell well = bioplate.getBioWell(r, c);
    408400            boolean isEmpty = well.isEmpty();
    409             boolean editable = well.hasPermission(Permission.USE) && !well.isLocked();
     401            boolean editable = well.hasPermission(Permission.USE); // && !well.isLocked();
    410402            MeasuredBioMaterial bm = null;
    411403            String cls = "well";
     
    606598      </t:tab>
    607599      <t:tab id="wells" title="Wells" />
    608       <t:tab id="events" title="Events" />
    609600      <t:tab id="history" title="Change history"
    610601        tooltip="Displays a log of all modifications made to this item"
  • trunk/www/biomaterials/bioplates/wells/list_biowells.jsp

    r5426 r5456  
    9999  final boolean createPermission = bioplate.hasPermission(Permission.WRITE);
    100100  final boolean deletePermission = createPermission;
    101   final boolean lockedWells = bioPlateType.getLockedWells();
     101  final boolean lockedWells = false; //bioPlateType.getLockedWells();
    102102
    103103  Enumeration<String, String> rows = new Enumeration<String,String>();
     
    164164      {
    165165        location.href = '../index.jsp?ID=<%=ID%>&cmd=ViewItem&item_id=<%=bioPlateId%>&tab='+tabId;
    166       }
    167       else if (tabId == 'events')
    168       {
    169         location.href = '../events/index.jsp?ID=<%=ID%>&bioplate_id=<%=bioPlateId%>';
    170166      }
    171167      else
     
    505501 
    506502    </t:tab>
    507     <t:tab id="events" title="Events" />
    508503    <t:tab id="history" title="Change history"
    509504        tooltip="Displays a log of all modifications made to this item"
  • trunk/www/biomaterials/bioplatetypes/edit_platetype.jsp

    r5426 r5456  
    7474    bioPlateType = BioPlateType.getById(dc, itemId);
    7575    bioPlateType.checkPermission(Permission.WRITE);
    76     isLocked = bioPlateType.getLockedWells();
     76    //isLocked = bioPlateType.getLockedWells();
    7777    cc.setObject("item", bioPlateType);
    7878    title = "Edit bio plate type -- " + HTML.encodeTags(bioPlateType.getName());
  • trunk/www/biomaterials/bioplatetypes/index.jsp

    r5426 r5456  
    148148    plateType.setName(Values.getStringOrNull(request.getParameter("name")));
    149149    plateType.setDescription(Values.getStringOrNull(request.getParameter("description")));
    150     plateType.setLockedWells(Values.getBoolean(request.getParameter("lockedWells")));
     150//    plateType.setLockedWells(Values.getBoolean(request.getParameter("lockedWells")));
    151151    dc.commit();
    152152    cc.removeObject("item");
  • trunk/www/biomaterials/bioplatetypes/list_platetypes.jsp

    r5426 r5456  
    400400                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
    401401                <tbl:cell column="bioMaterialType"><%=item.getBioMaterialType() == null ? "<i>- any -</i>" : item.getBioMaterialType().toString() %></tbl:cell>
    402                 <tbl:cell column="lockedWells"><%=item.getLockedWells() ? "yes" : "no" %></tbl:cell>
     402                <tbl:cell column="lockedWells"><% //item.getLockedWells() ? "yes" : "no" %></tbl:cell>
    403403                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
    404404              </tbl:row>
  • trunk/www/biomaterials/bioplatetypes/view_platetype.jsp

    r5426 r5456  
    220220      <tr>
    221221        <td class="prompt">Locked wells</td>
    222         <td><%=plateType.getLockedWells() ? "yes" : "no"%></td>
     222        <td><% //plateType.getLockedWells() ? "yes" : "no"%></td>
    223223      </tr>
    224224      <tr>
  • trunk/www/biomaterials/extracts/edit_extract.jsp

    r5451 r5456  
    176176      {
    177177        currentBioPlate = currentBioWell.getPlate();
    178         lockedWell = currentBioWell.isLocked();
     178        lockedWell = false; //currentBioWell.isLocked();
    179179      }
    180180    }
  • trunk/www/biomaterials/extracts/view_extract.jsp

    r5426 r5456  
    354354              %>
    355355              [<%=rowFormatter.format(bw.getRow())%>,<%=columnFormatter.format(bw.getColumn())%>]
    356               <base:icon image="locked.gif"  visible="<%=bw.isLocked() %>"/>
     356              <base:icon image="locked.gif"  visible="<% //bw.isLocked() %>"/>
    357357            <%
    358358            }
  • trunk/www/biomaterials/labeledextracts/edit_labeledextract.jsp

    r5451 r5456  
    200200      {
    201201        currentBioPlate = currentBioWell.getPlate();
    202         lockedWell = currentBioWell.isLocked();
     202        lockedWell = false; //currentBioWell.isLocked();
    203203      }
    204204    }
  • trunk/www/biomaterials/labeledextracts/view_labeledextract.jsp

    r5426 r5456  
    357357              %>
    358358              [<%=rowFormatter.format(bw.getRow())%>,<%=columnFormatter.format(bw.getColumn())%>]
    359               <base:icon image="locked.gif"  visible="<%=bw.isLocked() %>"/>
     359              <base:icon image="locked.gif"  visible="<% // bw.isLocked() %>"/>
    360360            <%
    361361            }
  • trunk/www/biomaterials/samples/edit_sample.jsp

    r5451 r5456  
    177177      {
    178178        currentBioPlate = currentBioWell.getPlate();
    179         lockedWell = currentBioWell.isLocked();
     179        lockedWell = false; //currentBioWell.isLocked();
    180180      }
    181181    }
  • trunk/www/biomaterials/samples/view_sample.jsp

    r5426 r5456  
    339339              %>
    340340              [<%=rowFormatter.format(bw.getRow())%>,<%=columnFormatter.format(bw.getColumn())%>]
    341               <base:icon image="locked.gif"  visible="<%=bw.isLocked() %>"/>
     341              <base:icon image="locked.gif"  visible="<% //bw.isLocked() %>"/>
    342342            <%
    343343            }
Note: See TracChangeset for help on using the changeset viewer.