Skip to content
Snippets Groups Projects
Commit 38964d9c authored by Hemming,J. (Jacob)'s avatar Hemming,J. (Jacob)
Browse files

added parsing needs MQ checking

parent e7145075
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@ package main
import (
"context"
"encoding/json"
"fmt"
"log"
"query-service/internal/aql"
......@@ -29,6 +30,15 @@ func main() {
redisclient.Start()
select {}
// file, _ := ioutil.ReadFile("./internal/data/jsonQuery.json")
// query, _ := aql.ConvertJSONToAQL(&file)
// result, _ := request.SendAQLQuery(*query)
// //fmt.Println(string(*result))
// querymap := make(map[string]interface{})
// querymap["type"] = "query_result"
// querymap["values"] = string(*result)
// fmt.Println(querymap)
}
func onMessageReceived(msg amqp.Delivery) {
......@@ -67,11 +77,18 @@ func onMessageReceived(msg amqp.Delivery) {
return // TODO: Send message in queue notifying of error
}
// TODO: Test MQ result
querymap := make(map[string]interface{})
querymap["type"] = "query_result"
querymap["values"] = string(*result)
querybyte, err := json.Marshal(querymap)
//fmt.Println(querymap)
// publish converted result
headers := amqp.Table{}
headers["sessionID"] = sessionID
headers["type"] = "schemaResult"
log.Println("publishing message")
producer.PublishMessage(*result, &queueID, &headers)
producer.PublishMessage(querybyte, &queueID, &headers)
msg.Ack(true)
}
......@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"strconv"
"strings"
)
/*
......@@ -142,14 +143,20 @@ func ConvertJSONToAQL(jsonMsg *[]byte) (*string, error) {
func createAllNodesQuery(returnEntitiesIndices []int, entities []entityStruct) *string {
var result string
var ret string
ret += "RETURN { \n"
for _, entityIndex := range returnEntitiesIndices {
nodeID := fmt.Sprintf("n%s", strconv.Itoa(entityIndex))
nodeQueryString := *createNodeQuery(&entities[entityIndex], nodeID)
ret += "\t" + nodeID + ":" + nodeID + ",\n"
result += fmt.Sprintf(" \n%s", nodeQueryString)
}
ret = strings.TrimSuffix(ret, ",\n")
ret += "\n}"
result += "\n" + ret
return &result
}
......@@ -192,10 +199,8 @@ func createNodeQuery(node *entityStruct, name string) *string {
returnStatement := "\n\tRETURN x\n)"
forLoop := fmt.Sprintf("\nFOR n in %s", name) + "\nRETURN n"
// Concatenate all the statements
result := letStatement + forStatement + filter + returnStatement + forLoop
result := letStatement + forStatement + filter + returnStatement
return &result
}
......
{
"Return": {
"Entities": [0],
"Relations": []
"Entities": [
0,
1
],
"Relations": []
},
"Nodes": [
{
"NodeType": "airports",
"Constraints":
{
"country": { "Value": "USA", "DataType": "text", "MatchType": "exact" },
"vip": { "Value": "true", "DataType": "bool", "MatchType": "exact" }
}
}
"Entities": [
{
"Type": "airports",
"Constraints": [
{
"Attribute": "city",
"Value": "New York",
"DataType": "text",
"MatchType": "exact"
}
]
},
{
"Type": "airports",
"Constraints": [
{
"Attribute": "city",
"Value": "Hilliard",
"DataType": "text",
"MatchType": "exact"
}
]
}
],
"Relations": [ ]
}
\ No newline at end of file
"Relations": []
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ package request
import (
"context"
"crypto/tls"
"fmt"
"log"
"encoding/json"
......@@ -15,8 +16,8 @@ import (
// Document with Empty struct to retrieve all data from the DB Document
type Document map[string]interface{}
// GeneralFormat is a generalformat to send data the frontend
type GeneralFormat map[string]interface{}
// GeneralFormat with Empty struct to retrieve all data from the DB Document
type GeneralFormat map[string][]Document
//attr interface{}
......@@ -50,6 +51,7 @@ func SendAQLQuery(AQLQuery string) (*[]byte, error) {
return nil, err
}
// CHANGED TO OTHER FORMAT
//fmt.Println(AQLQuery)
// query := `
// LET n0 = (
......@@ -67,7 +69,7 @@ func SendAQLQuery(AQLQuery string) (*[]byte, error) {
}
defer cursor.Close()
for {
var doc Document
var doc GeneralFormat
_, err := cursor.ReadDocument(ctx, &doc)
if driver.IsNoMoreDocuments(err) {
break
......@@ -75,8 +77,10 @@ func SendAQLQuery(AQLQuery string) (*[]byte, error) {
// handle other errors
return nil, err
}
//fmt.Printf("%T\n", doc)
queryResult = append(queryResult, formatToJSON(doc))
// fmt.Printf("%T\n", doc)
queryResult = append(queryResult, formatToJSON(doc)...)
//fmt.Println(doc)
//formatToJSON(doc)
}
writeJSON(queryResult)
......@@ -84,14 +88,21 @@ func SendAQLQuery(AQLQuery string) (*[]byte, error) {
return &file, err
}
func formatToJSON(doc Document) Document {
func formatToJSON(doc GeneralFormat) []Document {
//b, err := json.Marshal(doc)
//if err != nil {
//handle error
//}
// fmt.Println(doc)
return parseData(doc)
//fmt.Println(data)
var nodeList []Document
for _, v := range doc {
for _, j := range v {
nodeList = append(nodeList, parseData(j))
}
}
fmt.Println(nodeList)
return nodeList
}
func writeJSON(queryResult []Document) {
......
main.exe 0 → 100644
File added
[
{
"_id": "airports/AMA",
"_key": "AMA",
"_rev": "_c_FqKK2--d",
"_id": "airports/6N5",
"_key": "6N5",
"_rev": "_cIYKbr6-Aw",
"attributes": {
"city": "Amarillo",
"country": "USA",
"lat": 35.2193725,
"long": -101.7059272,
"name": "Amarillo International",
"state": "TX",
"vip": true
}
},
{
"_id": "airports/ATL",
"_key": "ATL",
"_rev": "_c_FqKK2-_7",
"attributes": {
"city": "Atlanta",
"city": "New York",
"country": "USA",
"lat": 33.64044444,
"long": -84.42694444,
"name": "William B Hartsfield-Atlanta Intl",
"state": "GA",
"vip": true
"lat": 40.74260167,
"long": -73.97208306,
"name": "E 34th St Heliport",
"state": "NY",
"vip": false
}
},
{
"_id": "airports/DFW",
"_key": "DFW",
"_rev": "_c_FqKL--Cc",
"_id": "airports/6N7",
"_key": "6N7",
"_rev": "_cIYKbr6-Ay",
"attributes": {
"city": "Dallas-Fort Worth",
"city": "New York",
"country": "USA",
"lat": 32.89595056,
"long": -97.0372,
"name": "Dallas-Fort Worth International",
"state": "TX",
"vip": true
"lat": 40.73399083,
"long": -73.97291639,
"name": "New York Skyports Inc. SPB",
"state": "NY",
"vip": false
}
},
{
"_id": "airports/JFK",
"_key": "JFK",
"_rev": "_c_FqKLa--f",
"_rev": "_cIYKbs2-_F",
"attributes": {
"city": "New York",
"country": "USA",
......@@ -56,45 +42,59 @@
}
},
{
"_id": "airports/LAX",
"_key": "LAX",
"_rev": "_c_FqKLe-_g",
"_id": "airports/JRA",
"_key": "JRA",
"_rev": "_cIYKbs2-_h",
"attributes": {
"city": "New York",
"country": "USA",
"lat": 40.75454583,
"long": -74.00708389,
"name": "Port Authority-W 30th St Midtown Heliport",
"state": "NY",
"vip": false
}
},
{
"_id": "airports/JRB",
"_key": "JRB",
"_rev": "_cIYKbs2-_j",
"attributes": {
"city": "Los Angeles",
"city": "New York",
"country": "USA",
"lat": 33.94253611,
"long": -118.4080744,
"name": "Los Angeles International",
"state": "CA",
"vip": true
"lat": 40.70121361,
"long": -74.00902833,
"name": "Downtown Manhattan/Wall St. Heliport",
"state": "NY",
"vip": false
}
},
{
"_id": "airports/ORD",
"_key": "ORD",
"_rev": "_c_FqKLu-BM",
"_id": "airports/LGA",
"_key": "LGA",
"_rev": "_cIYKbt---s",
"attributes": {
"city": "Chicago",
"city": "New York",
"country": "USA",
"lat": 41.979595,
"long": -87.90446417,
"name": "Chicago O'Hare International",
"state": "IL",
"vip": true
"lat": 40.77724306,
"long": -73.87260917,
"name": "LaGuardia",
"state": "NY",
"vip": false
}
},
{
"_id": "airports/SFO",
"_key": "SFO",
"_rev": "_c_FqKM--_8",
"_id": "airports/01J",
"_key": "01J",
"_rev": "_cIYKbri--H",
"attributes": {
"city": "San Francisco",
"city": "Hilliard",
"country": "USA",
"lat": 37.61900194,
"long": -122.3748433,
"name": "San Francisco International",
"state": "CA",
"vip": true
"lat": 30.6880125,
"long": -81.90594389,
"name": "Hilliard Airpark",
"state": "FL",
"vip": false
}
}
]
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment