174 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
|
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
|
|
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.JSONConverter;
|
|
|
17 |
import org.openconcerto.utils.io.Transferable;
|
|
|
18 |
|
|
|
19 |
import java.util.ArrayList;
|
|
|
20 |
import java.util.List;
|
|
|
21 |
|
|
|
22 |
import net.minidev.json.JSONArray;
|
|
|
23 |
import net.minidev.json.JSONAware;
|
|
|
24 |
import net.minidev.json.JSONObject;
|
|
|
25 |
|
|
|
26 |
public class UserSearch implements Transferable, JSONAware {
|
|
|
27 |
private String tableId;
|
|
|
28 |
private List<UserSearchItem> content = new ArrayList<>();
|
|
|
29 |
|
|
|
30 |
public UserSearch() {
|
|
|
31 |
// Serialization
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
public UserSearch(final String tableId) {
|
|
|
35 |
this.tableId = tableId;
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
public UserSearch(final JSONObject json) {
|
|
|
39 |
this.fromJSON(json);
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
public final String getTableId() {
|
|
|
43 |
return this.tableId;
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
public final List<UserSearchItem> getContent() {
|
|
|
47 |
return this.content;
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
@Override
|
|
|
51 |
public JSONObject toJSON() {
|
|
|
52 |
final JSONObject json = new JSONObject();
|
|
|
53 |
json.put("table-id", this.tableId);
|
|
|
54 |
json.put("content", JSONConverter.getJSON(this.content));
|
|
|
55 |
return json;
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
@Override
|
|
|
59 |
public void fromJSON(JSONObject json) {
|
|
|
60 |
this.tableId = JSONConverter.getParameterFromJSON(json, "table-id", String.class);
|
|
|
61 |
final JSONArray jsonContent = JSONConverter.getParameterFromJSON(json, "content", JSONArray.class);
|
|
|
62 |
if (jsonContent != null) {
|
|
|
63 |
this.content = new ArrayList<>();
|
|
|
64 |
for (final Object o : jsonContent) {
|
|
|
65 |
this.content.add(new UserSearchItem((JSONObject) JSONConverter.getObjectFromJSON(o, JSONObject.class)));
|
|
|
66 |
}
|
|
|
67 |
}
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
/*
|
|
|
71 |
* JSONAware pour que le JSONArray.toString() fonctionne quand cet objet est dans un JSONArray
|
|
|
72 |
*/
|
|
|
73 |
@Override
|
|
|
74 |
public String toJSONString() {
|
|
|
75 |
return toJSON().toJSONString();
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
@Override
|
|
|
79 |
public String toString() {
|
|
|
80 |
return "UserSearch on " + this.tableId + " " + this.content.size() + " items";
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
}
|