142 |
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.sql.ui.light;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.sql.Configuration;
|
174 |
ilm |
17 |
import org.openconcerto.sql.Log;
|
|
|
18 |
import org.openconcerto.sql.model.FieldPath;
|
142 |
ilm |
19 |
import org.openconcerto.sql.model.SQLSelect;
|
|
|
20 |
import org.openconcerto.sql.model.Where;
|
|
|
21 |
import org.openconcerto.sql.request.ListSQLRequest;
|
|
|
22 |
import org.openconcerto.sql.view.list.ITableModel;
|
|
|
23 |
import org.openconcerto.sql.view.list.SQLTableModelSource;
|
|
|
24 |
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
|
174 |
ilm |
25 |
import org.openconcerto.ui.light.TableSearchParameterType;
|
|
|
26 |
import org.openconcerto.ui.light.UserSearch;
|
|
|
27 |
import org.openconcerto.ui.light.UserSearchItem;
|
142 |
ilm |
28 |
import org.openconcerto.utils.cc.ITransformer;
|
|
|
29 |
|
|
|
30 |
import java.util.ArrayList;
|
174 |
ilm |
31 |
import java.util.Arrays;
|
142 |
ilm |
32 |
import java.util.List;
|
|
|
33 |
|
|
|
34 |
import net.minidev.json.JSONObject;
|
|
|
35 |
|
|
|
36 |
public class LightRowValuesTableOnline extends LightRowValuesTable {
|
156 |
ilm |
37 |
private ITransformer<SQLSelect, SQLSelect> orginTransformer;
|
142 |
ilm |
38 |
|
156 |
ilm |
39 |
public LightRowValuesTableOnline() {
|
|
|
40 |
// Serialization
|
|
|
41 |
}
|
|
|
42 |
|
142 |
ilm |
43 |
public LightRowValuesTableOnline(final Configuration configuration, final Number userId, final String id, final ITableModel model) {
|
|
|
44 |
super(configuration, userId, id, model);
|
|
|
45 |
this.orginTransformer = ((SQLTableModelSourceOnline) model.getReq()).getReq().getSelectTransf();
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
// Clone constructor
|
|
|
49 |
public LightRowValuesTableOnline(final LightRowValuesTableOnline tableElement) {
|
|
|
50 |
super(tableElement);
|
|
|
51 |
this.orginTransformer = tableElement.orginTransformer;
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
// Json constructor
|
|
|
55 |
public LightRowValuesTableOnline(final JSONObject json) {
|
|
|
56 |
super(json);
|
|
|
57 |
this.orginTransformer = null;
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
@Override
|
174 |
ilm |
61 |
public void doSearch(final Configuration configuration, final UserSearch searchSpec, final int offset) {
|
|
|
62 |
|
142 |
ilm |
63 |
this.getTableSpec().setSearch(searchSpec);
|
|
|
64 |
|
|
|
65 |
this.setOffset(offset);
|
|
|
66 |
|
|
|
67 |
final SQLTableModelSource tableSource = this.getModel().getReq();
|
174 |
ilm |
68 |
final ListSQLRequest req = tableSource.getReq();
|
|
|
69 |
final List<UserSearchItem> content = new ArrayList<>();
|
|
|
70 |
if (searchSpec != null) {
|
|
|
71 |
content.addAll(searchSpec.getContent());
|
142 |
ilm |
72 |
|
174 |
ilm |
73 |
for (UserSearchItem item : content) {
|
|
|
74 |
// ex "col0"
|
|
|
75 |
String colId = item.getColumn();
|
|
|
76 |
// ex "contains"
|
|
|
77 |
String searchType = item.getType();
|
|
|
78 |
TableSearchMatcher m = LightRowValuesTableOnline.this.getSearchMatcher(colId, searchType);
|
|
|
79 |
if (m != null && m.getAdditionnalFieldsToFetch() != null) {
|
|
|
80 |
for (FieldPath p : m.getAdditionnalFieldsToFetch()) {
|
|
|
81 |
req.addToGraphToFetch(p.getPath(), Arrays.asList(p.getField().getFieldName()));
|
142 |
ilm |
82 |
}
|
174 |
ilm |
83 |
}
|
142 |
ilm |
84 |
}
|
|
|
85 |
}
|
174 |
ilm |
86 |
req.setSelectTransf(new ITransformer<SQLSelect, SQLSelect>() {
|
|
|
87 |
@Override
|
|
|
88 |
public SQLSelect transformChecked(final SQLSelect sel) {
|
|
|
89 |
if (LightRowValuesTableOnline.this.orginTransformer != null) {
|
|
|
90 |
LightRowValuesTableOnline.this.orginTransformer.transformChecked(sel);
|
|
|
91 |
}
|
|
|
92 |
if (searchSpec != null) {
|
|
|
93 |
//
|
|
|
94 |
final List<Where> wheres = new ArrayList<>();
|
|
|
95 |
for (UserSearchItem item : content) {
|
|
|
96 |
// ex "col0"
|
|
|
97 |
String colId = item.getColumn();
|
|
|
98 |
// ex "hello"
|
|
|
99 |
String userText = item.getText();
|
|
|
100 |
// ex "contains"
|
|
|
101 |
String searchType = item.getType();
|
|
|
102 |
TableSearchMatcher m = LightRowValuesTableOnline.this.getSearchMatcher(colId, searchType);
|
|
|
103 |
if (m != null) {
|
|
|
104 |
final Where where = m.getWhere(sel, new TableSearchParameterType(searchType), userText);
|
|
|
105 |
if (where != null) {
|
|
|
106 |
wheres.add(where);
|
|
|
107 |
}
|
|
|
108 |
} else {
|
|
|
109 |
Log.get().warning("no TableSearchMatcher for " + item);
|
|
|
110 |
}
|
142 |
ilm |
111 |
|
174 |
ilm |
112 |
}
|
142 |
ilm |
113 |
|
174 |
ilm |
114 |
final Where w;
|
|
|
115 |
if (!wheres.isEmpty()) {
|
|
|
116 |
if (sel.getWhere() != null) {
|
|
|
117 |
w = Where.and(sel.getWhere(), Where.and(wheres));
|
|
|
118 |
} else {
|
|
|
119 |
w = Where.and(wheres);
|
|
|
120 |
}
|
|
|
121 |
sel.setWhere(w);
|
142 |
ilm |
122 |
}
|
|
|
123 |
}
|
174 |
ilm |
124 |
return sel;
|
142 |
ilm |
125 |
}
|
174 |
ilm |
126 |
});
|
142 |
ilm |
127 |
|
|
|
128 |
}
|
174 |
ilm |
129 |
|
142 |
ilm |
130 |
}
|