0815cb35fb
Basic Lint Checks * basic
98 lines
2.0 KiB
Go
98 lines
2.0 KiB
Go
package queryservice
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"queryorchestration/internal/job"
|
|
"queryorchestration/internal/query"
|
|
resultprocessor "queryorchestration/internal/query/result/processor"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
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) {
|
|
if query.RequiredQueryIDs != nil && len(*query.RequiredQueryIDs) == 0 {
|
|
query.RequiredQueryIDs = nil
|
|
}
|
|
|
|
qt, err := parseQueryType(query.Type)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
q := &Query{
|
|
Id: query.ID,
|
|
Type: qt,
|
|
ActiveVersion: query.ActiveVersion,
|
|
LatestVersion: query.LatestVersion,
|
|
RequiredQueries: query.RequiredQueryIDs,
|
|
Config: query.Config,
|
|
}
|
|
|
|
return q, nil
|
|
}
|
|
|
|
func parseQueryType(qType resultprocessor.Type) (QueryType, error) {
|
|
switch qType {
|
|
case resultprocessor.TypeJsonExtractor:
|
|
return JSONEXTRACTOR, nil
|
|
case resultprocessor.TypeContextFull:
|
|
return CONTEXTFULL, nil
|
|
default:
|
|
return "", errors.New("invalid query type")
|
|
}
|
|
}
|
|
|
|
func parseSpecQueryType(qType QueryType) (resultprocessor.Type, error) {
|
|
switch qType {
|
|
case JSONEXTRACTOR:
|
|
return resultprocessor.TypeJsonExtractor, nil
|
|
case CONTEXTFULL:
|
|
return resultprocessor.TypeContextFull, nil
|
|
default:
|
|
return resultprocessor.Type(-1), errors.New("invalid query type")
|
|
}
|
|
}
|
|
|
|
func parseStringToUUIDArray(sids *[]string) (*[]uuid.UUID, error) {
|
|
var ids []uuid.UUID
|
|
if sids != nil {
|
|
ids = make([]uuid.UUID, len(*sids))
|
|
for index, id := range *sids {
|
|
parsedID, err := uuid.Parse(id)
|
|
if err != nil {
|
|
return nil, errors.New("invalid required id")
|
|
}
|
|
|
|
ids[index] = parsedID
|
|
}
|
|
|
|
return &ids, nil
|
|
}
|
|
|
|
return nil, nil
|
|
}
|
|
|
|
func parseJobStatus(status job.Status) JobStatus {
|
|
switch status {
|
|
case job.IN_SYNC:
|
|
return INSYNC
|
|
}
|
|
|
|
return NOTSYNCED
|
|
}
|