1 |
6552a8ce
|
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.TYPE;
|
44 |
|
|
import static fr.cnes.sitools.dataset.plugins.filters.core.AbstractFormFilter.VALUES;
|
45 |
|
|
import java.util.logging.Level;
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
public final class ListBoxLumClassCorot extends AbstractFormFilter {
|
54 |
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
private enum TYPE_COMPONENT {
|
59 |
|
|
|
60 |
|
|
LISTBOXLUMCLASSCOROT
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
public ListBoxLumClassCorot() {
|
90 |
|
|
|
91 |
|
|
super();
|
92 |
|
|
this.setName("ListBoxLumClassCorot");
|
93 |
|
|
this.setDescription("Required when using List Box Lum Class for Corot Components");
|
94 |
|
|
|
95 |
|
|
this.setClassAuthor("Mnicolas");
|
96 |
|
|
this.setClassOwner("IAS");
|
97 |
|
|
this.setClassVersion("0.1");
|
98 |
|
|
this.setDefaultFilter(true);
|
99 |
|
|
|
100 |
|
|
HashMap<String, ParameterInfo> rpd = new HashMap<String, ParameterInfo>();
|
101 |
|
|
|
102 |
|
|
ParameterInfo paramInfo;
|
103 |
|
|
paramInfo = new ParameterInfo("p[#]", false, "xs:string", ParameterStyle.QUERY,
|
104 |
|
|
"LISTBOXLUMCLASSCOROT|columnAlias|value1|...|value n");
|
105 |
|
|
rpd.put("0", paramInfo);
|
106 |
|
|
this.setRequestParamsDescription(rpd);
|
107 |
|
|
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
@Override
|
111 |
|
|
public List<Predicat> createPredicats(Request request, List<Predicat> predicats) throws Exception {
|
112 |
|
|
|
113 |
|
|
DataSetApplication dsApplication = null;
|
114 |
|
|
DataSet ds = null;
|
115 |
|
|
boolean isConcept = true;
|
116 |
|
|
Form params = request.getResourceRef().getQueryAsForm();
|
117 |
|
|
boolean filterExists = true;
|
118 |
|
|
int i = 0;
|
119 |
|
|
|
120 |
|
|
while (filterExists) {
|
121 |
|
|
|
122 |
|
|
String index = TEMPLATE_PARAM_CONCEPT.replace("#", Integer.toString(i));
|
123 |
|
|
String formParam = params.getFirstValue(index);
|
124 |
|
|
if (formParam == null) {
|
125 |
|
|
isConcept = false;
|
126 |
|
|
index = TEMPLATE_PARAM.replace("#", Integer.toString(i));
|
127 |
|
|
formParam = params.getFirstValue(index);
|
128 |
|
|
}
|
129 |
|
|
i++;
|
130 |
|
|
if (formParam != null) {
|
131 |
|
|
String[] parameters = formParam.split("\\|");
|
132 |
|
|
TYPE_COMPONENT[] types = TYPE_COMPONENT.values();
|
133 |
|
|
Boolean trouve = false;
|
134 |
|
|
for (TYPE_COMPONENT typeCmp : types) {
|
135 |
|
|
if (typeCmp.name().equals(parameters[TYPE])) {
|
136 |
|
|
trouve = true;
|
137 |
|
|
}
|
138 |
|
|
}
|
139 |
|
|
if (trouve) {
|
140 |
|
|
if (dsApplication == null) {
|
141 |
|
|
dsApplication = (DataSetApplication) getContext().getAttributes().get("DataSetApplication");
|
142 |
|
|
ds = dsApplication.getDataSet();
|
143 |
|
|
}
|
144 |
|
|
String columnAlias = null;
|
145 |
|
|
if (parameters.length >= VALUES) {
|
146 |
|
|
|
147 |
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
|
|
|
151 |
|
|
|
152 |
|
|
|
153 |
|
|
|
154 |
|
|
columnAlias = getColumnAlias(isConcept, parameters, dsApplication);
|
155 |
|
|
if (columnAlias != null) {
|
156 |
|
|
Column col = ds.findByColumnAlias(columnAlias);
|
157 |
|
|
List<String> lumClassSeeked = new ArrayList<String>();
|
158 |
|
|
|
159 |
|
|
if (col != null && col.getFilter() != null && col.getFilter()) {
|
160 |
|
|
String[] values = Arrays.copyOfRange(parameters, VALUES, parameters.length);
|
161 |
|
|
Predicat predicat = new Predicat();
|
162 |
|
|
if (values != null) {
|
163 |
|
|
predicat.setLeftAttribute(col);
|
164 |
|
|
predicat.setNbOpenedParanthesis(0);
|
165 |
|
|
predicat.setNbClosedParanthesis(0);
|
166 |
|
|
predicat.setCompareOperator(Operator.IN);
|
167 |
|
|
|
168 |
|
|
boolean all = false;
|
169 |
|
|
for (String value : values) {
|
170 |
|
|
if(value.equalsIgnoreCase("All")){
|
171 |
|
|
all = true;
|
172 |
|
|
}else{
|
173 |
|
|
if(value.equalsIgnoreCase(" ")){
|
174 |
|
|
lumClassSeeked.add(value);
|
175 |
|
|
lumClassSeeked.add("null");
|
176 |
|
|
}else if(value.equalsIgnoreCase("III")){
|
177 |
|
|
lumClassSeeked.add(value);
|
178 |
|
|
lumClassSeeked.add("III:");
|
179 |
|
|
}else{
|
180 |
|
|
lumClassSeeked.add(value);
|
181 |
|
|
}
|
182 |
|
|
}
|
183 |
|
|
}
|
184 |
|
|
getContext().getLogger().log(Level.INFO, "lumClassSeeked : "+lumClassSeeked.toArray().toString());
|
185 |
|
|
if(!lumClassSeeked.isEmpty() && !all) {
|
186 |
|
|
predicat.setRightValue(lumClassSeeked);
|
187 |
|
|
predicats.add(predicat);
|
188 |
|
|
}
|
189 |
|
|
}
|
190 |
|
|
}
|
191 |
|
|
}
|
192 |
|
|
|
193 |
|
|
}
|
194 |
|
|
}
|
195 |
|
|
}else {
|
196 |
|
|
filterExists = false;
|
197 |
|
|
}
|
198 |
|
|
}
|
199 |
|
|
|
200 |
|
|
return predicats;
|
201 |
|
|
}
|
202 |
|
|
|
203 |
|
|
|
204 |
|
|
|
205 |
|
|
|
206 |
|
|
|
207 |
|
|
|
208 |
|
|
@Override
|
209 |
|
|
public Validator<AbstractFilter> getValidator() {
|
210 |
|
|
return new Validator<AbstractFilter>() {
|
211 |
|
|
@Override
|
212 |
|
|
public Set<ConstraintViolation> validate(AbstractFilter item) {
|
213 |
|
|
|
214 |
|
|
return null;
|
215 |
|
|
}
|
216 |
|
|
};
|
217 |
|
|
}
|
218 |
|
|
|
219 |
|
|
} |