extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/release/FlowThroughWriter.java

Code
Comments
Other
Rev Date Author Line
5131 21 Nov 18 nicklas 1 package net.sf.basedb.reggie.plugins.release;
5131 21 Nov 18 nicklas 2
5131 21 Nov 18 nicklas 3 import java.util.Date;
5131 21 Nov 18 nicklas 4 import java.util.List;
5131 21 Nov 18 nicklas 5
5131 21 Nov 18 nicklas 6 import org.json.simple.JSONArray;
5131 21 Nov 18 nicklas 7 import org.json.simple.JSONObject;
5131 21 Nov 18 nicklas 8
5170 03 Dec 18 nicklas 9 import net.sf.basedb.core.BioMaterialEvent;
5131 21 Nov 18 nicklas 10 import net.sf.basedb.core.DbControl;
5131 21 Nov 18 nicklas 11 import net.sf.basedb.core.Extract;
5131 21 Nov 18 nicklas 12 import net.sf.basedb.core.Item;
5170 03 Dec 18 nicklas 13 import net.sf.basedb.core.Quantity;
5131 21 Nov 18 nicklas 14 import net.sf.basedb.core.Type;
5170 03 Dec 18 nicklas 15 import net.sf.basedb.core.Unit;
5131 21 Nov 18 nicklas 16 import net.sf.basedb.core.snapshot.SnapshotManager;
5131 21 Nov 18 nicklas 17 import net.sf.basedb.reggie.Reggie;
5131 21 Nov 18 nicklas 18 import net.sf.basedb.reggie.dao.Annotationtype;
5132 21 Nov 18 nicklas 19 import net.sf.basedb.reggie.dao.FlowThrough;
5132 21 Nov 18 nicklas 20 import net.sf.basedb.reggie.dao.Lysate;
5131 21 Nov 18 nicklas 21 import net.sf.basedb.reggie.json.FilteredJSONArray;
5131 21 Nov 18 nicklas 22 import net.sf.basedb.util.filter.NotNullFilter;
5170 03 Dec 18 nicklas 23 import net.sf.basedb.util.units.UnitUtil;
5131 21 Nov 18 nicklas 24
5131 21 Nov 18 nicklas 25 /**
5131 21 Nov 18 nicklas 26   Cohort writer implementation for the FlowThrough data table.
5131 21 Nov 18 nicklas 27   @since 4.21
5131 21 Nov 18 nicklas 28 */
5131 21 Nov 18 nicklas 29 public class FlowThroughWriter 
5131 21 Nov 18 nicklas 30   extends CohortWriter 
5131 21 Nov 18 nicklas 31 {
5131 21 Nov 18 nicklas 32   
5131 21 Nov 18 nicklas 33   public FlowThroughWriter(DbControl dc, ReleaseWriterOptions options)
5131 21 Nov 18 nicklas 34   {
5131 21 Nov 18 nicklas 35     super(dc, options);
5131 21 Nov 18 nicklas 36   }
5131 21 Nov 18 nicklas 37   
5131 21 Nov 18 nicklas 38   @Override
5131 21 Nov 18 nicklas 39   public JSONArray toJSONObjects(CohortItem item)
5131 21 Nov 18 nicklas 40   {
5132 21 Nov 18 nicklas 41     List<FlowThrough> ftList = item.getFlowThrough();
5131 21 Nov 18 nicklas 42     if (ftList.size() == 0) return null;
5131 21 Nov 18 nicklas 43     
5131 21 Nov 18 nicklas 44     JSONArray json = new JSONArray();
5132 21 Nov 18 nicklas 45     for (FlowThrough ft : ftList)
5131 21 Nov 18 nicklas 46     {
5132 21 Nov 18 nicklas 47       Extract flowThrough = ft.getExtract();
5132 21 Nov 18 nicklas 48       Lysate lys = ft.getLysate();
5170 03 Dec 18 nicklas 49       BioMaterialEvent creationEvent = flowThrough.getCreationEvent();
5131 21 Nov 18 nicklas 50       
5131 21 Nov 18 nicklas 51       DbControl dc = item.getDbControl();
5131 21 Nov 18 nicklas 52       SnapshotManager manager = item.getSnapshotManager();
5131 21 Nov 18 nicklas 53       
5131 21 Nov 18 nicklas 54       JSONObject jsonFt = new JSONObject();
5132 21 Nov 18 nicklas 55       jsonFt.put("name", item.toReleaseId(flowThrough.getName()));
5132 21 Nov 18 nicklas 56       jsonFt.put("type", flowThrough.getType().name());
5132 21 Nov 18 nicklas 57       jsonFt.put("subtype", getName(flowThrough.getItemSubtype()));
5131 21 Nov 18 nicklas 58       jsonFt.put("parent", item.toReleaseId(lys.getName()));
5131 21 Nov 18 nicklas 59       
5131 21 Nov 18 nicklas 60       JSONArray jsonAnnotations = new FilteredJSONArray(new NotNullFilter<>(false));
5131 21 Nov 18 nicklas 61       jsonFt.put("annotations", jsonAnnotations);
5131 21 Nov 18 nicklas 62       
5132 21 Nov 18 nicklas 63       String qiacubeDate = Reggie.CONVERTER_DATE_TO_STRING.convert((Date)item.getAnnotationValue(Annotationtype.QIACUBE_DATE, flowThrough));
5132 21 Nov 18 nicklas 64       Integer qiacubeRunNo = (Integer)item.getAnnotationValue(Annotationtype.QIACUBE_RUN_NO, flowThrough);
5131 21 Nov 18 nicklas 65       qiacubeDate += qiacubeRunNo == null ? ":0" : ":"+qiacubeRunNo;
5131 21 Nov 18 nicklas 66
5131 21 Nov 18 nicklas 67       jsonAnnotations.add(item.createBatchIndexAnnotationJSON("QiacubeBatchNo", qiacubeDate));
5170 03 Dec 18 nicklas 68       jsonAnnotations.add(item.createAnnotationJSON("Protocol", getName(creationEvent.getProtocol())));
5170 03 Dec 18 nicklas 69       jsonAnnotations.add(item.createAnnotationJSON("FTOriginalVolume", flowThrough.getOriginalQuantity()));
5170 03 Dec 18 nicklas 70       jsonAnnotations.add(item.createAnnotationJSON("FTRemainingVolume", flowThrough.getRemainingQuantity()));
5131 21 Nov 18 nicklas 71
5131 21 Nov 18 nicklas 72       json.add(jsonFt);
5131 21 Nov 18 nicklas 73     }
5131 21 Nov 18 nicklas 74     
5131 21 Nov 18 nicklas 75     return json;
5131 21 Nov 18 nicklas 76   }
5131 21 Nov 18 nicklas 77   
5131 21 Nov 18 nicklas 78   @Override
5131 21 Nov 18 nicklas 79   public List<CohortTypeDef> getTypeDefsInJSON()
5131 21 Nov 18 nicklas 80   {
5131 21 Nov 18 nicklas 81     DbControl dc = getDbControl();
5131 21 Nov 18 nicklas 82     CohortTypeDefFactory ftFactory = new CohortTypeDefFactory(dc, Item.EXTRACT, "FlowThrough");
5131 21 Nov 18 nicklas 83
5170 03 Dec 18 nicklas 84     Unit µl = UnitUtil.getUnit(dc, Quantity.VOLUME, "µl");
5170 03 Dec 18 nicklas 85
5131 21 Nov 18 nicklas 86     // FlowThrough annotations
5131 21 Nov 18 nicklas 87     ftFactory.createAnnotationType("QiacubeBatchNo", Type.INT).setProjectSpecificValues(true);
5170 03 Dec 18 nicklas 88     ftFactory.createAnnotationType("Protocol", Type.STRING);
5170 03 Dec 18 nicklas 89     ftFactory.createAnnotationType("FTOriginalVolume", Type.FLOAT).setUnit(µl);
5170 03 Dec 18 nicklas 90     ftFactory.createAnnotationType("FTRemainingVolume", Type.FLOAT).setUnit(µl).setProjectSpecificValues(true);
5131 21 Nov 18 nicklas 91     
5131 21 Nov 18 nicklas 92     return ftFactory.allCreated();
5131 21 Nov 18 nicklas 93   }
5131 21 Nov 18 nicklas 94
5131 21 Nov 18 nicklas 95 }