diff --git a/internal/entity/querystruct.go b/internal/entity/querystruct.go new file mode 100644 index 0000000000000000000000000000000000000000..8e3d4f28fc6bcf4a0e502d871db3fca36fce1b2d --- /dev/null +++ b/internal/entity/querystruct.go @@ -0,0 +1,53 @@ +package entity + +// QueryParsedJSON is used for JSON conversion of the incoming byte array +type QueryParsedJSON struct { + Return QueryReturnStruct + Entities []QueryEntityStruct + Relations []QueryRelationStruct + + // Limit is for limiting the amount of paths AQL will return in a relation let statement + Limit int +} + +// QueryReturnStruct holds the indices of the entities and relations that need to be returned +type QueryReturnStruct struct { + Entities []int + Relations []int +} + +// QueryEntityStruct encapsulates a single entity with its corresponding constraints +type QueryEntityStruct struct { + Type string + Constraints []QueryConstraintStruct +} + +// QueryRelationStruct encapsulates a single relation with its corresponding constraints +type QueryRelationStruct struct { + Type string + EntityFrom int + EntityTo int + Depth QuerySearchDepthStruct + Constraints []QueryConstraintStruct +} + +// QuerySearchDepthStruct holds the range of traversals for the relation +type QuerySearchDepthStruct struct { + Min int + Max int +} + +/* +QueryConstraintStruct holds the information of the constraint + +Constraint datatypes + text MatchTypes: exact/contains/startswith/endswith + number MatchTypes: GT/LT/EQ + bool MatchTypes: EQ/NEQ +*/ +type QueryConstraintStruct struct { + Attribute string + Value string + DataType string + MatchType string +} diff --git a/internal/usecases/convertquery/aql.go b/internal/usecases/convertquery/aql.go index ef6ff1eb597b4a709c8dcc1300c76f63193b063c..e6678f8de3b5230a108a2872db1dc242d385f59f 100644 --- a/internal/usecases/convertquery/aql.go +++ b/internal/usecases/convertquery/aql.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "query-service/internal/entity" ) /* @@ -57,8 +58,8 @@ Parameters: jsonMsg is the JSON file directly outputted by the drag and drop que Return: parsedJSON is a struct with the same structure and holding the same data as jsonMsg */ -func convertJSONToStruct(jsonMsg *[]byte) (*parsedJSON, error) { - jsonStruct := parsedJSON{} +func convertJSONToStruct(jsonMsg *[]byte) (*entity.QueryParsedJSON, error) { + jsonStruct := entity.QueryParsedJSON{} err := json.Unmarshal(*jsonMsg, &jsonStruct) if err != nil { @@ -73,7 +74,7 @@ Parameters: jsonQuery is a parsedJSON struct holding all the data needed to form Return: a string containing the corresponding AQL query and an error */ -func createQuery(jsonQuery *parsedJSON) *string { +func createQuery(jsonQuery *entity.QueryParsedJSON) *string { // GROTE SIDENOTE: // Vrij zeker dat een query waar alléén edges worden opgevraagd (#4) // niet wordt gesupport door zowel de result parser als de frontend receiver @@ -172,7 +173,7 @@ name is the autogenerated name of the node consisting of "n" + the index of the Return: a string containing a single LET-statement in AQL */ -func createNodeLet(node *entityStruct, name *string) *string { +func createNodeLet(node *entity.QueryEntityStruct, name *string) *string { header := fmt.Sprintf("LET %v = (\n\tFOR x IN %v \n", *name, node.Type) footer := "\tRETURN x\n)\n" constraints := *createConstraintStatements(&node.Constraints, "x", false) @@ -188,7 +189,7 @@ entities is a list of entityStructs that are needed to form the relation LET-sta Return: a string containing a single LET-statement in AQL */ -func createRelationLetWithFromEntity(relation *relationStruct, name string, entities *[]entityStruct, limit int) *string { +func createRelationLetWithFromEntity(relation *entity.QueryRelationStruct, name string, entities *[]entity.QueryEntityStruct, limit int) *string { header := fmt.Sprintf("LET %v = (\n\tFOR x IN n%v \n", name, relation.EntityFrom) forStatement := fmt.Sprintf("\tFOR v, e, p IN %v..%v OUTBOUND x %s \n", relation.Depth.Min, relation.Depth.Max, relation.Type) @@ -222,7 +223,7 @@ entities is a list of entityStructs that are needed to form the relation LET-sta Return: a string containing a single LET-statement in AQL */ -func createRelationLetWithOnlyToEntity(relation *relationStruct, name string, entities *[]entityStruct, limit int) *string { +func createRelationLetWithOnlyToEntity(relation *entity.QueryRelationStruct, name string, entities *[]entity.QueryEntityStruct, limit int) *string { header := fmt.Sprintf("LET %v = (\n\tFOR x IN n%v \n", name, relation.EntityTo) forStatement := fmt.Sprintf("\tFOR v, e, p IN %v..%v INBOUND x %s \n", relation.Depth.Min, relation.Depth.Max, relation.Type) diff --git a/internal/usecases/convertquery/aqlStructs.go b/internal/usecases/convertquery/aqlStructs.go index c9a042430588cc706503a59d8916476ea1ef26aa..ad1be5eeb27d258675af096fa1596c9711470cf5 100644 --- a/internal/usecases/convertquery/aqlStructs.go +++ b/internal/usecases/convertquery/aqlStructs.go @@ -8,55 +8,3 @@ type Service struct { func NewService() *Service { return &Service{} } - -// Struct used for JSON conversion of the incoming byte array -type parsedJSON struct { - Return returnStruct - Entities []entityStruct - Relations []relationStruct - - // Limit is for limiting the amount of paths AQL will return in a relation let statement - Limit int -} - -// returnStruct holds the indices of the entities and relations that need to be returned -type returnStruct struct { - Entities []int - Relations []int -} - -// entityStruct encapsulates a single entity with its corresponding constraints -type entityStruct struct { - Type string - Constraints []constraintStruct -} - -// relationStruct encapsulates a single relation with its corresponding constraints -type relationStruct struct { - Type string - EntityFrom int - EntityTo int - Depth searchDepthStruct - Constraints []constraintStruct -} - -// searchDepthStruct holds the range of traversals for the relation -type searchDepthStruct struct { - Min int - Max int -} - -/* -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 - Value string - DataType string - MatchType string -} diff --git a/internal/usecases/convertquery/createConstraints.go b/internal/usecases/convertquery/createConstraints.go index 2f92a5cb8adf20a9648c27d6404f7eb219a8b80a..b03d06f79342d39122612dd076eeedf5afe37f8b 100644 --- a/internal/usecases/convertquery/createConstraints.go +++ b/internal/usecases/convertquery/createConstraints.go @@ -1,6 +1,9 @@ package convertquery -import "fmt" +import ( + "fmt" + "query-service/internal/entity" +) /* createConstraintStatements generates the appropriate amount of constraint lines calling createConstraingBoolExpression Parameters: constraints is a list of constraintStructs that specify the constraints of a node or relation, @@ -9,7 +12,7 @@ isRelation is a boolean specifying if this constraint comes from a node or relat Return: a string containing a FILTER-statement with all the constraints */ -func createConstraintStatements(constraints *[]constraintStruct, name string, isRelation bool) *string { +func createConstraintStatements(constraints *[]entity.QueryConstraintStruct, name string, isRelation bool) *string { s := "" if len(*constraints) == 0 { return &s @@ -34,7 +37,7 @@ isRelation is a boolean specifying if this constraint comes from a node or relat Return: a string containing an boolean expression of a single constraint */ -func createConstraintBoolExpression(constraint *constraintStruct, name string, isRelation bool) *string { +func createConstraintBoolExpression(constraint *entity.QueryConstraintStruct, name string, isRelation bool) *string { var ( match string value string