1 |
779bac69
|
Marc NICOLAS
|
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
package fr.ias.sitools.filters.basic;
|
20 |
|
|
|
21 |
|
|
import java.util.ArrayList;
|
22 |
|
|
import java.util.Arrays;
|
23 |
|
|
import java.util.HashMap;
|
24 |
|
|
import java.util.List;
|
25 |
|
|
import java.util.Set;
|
26 |
|
|
|
27 |
|
|
import org.restlet.Request;
|
28 |
|
|
import org.restlet.data.Form;
|
29 |
|
|
import org.restlet.ext.wadl.ParameterInfo;
|
30 |
|
|
import org.restlet.ext.wadl.ParameterStyle;
|
31 |
|
|
|
32 |
|
|
import fr.cnes.sitools.common.validator.ConstraintViolation;
|
33 |
|
|
import fr.cnes.sitools.common.validator.Validator;
|
34 |
|
|
import fr.cnes.sitools.dataset.DataSetApplication;
|
35 |
|
|
import fr.cnes.sitools.dataset.filter.business.AbstractFilter;
|
36 |
|
|
import fr.cnes.sitools.dataset.model.Column;
|
37 |
|
|
import fr.cnes.sitools.dataset.model.DataSet;
|
38 |
|
|
import fr.cnes.sitools.dataset.model.Operator;
|
39 |
|
|
import fr.cnes.sitools.dataset.model.Predicat;
|
40 |
|
|
import fr.cnes.sitools.dataset.plugins.filters.core.AbstractFormFilter;
|
41 |
|
|
import static fr.cnes.sitools.dataset.plugins.filters.core.AbstractFormFilter.TEMPLATE_PARAM;
|
42 |
|
|
import static fr.cnes.sitools.dataset.plugins.filters.core.AbstractFormFilter.TEMPLATE_PARAM_CONCEPT;
|
43 |
|
|
import static fr.cnes.sitools.dataset.plugins.filters.core.AbstractFormFilter.VALUES;
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
public final class ListBoxSpectralTypeCorot extends AbstractFormFilter {
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
|
|
|
56 |
|
|
private enum TYPE_COMPONENT {
|
57 |
|
|
|
58 |
|
|
LISTBOXSPECTRALTYPECOROT
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
private final List<String> spectralTypeO = Arrays.asList("O5","O6","O8","O8.5","O9");
|
62 |
|
|
private final List<String> spectralTypeB = Arrays.asList("B0","B1","B2","B3","B5","B6","B8","B9","B2.5","B.5");
|
63 |
|
|
private final List<String> spectralTypeA = Arrays.asList("A0","A1","A2","A3","A4","A5","A6","A7","A8","A9");
|
64 |
|
|
private final List<String> spectralTypeF = Arrays.asList("F0","F1","F2","F3","F4","F5","F6","F7","F8","F9");
|
65 |
|
|
private final List<String> spectralTypeG = Arrays.asList("G0","G1","G2","G3","G4","G5","G6","G7","G8","G9");
|
66 |
|
|
private final List<String> spectralTypeK = Arrays.asList("K0","K1","K2","K3","K4","K5","K6","K7","K8","K9");
|
67 |
|
|
private final List<String> spectralTypeM = Arrays.asList("M","M0","M1","M2","M3","M4","M5","M6","M7","M8","M9");
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
|
|
public ListBoxSpectralTypeCorot() {
|
73 |
|
|
|
74 |
|
|
super();
|
75 |
|
|
this.setName("ListBoxSpectralTypeCorot");
|
76 |
|
|
this.setDescription("Required when using List Box Spectral Type for Corot Components");
|
77 |
|
|
|
78 |
|
|
this.setClassAuthor("Mnicolas");
|
79 |
|
|
this.setClassOwner("IAS");
|
80 |
|
|
this.setClassVersion("0.1");
|
81 |
|
|
this.setDefaultFilter(true);
|
82 |
|
|
|
83 |
|
|
HashMap<String, ParameterInfo> rpd = new HashMap<String, ParameterInfo>();
|
84 |
|
|
|
85 |
|
|
ParameterInfo paramInfo;
|
86 |
|
|
paramInfo = new ParameterInfo("p[#]", false, "xs:string", ParameterStyle.QUERY,
|
87 |
|
|
"LISTBOXSPECTRALTYPECOROT|columnAlias|value1|...|value n");
|
88 |
|
|
rpd.put("0", paramInfo);
|
89 |
|
|
this.setRequestParamsDescription(rpd);
|
90 |
|
|
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
@Override
|
94 |
|
|
public List<Predicat> createPredicats(Request request, List<Predicat> predicats) throws Exception {
|
95 |
|
|
|
96 |
|
|
DataSetApplication dsApplication = null;
|
97 |
|
|
DataSet ds = null;
|
98 |
|
|
boolean isConcept = true;
|
99 |
|
|
Form params = request.getResourceRef().getQueryAsForm();
|
100 |
|
|
boolean filterExists = true;
|
101 |
|
|
int i = 0;
|
102 |
|
|
|
103 |
|
|
while (filterExists) {
|
104 |
|
|
|
105 |
|
|
String index = TEMPLATE_PARAM_CONCEPT.replace("#", Integer.toString(i));
|
106 |
|
|
String formParam = params.getFirstValue(index);
|
107 |
|
|
if (formParam == null) {
|
108 |
|
|
isConcept = false;
|
109 |
|
|
index = TEMPLATE_PARAM.replace("#", Integer.toString(i));
|
110 |
|
|
formParam = params.getFirstValue(index);
|
111 |
|
|
}
|
112 |
|
|
i++;
|
113 |
|
|
if (formParam != null) {
|
114 |
|
|
String[] parameters = formParam.split("\\|");
|
115 |
|
|
TYPE_COMPONENT[] types = TYPE_COMPONENT.values();
|
116 |
|
|
Boolean trouve = false;
|
117 |
|
|
for (TYPE_COMPONENT typeCmp : types) {
|
118 |
|
|
if (typeCmp.name().equals(parameters[TYPE])) {
|
119 |
|
|
trouve = true;
|
120 |
|
|
}
|
121 |
|
|
}
|
122 |
|
|
if (trouve) {
|
123 |
|
|
if (dsApplication == null) {
|
124 |
|
|
dsApplication = (DataSetApplication) getContext().getAttributes().get("DataSetApplication");
|
125 |
|
|
ds = dsApplication.getDataSet();
|
126 |
|
|
}
|
127 |
|
|
String columnAlias = null;
|
128 |
|
|
if (parameters.length >= VALUES) {
|
129 |
|
|
|
130 |
|
|
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
|
137 |
|
|
columnAlias = getColumnAlias(isConcept, parameters, dsApplication);
|
138 |
|
|
if (columnAlias != null) {
|
139 |
|
|
Column col = ds.findByColumnAlias(columnAlias);
|
140 |
|
|
|
141 |
|
|
if (col != null && col.getFilter() != null && col.getFilter()) {
|
142 |
|
|
String[] values = Arrays.copyOfRange(parameters, VALUES, parameters.length);
|
143 |
|
|
Predicat predicat = new Predicat();
|
144 |
|
|
if (values != null) {
|
145 |
|
|
predicat.setLeftAttribute(col);
|
146 |
|
|
predicat.setNbOpenedParanthesis(0);
|
147 |
|
|
predicat.setNbClosedParanthesis(0);
|
148 |
|
|
predicat.setCompareOperator(Operator.IN);
|
149 |
|
|
|
150 |
|
|
boolean all = false;
|
151 |
|
|
List<String> spectralTypeSeeked = new ArrayList<String>();
|
152 |
|
|
for (String value : values) {
|
153 |
|
|
if(value.equalsIgnoreCase("O")){
|
154 |
|
|
spectralTypeSeeked.addAll(this.spectralTypeO);
|
155 |
|
|
}else if(value.equalsIgnoreCase("B")){
|
156 |
|
|
spectralTypeSeeked.addAll(this.spectralTypeB);
|
157 |
|
|
}else if(value.equalsIgnoreCase("A")){
|
158 |
|
|
spectralTypeSeeked.addAll(this.spectralTypeA);
|
159 |
|
|
}else if(value.equalsIgnoreCase("F")){
|
160 |
|
|
spectralTypeSeeked.addAll(this.spectralTypeF);
|
161 |
|
|
}else if(value.equalsIgnoreCase("G")){
|
162 |
|
|
spectralTypeSeeked.addAll(this.spectralTypeG);
|
163 |
|
|
}else if(value.equalsIgnoreCase("K")){
|
164 |
|
|
spectralTypeSeeked.addAll(this.spectralTypeK);
|
165 |
|
|
}else if(value.equalsIgnoreCase("M")){
|
166 |
|
|
spectralTypeSeeked.addAll(this.spectralTypeM);
|
167 |
|
|
}else if(value.equalsIgnoreCase("All")){
|
168 |
|
|
all = true;
|
169 |
|
|
}
|
170 |
|
|
|
171 |
|
|
|
172 |
|
|
}
|
173 |
|
|
if(!spectralTypeSeeked.isEmpty()&& !all) {
|
174 |
|
|
predicat.setRightValue(spectralTypeSeeked);
|
175 |
|
|
predicats.add(predicat);
|
176 |
|
|
}
|
177 |
|
|
}
|
178 |
|
|
}
|
179 |
|
|
}
|
180 |
|
|
|
181 |
|
|
}
|
182 |
|
|
}
|
183 |
|
|
}else {
|
184 |
|
|
filterExists = false;
|
185 |
|
|
}
|
186 |
|
|
}
|
187 |
|
|
|
188 |
|
|
return predicats;
|
189 |
|
|
}
|
190 |
|
|
|
191 |
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
|
|
|
195 |
|
|
|
196 |
|
|
@Override
|
197 |
|
|
public Validator<AbstractFilter> getValidator() {
|
198 |
|
|
return new Validator<AbstractFilter>() {
|
199 |
|
|
@Override
|
200 |
|
|
public Set<ConstraintViolation> validate(AbstractFilter item) {
|
201 |
|
|
|
202 |
|
|
return null;
|
203 |
|
|
}
|
204 |
|
|
};
|
205 |
|
|
}
|
206 |
|
|
|
207 |
|
|
} |