Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release/0.4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Wegener committed Aug 9, 2017
2 parents eab7420 + 3068738 commit 13adef9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gdk-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<groupId>com.github.libgraviton</groupId>
<artifactId>gdk</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
</parent>
<artifactId>gdk-core</artifactId>
<name>gdk-core</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
import com.github.libgraviton.gdk.api.query.rql.statements.Limit;
import com.github.libgraviton.gdk.api.query.rql.statements.Select;
import com.github.libgraviton.gdk.data.GravitonBase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.ArrayList;
Expand All @@ -25,10 +29,30 @@
*/
public class Rql extends Query {

private static final Logger LOG = LoggerFactory.getLogger(Rql.class);

public static final String DEFAULT_ENCODING = "UTF-8";

private Rql(List<QueryStatement> statements) {
this.statements = statements;
}

/**
* RQL encoding string according to https://github.com/xiag-ag/rql-parser
*
* @param input string to encode
* @param encoding encoding
* @return RQL encoded string
* @throws UnsupportedEncodingException if the named encoding is not supported
*/
public static String encode(String input, String encoding) throws UnsupportedEncodingException {
return URLEncoder.encode(input, encoding)
.replace("-", "%2D")
.replace("_", "%5F")
.replace(".", "%2E")
.replace("~", "%7E");
}

public static class Builder {

private Limit limit;
Expand Down Expand Up @@ -120,6 +144,11 @@ protected List<QueryStatement> getQueryStatementsFromNode(JsonNode node, DateFor
try {
dateFormat.parse(value);
} catch (ParseException e) {
try {
value = encode(value, DEFAULT_ENCODING);
} catch (UnsupportedEncodingException uee) {
LOG.warn("Unsupported encoding '" + DEFAULT_ENCODING + "', using unencoded value '" + value + "'.");
}
value = "string:" + value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.github.libgraviton.gdk.util.PropertiesLoader;
import org.junit.Test;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Properties;
Expand Down Expand Up @@ -65,4 +66,22 @@ public void testAddRqlStatements() {
String expectedRql = "?limit(2,3)&select(attribute1)";
assertEquals(expectedRql, rql1.generate());
}

@Test
public void testEncodeSuccessfully() throws UnsupportedEncodingException {
String unencoded = "http://a-host/endpoint?query=123_5.6~7";
String encoded = "http%3A%2F%2Fa%2Dhost%2Fendpoint%3Fquery%3D123%5F5%2E6%7E7";
assertEquals(encoded, Rql.encode(unencoded, Rql.DEFAULT_ENCODING));
}

@Test
public void testEncodeUnchanged() throws UnsupportedEncodingException {
String unencoded = "asdf123";
assertEquals(unencoded, Rql.encode(unencoded, Rql.DEFAULT_ENCODING));
}

@Test(expected = UnsupportedEncodingException.class)
public void testEncodeUnsupportedEncoding() throws UnsupportedEncodingException {
Rql.encode("asdf123", "non-existing-encoding");
}
}
4 changes: 2 additions & 2 deletions gdk-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.github.libgraviton</groupId>
<artifactId>gdk</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
</parent>
<artifactId>gdk-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
Expand Down Expand Up @@ -34,7 +34,7 @@
<dependency>
<groupId>com.github.libgraviton</groupId>
<artifactId>gdk-core</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
</dependency>
<dependency>
<groupId>org.jsonschema2pojo</groupId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.libgraviton</groupId>
<artifactId>gdk</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
<packaging>pom</packaging>
<name>gdk</name>
<description>Graviton Development Kit</description>
Expand Down

0 comments on commit 13adef9

Please sign in to comment.