• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / reporting / 739771832

pending completion
739771832

Pull #87

gitlab-ci

Fabio Tranchitella
chore: bump the copyright year in the LICENSE file
Pull Request #87: MEN-5930: index device deployment objects

644 of 887 new or added lines in 15 files covered. (72.6%)

2 existing lines in 2 files now uncovered.

2555 of 3142 relevant lines covered (81.32%)

16.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/model/query_deployments.go
1
// Copyright 2022 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14

15
package model
16

NEW
17
func BuildDeploymentsQuery(params DeploymentsSearchParams) (Query, error) {
×
NEW
18
        query := NewQuery()
×
NEW
19

×
NEW
20
        for _, f := range params.Filters {
×
NEW
21
                fpart, err := getFilterPart(FilterPredicate{
×
NEW
22
                        Attribute: f.Attribute,
×
NEW
23
                        Type:      f.Type,
×
NEW
24
                        Value:     f.Value,
×
NEW
25
                })
×
NEW
26
                if err != nil {
×
NEW
27
                        return nil, err
×
NEW
28
                }
×
NEW
29
                query = fpart.AddTo(query)
×
30
        }
31

NEW
32
        for _, s := range params.Sort {
×
NEW
33
                sort := NewDeploymentsSort(s)
×
NEW
34
                query = sort.AddTo(query)
×
NEW
35
        }
×
36

NEW
37
        query = query.WithPage(params.Page, params.PerPage)
×
NEW
38

×
NEW
39
        if len(params.Attributes) > 0 {
×
NEW
40
                sel := NewDeploymentsSelect(params.Attributes)
×
NEW
41
                query = sel.AddTo(query)
×
NEW
42
        }
×
43

NEW
44
        if len(params.DeviceIDs) > 0 {
×
NEW
45
                devs := NewDevIDsFilter(params.DeviceIDs)
×
NEW
46
                query = devs.AddTo(query)
×
NEW
47
        }
×
48

NEW
49
        return query, nil
×
50
}
51

52
type deploymentsSort struct {
53
        attrStr  string
54
        attrNum  string
55
        attrBool string
56
        order    string
57
}
58

NEW
59
func NewDeploymentsSort(sc DeploymentsSortCriteria) *deploymentsSort {
×
NEW
60
        order := sc.Order
×
NEW
61
        if order == "" {
×
NEW
62
                order = SortOrderAsc
×
NEW
63
        }
×
NEW
64
        return &deploymentsSort{
×
NEW
65
                attrStr:  sc.Attribute,
×
NEW
66
                attrNum:  sc.Attribute,
×
NEW
67
                attrBool: sc.Attribute,
×
NEW
68
                order:    order,
×
NEW
69
        }
×
70
}
71

NEW
72
func (s *deploymentsSort) AddTo(q Query) Query {
×
NEW
73
        q = q.
×
NEW
74
                WithSort(
×
NEW
75
                        M{
×
NEW
76
                                s.attrStr: M{
×
NEW
77
                                        "order":         s.order,
×
NEW
78
                                        "unmapped_type": "keyword",
×
NEW
79
                                },
×
NEW
80
                        },
×
NEW
81
                ).WithSort(
×
NEW
82
                M{
×
NEW
83
                        s.attrNum: M{
×
NEW
84
                                "order":         s.order,
×
NEW
85
                                "unmapped_type": "double",
×
NEW
86
                        },
×
NEW
87
                },
×
NEW
88
        )
×
NEW
89

×
NEW
90
        return q
×
NEW
91
}
×
92

93
type deploymentsSel struct {
94
        attrs []DeploymentsSelectAttribute
95
}
96

NEW
97
func NewDeploymentsSelect(attrs []DeploymentsSelectAttribute) *deploymentsSel {
×
NEW
98
        return &deploymentsSel{
×
NEW
99
                attrs: attrs,
×
NEW
100
        }
×
NEW
101
}
×
102

NEW
103
func (s *deploymentsSel) AddTo(q Query) Query {
×
NEW
104
        fields := []string{}
×
NEW
105

×
NEW
106
        for _, a := range s.attrs {
×
NEW
107
                fields = append(fields, a.Attribute)
×
NEW
108
        }
×
109

110
        // always include the deployment id
NEW
111
        fields = append(fields, "id")
×
NEW
112

×
NEW
113
        return q.With(map[string]interface{}{
×
NEW
114
                "fields":  fields,
×
NEW
115
                "_source": false,
×
NEW
116
        })
×
117

118
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc