extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/dao/ReactionPlate.java

Code
Comments
Other
Rev Date Author Line
1543 28 Feb 12 nicklas 1 package net.sf.basedb.reggie.dao;
1543 28 Feb 12 nicklas 2
1543 28 Feb 12 nicklas 3 import java.util.ArrayList;
5407 08 May 19 nicklas 4 import java.util.Collection;
1543 28 Feb 12 nicklas 5 import java.util.List;
1543 28 Feb 12 nicklas 6
1543 28 Feb 12 nicklas 7 import org.json.simple.JSONArray;
1543 28 Feb 12 nicklas 8 import org.json.simple.JSONObject;
1543 28 Feb 12 nicklas 9
4482 05 May 17 nicklas 10 import net.sf.basedb.core.AnnotationRestriction;
1543 28 Feb 12 nicklas 11 import net.sf.basedb.core.AnnotationType;
1668 25 May 12 nicklas 12 import net.sf.basedb.core.BioMaterial;
1543 28 Feb 12 nicklas 13 import net.sf.basedb.core.BioPlate;
1865 19 Feb 13 nicklas 14 import net.sf.basedb.core.BioPlateEvent;
1543 28 Feb 12 nicklas 15 import net.sf.basedb.core.BioPlateType;
1543 28 Feb 12 nicklas 16 import net.sf.basedb.core.BioWell;
1543 28 Feb 12 nicklas 17 import net.sf.basedb.core.DbControl;
1543 28 Feb 12 nicklas 18 import net.sf.basedb.core.HasAnnotationRestriction;
1865 19 Feb 13 nicklas 19 import net.sf.basedb.core.Include;
1668 25 May 12 nicklas 20 import net.sf.basedb.core.InvalidDataException;
1865 19 Feb 13 nicklas 21 import net.sf.basedb.core.Item;
1543 28 Feb 12 nicklas 22 import net.sf.basedb.core.ItemQuery;
1543 28 Feb 12 nicklas 23 import net.sf.basedb.core.ItemSubtype;
1668 25 May 12 nicklas 24 import net.sf.basedb.core.MeasuredBioMaterial;
1543 28 Feb 12 nicklas 25 import net.sf.basedb.core.PlateGeometry;
1865 19 Feb 13 nicklas 26 import net.sf.basedb.core.SystemItems;
1543 28 Feb 12 nicklas 27 import net.sf.basedb.core.Type;
1543 28 Feb 12 nicklas 28 import net.sf.basedb.core.query.Expressions;
1543 28 Feb 12 nicklas 29 import net.sf.basedb.core.query.Hql;
1553 08 Mar 12 nicklas 30 import net.sf.basedb.core.query.Orders;
1543 28 Feb 12 nicklas 31 import net.sf.basedb.core.query.Restrictions;
1668 25 May 12 nicklas 32 import net.sf.basedb.reggie.JsonUtil;
1543 28 Feb 12 nicklas 33 import net.sf.basedb.reggie.Reggie;
1668 25 May 12 nicklas 34 import net.sf.basedb.reggie.converter.IdentityConverter;
1668 25 May 12 nicklas 35 import net.sf.basedb.reggie.converter.ValueConverter;
1543 28 Feb 12 nicklas 36
1543 28 Feb 12 nicklas 37 /**
1543 28 Feb 12 nicklas 38   Class for loading information that is related to reaction bioplates.
1543 28 Feb 12 nicklas 39   
1543 28 Feb 12 nicklas 40   @author nicklas
1543 28 Feb 12 nicklas 41   @since 2.4
1543 28 Feb 12 nicklas 42 */
1543 28 Feb 12 nicklas 43 public class ReactionPlate
1543 28 Feb 12 nicklas 44   extends ReggieItem<BioPlate>
1543 28 Feb 12 nicklas 45 {
1543 28 Feb 12 nicklas 46
1543 28 Feb 12 nicklas 47   /**
1890 01 Mar 13 nicklas 48     Value for the {@link Annotationtype#PLATE_PROCESS_RESULT} annotation 
1890 01 Mar 13 nicklas 49     when the processing of the bioplate was successful.
1890 01 Mar 13 nicklas 50     @since 2.12
1890 01 Mar 13 nicklas 51   */
1890 01 Mar 13 nicklas 52   public static final String PROCESS_SUCCESSFUL = "Successful";
1890 01 Mar 13 nicklas 53   
1890 01 Mar 13 nicklas 54   /**
1890 01 Mar 13 nicklas 55     Value for the {@link Annotationtype#PLATE_PROCESS_RESULT} annotation when
1890 01 Mar 13 nicklas 56     the processing of the entire bioplate failed.
1890 01 Mar 13 nicklas 57     @since 2.12
1890 01 Mar 13 nicklas 58   */
1890 01 Mar 13 nicklas 59   public static final String PROCESS_FAILED = "Failed";
1890 01 Mar 13 nicklas 60   
1890 01 Mar 13 nicklas 61   /**
1543 28 Feb 12 nicklas 62     Find all active reaction plates which can hold biomaterial items of the given 
1543 28 Feb 12 nicklas 63     subtype. Active plates are plates that:
1543 28 Feb 12 nicklas 64     
1543 28 Feb 12 nicklas 65     <ul>
1543 28 Feb 12 nicklas 66     <li>Are not marked as destroyed
1544 29 Feb 12 nicklas 67     <li>Have at least the specified number of free wells
1543 28 Feb 12 nicklas 68     <li>Have no value set for the 'run date' annotation
1543 28 Feb 12 nicklas 69     </ul>
1543 28 Feb 12 nicklas 70     
1543 28 Feb 12 nicklas 71     @param dc
1544 29 Feb 12 nicklas 72     @param bioPlateType The required bioplate type, or null to not filter on bioplate type
1543 28 Feb 12 nicklas 73     @param subtype A biomaterial subtype, or null to not filter on subtype
1543 28 Feb 12 nicklas 74     @param runDateAnnotation The name of an annotation type, or null to not filter on annotation
1543 28 Feb 12 nicklas 75   */
1544 29 Feb 12 nicklas 76   public static List<ReactionPlate> findActiveByBioMaterialSubtype(DbControl dc, 
1610 23 Apr 12 nicklas 77     BioplateType bioPlateType, Subtype subtype, int numFreeWells, Annotationtype runDateAnnotation)
1543 28 Feb 12 nicklas 78   {
1543 28 Feb 12 nicklas 79     ItemQuery<BioPlate> query = BioPlate.getQuery();
1560 14 Mar 12 nicklas 80     query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
1544 29 Feb 12 nicklas 81     if (subtype != null || bioPlateType != null)
1543 28 Feb 12 nicklas 82     {
1543 28 Feb 12 nicklas 83       query.join(Hql.innerJoin("bioPlateType", "bpt"));
1544 29 Feb 12 nicklas 84       if (bioPlateType != null) bioPlateType.addFilter(dc, query, false);
1544 29 Feb 12 nicklas 85       if (subtype != null) subtype.addFilter(dc, query, "bpt");
1543 28 Feb 12 nicklas 86     }
1543 28 Feb 12 nicklas 87     
1543 28 Feb 12 nicklas 88     query.restrict(Restrictions.eq(Hql.property("destroyed"), Expressions.parameter("destroyed", false, Type.BOOLEAN)));
1544 29 Feb 12 nicklas 89     query.restrict(Restrictions.gteq(Hql.property("freeWells"), Expressions.integer(numFreeWells)));
1543 28 Feb 12 nicklas 90     if (runDateAnnotation != null)
1543 28 Feb 12 nicklas 91     {
1610 23 Apr 12 nicklas 92       AnnotationType at = runDateAnnotation.load(dc);
4482 05 May 17 nicklas 93       query.restrict(new HasAnnotationRestriction(null, at, false, new AnnotationRestriction.Options()));
1543 28 Feb 12 nicklas 94     }
1553 08 Mar 12 nicklas 95     query.order(Orders.asc(Hql.property("name")));
1543 28 Feb 12 nicklas 96     
1543 28 Feb 12 nicklas 97     List<BioPlate> tmp = query.list(dc);
1543 28 Feb 12 nicklas 98     List<ReactionPlate> plates = new ArrayList<ReactionPlate>(tmp.size());
1543 28 Feb 12 nicklas 99     for (BioPlate plate : tmp)
1543 28 Feb 12 nicklas 100     {
1668 25 May 12 nicklas 101       plates.add(new ReactionPlate(plate, bioPlateType));
1543 28 Feb 12 nicklas 102     }
1543 28 Feb 12 nicklas 103     return plates;
1543 28 Feb 12 nicklas 104   }
1543 28 Feb 12 nicklas 105   
1668 25 May 12 nicklas 106   /**
1668 25 May 12 nicklas 107     Find a reaction plate given it's name and plate type. If more than one
1668 25 May 12 nicklas 108     plate is found an exception is thrown. If no plate is found null is
1668 25 May 12 nicklas 109     returned.
1668 25 May 12 nicklas 110     @since 2.7
1668 25 May 12 nicklas 111   */
1668 25 May 12 nicklas 112   public static ReactionPlate findByNameAndType(DbControl dc, String plateName, BioplateType plateType)
1543 28 Feb 12 nicklas 113   {
1668 25 May 12 nicklas 114     ItemQuery<BioPlate> query = BioPlate.getQuery();
1695 11 Jun 12 nicklas 115     query.include(Reggie.INCLUDE_IN_CURRENT_PROJECT);
1668 25 May 12 nicklas 116     if (plateType != null)
1668 25 May 12 nicklas 117     {
1668 25 May 12 nicklas 118       plateType.addFilter(dc, query, true);
1668 25 May 12 nicklas 119     }
1668 25 May 12 nicklas 120     
1668 25 May 12 nicklas 121     query.restrict(Restrictions.eq(Hql.property("name"), Expressions.string(plateName)));
1668 25 May 12 nicklas 122     
1668 25 May 12 nicklas 123     ReactionPlate plate = null;
1668 25 May 12 nicklas 124     List<BioPlate> result = query.list(dc);
1668 25 May 12 nicklas 125     if (result.size() > 1)
1668 25 May 12 nicklas 126     {
1668 25 May 12 nicklas 127       throw new InvalidDataException("Found > 1 BioPlate["+plateName+"]");
1668 25 May 12 nicklas 128     }
1668 25 May 12 nicklas 129     else if (result.size() == 1)
1668 25 May 12 nicklas 130     {
1668 25 May 12 nicklas 131       plate = new ReactionPlate(result.get(0), plateType);
1668 25 May 12 nicklas 132     }
1668 25 May 12 nicklas 133     
1668 25 May 12 nicklas 134     return plate;
1668 25 May 12 nicklas 135   }
1668 25 May 12 nicklas 136   
1668 25 May 12 nicklas 137   public static ReactionPlate getById(DbControl dc, int bioPlateId, BioplateType plateType)
1668 25 May 12 nicklas 138   {
1543 28 Feb 12 nicklas 139     BioPlate plate = BioPlate.getById(dc, bioPlateId);
1668 25 May 12 nicklas 140     return plate == null ? null : new ReactionPlate(plate, plateType);
1543 28 Feb 12 nicklas 141   }
1543 28 Feb 12 nicklas 142   
1552 07 Mar 12 nicklas 143   public static ReactionPlate getNew(DbControl dc, BioplateType bioplateType)
1552 07 Mar 12 nicklas 144   {
1552 07 Mar 12 nicklas 145     BioPlate plate = BioPlate.getNew(dc, bioplateType.getPlateGeometry(dc), bioplateType.load(dc));
1668 25 May 12 nicklas 146     return new ReactionPlate(plate, bioplateType);
1552 07 Mar 12 nicklas 147   }
1552 07 Mar 12 nicklas 148   
5407 08 May 19 nicklas 149   public static List<ReactionPlate> toList(BioplateType bioPlateType, Collection<BioPlate> plates)
5407 08 May 19 nicklas 150   {
5407 08 May 19 nicklas 151     List<ReactionPlate> list = new ArrayList<ReactionPlate>(plates.size());
5407 08 May 19 nicklas 152     for (BioPlate p : plates)
5407 08 May 19 nicklas 153     {
5407 08 May 19 nicklas 154       list.add(new ReactionPlate(p, bioPlateType));
5407 08 May 19 nicklas 155     }
5407 08 May 19 nicklas 156     return list;
5407 08 May 19 nicklas 157   }
5407 08 May 19 nicklas 158
5407 08 May 19 nicklas 159   
1668 25 May 12 nicklas 160   private final BioplateType plateType;
1543 28 Feb 12 nicklas 161   private JSONArray jsonWells;
1543 28 Feb 12 nicklas 162   
1668 25 May 12 nicklas 163   private ReactionPlate(BioPlate plate, BioplateType plateType)
1543 28 Feb 12 nicklas 164   {
1543 28 Feb 12 nicklas 165     super(plate);
1668 25 May 12 nicklas 166     this.plateType = plateType;
1543 28 Feb 12 nicklas 167   }
1543 28 Feb 12 nicklas 168   
1543 28 Feb 12 nicklas 169   
1543 28 Feb 12 nicklas 170   /**
1543 28 Feb 12 nicklas 171     Get the real bioplate that represents this reaction plate in BASE.
1543 28 Feb 12 nicklas 172   */
1543 28 Feb 12 nicklas 173   public BioPlate getBioPlate()
1543 28 Feb 12 nicklas 174   {
1543 28 Feb 12 nicklas 175     return getItem();
1543 28 Feb 12 nicklas 176   }
1543 28 Feb 12 nicklas 177   
1668 25 May 12 nicklas 178   /**
1668 25 May 12 nicklas 179     Get the type of reaction plate (if known)
1668 25 May 12 nicklas 180     @return Can be null
1668 25 May 12 nicklas 181     @since 2.7
1668 25 May 12 nicklas 182   */
1668 25 May 12 nicklas 183   public BioplateType getBioplateType()
1668 25 May 12 nicklas 184   {
1668 25 May 12 nicklas 185     return plateType;
1668 25 May 12 nicklas 186   }
1668 25 May 12 nicklas 187   
1668 25 May 12 nicklas 188   public void loadBioWells(DbControl dc, boolean loadBioMaterial)
1543 28 Feb 12 nicklas 189   {
1543 28 Feb 12 nicklas 190     if (jsonWells != null) return;
1543 28 Feb 12 nicklas 191     
1543 28 Feb 12 nicklas 192     BioPlate plate = getItem();
1552 07 Mar 12 nicklas 193     int rows = plate.getRows();
1552 07 Mar 12 nicklas 194     int cols = plate.getColumns();
1543 28 Feb 12 nicklas 195     
1543 28 Feb 12 nicklas 196     jsonWells = new JSONArray();
1552 07 Mar 12 nicklas 197     for (int r = 0; r < rows; ++r)
1543 28 Feb 12 nicklas 198     {
1552 07 Mar 12 nicklas 199       for (int c = 0; c < cols; ++c)
1552 07 Mar 12 nicklas 200       {
1552 07 Mar 12 nicklas 201         BioWell well = plate.getBioWell(r, c);
1552 07 Mar 12 nicklas 202         JSONObject jsonWell = new JSONObject();
1552 07 Mar 12 nicklas 203         jsonWell.put("id", well.getId());
1552 07 Mar 12 nicklas 204         jsonWell.put("row", well.getRow());
1552 07 Mar 12 nicklas 205         jsonWell.put("column", well.getColumn());
1552 07 Mar 12 nicklas 206         jsonWell.put("canAdd", well.canAddBioMaterial());
1552 07 Mar 12 nicklas 207         jsonWell.put("canRemove", well.canClearBioMaterial());
3555 21 Oct 15 nicklas 208         jsonWell.put("location", well.getCoordinate());
3555 21 Oct 15 nicklas 209
1668 25 May 12 nicklas 210         if (loadBioMaterial)
1668 25 May 12 nicklas 211         {
1668 25 May 12 nicklas 212           MeasuredBioMaterial bm = well.getBioMaterial();
1668 25 May 12 nicklas 213           if (bm != null)
1668 25 May 12 nicklas 214           {
1668 25 May 12 nicklas 215             JSONObject jsonBm = new JSONObject();
1668 25 May 12 nicklas 216             jsonBm.put("id", bm.getId());
1668 25 May 12 nicklas 217             jsonBm.put("name", bm.getName());
2244 21 Feb 14 nicklas 218             jsonBm.put("comment", bm.getDescription());
1668 25 May 12 nicklas 219             jsonWell.put("bioMaterial", jsonBm);
1668 25 May 12 nicklas 220           }
1668 25 May 12 nicklas 221         }
1668 25 May 12 nicklas 222         
1552 07 Mar 12 nicklas 223         jsonWells.add(jsonWell);
1552 07 Mar 12 nicklas 224       }
1552 07 Mar 12 nicklas 225     }  
1543 28 Feb 12 nicklas 226   }
1543 28 Feb 12 nicklas 227   
1668 25 May 12 nicklas 228   /**
1668 25 May 12 nicklas 229     Load biomaterial annotations for the given annotation type and store the values in
1668 25 May 12 nicklas 230     the given JSON key. Single-valued annotation types are stored as a simple
1668 25 May 12 nicklas 231     key-value pair. Multi-valued annotation types are stored as a
1668 25 May 12 nicklas 232     key-array pair (even if there is only one value in the array).
1668 25 May 12 nicklas 233     NOTE! The {@link #loadBioWells(DbControl, boolean)} must be called first to
1668 25 May 12 nicklas 234     load the well AND biomaterial information for the plate
1668 25 May 12 nicklas 235     @since 2.7
1668 25 May 12 nicklas 236   */
3572 02 Nov 15 nicklas 237   @SuppressWarnings({ "unchecked", "rawtypes" })
1668 25 May 12 nicklas 238   public void loadBioMaterialAnnotations(DbControl dc, String jsonKey, Annotationtype annotationType, ValueConverter converter)
1668 25 May 12 nicklas 239   {
1668 25 May 12 nicklas 240     if (jsonWells == null) return;
1668 25 May 12 nicklas 241     
1668 25 May 12 nicklas 242     if (converter == null) converter = IdentityConverter.INSTANCE;
1668 25 May 12 nicklas 243     AnnotationType at = annotationType.load(dc);
1668 25 May 12 nicklas 244     
1668 25 May 12 nicklas 245     for (int i = 0; i < jsonWells.size(); ++i)
1668 25 May 12 nicklas 246     {
1668 25 May 12 nicklas 247       JSONObject jsonWell = (JSONObject)jsonWells.get(i);
1668 25 May 12 nicklas 248       JSONObject jsonBm = (JSONObject)jsonWell.get("bioMaterial");
1668 25 May 12 nicklas 249       
1668 25 May 12 nicklas 250       if (jsonBm == null) continue; // with the next well
1668 25 May 12 nicklas 251       
1668 25 May 12 nicklas 252       Number id = (Number)jsonBm.get("id");
1668 25 May 12 nicklas 253       BioMaterial bm = BioMaterial.getById(dc, id.intValue());
1668 25 May 12 nicklas 254       
1668 25 May 12 nicklas 255       if (at.getMultiplicity() == 1)
1668 25 May 12 nicklas 256       {
1668 25 May 12 nicklas 257         jsonBm.put(jsonKey, converter.convert(annotationType.getAnnotationValue(dc, bm)));
1668 25 May 12 nicklas 258       }
1668 25 May 12 nicklas 259       else
1668 25 May 12 nicklas 260       {
1668 25 May 12 nicklas 261         jsonBm.put(jsonKey, JsonUtil.toArray(annotationType.getAnnotationValues(dc, bm), converter));
1668 25 May 12 nicklas 262       }
1668 25 May 12 nicklas 263     }
1668 25 May 12 nicklas 264   }
1668 25 May 12 nicklas 265
1668 25 May 12 nicklas 266   
1668 25 May 12 nicklas 267   /**
1668 25 May 12 nicklas 268     Find all child bioplates of a give type to this reaction plate. Since there is
1668 25 May 12 nicklas 269     no actual database reference between child and parent plates the plates are
1668 25 May 12 nicklas 270     located by name as follows:
1668 25 May 12 nicklas 271     
1668 25 May 12 nicklas 272     The plate prefix of this reacation plate is replaced with the plate prefix
1668 25 May 12 nicklas 273     of the given bioPlateType.
1668 25 May 12 nicklas 274     
1668 25 May 12 nicklas 275     @param dc 
3571 30 Oct 15 nicklas 276     @param childType The type of child plates to find
1668 25 May 12 nicklas 277   */
1668 25 May 12 nicklas 278   public List<ReactionPlate> findChildPlates(DbControl dc, BioplateType childType)
1668 25 May 12 nicklas 279   {
1668 25 May 12 nicklas 280     // Replace the parent prefix with the child prefix
1668 25 May 12 nicklas 281     String prefix = getName().replace(this.getBioplateType().getPlateNamePrefix(), childType.getPlateNamePrefix());
1668 25 May 12 nicklas 282     
1668 25 May 12 nicklas 283     ItemQuery<BioPlate> query = BioPlate.getQuery();
1695 11 Jun 12 nicklas 284     query.include(Reggie.INCLUDE_IN_CURRENT_PROJECT);
1668 25 May 12 nicklas 285     // Find plates with prefix + . + numeric suffix
1668 25 May 12 nicklas 286     query.restrict(Restrictions.rlike(Hql.property("name"), Expressions.string("^" + prefix + "\\.[0-9]+$")));
1668 25 May 12 nicklas 287     childType.addFilter(dc, query, true);
3121 06 Feb 15 nicklas 288     query.order(Orders.asc(Hql.property("name")));
1668 25 May 12 nicklas 289     
1668 25 May 12 nicklas 290     List<BioPlate> tmp = query.list(dc);
1668 25 May 12 nicklas 291     List<ReactionPlate> plates = new ArrayList<ReactionPlate>(tmp.size());
1668 25 May 12 nicklas 292     for (BioPlate plate : tmp)
1668 25 May 12 nicklas 293     {
1668 25 May 12 nicklas 294       plates.add(new ReactionPlate(plate, childType));
1668 25 May 12 nicklas 295     }
1668 25 May 12 nicklas 296     return plates;
1668 25 May 12 nicklas 297   }
4888 05 Jul 18 nicklas 298   
4888 05 Jul 18 nicklas 299   /**
4888 05 Jul 18 nicklas 300     Get the name of child plate to this reaction plate. It is 
4888 05 Jul 18 nicklas 301     expected that a reaction plate only has a single child of 
4888 05 Jul 18 nicklas 302     the specified type and the name is created as follow:
4888 05 Jul 18 nicklas 303     
4888 05 Jul 18 nicklas 304     The plate prefix of this reacation plate is replaced with the plate prefix
4888 05 Jul 18 nicklas 305     of the given bioPlateType.
4888 05 Jul 18 nicklas 306     
4888 05 Jul 18 nicklas 307     @param dc 
4888 05 Jul 18 nicklas 308     @param childType The type of child plates to find
4888 05 Jul 18 nicklas 309     @since 4.19
4888 05 Jul 18 nicklas 310   */
4888 05 Jul 18 nicklas 311   public String getChildPlateName(DbControl dc, BioplateType childType)
4888 05 Jul 18 nicklas 312   {
4888 05 Jul 18 nicklas 313     String childName = getName().replace(getBioplateType().getPlateNamePrefix(), childType.getPlateNamePrefix());
4888 05 Jul 18 nicklas 314     return childName;
4888 05 Jul 18 nicklas 315     
4888 05 Jul 18 nicklas 316   }
1668 25 May 12 nicklas 317
1865 19 Feb 13 nicklas 318   /**
1865 19 Feb 13 nicklas 319     Find all bioplate events for the current bioplate. If
1865 19 Feb 13 nicklas 320     a role is specified, the list is filter to only
1865 19 Feb 13 nicklas 321     include events where the bioplate has the given role.
1867 19 Feb 13 nicklas 322     @since 2.12
1865 19 Feb 13 nicklas 323   */
1865 19 Feb 13 nicklas 324   public List<BioPlateEvent> findEvents(DbControl dc, String eventType, String role)
1865 19 Feb 13 nicklas 325   {
1865 19 Feb 13 nicklas 326     ItemQuery<BioPlateEvent> query = getItem().getEvents();
1865 19 Feb 13 nicklas 327     if (eventType != null)
1865 19 Feb 13 nicklas 328     {
1865 19 Feb 13 nicklas 329       int eventTypeId = SystemItems.getId(eventType);
1865 19 Feb 13 nicklas 330       if (eventTypeId != 0)
1865 19 Feb 13 nicklas 331       {
1865 19 Feb 13 nicklas 332         // Restrict on event type
1865 19 Feb 13 nicklas 333         query.restrict(Restrictions.eq(Hql.property("eventType"), Expressions.integer(eventTypeId)));
1865 19 Feb 13 nicklas 334       }
1865 19 Feb 13 nicklas 335       
1865 19 Feb 13 nicklas 336     }
1865 19 Feb 13 nicklas 337     if (role != null)
1865 19 Feb 13 nicklas 338     {
1865 19 Feb 13 nicklas 339       // Restrict on role
1865 19 Feb 13 nicklas 340       query.restrict(Restrictions.eq(
1865 19 Feb 13 nicklas 341         Hql.property(Item.BIOPLATEEVENTPARTICIPANT.getAlias(), "role"), Expressions.string(role)));
1865 19 Feb 13 nicklas 342     }
1865 19 Feb 13 nicklas 343     query.setIncludes(Include.ALL);
1865 19 Feb 13 nicklas 344     return query.list(dc);
1865 19 Feb 13 nicklas 345   }
1668 25 May 12 nicklas 346   
1543 28 Feb 12 nicklas 347   @Override
1543 28 Feb 12 nicklas 348   protected void initJSON(JSONObject json)
1543 28 Feb 12 nicklas 349   {
1543 28 Feb 12 nicklas 350     super.initJSON(json);
1543 28 Feb 12 nicklas 351     BioPlate plate = getItem();
1543 28 Feb 12 nicklas 352     BioPlateType plateType = plate.getBioPlateType();
1543 28 Feb 12 nicklas 353     PlateGeometry geometry = plate.getPlateGeometry();
1543 28 Feb 12 nicklas 354     ItemSubtype bioMaterialSubtype = plateType.getItemSubtype();
1543 28 Feb 12 nicklas 355     
1543 28 Feb 12 nicklas 356     json.put("freeWells", plate.getFreeWells());
1544 29 Feb 12 nicklas 357     json.put("usedWells", plate.getUsedWells());
1543 28 Feb 12 nicklas 358     json.put("barcode", plate.getBarcode());
1552 07 Mar 12 nicklas 359     
1552 07 Mar 12 nicklas 360     JSONObject jsonBioPlateType = new JSONObject();
1552 07 Mar 12 nicklas 361     jsonBioPlateType.put("id", plateType.getId());
1552 07 Mar 12 nicklas 362     jsonBioPlateType.put("bioMaterialType", plateType.getBioMaterialType().name());
1552 07 Mar 12 nicklas 363     json.put("bioPlateType", jsonBioPlateType);
1552 07 Mar 12 nicklas 364     
1552 07 Mar 12 nicklas 365     JSONObject jsonGeometry = new JSONObject();
1552 07 Mar 12 nicklas 366     jsonGeometry.put("id", geometry.getId());
1552 07 Mar 12 nicklas 367     jsonGeometry.put("rows", geometry.getRows());
1552 07 Mar 12 nicklas 368     jsonGeometry.put("columns", geometry.getColumns());
1552 07 Mar 12 nicklas 369     json.put("geometry", jsonGeometry);
1552 07 Mar 12 nicklas 370     
1543 28 Feb 12 nicklas 371     if (bioMaterialSubtype != null)
1543 28 Feb 12 nicklas 372     {
1543 28 Feb 12 nicklas 373       json.put("bioMaterialSubtype", Subtype.get(bioMaterialSubtype).asJSONObject(null));
1543 28 Feb 12 nicklas 374     }
1543 28 Feb 12 nicklas 375     if (jsonWells != null)
1543 28 Feb 12 nicklas 376     {
1543 28 Feb 12 nicklas 377       json.put("bioWells", jsonWells);
1543 28 Feb 12 nicklas 378     }
1543 28 Feb 12 nicklas 379   }
1543 28 Feb 12 nicklas 380
1543 28 Feb 12 nicklas 381   
1543 28 Feb 12 nicklas 382 }