Skip to content
Snippets Groups Projects
Commit 1c83db0d authored by sivan's avatar sivan
Browse files

also publish query translation result to the client

parent fdf8958c
No related branches found
No related tags found
No related merge requests found
......@@ -19,9 +19,21 @@ func (s *Service) HandleMessage(msg *brokeradapter.Message) {
// Convert the json byte msg to a query string
query, err := s.queryConverter.ConvertQuery(&msg.Body)
if err != nil {
errorhandler.LogError(err, "failed to parse incoming msg to query language") // TODO: don't panic on error, send error message to client instead
errorhandler.LogError(err, "failed to parse incoming msg to query language") // TODO: send error message to client instead
return
}
// Send the resulting query back to the client
msgmap := make(map[string]interface{})
msgmap["type"] = "query_translation_result"
msgmap["pod"] = podName
msgmap["values"] = *query
msgbyte, err := json.Marshal(msgmap)
if err != nil {
errorhandler.LogError(err, "Marshalling query_translation_result went wrong!") // TODO: send error message to client instead
return
}
s.producer.PublishMessage(&msgbyte, &sessionID) // TODO: should this be a go routine?
fmt.Println("Query: " + *query)
// Make request to database
......@@ -35,12 +47,15 @@ func (s *Service) HandleMessage(msg *brokeradapter.Message) {
}
// Add type indicator to result from database
querymap := make(map[string]interface{})
querymap["type"] = "query_result"
querymap["pod"] = podName
querymap["values"] = *result
querybyte, err := json.Marshal(querymap)
//fmt.Println(querymap)
resultMsgMap := make(map[string]interface{})
resultMsgMap["type"] = "query_result"
resultMsgMap["pod"] = podName
resultMsgMap["values"] = *result
resultMsgByte, err := json.Marshal(resultMsgMap)
if err != nil {
errorhandler.LogError(err, "Marshalling query_result went wrong!") // TODO: send error message to client instead
return
}
s.producer.PublishMessage(&querybyte, &sessionID)
s.producer.PublishMessage(&resultMsgByte, &sessionID)
}
......@@ -9,35 +9,28 @@ func NewService() *Service {
return &Service{}
}
// Constraint datatypes
// text MatchTypes: exact/contains/startswith/endswith
// number MatchTypes: GT/LT/EQ
// bool MatchTypes: EQ/NEQ
// Ranges dus tussen 10 half 5 bijv.
// Struct used for JSON conversion of the incoming byte array
type parsedJSON struct {
Return returnStruct //`json:"return"`
Entities []entityStruct //`json:"entities"`
Relations []relationStruct //`json:"relations"`
Return returnStruct
Entities []entityStruct
Relations []relationStruct
}
// returnStruct holds the indices of the entities and relations that need to be returned
type returnStruct struct {
Entities []int //`json:"entities"`
Relations []int //`json:"relation"`
Entities []int
Relations []int
}
// entityStruct encapsulates a single entity with its corresponding constraints
type entityStruct struct {
Type string //`json:"type"`
Constraints []constraintStruct //`json:"constraints"`
Type string
Constraints []constraintStruct
}
// relationStruct encapsulates a single relation with its corresponding constraints
type relationStruct struct {
Type string //`json:"type"`
Type string
EntityFrom int
EntityTo int
Depth searchDepthStruct
......@@ -50,10 +43,17 @@ type searchDepthStruct struct {
Max int
}
// constraintStruct holds the information of the constraint
/*
constraintStruct holds the information of the constraint
Constraint datatypes
text MatchTypes: exact/contains/startswith/endswith
number MatchTypes: GT/LT/EQ
bool MatchTypes: EQ/NEQ
*/
type constraintStruct struct {
Attribute string //`json:"attribute"`
Value string //`json:"value"`
DataType string //`json:"dataType"`
MatchType string //`json:"matchType"`
Attribute string
Value string
DataType string
MatchType string
}
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