-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.go
70 lines (59 loc) · 1.98 KB
/
report.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
package report
import (
"time"
"gopkg.in/mgo.v2/bson"
"github.com/bearded-web/bearded/models/file"
"github.com/bearded-web/bearded/models/issue"
"github.com/bearded-web/bearded/models/tech"
"github.com/bearded-web/bearded/pkg/pagination"
)
type Raw struct {
Raw string `json:"raw"`
Files []*file.Meta `json:"files,omitempty" bson:"files,omitempty"`
}
type Report struct {
Id bson.ObjectId `json:"id,omitempty" bson:"_id"`
Type ReportType `json:"type" description:"one of [raw,issues,techs,multi,empty]"`
Created time.Time `json:"created,omitempty" description:"when report is created"`
Updated time.Time `json:"updated,omitempty" description:"when report is updated"`
Scan bson.ObjectId `json:"scan,omitempty" description:"scan id"`
ScanSession bson.ObjectId `json:"scanSession,omitempty" bson:"scanSession" description:"scan session id"`
Raw `json:",inline,omitempty" bson:"raw,inline"`
Multi []*Report `json:"multi,omitempty" bson:"multi,omitempty"`
Issues []*issue.Issue `json:"issues,omitempty" bson:"issues,omitempty"`
Techs []*tech.Tech `json:"techs,omitempty"`
}
type ReportList struct {
pagination.Meta `json:",inline"`
Results []*Report `json:"results"`
}
// set scan to report and all underlying multi reports if they are existed
func (r *Report) SetScan(scanId bson.ObjectId) {
r.Scan = scanId
if r.Type == TypeMulti {
for _, rep := range r.Multi {
rep.SetScan(scanId)
}
}
}
func (r *Report) SetScanSession(sessionId bson.ObjectId) {
r.ScanSession = sessionId
if r.Type == TypeMulti {
for _, rep := range r.Multi {
rep.SetScanSession(sessionId)
}
}
}
// get all issues from the report and underlying multi reports
func (r *Report) GetAllIssues() []*issue.Issue {
var issues []*issue.Issue
switch r.Type {
case TypeMulti:
for _, subReport := range r.Multi {
issues = append(issues, subReport.GetAllIssues()...)
}
case TypeIssues:
issues = append(issues, r.Issues...)
}
return issues
}