4379 |
06 Mar 17 |
nicklas |
1 |
package net.sf.basedb.reggie.plugins.release; |
4379 |
06 Mar 17 |
nicklas |
2 |
|
4437 |
31 Mar 17 |
nicklas |
3 |
import java.util.Arrays; |
4379 |
06 Mar 17 |
nicklas |
4 |
import java.util.List; |
4379 |
06 Mar 17 |
nicklas |
5 |
|
4379 |
06 Mar 17 |
nicklas |
6 |
import org.json.simple.JSONArray; |
4379 |
06 Mar 17 |
nicklas |
7 |
import org.json.simple.JSONObject; |
4379 |
06 Mar 17 |
nicklas |
8 |
|
4379 |
06 Mar 17 |
nicklas |
9 |
import net.sf.basedb.core.Item; |
4379 |
06 Mar 17 |
nicklas |
10 |
import net.sf.basedb.core.Type; |
4462 |
21 Apr 17 |
nicklas |
11 |
import net.sf.basedb.core.Unit; |
4379 |
06 Mar 17 |
nicklas |
12 |
|
4379 |
06 Mar 17 |
nicklas |
13 |
/** |
4408 |
20 Mar 17 |
nicklas |
Basic type-def implementation of an annotation type used |
4408 |
20 Mar 17 |
nicklas |
in the cohort data. Required properties are set by the constructor. |
4408 |
20 Mar 17 |
nicklas |
Other properties can be set by setter methods. |
4379 |
06 Mar 17 |
nicklas |
17 |
|
4379 |
06 Mar 17 |
nicklas |
@author nicklas |
4379 |
06 Mar 17 |
nicklas |
@since 4.10 |
4379 |
06 Mar 17 |
nicklas |
20 |
*/ |
4469 |
26 Apr 17 |
nicklas |
21 |
public class CohortAnnotationType |
4408 |
20 Mar 17 |
nicklas |
22 |
implements CohortTypeDef |
4379 |
06 Mar 17 |
nicklas |
23 |
{ |
4379 |
06 Mar 17 |
nicklas |
24 |
|
4513 |
31 May 17 |
nicklas |
25 |
private String name; |
4379 |
06 Mar 17 |
nicklas |
26 |
private final Type valueType; |
4379 |
06 Mar 17 |
nicklas |
27 |
private final Item itemType; |
4379 |
06 Mar 17 |
nicklas |
28 |
private final String subtype; |
4379 |
06 Mar 17 |
nicklas |
29 |
private List<?> enumeration; |
4389 |
09 Mar 17 |
nicklas |
30 |
private boolean projectSpecificValues; |
4462 |
21 Apr 17 |
nicklas |
31 |
private Unit unit; |
4379 |
06 Mar 17 |
nicklas |
32 |
|
4469 |
26 Apr 17 |
nicklas |
33 |
public CohortAnnotationType(String name, Type valueType, Item itemType, String subtype) |
4379 |
06 Mar 17 |
nicklas |
34 |
{ |
4379 |
06 Mar 17 |
nicklas |
35 |
this.name = name; |
4379 |
06 Mar 17 |
nicklas |
36 |
this.valueType = valueType; |
4379 |
06 Mar 17 |
nicklas |
37 |
this.itemType = itemType; |
4379 |
06 Mar 17 |
nicklas |
38 |
this.subtype = subtype; |
4379 |
06 Mar 17 |
nicklas |
39 |
} |
4379 |
06 Mar 17 |
nicklas |
40 |
|
4379 |
06 Mar 17 |
nicklas |
41 |
@Override |
4379 |
06 Mar 17 |
nicklas |
42 |
public String getName() |
4379 |
06 Mar 17 |
nicklas |
43 |
{ |
4379 |
06 Mar 17 |
nicklas |
44 |
return name; |
4379 |
06 Mar 17 |
nicklas |
45 |
} |
4513 |
31 May 17 |
nicklas |
46 |
|
4513 |
31 May 17 |
nicklas |
47 |
public CohortAnnotationType rename(String name) |
4513 |
31 May 17 |
nicklas |
48 |
{ |
4513 |
31 May 17 |
nicklas |
49 |
this.name = name; |
4513 |
31 May 17 |
nicklas |
50 |
return this; |
4513 |
31 May 17 |
nicklas |
51 |
} |
4379 |
06 Mar 17 |
nicklas |
52 |
|
4469 |
26 Apr 17 |
nicklas |
53 |
public CohortAnnotationType setEnumeration(List<?> values) |
4379 |
06 Mar 17 |
nicklas |
54 |
{ |
4379 |
06 Mar 17 |
nicklas |
55 |
this.enumeration = values; |
4469 |
26 Apr 17 |
nicklas |
56 |
return this; |
4379 |
06 Mar 17 |
nicklas |
57 |
} |
4379 |
06 Mar 17 |
nicklas |
58 |
|
4469 |
26 Apr 17 |
nicklas |
59 |
public CohortAnnotationType setEnumeration(String... values) |
4437 |
31 Mar 17 |
nicklas |
60 |
{ |
4437 |
31 Mar 17 |
nicklas |
61 |
this.enumeration = Arrays.asList(values); |
4469 |
26 Apr 17 |
nicklas |
62 |
return this; |
4437 |
31 Mar 17 |
nicklas |
63 |
} |
4437 |
31 Mar 17 |
nicklas |
64 |
|
4469 |
26 Apr 17 |
nicklas |
65 |
public CohortAnnotationType setProjectSpecificValues(boolean projectSpecificValues) |
4389 |
09 Mar 17 |
nicklas |
66 |
{ |
4389 |
09 Mar 17 |
nicklas |
67 |
this.projectSpecificValues = projectSpecificValues; |
4469 |
26 Apr 17 |
nicklas |
68 |
return this; |
4389 |
09 Mar 17 |
nicklas |
69 |
} |
4389 |
09 Mar 17 |
nicklas |
70 |
|
4469 |
26 Apr 17 |
nicklas |
71 |
public CohortAnnotationType setUnit(Unit unit) |
4462 |
21 Apr 17 |
nicklas |
72 |
{ |
4462 |
21 Apr 17 |
nicklas |
73 |
this.unit = unit; |
4469 |
26 Apr 17 |
nicklas |
74 |
return this; |
4462 |
21 Apr 17 |
nicklas |
75 |
} |
4462 |
21 Apr 17 |
nicklas |
76 |
|
4379 |
06 Mar 17 |
nicklas |
77 |
@Override |
4379 |
06 Mar 17 |
nicklas |
78 |
public JSONObject toJSONObject() |
4379 |
06 Mar 17 |
nicklas |
79 |
{ |
4379 |
06 Mar 17 |
nicklas |
80 |
JSONObject json = new JSONObject(); |
4379 |
06 Mar 17 |
nicklas |
81 |
|
4407 |
20 Mar 17 |
nicklas |
82 |
json.put("type", Item.ANNOTATIONTYPE.name()); |
4379 |
06 Mar 17 |
nicklas |
83 |
json.put("name", name); |
4379 |
06 Mar 17 |
nicklas |
84 |
json.put("valueType", valueType.name()); |
4379 |
06 Mar 17 |
nicklas |
85 |
json.put("itemType", itemType.name()); |
4402 |
17 Mar 17 |
nicklas |
86 |
if (subtype != null) |
4402 |
17 Mar 17 |
nicklas |
87 |
{ |
4402 |
17 Mar 17 |
nicklas |
88 |
json.put("subtype", subtype); |
4402 |
17 Mar 17 |
nicklas |
89 |
} |
4389 |
09 Mar 17 |
nicklas |
90 |
if (projectSpecificValues) |
4389 |
09 Mar 17 |
nicklas |
91 |
{ |
4389 |
09 Mar 17 |
nicklas |
92 |
json.put("projectSpecificValues", true); |
4389 |
09 Mar 17 |
nicklas |
93 |
} |
4379 |
06 Mar 17 |
nicklas |
94 |
|
4379 |
06 Mar 17 |
nicklas |
95 |
if (enumeration != null && enumeration.size() > 0) |
4379 |
06 Mar 17 |
nicklas |
96 |
{ |
4379 |
06 Mar 17 |
nicklas |
97 |
JSONArray jsonEnum = new JSONArray(); |
4379 |
06 Mar 17 |
nicklas |
98 |
jsonEnum.addAll(enumeration); |
4379 |
06 Mar 17 |
nicklas |
99 |
json.put("enumeration", jsonEnum); |
4379 |
06 Mar 17 |
nicklas |
100 |
} |
4379 |
06 Mar 17 |
nicklas |
101 |
|
4462 |
21 Apr 17 |
nicklas |
102 |
if (unit != null) |
4462 |
21 Apr 17 |
nicklas |
103 |
{ |
4462 |
21 Apr 17 |
nicklas |
104 |
JSONObject jsonUnit = new JSONObject(); |
4462 |
21 Apr 17 |
nicklas |
105 |
jsonUnit.put("symbol", unit.getDisplaySymbol()); |
4462 |
21 Apr 17 |
nicklas |
106 |
jsonUnit.put("quantity", unit.getQuantity().getSystemId()); |
4462 |
21 Apr 17 |
nicklas |
107 |
json.put("unit", jsonUnit); |
4462 |
21 Apr 17 |
nicklas |
108 |
} |
4462 |
21 Apr 17 |
nicklas |
109 |
|
4379 |
06 Mar 17 |
nicklas |
110 |
return json; |
4379 |
06 Mar 17 |
nicklas |
111 |
} |
4379 |
06 Mar 17 |
nicklas |
112 |
|
4379 |
06 Mar 17 |
nicklas |
113 |
} |