Skip to content

Commit

Permalink
APPS-884 Fix GeoJSON insert (#145)
Browse files Browse the repository at this point in the history
* docs: APPS-882 Clarify providing GeoJSON bin types

* fix: APPS-884 GeoJSON bins are inserted as Aerospike Maps

---------

Co-authored-by: Eugene R. <[email protected]>
  • Loading branch information
jdogmcsteezy and reugn authored Sep 6, 2023
1 parent 4ff60e1 commit cfa87e3
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 153 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ package: clean validatedocs build
build:
./gradlew build -x test

.PHONY: run
run:
./gradlew bootRun

.PHONY: clean
clean:
echo $(VERSION)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ here [Aerospike REST Gateway API Documentation](https://docs.aerospike.com/apido

## Prerequisites

* Java 17 or later for REST Gateway 2.0 and newer. Java 8 or later for REST Gateway 1.11 and earlier.
* Java 17 or later for REST Gateway 2.0 and newer. Java 8 or later for REST Gateway 1.11 and earlier.
* Aerospike Server version 4.9+

## Installation
Expand Down Expand Up @@ -85,7 +85,7 @@ languages.

1. Go to [Swagger Editor](https://editor.swagger.io/).
2. Import the Aerospike REST
Client [openapi.json](https://github.com/aerospike/aerospike-rest-gateway/blob/master/docs/openapi.json) file.
Client [openapi.json](https://aerospike.github.io/aerospike-rest-gateway/openapi.json) file.
3. Click on Generate Server/Generate Client and choose the desired language/framework.
4. A .zip file that contains all the necessary files for a server/client will be downloaded.

Expand Down
46 changes: 28 additions & 18 deletions docs/data-formats.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Rest Gateway Data Formats
# REST Gateway Data Formats

API Requests which involve sending data can use the `JSON`, or `MessagePack` formats. By default JSON will be assumed.
To use `MessagePack`, set the `Content-Type` header to ``"application/msgpack"``. Similarly
Expand All @@ -11,13 +11,9 @@ For many uses `JSON` is a simpler and completely valid option. It provides simpl
Key Value operations are being used, and neither Maps with non string keys, Bytes nor GeoJSON are required, then `JSON`
will work completely with the Aerospike data model.

**Note**: In version 1.0 GeoJSON and ByteArray bin values are supported. A GeoJSON map with the keys "type" and "
coordinates" will automatically be understood as a GeoJSON type. Similarly, a ByteArray can be provided using a map with
the keys "type"
and "value" where the type is "byteArray" and the value is a base64 encoded string. One caveat is GeoJSON and ByteArrays
can not be nested in CDTs.
**Note**: GeoJSON and ByteArrays can not be nested in CDTs.

Ex. GeoJSON
In 2.0.4, a GeoJSON map with the keys "type" and "coordinates" will automatically be understood as a GeoJSON type.

```javascript
{
Expand All @@ -26,7 +22,21 @@ Ex. GeoJSON
}
```

Ex. ByteArray
In version prior to 2.0.4, a GeoJSON object can be provided by sending a base64 encoded GeoJSON string.
Base64 encoding the following string `{"type": "Point", "coordinates": [1.123, 4.156]}` results
in `eyJ0eXBlIjogIlBvaW50IiwgImNvb3JkaW5hdGVzIjogWzEuMTIzLCA0LjE1Nl19Cg==`.
To write the GeoJSON object use

```javascript
{
"type": "GEO_JSON",
"value": "eyJ0eXBlIjogIlBvaW50IiwgImNvb3JkaW5hdGVzIjogWzEuMTIzLCA0LjE1Nl19Cg=="
}
```

Similarly, starting in 1.0.0 a ByteArray can be provided using a map with
the keys "type"
and "value" where the type is "byteArray" and the value is a base64 encoded string.

```javascript
{
Expand Down Expand Up @@ -57,17 +67,17 @@ differentiate a normal string from GeoJSON.
For example to write a bin map usable by the API with a GeoJSON value utilizing Python.

```python
# Python 2.7
import msgpack
packed_geojson = msgpack.ExtType(23, "{\"coordinates\": [-122.0, 37.5], \"type\": \"Point\"}")
packed_bins = {u'geo_bin': packed_geojson}
mp_bins = msgpack.packb(packed_bins)
# Python 2.7
import msgpack
packed_geojson = msgpack.ExtType(23, "{\"coordinates\": [-122.0, 37.5], \"type\": \"Point\"}")
packed_bins = {u'geo_bin': packed_geojson}
mp_bins = msgpack.packb(packed_bins)
```

Or with Java

```java
MessageBufferPacker packer=new MessagePack.PackerConfig().newBufferPacker();
MessageBufferPacker packer=new MessagePack.PackerConfig().newBufferPacker();
String geoString="{\"coordinates\": [-122.0, 37.5], \"type\": \"Point\"}";
packer.packMapHeader(1);
packer.packString("geo_bin");
Expand All @@ -78,13 +88,13 @@ MessageBufferPacker packer=new MessagePack.PackerConfig().newBufferPacker();
Bytes are a standard Message Pack type. Here is an example of creating a Bin Map to be used with the API

```python
# Python 2.7
test_bytes = bytearray([1,2,3])
mp_bytes_bins = msgpack.packb({u'my_bytes': test_bytes}, use_bin_type=True)
# Python 2.7
test_bytes = bytearray([1,2,3])
mp_bytes_bins = msgpack.packb({u'my_bytes': test_bytes}, use_bin_type=True)
```

```java
byte[]testBytes={1,2,3};
byte[]testBytes={1,2,3};
MessageBufferPacker packer=new MessagePack.PackerConfig().newBufferPacker();

packer.packMapHeader(1);
Expand Down
2 changes: 1 addition & 1 deletion docs/installation-and-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ make build
* Run Locally during development:

```sh
./gradlew bootRun
make run
```

### Run using a Jar file
Expand Down
2 changes: 1 addition & 1 deletion docs/operate.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# DEPRECATED

Operatation documentation is now imbedded in the swagger documentation.
# Operation documentation is now embedded in the swagger documentation as of 2.0.1

# Rest Gateway Operations

Expand Down
Loading

0 comments on commit cfa87e3

Please sign in to comment.