diff --git a/integration-testing/config.json b/integration-testing/config.json index c11ee836a9eb78785df21c91d5a28bfb3e46cf42..e9818c2bc5c8daf07a5db48b8ec662778f46bb6c 100644 --- a/integration-testing/config.json +++ b/integration-testing/config.json @@ -6,21 +6,22 @@ "exchange": "requests-exchange", "exchangeType": "direct", "messages": [ + { "routingKey": "aql-query-request", "headers": { "sessionID": "test-session", - "clientID": "c24l4vd2ngurnrncjdi0" + "clientID": "c28ha5d2ngurnrncjgkg" }, - "data":"This is not a valid query" + "data":"{\"DatabaseName\":\"test\",\"Return\":{\"Entities\":[0,1],\"Relations\":[0]},\"Entities\":[{\"Type\":\"airports\",\"Constraints\":[{\"Attribute\":\"city\",\"Value\":\"New York\",\"DataType\":\"text\",\"MatchType\":\"exact\"}]},{\"Type\":\"airports\",\"Constraints\":[{\"Attribute\":\"city\",\"Value\":\"San Francisco\",\"DataType\":\"text\",\"MatchType\":\"exact\"},{\"Attribute\":\"vip\",\"Value\":\"true\",\"DataType\":\"bool\",\"MatchType\":\"exact\"}]}],\"Relations\":[{\"Type\":\"flights\",\"Depth\":{\"min\":1,\"max\":1},\"EntityFrom\":0,\"EntityTo\":1,\"Constraints\":[{\"Attribute\":\"Month\",\"Value\":\"1\",\"DataType\":\"number\",\"MatchType\":\"exact\"},{\"Attribute\":\"Day\",\"Value\":\"15\",\"DataType\":\"number\",\"MatchType\":\"exact\"}]}], \"limit\": 1000}" }, { "routingKey": "aql-query-request", "headers": { "sessionID": "test-session", - "clientID": "c24l4vd2ngurnrncjdi0" + "clientID": "c28ha5d2ngurnrncjgkg" }, - "data":"{\"DatabaseName\":\"test\",\"Return\":{\"Entities\":[0,1],\"Relations\":[0]},\"Entities\":[{\"Type\":\"airports\",\"Constraints\":[{\"Attribute\":\"city\",\"Value\":\"New York\",\"DataType\":\"text\",\"MatchType\":\"exact\"}]},{\"Type\":\"airports\",\"Constraints\":[{\"Attribute\":\"city\",\"Value\":\"San Francisco\",\"DataType\":\"text\",\"MatchType\":\"exact\"},{\"Attribute\":\"vip\",\"Value\":\"true\",\"DataType\":\"bool\",\"MatchType\":\"exact\"}]}],\"Relations\":[{\"Type\":\"flights\",\"Depth\":{\"min\":1,\"max\":1},\"EntityFrom\":0,\"EntityTo\":1,\"Constraints\":[{\"Attribute\":\"Month\",\"Value\":\"1\",\"DataType\":\"number\",\"MatchType\":\"exact\"},{\"Attribute\":\"Day\",\"Value\":\"15\",\"DataType\":\"number\",\"MatchType\":\"exact\"}]}], \"limit\": 1000}" + "data":"This is not a valid query" } ] } diff --git a/internal/usecases/request/request.go b/internal/usecases/request/request.go index b7a8d1b630674f39af18d044605b6060a315e24c..744f3f910379bd572fbe7d4e2acdb53e131fa03c 100644 --- a/internal/usecases/request/request.go +++ b/internal/usecases/request/request.go @@ -75,32 +75,39 @@ func (s *Service) SendAQLQuery(query string, username string, password string, h break } else if err != nil { // handle other errors + fmt.Println(err) return nil, err } - // If the result is only numerical, break out of the loop - num, isNum = doc.(float64) - if isNum { + // Switch on the type of return, to filter out the case of a single number + switch doc.(type) { + case float64: + num = doc.(float64) + isNum = true + break + case map[string]interface{}: + pdoc := doc.(map[string]interface{}) + parseResult(pdoc, &listContainer) + break + default: + fmt.Println("Incompatible result type") break } - - parseResult(doc, &listContainer) } if !isNum { - + // Return nodes and edges queryResult["nodes"] = listContainer.NodeList queryResult["edges"] = listContainer.EdgeList - //writeJSON(queryResult) - //file, err := json.MarshalIndent(queryResult, "", " ") jsonQ, err := json.Marshal(queryResult) return &jsonQ, err + } else { + // Return just a number + numQ, err := json.Marshal(num) + return &numQ, err } - numQ, err := json.Marshal(num) - return &numQ, err - } /* parseResult takes the result of the query and translates this to two lists: a nodelist and an edgelist, stored in a listcontainer @@ -110,11 +117,11 @@ listContainer is a struct containing the nodelist and edgelist that will be retu Return: Nothing because the result is stored in the listContainer */ -func parseResult(incomingDoc interface{}, listContainer *entity.ListContainer) { +func parseResult(doc map[string]interface{}, listContainer *entity.ListContainer) { - doc := incomingDoc.(map[string][]interface{}) - vertices := doc["vertices"] - edges := doc["edges"] + //doc, ok := incomingDoc.(map[string][]interface{}) + vertices := doc["vertices"].([]interface{}) + edges := doc["edges"].([]interface{}) for _, vertex := range vertices { vertexDoc := vertex.(map[string]interface{})