Skip to content

Commit 8a205ab

Browse files
committed
allow searching for charge points by free text input as description
1 parent 042ea66 commit 8a205ab

4 files changed

Lines changed: 40 additions & 2 deletions

File tree

src/main/java/de/rwth/idsg/steve/repository/ChargePointRepositoryImpl.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.List;
3333

3434
import static de.rwth.idsg.steve.utils.CustomDSL.date;
35+
import static de.rwth.idsg.steve.utils.CustomDSL.includes;
3536
import static jooq.steve.db.tables.Address.ADDRESS;
3637
import static jooq.steve.db.tables.ChargeBox.CHARGE_BOX;
3738
import static jooq.steve.db.tables.Connector.CONNECTOR;
@@ -107,7 +108,13 @@ private Result<Record4<String, String, String, DateTime>> getOverviewInternal(Ch
107108
);
108109

109110
if (form.isSetOcppVersion()) {
110-
selectQuery.addConditions(CHARGE_BOX.OCPP_PROTOCOL.like(form.getOcppVersion().getValue() + "%"));
111+
112+
// http://dev.mysql.com/doc/refman/5.7/en/pattern-matching.html
113+
selectQuery.addConditions(CHARGE_BOX.OCPP_PROTOCOL.like(form.getOcppVersion().getValue() + "_"));
114+
}
115+
116+
if (form.isSetDescription()) {
117+
selectQuery.addConditions(includes(CHARGE_BOX.DESCRIPTION, form.getDescription()));
111118
}
112119

113120
switch (form.getHeartbeatPeriod()) {

src/main/java/de/rwth/idsg/steve/utils/CustomDSL.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package de.rwth.idsg.steve.utils;
22

33
import org.joda.time.DateTime;
4+
import org.jooq.Condition;
45
import org.jooq.Field;
56
import org.jooq.impl.DSL;
67

@@ -11,7 +12,8 @@
1112
* @since 03.09.2015
1213
*/
1314
public final class CustomDSL {
14-
private CustomDSL() { }
15+
private CustomDSL() {
16+
}
1517

1618
public static Field<DateTime> utcTimestamp() {
1719
return field("{utc_timestamp(6)}", DateTime.class);
@@ -31,4 +33,24 @@ public static Field<DateTime> date(Field<DateTime> dt) {
3133
public static Field<Integer> lastInsertId() {
3234
return field("last_insert_id()", Integer.class);
3335
}
36+
37+
/**
38+
* http://dev.mysql.com/doc/refman/5.7/en/pattern-matching.html
39+
*
40+
* It's not as advanced as fuzzy full-text search, but still better than nothing. DB will look
41+
* for all the fields that include the input. On the downside, it has the potential to be inefficient,
42+
* when the table is big. We should probably keep an eye on this.
43+
*/
44+
public static Condition includes(Field<String> field, String input) {
45+
46+
// The user can send the search parameter with empty spaces within the input. We replace this
47+
// with '%' since DB uses it to match any string of zero or more characters.
48+
//
49+
// The method returns a reference to the old object, when empty space does not occur in the string.
50+
// Therefore, no if-statement is needed.
51+
//
52+
input = input.replaceAll("\\s+", "%");
53+
54+
return field.like("%" + input + "%");
55+
}
3456
}

src/main/java/de/rwth/idsg/steve/web/dto/ChargePointQueryForm.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
@Setter
1414
public class ChargePointQueryForm {
1515

16+
private String description;
1617
private OcppVersion ocppVersion;
1718
private QueryPeriodType heartbeatPeriod;
1819

@@ -27,6 +28,10 @@ public boolean isSetOcppVersion() {
2728
return ocppVersion != null;
2829
}
2930

31+
public boolean isSetDescription() {
32+
return description != null;
33+
}
34+
3035
@RequiredArgsConstructor
3136
public enum QueryPeriodType {
3237
ALL("All"),

src/main/resources/webapp/WEB-INF/views/data-man/chargepoints.jsp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
</span></section>
99
<form:form action="/steve/manager/chargepoints/query" method="get" modelAttribute="params">
1010
<table class="userInput">
11+
<tr>
12+
<td>Description:</td>
13+
<td><form:input path="description"/></td>
14+
</tr>
1115
<tr>
1216
<td>Ocpp Version:</td>
1317
<td><form:select path="ocppVersion">

0 commit comments

Comments
 (0)