Skip to content

Commit 25c83d9

Browse files
author
Gerald Unterrainer
committedAug 9, 2021
Merge branch 'develop'
2 parents cdd2a15 + 156e1bb commit 25c83d9

File tree

6 files changed

+22
-13
lines changed

6 files changed

+22
-13
lines changed
 

‎README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ server.handlerGroupFor(UserJpa.class, UserJson.class, new JpqlDao<UserJpa>(emf,
116116
.endpoints(Endpoint.ALL)
117117
.addRoleFor(Endpoint.ALL, RoleBuilder.open())
118118
.getListInterceptor()
119-
.query("userName = :userName[string]")
119+
.query("o.userName = :userName[string]")
120120
.build()
121121
.add();
122122

@@ -251,7 +251,7 @@ server.handlerGroupFor(SubscriptionJpa.class, SubscriptionJson.class, subscripti
251251
.endpoints(Endpoint.ALL)
252252
.addRoleFor(Endpoint.ALL, RoleBuilder.open())
253253
.getListInterceptor()
254-
.query("idString = :stringId[string]")
254+
.query("o.idString = :stringId[string]")
255255
.build()
256256
.add();
257257
server.start();
@@ -271,7 +271,7 @@ You may specify a parameter as optional by pre-fixing the database-field name wi
271271
272272
```java
273273
.getListInterceptor()
274-
.query("scanId = :scanId[long] AND (?name LIKE :sn[string] OR ?idString LIKE :sn[string] OR ?description LIKE :sn[string])")
274+
.query("o.scanId = :scanId[long] AND (?o.name LIKE :sn[string] OR ?o.idString LIKE :sn[string] OR ?o.description LIKE :sn[string])")
275275
.build()
276276
```
277277
@@ -312,7 +312,7 @@ Where `scanId` is a numeric mandatory parameter and the rest is checked using th
312312
313313
```java
314314
.getListInterceptor()
315-
.query("endsOn >= :startOn[datetime] AND ?type = :type[~EventType]")
315+
.query("o.endsOn >= :startOn[datetime] AND ?o.type = :type[~EventType]")
316316
.build()
317317
```
318318

‎pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<modelVersion>4.0.0</modelVersion>
1919
<artifactId>http-server</artifactId>
20-
<version>0.2.29</version>
20+
<version>0.2.30</version>
2121
<name>HttpServer</name>
2222
<packaging>jar</packaging>
2323

‎src/main/java/info/unterrainer/commons/httpserver/HttpServer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class HttpServer {
6565
private UserAccessInterceptor userAccessInterceptor;
6666
@Getter
6767
@Setter
68-
private String enumLookupFqnForInterceptorParser;
68+
private List<String> enumLookupFqnForInterceptorParser;
6969

7070
private HttpServer() {
7171
}

‎src/main/java/info/unterrainer/commons/httpserver/rql/RqlUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class RqlUtils {
1919

2020
private final Context ctx;
2121
private final HandlerUtils hu;
22-
private final String enumFqn;
22+
private final List<String> enumFqn;
2323

2424
public RqlData parseRql(final String expression) {
2525
CharStream in = CharStreams.fromString(expression);

‎src/main/java/info/unterrainer/commons/httpserver/rql/RqlVisitor.java

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package info.unterrainer.commons.httpserver.rql;
22

3+
import java.util.List;
4+
35
import org.antlr.v4.runtime.ParserRuleContext;
46

57
import info.unterrainer.commons.httpserver.HandlerUtils;
@@ -21,7 +23,7 @@ public class RqlVisitor extends RqlBaseVisitor<String> {
2123
private final RqlData data;
2224
private final HandlerUtils hu;
2325
private final Context ctx;
24-
private final String enumFqn;
26+
private final List<String> enumFqn;
2527

2628
@Override
2729
public String visitAnd(final AndContext ctx) {
@@ -194,13 +196,20 @@ private Object castToPrimitive(final String value, final String type, final Stri
194196
@SuppressWarnings({ "unchecked", "rawtypes" })
195197
private Enum castToEnum(final String value, final String type, final String field) {
196198
try {
197-
final Class<Enum> cl = (Class<Enum>) Class.forName(enumFqn + "." + type);
199+
Class<Enum> cl = null;
200+
for (String enumFqn : this.enumFqn)
201+
try {
202+
cl = (Class<Enum>) Class.forName(enumFqn + "." + type);
203+
break;
204+
} catch (ClassNotFoundException e) {
205+
// NOOP
206+
}
207+
if (cl == null)
208+
throw new InternalServerErrorException(
209+
String.format("The Enum type [%s] you want to cast to is not available", type));
198210
return Enum.valueOf(cl, value);
199211
} catch (ClassCastException e) {
200212
throw new InternalServerErrorException();
201-
} catch (ClassNotFoundException e) {
202-
throw new InternalServerErrorException(
203-
String.format("The Enum type [%s] you want to cast to is not available", type));
204213
} catch (IllegalArgumentException e) {
205214
throw new BadRequestException(
206215
String.format("Value [%s] of field [%s] has to be of type [%s]", value, field, type));

‎src/test/java/info/unterrainer/commons/httpserver/rql/RqlParserTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void rqlUtilTest(final String input, final String expected, final Map<Str
101101

102102
private void setupMocks(final Map<String, String> queryParams) {
103103
hu = mock(HandlerUtils.class);
104-
rqlUtils = new RqlUtils(null, hu, "");
104+
rqlUtils = new RqlUtils(null, hu, List.of(""));
105105

106106
lenient().when(hu.getQueryParamAsString(any(), anyString())).thenAnswer(invocation -> {
107107
String name = invocation.getArgument(1, String.class);

0 commit comments

Comments
 (0)