Skip to content

Commit 60d2f8b

Browse files
committed
Test HQL: GWT
- Test HQL page rewritten to GWT (set unitime.legacy.hibernateQueryTest to true for the old Struts-based page) - A few changes done to the HQL Reports page, so that the two pages share as much code as possible
1 parent 943fba8 commit 60d2f8b

18 files changed

Lines changed: 1880 additions & 853 deletions

JavaSource/org/unitime/timetable/action/HibernateQueryTestAction.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.ArrayList;
2626
import java.util.Comparator;
2727
import java.util.Date;
28+
import java.util.Enumeration;
2829
import java.util.Iterator;
2930
import java.util.List;
3031
import java.util.Map;
@@ -103,6 +104,17 @@ public class HibernateQueryTestAction extends UniTimeAction<HibernateQueryTestFo
103104

104105
@Override
105106
public String execute() throws Exception {
107+
if (ApplicationProperty.LegacyTestHQL.isFalse()) {
108+
String url = "hibernateQueryTest";
109+
boolean first = true;
110+
for (Enumeration<String> e = getRequest().getParameterNames(); e.hasMoreElements(); ) {
111+
String param = e.nextElement();
112+
url += (first ? "?" : "&") + param + "=" + URLEncoder.encode(getRequest().getParameter(param), "utf-8");
113+
first = false;
114+
}
115+
response.sendRedirect(url);
116+
return null;
117+
}
106118
sessionContext.checkPermission(Right.TestHQL);
107119
if (form == null)
108120
form = new HibernateQueryTestForm();
@@ -168,7 +180,7 @@ public String execute() throws Exception {
168180
response.setDateHeader("Date", new Date().getTime());
169181
response.setDateHeader("Expires", 0);
170182
response.setHeader("Content-Disposition", "attachment; filename=\"hql-test.csv\"" );
171-
TestHqlExportToCSV.execute(sessionContext.getUser(), out, query, 0, -1);
183+
TestHqlExportToCSV.execute(sessionContext.getUser(), out, query, null, 0, -1);
172184
out.close();
173185
return null;
174186
}

JavaSource/org/unitime/timetable/defaults/ApplicationProperty.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3863,6 +3863,11 @@ public enum ApplicationProperty {
38633863
@Description("Contact Us: switch the user interface back to the old (Struts-based) contact us page")
38643864
LegacyInquiry("unitime.legacy.inquiry"),
38653865

3866+
@Type(Boolean.class)
3867+
@DefaultValue("false")
3868+
@Description("Test HQL: switch the user interface back to the old (Struts-based) test HQL page")
3869+
LegacyTestHQL("unitime.legacy.hibernateQueryTest"),
3870+
38663871
@Type(Boolean.class)
38673872
@DefaultValue("false")
38683873
@Description("Student Scheduling: provide associated (parent) course -- a student requesting both courses cannot get the course without also getting the associated course")

JavaSource/org/unitime/timetable/export/hql/SavedHqlExportToCSV.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,17 @@ public void export(ExportHelper helper) throws IOException {
181181

182182
execute(context.getUser(), out, hql.getQuery(), params, 0, -1, hql.getParameters());
183183

184+
sort(out.getBuffer(), helper);
185+
186+
out.close();
187+
}
188+
189+
public static void sort(List<String[]> lines, ExportHelper helper) {
184190
String sort = helper.getParameter("sort");
185191
if (sort != null && !"0".equals(sort)) {
186192
final boolean asc = Integer.parseInt(sort) > 0;
187193
final int col = Math.abs(Integer.parseInt(sort)) - 1;
188-
Collections.sort(out.getBuffer(), new Comparator<String[]>() {
194+
Collections.sort(lines, new Comparator<String[]>() {
189195
int compare(String[] a, String[] b, int col) {
190196
for (int i = 0; i < a.length; i++) {
191197
int c = (col + i) % a.length;
@@ -205,8 +211,23 @@ public int compare(String[] a, String[] b) {
205211
}
206212
});
207213
}
208-
209-
out.close();
214+
}
215+
216+
public static void enumerate(Printer out, org.hibernate.query.Query<Tuple> q) throws IOException {
217+
int len = -1;
218+
for (Tuple o: q.list()) {
219+
if (len < 0) {
220+
len = length(o);
221+
String[] line = new String[len];
222+
header(line, o);
223+
if (line.length > 0 && line[0].startsWith("__")) out.hideColumn(0);
224+
out.printHeader(line);
225+
}
226+
String[] line = new String[len];
227+
line(line, o);
228+
out.printLine(line);
229+
out.flush();
230+
}
210231
}
211232

212233
public static void execute(UserContext user, Printer out, String hql, List<SavedHQLInterface.IdValue> options, int fromRow, int maxRows, Collection<SavedHQLParameter> parameters) throws SavedHQLException, PageAccessException {
@@ -349,7 +370,7 @@ private static boolean skip(Attribute t) {
349370
}
350371
}
351372

352-
private static int length(Tuple o) {
373+
protected static int length(Tuple o) {
353374
if (o == null) return 1;
354375
int len = 0;
355376
for (TupleElement te: o.getElements()) {
@@ -377,7 +398,7 @@ private static String format(String column) {
377398
return column.substring(0, 1).toUpperCase() + column.substring(1);
378399
}
379400

380-
private static void header(String[] ret, Tuple o) {
401+
protected static void header(String[] ret, Tuple o) {
381402
int idx = 0;
382403
for (TupleElement te: o.getElements()) {
383404
EntityType et = null;
@@ -409,7 +430,7 @@ private static String toString(Object o) {
409430
return (o == null ? "" : o.toString());
410431
}
411432

412-
private static void line(String[] ret, Tuple o) {
433+
protected static void line(String[] ret, Tuple o) {
413434
int idx = 0;
414435
for (TupleElement te: o.getElements()) {
415436
EntityType et = null;

JavaSource/org/unitime/timetable/export/hql/SavedHqlExportToXLS.java

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
import java.io.IOException;
2323
import java.util.ArrayList;
24-
import java.util.Collections;
25-
import java.util.Comparator;
2624
import java.util.List;
2725

2826
import org.springframework.stereotype.Service;
@@ -152,30 +150,7 @@ public void export(ExportHelper helper) throws IOException {
152150

153151
execute(context.getUser(), out, hql.getQuery(), params, 0, -1, hql.getParameters());
154152

155-
String sort = helper.getParameter("sort");
156-
if (sort != null && !"0".equals(sort)) {
157-
final boolean asc = Integer.parseInt(sort) > 0;
158-
final int col = Math.abs(Integer.parseInt(sort)) - 1;
159-
Collections.sort(out.getBuffer(), new Comparator<String[]>() {
160-
int compare(String[] a, String[] b, int col) {
161-
for (int i = 0; i < a.length; i++) {
162-
int c = (col + i) % a.length;
163-
try {
164-
int cmp = Double.valueOf(a[c] == null ? "0" : a[c]).compareTo(Double.valueOf(b[c] == null ? "0" : b[c]));
165-
if (cmp != 0) return cmp;
166-
} catch (NumberFormatException e) {
167-
int cmp = (a[c] == null ? "" : a[c]).compareTo(b[c] == null ? "" : b[c]);
168-
if (cmp != 0) return cmp;
169-
}
170-
}
171-
return 0;
172-
}
173-
@Override
174-
public int compare(String[] a, String[] b) {
175-
return asc ? compare(a, b, col) : compare(b, a, col);
176-
}
177-
});
178-
}
153+
sort(out.getBuffer(), helper);
179154

180155
out.close();
181156
}

0 commit comments

Comments
 (0)