2722 |
02 Oct 14 |
nicklas |
1 |
package net.sf.basedb.reggie.dao; |
2722 |
02 Oct 14 |
nicklas |
2 |
|
2722 |
02 Oct 14 |
nicklas |
3 |
import java.util.ArrayList; |
2722 |
02 Oct 14 |
nicklas |
4 |
import java.util.List; |
2722 |
02 Oct 14 |
nicklas |
5 |
|
2722 |
02 Oct 14 |
nicklas |
6 |
import org.json.simple.JSONObject; |
2722 |
02 Oct 14 |
nicklas |
7 |
|
2722 |
02 Oct 14 |
nicklas |
8 |
import net.sf.basedb.core.ArrayDesign; |
2722 |
02 Oct 14 |
nicklas |
9 |
import net.sf.basedb.core.DbControl; |
2722 |
02 Oct 14 |
nicklas |
10 |
import net.sf.basedb.core.InvalidDataException; |
3069 |
09 Jan 15 |
nicklas |
11 |
import net.sf.basedb.core.Item; |
2722 |
02 Oct 14 |
nicklas |
12 |
import net.sf.basedb.core.ItemQuery; |
3069 |
09 Jan 15 |
nicklas |
13 |
import net.sf.basedb.core.PlatformVariant; |
3069 |
09 Jan 15 |
nicklas |
14 |
import net.sf.basedb.core.Project; |
2722 |
02 Oct 14 |
nicklas |
15 |
import net.sf.basedb.core.Type; |
2722 |
02 Oct 14 |
nicklas |
16 |
import net.sf.basedb.core.query.Expressions; |
2722 |
02 Oct 14 |
nicklas |
17 |
import net.sf.basedb.core.query.Hql; |
2722 |
02 Oct 14 |
nicklas |
18 |
import net.sf.basedb.core.query.Orders; |
2722 |
02 Oct 14 |
nicklas |
19 |
import net.sf.basedb.core.query.Restrictions; |
2722 |
02 Oct 14 |
nicklas |
20 |
import net.sf.basedb.reggie.Reggie; |
6819 |
26 Aug 22 |
nicklas |
21 |
import net.sf.basedb.util.filter.Filter; |
2722 |
02 Oct 14 |
nicklas |
22 |
|
2722 |
02 Oct 14 |
nicklas |
23 |
/** |
2722 |
02 Oct 14 |
nicklas |
Class for loading information about array designs. |
2722 |
02 Oct 14 |
nicklas |
25 |
|
2722 |
02 Oct 14 |
nicklas |
@author nicklas |
2722 |
02 Oct 14 |
nicklas |
@since 2.17 |
2722 |
02 Oct 14 |
nicklas |
28 |
*/ |
2722 |
02 Oct 14 |
nicklas |
29 |
public class Arraydesign |
2722 |
02 Oct 14 |
nicklas |
30 |
extends ReggieItem<ArrayDesign> |
2722 |
02 Oct 14 |
nicklas |
31 |
{ |
2722 |
02 Oct 14 |
nicklas |
32 |
|
2722 |
02 Oct 14 |
nicklas |
33 |
|
2722 |
02 Oct 14 |
nicklas |
34 |
/** |
2722 |
02 Oct 14 |
nicklas |
Find all array design for the given sequencing platform variant. |
2722 |
02 Oct 14 |
nicklas |
36 |
*/ |
6819 |
26 Aug 22 |
nicklas |
37 |
public static List<Arraydesign> findByPlatformVariant(DbControl dc, String variantId, Filter<? super ArrayDesign> filter) |
2722 |
02 Oct 14 |
nicklas |
38 |
{ |
2722 |
02 Oct 14 |
nicklas |
39 |
ItemQuery<ArrayDesign> query = ArrayDesign.getQuery(); |
2722 |
02 Oct 14 |
nicklas |
40 |
query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT); |
2722 |
02 Oct 14 |
nicklas |
41 |
query.join(Hql.innerJoin("variant", "v")); |
2722 |
02 Oct 14 |
nicklas |
42 |
query.restrict(Restrictions.eq(Hql.property("v", "externalId"), Expressions.string(variantId))); |
2722 |
02 Oct 14 |
nicklas |
43 |
query.order(Orders.asc(Hql.property("name"))); |
2722 |
02 Oct 14 |
nicklas |
44 |
|
2722 |
02 Oct 14 |
nicklas |
45 |
List<ArrayDesign> tmp = query.list(dc); |
2722 |
02 Oct 14 |
nicklas |
46 |
List<Arraydesign> designs = new ArrayList<Arraydesign>(tmp.size()); |
2722 |
02 Oct 14 |
nicklas |
47 |
for (ArrayDesign design : tmp) |
2722 |
02 Oct 14 |
nicklas |
48 |
{ |
6819 |
26 Aug 22 |
nicklas |
49 |
if (filter == null || filter.evaluate(design)) |
6819 |
26 Aug 22 |
nicklas |
50 |
{ |
6819 |
26 Aug 22 |
nicklas |
51 |
designs.add(new Arraydesign(design)); |
6819 |
26 Aug 22 |
nicklas |
52 |
} |
2722 |
02 Oct 14 |
nicklas |
53 |
} |
2722 |
02 Oct 14 |
nicklas |
54 |
return designs; |
2722 |
02 Oct 14 |
nicklas |
55 |
} |
2722 |
02 Oct 14 |
nicklas |
56 |
|
2722 |
02 Oct 14 |
nicklas |
57 |
/** |
3069 |
09 Jan 15 |
nicklas |
Get the latest array design that is the project default item with the |
3069 |
09 Jan 15 |
nicklas |
given platform variant. In this case, an item with a higher ID is considerd |
3069 |
09 Jan 15 |
nicklas |
later than an item with a lower ID. |
6819 |
26 Aug 22 |
nicklas |
@since 3.0, 4.40 |
3069 |
09 Jan 15 |
nicklas |
62 |
*/ |
6819 |
26 Aug 22 |
nicklas |
63 |
public static Arraydesign getLatestProjectDefault(DbControl dc, String variantId, Filter<? super ArrayDesign> filter) |
3069 |
09 Jan 15 |
nicklas |
64 |
{ |
3069 |
09 Jan 15 |
nicklas |
65 |
int projectId = dc.getSessionControl().getActiveProjectId(); |
3069 |
09 Jan 15 |
nicklas |
66 |
ArrayDesign bestMatch = null; |
3069 |
09 Jan 15 |
nicklas |
67 |
if (projectId != 0) |
3069 |
09 Jan 15 |
nicklas |
68 |
{ |
3069 |
09 Jan 15 |
nicklas |
69 |
PlatformVariant variant = PlatformVariant.getByExternalId(dc, variantId); |
3069 |
09 Jan 15 |
nicklas |
70 |
Project p = Project.getById(dc, projectId); |
5363 |
16 Apr 19 |
nicklas |
71 |
List<ArrayDesign> defaultItems = p.findDefaultItems(dc, Item.ARRAYDESIGN, false); |
3069 |
09 Jan 15 |
nicklas |
72 |
for (ArrayDesign item : defaultItems) |
3069 |
09 Jan 15 |
nicklas |
73 |
{ |
3069 |
09 Jan 15 |
nicklas |
74 |
if (!variant.equals(item.getVariant())) continue; |
3069 |
09 Jan 15 |
nicklas |
75 |
|
3069 |
09 Jan 15 |
nicklas |
76 |
if (bestMatch == null || bestMatch.getId() < item.getId()) |
3069 |
09 Jan 15 |
nicklas |
77 |
{ |
6819 |
26 Aug 22 |
nicklas |
78 |
if (filter == null || filter.evaluate(item)) |
6819 |
26 Aug 22 |
nicklas |
79 |
{ |
6819 |
26 Aug 22 |
nicklas |
80 |
bestMatch = item; |
6819 |
26 Aug 22 |
nicklas |
81 |
} |
3069 |
09 Jan 15 |
nicklas |
82 |
} |
3069 |
09 Jan 15 |
nicklas |
83 |
} |
3069 |
09 Jan 15 |
nicklas |
84 |
} |
3069 |
09 Jan 15 |
nicklas |
85 |
return bestMatch == null ? null : new Arraydesign(bestMatch); |
3069 |
09 Jan 15 |
nicklas |
86 |
} |
3069 |
09 Jan 15 |
nicklas |
87 |
|
3069 |
09 Jan 15 |
nicklas |
88 |
|
3069 |
09 Jan 15 |
nicklas |
89 |
/** |
2722 |
02 Oct 14 |
nicklas |
Find the array design with the given name. |
2722 |
02 Oct 14 |
nicklas |
91 |
*/ |
2722 |
02 Oct 14 |
nicklas |
92 |
public static Arraydesign findByName(DbControl dc, String name) |
2722 |
02 Oct 14 |
nicklas |
93 |
{ |
2722 |
02 Oct 14 |
nicklas |
94 |
|
2722 |
02 Oct 14 |
nicklas |
95 |
ItemQuery<ArrayDesign> query = ArrayDesign.getQuery(); |
2722 |
02 Oct 14 |
nicklas |
96 |
query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT); |
2722 |
02 Oct 14 |
nicklas |
97 |
query.restrict(Restrictions.eq(Hql.property("name"), Expressions.parameter("name", name, Type.STRING))); |
2722 |
02 Oct 14 |
nicklas |
98 |
|
2722 |
02 Oct 14 |
nicklas |
99 |
List<ArrayDesign> tmp = query.list(dc); |
2722 |
02 Oct 14 |
nicklas |
100 |
Arraydesign design = null; |
2722 |
02 Oct 14 |
nicklas |
101 |
|
2722 |
02 Oct 14 |
nicklas |
102 |
if (tmp.size() > 1) |
2722 |
02 Oct 14 |
nicklas |
103 |
{ |
2722 |
02 Oct 14 |
nicklas |
104 |
throw new InvalidDataException( |
2722 |
02 Oct 14 |
nicklas |
105 |
"Found " + tmp.size() + " array designs with the same name (" + name + |
2722 |
02 Oct 14 |
nicklas |
106 |
"). This wizard can't be used until that is corrected."); |
2722 |
02 Oct 14 |
nicklas |
107 |
} |
2722 |
02 Oct 14 |
nicklas |
108 |
else if (tmp.size() == 1) |
2722 |
02 Oct 14 |
nicklas |
109 |
{ |
2722 |
02 Oct 14 |
nicklas |
110 |
design = new Arraydesign(tmp.get(0)); |
2722 |
02 Oct 14 |
nicklas |
111 |
} |
2722 |
02 Oct 14 |
nicklas |
112 |
return design; |
2722 |
02 Oct 14 |
nicklas |
113 |
} |
2722 |
02 Oct 14 |
nicklas |
114 |
|
2722 |
02 Oct 14 |
nicklas |
115 |
public static Arraydesign getById(DbControl dc, int arrayDesignId) |
2722 |
02 Oct 14 |
nicklas |
116 |
{ |
2722 |
02 Oct 14 |
nicklas |
117 |
ArrayDesign design = ArrayDesign.getById(dc, arrayDesignId); |
2722 |
02 Oct 14 |
nicklas |
118 |
return design == null ? null : new Arraydesign(design); |
2722 |
02 Oct 14 |
nicklas |
119 |
} |
2722 |
02 Oct 14 |
nicklas |
120 |
|
2722 |
02 Oct 14 |
nicklas |
121 |
|
2722 |
02 Oct 14 |
nicklas |
122 |
private Arraydesign(ArrayDesign design) |
2722 |
02 Oct 14 |
nicklas |
123 |
{ |
2722 |
02 Oct 14 |
nicklas |
124 |
super(design); |
2722 |
02 Oct 14 |
nicklas |
125 |
} |
2722 |
02 Oct 14 |
nicklas |
126 |
|
2722 |
02 Oct 14 |
nicklas |
127 |
|
2722 |
02 Oct 14 |
nicklas |
128 |
/** |
2722 |
02 Oct 14 |
nicklas |
Get the array design item that represents this in BASE. |
2722 |
02 Oct 14 |
nicklas |
130 |
*/ |
2722 |
02 Oct 14 |
nicklas |
131 |
public ArrayDesign getArrayDesign() |
2722 |
02 Oct 14 |
nicklas |
132 |
{ |
2722 |
02 Oct 14 |
nicklas |
133 |
return getItem(); |
2722 |
02 Oct 14 |
nicklas |
134 |
} |
2722 |
02 Oct 14 |
nicklas |
135 |
|
2722 |
02 Oct 14 |
nicklas |
136 |
@Override |
2722 |
02 Oct 14 |
nicklas |
137 |
protected void initJSON(JSONObject json) |
2722 |
02 Oct 14 |
nicklas |
138 |
{ |
2722 |
02 Oct 14 |
nicklas |
139 |
super.initJSON(json); |
2722 |
02 Oct 14 |
nicklas |
140 |
ArrayDesign ad = getItem(); |
4667 |
01 Feb 18 |
nicklas |
141 |
if (ad.isFileOnlyPlatform()) |
4667 |
01 Feb 18 |
nicklas |
142 |
{ |
4667 |
01 Feb 18 |
nicklas |
143 |
json.put("numFeatures", ad.getNumFileFeatures()); |
4667 |
01 Feb 18 |
nicklas |
144 |
} |
4667 |
01 Feb 18 |
nicklas |
145 |
else |
4667 |
01 Feb 18 |
nicklas |
146 |
{ |
4667 |
01 Feb 18 |
nicklas |
147 |
json.put("numFeatures", ad.getNumDbFeatures()); |
4667 |
01 Feb 18 |
nicklas |
148 |
} |
2722 |
02 Oct 14 |
nicklas |
149 |
} |
2722 |
02 Oct 14 |
nicklas |
150 |
|
2722 |
02 Oct 14 |
nicklas |
151 |
|
2722 |
02 Oct 14 |
nicklas |
152 |
} |