73 lines
1.5 KiB
Go
73 lines
1.5 KiB
Go
|
|
package queryservice
|
||
|
|
|
||
|
|
import (
|
||
|
|
"errors"
|
||
|
|
"queryorchestration/internal/query"
|
||
|
|
queryprocessor "queryorchestration/internal/queryProcessor"
|
||
|
|
)
|
||
|
|
|
||
|
|
func parseQueries(queries []*query.Query) ([]Query, error) {
|
||
|
|
outQueries := make([]Query, len(queries))
|
||
|
|
for index, query := range queries {
|
||
|
|
qt, err := parseQuery(query)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
outQueries[index] = *qt
|
||
|
|
}
|
||
|
|
|
||
|
|
return outQueries, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func parseQuery(query *query.Query) (*Query, error) {
|
||
|
|
requiredQueries := make([]string, len(query.RequiredQueryIDs))
|
||
|
|
for index, id := range query.RequiredQueryIDs {
|
||
|
|
requiredQueries[index] = id.String()
|
||
|
|
}
|
||
|
|
|
||
|
|
qt, err := parseQueryType(query.Type)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
q := &Query{
|
||
|
|
Id: query.ID.String(),
|
||
|
|
Type: qt,
|
||
|
|
ActiveVersion: query.ActiveVersion,
|
||
|
|
LatestVersion: query.LatestVersion,
|
||
|
|
}
|
||
|
|
|
||
|
|
if query.Config != "" {
|
||
|
|
q.Config = &query.Config
|
||
|
|
}
|
||
|
|
|
||
|
|
if len(query.RequiredQueryIDs) > 0 {
|
||
|
|
q.RequiredQueries = requiredQueries
|
||
|
|
}
|
||
|
|
|
||
|
|
return q, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func parseQueryType(qType queryprocessor.Type) (QueryType, error) {
|
||
|
|
switch qType {
|
||
|
|
case queryprocessor.TypeJsonExtractor:
|
||
|
|
return JSONEXTRACTOR, nil
|
||
|
|
case queryprocessor.TypeContextFull:
|
||
|
|
return CONTEXTFULL, nil
|
||
|
|
default:
|
||
|
|
return "", errors.New("invalid query type")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func parseSpecQueryType(qType QueryType) (queryprocessor.Type, error) {
|
||
|
|
switch qType {
|
||
|
|
case JSONEXTRACTOR:
|
||
|
|
return queryprocessor.TypeJsonExtractor, nil
|
||
|
|
case CONTEXTFULL:
|
||
|
|
return queryprocessor.TypeContextFull, nil
|
||
|
|
default:
|
||
|
|
return queryprocessor.Type(-1), errors.New("invalid query type")
|
||
|
|
}
|
||
|
|
}
|