-
Notifications
You must be signed in to change notification settings - Fork 8
/
property_value_batch.go
73 lines (61 loc) · 2.09 KB
/
property_value_batch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package api
import (
"context"
"github.com/grafana/iot-sitewise-datasource/pkg/framer"
"github.com/grafana/iot-sitewise-datasource/pkg/util"
"github.com/grafana/iot-sitewise-datasource/pkg/sitewise/client"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/iotsitewise"
"github.com/grafana/iot-sitewise-datasource/pkg/models"
)
func valueBatchQueryToInput(query models.AssetPropertyValueQuery) *iotsitewise.BatchGetAssetPropertyValueInput {
entries := make([]*iotsitewise.BatchGetAssetPropertyValueEntry, 0)
switch {
case query.PropertyAlias != "":
entries = append(entries, &iotsitewise.BatchGetAssetPropertyValueEntry{
EntryId: util.GetEntryId(query.BaseQuery),
PropertyAlias: util.GetPropertyAlias(query.BaseQuery),
})
default:
for _, assetId := range query.AssetIds {
var id *string
if assetId != "" {
id = aws.String(assetId)
}
entries = append(entries, &iotsitewise.BatchGetAssetPropertyValueEntry{
EntryId: id,
AssetId: id,
PropertyId: aws.String(query.PropertyId),
})
}
}
return &iotsitewise.BatchGetAssetPropertyValueInput{
Entries: entries,
NextToken: getNextToken(query.BaseQuery),
}
}
func BatchGetAssetPropertyValue(ctx context.Context, client client.SitewiseClient, query models.AssetPropertyValueQuery) (models.AssetPropertyValueQuery, *framer.AssetPropertyValueBatch, error) {
modifiedQuery, err := getAssetIdAndPropertyId(query, client, ctx)
if err != nil {
return models.AssetPropertyValueQuery{}, nil, err
}
req := valueBatchQueryToInput(modifiedQuery)
resp, err := client.BatchGetAssetPropertyValueWithContext(ctx, req)
if err != nil {
return models.AssetPropertyValueQuery{}, nil, err
}
anomalyAssetIds := []string{}
if query.FlattenL4e {
anomalyAssetIds, err = filterAnomalyAssetIds(ctx, client, modifiedQuery)
if err != nil {
return models.AssetPropertyValueQuery{}, nil, err
}
}
return modifiedQuery,
&framer.AssetPropertyValueBatch{
BatchGetAssetPropertyValueOutput: resp,
AnomalyAssetIds: anomalyAssetIds,
SitewiseClient: client,
},
nil
}