+
Skip to content
This repository was archived by the owner on Sep 28, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 40 additions & 18 deletions internal/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"sort"

"github.com/qlik-oss/enigma-go"
)
Expand Down Expand Up @@ -41,7 +42,7 @@ func (o Object) validate() error {
func ListObjects(ctx context.Context, doc *enigma.Doc) []NamedItemWithType {
allInfos, _ := doc.GetAllInfos(ctx)
unsortedResult := make(map[string]*NamedItemWithType)
resultInOriginalOrder := []NamedItemWithType{}
keys := []string{}

waitChannel := make(chan *NamedItemWithType)
defer close(waitChannel)
Expand All @@ -63,18 +64,20 @@ func ListObjects(ctx context.Context, doc *enigma.Doc) []NamedItemWithType {
for range allInfos {
item := <-waitChannel
if item != nil {
keys = append(keys, item.Id)
unsortedResult[item.Id] = item
}
}
//Loop over the original sort order, fetch the result items from the map and build the final result array
for _, item := range allInfos {
if unsortedResult[item.Id] != nil {
resultInOriginalOrder = append(resultInOriginalOrder, *unsortedResult[item.Id])
}
//Loop over the keys that are sorted on qId and fetch the result for each object
sort.Strings(keys)
resultInSortedOrder := make([]NamedItemWithType, len(keys))
for i, key := range keys {
resultInSortedOrder[i] = *unsortedResult[key]
}
return resultInOriginalOrder
return resultInSortedOrder
}

// SetObjects creates or updates all objects on given glob patterns
func SetObjects(ctx context.Context, doc *enigma.Doc, commandLineGlobPattern string) {
paths, err := getEntityPaths(commandLineGlobPattern, "objects")
if err != nil {
Expand All @@ -85,21 +88,40 @@ func SetObjects(ctx context.Context, doc *enigma.Doc, commandLineGlobPattern str
if err != nil {
FatalErrorf("could not parse file %s: %s", path, err)
}

// Run in parallel
ch := make(chan error)

for _, raw := range rawEntities {
var object Object
err = json.Unmarshal(raw, &object)
if err != nil {
FatalErrorf("could not parse data in file %s: %s", path, err)
}
err = object.validate()
if err != nil {
FatalErrorf("validation error in file %s: %s", path, err)
}
err = setObject(ctx, doc, object.Info, object.Properties, raw)
go func(raw json.RawMessage) {
var object Object
err = json.Unmarshal(raw, &object)
if err != nil {
ch <- fmt.Errorf("could not parse data in file %s: %s", path, err)
return
}
err = object.validate()
if err != nil {
ch <- fmt.Errorf("validation error in file %s: %s", path, err)
return
}
ch <- setObject(ctx, doc, object.Info, object.Properties, raw)
}(raw)
}

// Loop through the responses and see if there are any failures, if so exit with a fatal
success := true
for range rawEntities {
err := <-ch
if err != nil {
FatalError(err)
fmt.Printf("ERROR " + err.Error())
success = false
}
}

if !success {
FatalError("One or more objects failed to be created or updated")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"title": ""
},
{
"qId": "sZAVcpj",
"qId": "gCCkr",
"qType": "auto-chart",
"title": ""
},
{
"qId": "gCCkr",
"qId": "sZAVcpj",
"qType": "auto-chart",
"title": ""
}
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载