diff --git a/cmd/query-service/main.go b/cmd/query-service/main.go index 9ed0e1ea28c6aa586c5ae81910b566389c28b01c..6688ed61a03a27a86da334bea94777f7a1e06c07 100644 --- a/cmd/query-service/main.go +++ b/cmd/query-service/main.go @@ -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) } diff --git a/internal/aql/aql.go b/internal/aql/aql.go index b803b6a301d30244e2c24ed7e3724e6b2df3bb4c..f4f3ad043c2ee8bdf9076f474702b5268ff40cd3 100644 --- a/internal/aql/aql.go +++ b/internal/aql/aql.go @@ -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 } diff --git a/internal/data/jsonQuery.json b/internal/data/jsonQuery.json index ec66b21614d12cb2170e34780cfa669cf0c16d1e..7efe1bb2970cc16c7fcad9e5477fd9ac41acc5a9 100644 --- a/internal/data/jsonQuery.json +++ b/internal/data/jsonQuery.json @@ -1,17 +1,34 @@ { "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 diff --git a/internal/request/request.go b/internal/request/request.go index 2092096142e626af322143e8ec34da2c52209fd8..45f1b06a8013431852d30d21a0df779d005a89a0 100644 --- a/internal/request/request.go +++ b/internal/request/request.go @@ -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) { diff --git a/main.exe b/main.exe new file mode 100644 index 0000000000000000000000000000000000000000..cf37186e615e25dabd0ee61f39baf8b95aa572c0 Binary files /dev/null and b/main.exe differ diff --git a/result.json b/result.json index 5b3220a475e637cd9797fff2351081948b141102..4e4af0a83944a020ecf8aee9af950e7ad52a437a 100644 --- a/result.json +++ b/result.json @@ -1,50 +1,36 @@ [ { - "_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