174 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
182 |
ilm |
4 |
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
|
174 |
ilm |
5 |
*
|
|
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
|
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
|
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
|
|
9 |
* language governing permissions and limitations under the License.
|
|
|
10 |
*
|
|
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
package org.openconcerto.ui.light;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.utils.io.Transferable;
|
|
|
17 |
|
|
|
18 |
import net.minidev.json.JSONObject;
|
|
|
19 |
|
|
|
20 |
public class UserSearchItem implements Transferable {
|
|
|
21 |
// column id (or subject id of the search)
|
|
|
22 |
private String column;
|
|
|
23 |
// value as text typed by the user
|
|
|
24 |
private String text;
|
|
|
25 |
public static final String TYPE_IS = "is";
|
|
|
26 |
public static final String TYPE_CONTAINS = "contains";
|
|
|
27 |
public static final String TYPE_STARTS_WITH = "starts";
|
|
|
28 |
public static final String TYPE_ENDS_WITH = "ends";
|
|
|
29 |
public static final String TYPE_EQUALS = "equals";
|
|
|
30 |
public static final String TYPE_LESS_THAN = "lth";
|
|
|
31 |
public static final String TYPE_GREATER_THAN = "gth";
|
|
|
32 |
// type of search (contains,equals,...)
|
|
|
33 |
private String type;
|
|
|
34 |
// operator to apply (and / or)
|
|
|
35 |
private String operator;
|
|
|
36 |
|
|
|
37 |
public UserSearchItem(final JSONObject json) {
|
|
|
38 |
this.fromJSON(json);
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
public String getColumn() {
|
|
|
42 |
return this.column;
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
public String getText() {
|
|
|
46 |
return this.text;
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
public String getType() {
|
|
|
50 |
return this.type;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
public String getOperator() {
|
|
|
54 |
return this.operator;
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
@Override
|
|
|
58 |
public JSONObject toJSON() {
|
|
|
59 |
final JSONObject json = new JSONObject();
|
|
|
60 |
json.put("column", this.column);
|
|
|
61 |
json.put("text", this.text);
|
|
|
62 |
json.put("type", this.type);
|
|
|
63 |
json.put("operator", this.operator);
|
|
|
64 |
return json;
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
@Override
|
|
|
68 |
public void fromJSON(final JSONObject json) {
|
|
|
69 |
if (!json.containsKey("column") || !(json.get("column") instanceof String)) {
|
|
|
70 |
throw new IllegalArgumentException("value for 'column' not found or invalid");
|
|
|
71 |
}
|
|
|
72 |
if (!json.containsKey("text") || !(json.get("text") instanceof String)) {
|
|
|
73 |
throw new IllegalArgumentException("value for 'text' not found or invalid");
|
|
|
74 |
}
|
|
|
75 |
if (!json.containsKey("type") || !(json.get("type") instanceof String)) {
|
|
|
76 |
throw new IllegalArgumentException("value for 'type' not found or invalid");
|
|
|
77 |
}
|
|
|
78 |
if (json.containsKey("operator")) {
|
|
|
79 |
if (!(json.get("operator") instanceof String)) {
|
|
|
80 |
throw new IllegalArgumentException("value for 'operator' not found or invalid");
|
|
|
81 |
} else {
|
|
|
82 |
this.operator = (String) json.get("operator");
|
|
|
83 |
}
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
this.column = (String) json.get("column");
|
|
|
87 |
this.text = (String) json.get("text");
|
|
|
88 |
this.type = (String) json.get("type");
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
@Override
|
|
|
92 |
public String toString() {
|
|
|
93 |
return super.toString() + " column:" + this.column + " text:" + this.text + " type:" + this.type + " operator:" + this.operator;
|
|
|
94 |
}
|
|
|
95 |
}
|