2098 |
23 Oct 13 |
nicklas |
1 |
package net.sf.basedb.reggie.dao; |
2098 |
23 Oct 13 |
nicklas |
2 |
|
2098 |
23 Oct 13 |
nicklas |
3 |
import java.util.ArrayList; |
2098 |
23 Oct 13 |
nicklas |
4 |
import java.util.Collection; |
2098 |
23 Oct 13 |
nicklas |
5 |
import java.util.List; |
2098 |
23 Oct 13 |
nicklas |
6 |
|
2098 |
23 Oct 13 |
nicklas |
7 |
import org.json.simple.JSONObject; |
2098 |
23 Oct 13 |
nicklas |
8 |
|
2098 |
23 Oct 13 |
nicklas |
9 |
import net.sf.basedb.core.DbControl; |
2098 |
23 Oct 13 |
nicklas |
10 |
import net.sf.basedb.core.Extract; |
2098 |
23 Oct 13 |
nicklas |
11 |
import net.sf.basedb.core.ItemQuery; |
2098 |
23 Oct 13 |
nicklas |
12 |
import net.sf.basedb.core.Type; |
2098 |
23 Oct 13 |
nicklas |
13 |
import net.sf.basedb.core.query.Expressions; |
2098 |
23 Oct 13 |
nicklas |
14 |
import net.sf.basedb.core.query.Hql; |
2917 |
11 Nov 14 |
nicklas |
15 |
import net.sf.basedb.core.query.Orders; |
2098 |
23 Oct 13 |
nicklas |
16 |
import net.sf.basedb.core.query.Restrictions; |
2098 |
23 Oct 13 |
nicklas |
17 |
import net.sf.basedb.reggie.JsonUtil; |
2917 |
11 Nov 14 |
nicklas |
18 |
import net.sf.basedb.reggie.Reggie; |
2098 |
23 Oct 13 |
nicklas |
19 |
|
2098 |
23 Oct 13 |
nicklas |
20 |
/** |
2098 |
23 Oct 13 |
nicklas |
Class for loading information that is related to FlowThrough extracts. |
2098 |
23 Oct 13 |
nicklas |
22 |
|
2098 |
23 Oct 13 |
nicklas |
@author nicklas |
2098 |
23 Oct 13 |
nicklas |
@since 2.13 |
2098 |
23 Oct 13 |
nicklas |
25 |
*/ |
2098 |
23 Oct 13 |
nicklas |
26 |
public class FlowThrough |
2098 |
23 Oct 13 |
nicklas |
27 |
extends ReggieItem<Extract> |
2098 |
23 Oct 13 |
nicklas |
28 |
{ |
2098 |
23 Oct 13 |
nicklas |
29 |
|
2098 |
23 Oct 13 |
nicklas |
30 |
|
2098 |
23 Oct 13 |
nicklas |
31 |
/** |
2098 |
23 Oct 13 |
nicklas |
Find all FlowThrough items by case name. This method will check for {@link Subtype#FLOW_THROUGH} |
2098 |
23 Oct 13 |
nicklas |
extracts with a name matching the case name (eg. xxx.d). |
2098 |
23 Oct 13 |
nicklas |
34 |
*/ |
2098 |
23 Oct 13 |
nicklas |
35 |
public static List<FlowThrough> findByCaseName(DbControl dc, String name) |
2098 |
23 Oct 13 |
nicklas |
36 |
{ |
2098 |
23 Oct 13 |
nicklas |
// Get rid of suffixes in the name (eg. 'C' which is used for pre-neoadjuvant forms) |
2098 |
23 Oct 13 |
nicklas |
38 |
if (name.length() > 7) name = name.substring(0, 7); |
2098 |
23 Oct 13 |
nicklas |
39 |
|
2098 |
23 Oct 13 |
nicklas |
// Look for a flow through with the given name |
2098 |
23 Oct 13 |
nicklas |
41 |
ItemQuery<Extract> ftQuery = Extract.getQuery(); |
2098 |
23 Oct 13 |
nicklas |
42 |
Subtype.FLOW_THROUGH.addFilter(dc, ftQuery); |
2917 |
11 Nov 14 |
nicklas |
43 |
ftQuery.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT); |
2098 |
23 Oct 13 |
nicklas |
44 |
ftQuery.restrict(Restrictions.like(Hql.property("name"), Expressions.parameter("name", name+".%", Type.STRING))); |
2917 |
11 Nov 14 |
nicklas |
45 |
ftQuery.order(Orders.asc(Hql.property("name"))); |
2917 |
11 Nov 14 |
nicklas |
46 |
|
2098 |
23 Oct 13 |
nicklas |
47 |
List<Extract> tmp = ftQuery.list(dc); |
2098 |
23 Oct 13 |
nicklas |
48 |
List<FlowThrough> ft = new ArrayList<FlowThrough>(tmp.size()); |
2098 |
23 Oct 13 |
nicklas |
49 |
for (Extract e : tmp) |
2098 |
23 Oct 13 |
nicklas |
50 |
{ |
2098 |
23 Oct 13 |
nicklas |
51 |
ft.add(new FlowThrough(e)); |
2098 |
23 Oct 13 |
nicklas |
52 |
} |
2098 |
23 Oct 13 |
nicklas |
53 |
return ft; |
2098 |
23 Oct 13 |
nicklas |
54 |
} |
2098 |
23 Oct 13 |
nicklas |
55 |
|
2098 |
23 Oct 13 |
nicklas |
56 |
|
2098 |
23 Oct 13 |
nicklas |
57 |
/** |
2098 |
23 Oct 13 |
nicklas |
Get a FlowThrough extract when the id is known. |
2098 |
23 Oct 13 |
nicklas |
59 |
*/ |
2098 |
23 Oct 13 |
nicklas |
60 |
public static FlowThrough getById(DbControl dc, int id) |
2098 |
23 Oct 13 |
nicklas |
61 |
{ |
2098 |
23 Oct 13 |
nicklas |
62 |
return new FlowThrough(Extract.getById(dc, id)); |
2098 |
23 Oct 13 |
nicklas |
63 |
} |
2098 |
23 Oct 13 |
nicklas |
64 |
|
2098 |
23 Oct 13 |
nicklas |
65 |
public static FlowThrough get(Extract extract) |
2098 |
23 Oct 13 |
nicklas |
66 |
{ |
7142 |
04 May 23 |
nicklas |
67 |
return extract == null ? null : new FlowThrough(extract); |
2098 |
23 Oct 13 |
nicklas |
68 |
} |
2098 |
23 Oct 13 |
nicklas |
69 |
|
2098 |
23 Oct 13 |
nicklas |
70 |
public static List<FlowThrough> toFlowThrough(Collection<Extract> extracts) |
2098 |
23 Oct 13 |
nicklas |
71 |
{ |
2098 |
23 Oct 13 |
nicklas |
72 |
List<FlowThrough> ft = new ArrayList<FlowThrough>(extracts.size()); |
2098 |
23 Oct 13 |
nicklas |
73 |
for (Extract e : extracts) |
2098 |
23 Oct 13 |
nicklas |
74 |
{ |
2098 |
23 Oct 13 |
nicklas |
75 |
ft.add(new FlowThrough(e)); |
2098 |
23 Oct 13 |
nicklas |
76 |
} |
2098 |
23 Oct 13 |
nicklas |
77 |
return ft; |
2098 |
23 Oct 13 |
nicklas |
78 |
} |
2098 |
23 Oct 13 |
nicklas |
79 |
|
2098 |
23 Oct 13 |
nicklas |
80 |
private JSONObject jsonWell; |
2098 |
23 Oct 13 |
nicklas |
81 |
|
2098 |
23 Oct 13 |
nicklas |
82 |
private FlowThrough(Extract extract) |
2098 |
23 Oct 13 |
nicklas |
83 |
{ |
2098 |
23 Oct 13 |
nicklas |
84 |
super(extract); |
2098 |
23 Oct 13 |
nicklas |
85 |
} |
2098 |
23 Oct 13 |
nicklas |
86 |
|
2098 |
23 Oct 13 |
nicklas |
87 |
|
2098 |
23 Oct 13 |
nicklas |
88 |
/** |
2098 |
23 Oct 13 |
nicklas |
Get the real extract that represents this FlowThrough item in BASE. |
2098 |
23 Oct 13 |
nicklas |
90 |
*/ |
2098 |
23 Oct 13 |
nicklas |
91 |
public Extract getExtract() |
2098 |
23 Oct 13 |
nicklas |
92 |
{ |
2098 |
23 Oct 13 |
nicklas |
93 |
return getItem(); |
2098 |
23 Oct 13 |
nicklas |
94 |
} |
2098 |
23 Oct 13 |
nicklas |
95 |
|
5133 |
21 Nov 18 |
nicklas |
96 |
/** |
5133 |
21 Nov 18 |
nicklas |
@since 4.21 |
5133 |
21 Nov 18 |
nicklas |
98 |
*/ |
5133 |
21 Nov 18 |
nicklas |
99 |
public Lysate getLysate() |
5133 |
21 Nov 18 |
nicklas |
100 |
{ |
5133 |
21 Nov 18 |
nicklas |
101 |
Extract ft = getItem(); |
5133 |
21 Nov 18 |
nicklas |
102 |
Extract lysate = (Extract)ft.getParent(); |
5133 |
21 Nov 18 |
nicklas |
103 |
return lysate == null ? null : Lysate.get(lysate); |
5133 |
21 Nov 18 |
nicklas |
104 |
} |
5133 |
21 Nov 18 |
nicklas |
105 |
|
2098 |
23 Oct 13 |
nicklas |
106 |
@Override |
2098 |
23 Oct 13 |
nicklas |
107 |
protected void initJSON(JSONObject json) |
2098 |
23 Oct 13 |
nicklas |
108 |
{ |
2098 |
23 Oct 13 |
nicklas |
109 |
super.initJSON(json); |
2098 |
23 Oct 13 |
nicklas |
110 |
if (jsonWell != null) json.put("bioWell", jsonWell); |
2098 |
23 Oct 13 |
nicklas |
111 |
|
2098 |
23 Oct 13 |
nicklas |
112 |
} |
2098 |
23 Oct 13 |
nicklas |
113 |
|
2098 |
23 Oct 13 |
nicklas |
114 |
/** |
2098 |
23 Oct 13 |
nicklas |
Load information about the plate and location the current FlowThrough |
2098 |
23 Oct 13 |
nicklas |
is located on. |
2098 |
23 Oct 13 |
nicklas |
117 |
*/ |
2098 |
23 Oct 13 |
nicklas |
118 |
public JSONObject loadBioPlateLocation() |
2098 |
23 Oct 13 |
nicklas |
119 |
{ |
2098 |
23 Oct 13 |
nicklas |
120 |
if (jsonWell == null) |
2098 |
23 Oct 13 |
nicklas |
121 |
{ |
2134 |
11 Nov 13 |
nicklas |
122 |
jsonWell = JsonUtil.getBioWellAsJSON(getItem().getBioWell(), true); |
2098 |
23 Oct 13 |
nicklas |
123 |
} |
2098 |
23 Oct 13 |
nicklas |
124 |
return jsonWell; |
2098 |
23 Oct 13 |
nicklas |
125 |
} |
2098 |
23 Oct 13 |
nicklas |
126 |
|
2098 |
23 Oct 13 |
nicklas |
127 |
} |