Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerald Unterrainer committed Aug 9, 2021
2 parents cdd2a15 + 156e1bb commit 25c83d9
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ server.handlerGroupFor(UserJpa.class, UserJson.class, new JpqlDao<UserJpa>(emf,
.endpoints(Endpoint.ALL)
.addRoleFor(Endpoint.ALL, RoleBuilder.open())
.getListInterceptor()
.query("userName = :userName[string]")
.query("o.userName = :userName[string]")
.build()
.add();

Expand Down Expand Up @@ -251,7 +251,7 @@ server.handlerGroupFor(SubscriptionJpa.class, SubscriptionJson.class, subscripti
.endpoints(Endpoint.ALL)
.addRoleFor(Endpoint.ALL, RoleBuilder.open())
.getListInterceptor()
.query("idString = :stringId[string]")
.query("o.idString = :stringId[string]")
.build()
.add();
server.start();
Expand All @@ -271,7 +271,7 @@ You may specify a parameter as optional by pre-fixing the database-field name wi
```java
.getListInterceptor()
.query("scanId = :scanId[long] AND (?name LIKE :sn[string] OR ?idString LIKE :sn[string] OR ?description LIKE :sn[string])")
.query("o.scanId = :scanId[long] AND (?o.name LIKE :sn[string] OR ?o.idString LIKE :sn[string] OR ?o.description LIKE :sn[string])")
.build()
```
Expand Down Expand Up @@ -312,7 +312,7 @@ Where `scanId` is a numeric mandatory parameter and the rest is checked using th
```java
.getListInterceptor()
.query("endsOn >= :startOn[datetime] AND ?type = :type[~EventType]")
.query("o.endsOn >= :startOn[datetime] AND ?o.type = :type[~EventType]")
.build()
```
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<modelVersion>4.0.0</modelVersion>
<artifactId>http-server</artifactId>
<version>0.2.29</version>
<version>0.2.30</version>
<name>HttpServer</name>
<packaging>jar</packaging>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class HttpServer {
private UserAccessInterceptor userAccessInterceptor;
@Getter
@Setter
private String enumLookupFqnForInterceptorParser;
private List<String> enumLookupFqnForInterceptorParser;

private HttpServer() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class RqlUtils {

private final Context ctx;
private final HandlerUtils hu;
private final String enumFqn;
private final List<String> enumFqn;

public RqlData parseRql(final String expression) {
CharStream in = CharStreams.fromString(expression);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package info.unterrainer.commons.httpserver.rql;

import java.util.List;

import org.antlr.v4.runtime.ParserRuleContext;

import info.unterrainer.commons.httpserver.HandlerUtils;
Expand All @@ -21,7 +23,7 @@ public class RqlVisitor extends RqlBaseVisitor<String> {
private final RqlData data;
private final HandlerUtils hu;
private final Context ctx;
private final String enumFqn;
private final List<String> enumFqn;

@Override
public String visitAnd(final AndContext ctx) {
Expand Down Expand Up @@ -194,13 +196,20 @@ private Object castToPrimitive(final String value, final String type, final Stri
@SuppressWarnings({ "unchecked", "rawtypes" })
private Enum castToEnum(final String value, final String type, final String field) {
try {
final Class<Enum> cl = (Class<Enum>) Class.forName(enumFqn + "." + type);
Class<Enum> cl = null;
for (String enumFqn : this.enumFqn)
try {
cl = (Class<Enum>) Class.forName(enumFqn + "." + type);
break;
} catch (ClassNotFoundException e) {
// NOOP
}
if (cl == null)
throw new InternalServerErrorException(
String.format("The Enum type [%s] you want to cast to is not available", type));
return Enum.valueOf(cl, value);
} catch (ClassCastException e) {
throw new InternalServerErrorException();
} catch (ClassNotFoundException e) {
throw new InternalServerErrorException(
String.format("The Enum type [%s] you want to cast to is not available", type));
} catch (IllegalArgumentException e) {
throw new BadRequestException(
String.format("Value [%s] of field [%s] has to be of type [%s]", value, field, type));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void rqlUtilTest(final String input, final String expected, final Map<Str

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

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

0 comments on commit 25c83d9

Please sign in to comment.