Merged in feature/docresult (pull request #105)
Document Result Endpoint * testing * cleantesting * progress * query * lint * readme * dockerclient * api * passtest * tests * test
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
package queryapi
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"queryorchestration/internal/client"
|
||||
"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 parseClientStatus(status client.Status) ClientStatus {
|
||||
switch status {
|
||||
case client.IN_SYNC:
|
||||
return INSYNC
|
||||
case client.NOT_SYNCING:
|
||||
return NOTSYNCING
|
||||
}
|
||||
|
||||
return NOTSYNCED
|
||||
}
|
||||
Reference in New Issue
Block a user