Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
122 lines
2.3 KiB
Go
122 lines
2.3 KiB
Go
package resource
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"github.com/cortezaproject/corteza/server/system/types"
|
|
)
|
|
|
|
type (
|
|
Report struct {
|
|
*base
|
|
Res *types.Report
|
|
|
|
Sources []*ReportSource
|
|
Blocks []*ReportBlock
|
|
}
|
|
|
|
ReportSource struct {
|
|
*base
|
|
Res *types.ReportDataSource
|
|
}
|
|
|
|
ReportBlock struct {
|
|
*base
|
|
Res *types.ReportBlock
|
|
}
|
|
)
|
|
|
|
func NewReport(res *types.Report) *Report {
|
|
r := &Report{
|
|
base: &base{},
|
|
}
|
|
r.SetResourceType(types.ReportResourceType)
|
|
r.Res = res
|
|
|
|
r.AddIdentifier(identifiers(res.Handle, res.ID)...)
|
|
|
|
// Initial stamps
|
|
r.SetTimestamps(MakeTimestampsCUDA(&res.CreatedAt, res.UpdatedAt, res.DeletedAt, nil))
|
|
r.SetUserstamps(MakeUserstampsCUDO(res.CreatedBy, res.UpdatedBy, res.DeletedBy, res.OwnedBy))
|
|
|
|
return r
|
|
}
|
|
|
|
func (r *Report) Resource() interface{} {
|
|
return r.Res
|
|
}
|
|
|
|
func (r *Report) AddReportSource(res *types.ReportDataSource) *ReportSource {
|
|
s := &ReportSource{
|
|
base: &base{},
|
|
}
|
|
|
|
s.Res = res
|
|
r.Sources = append(r.Sources, s)
|
|
|
|
return s
|
|
}
|
|
|
|
func (r *Report) RBACParts() (resource string, ref *Ref, path []*Ref) {
|
|
ref = r.Ref()
|
|
path = nil
|
|
resource = fmt.Sprintf(types.ReportRbacResourceTpl(), types.ReportResourceType, firstOkString(strconv.FormatUint(r.Res.ID, 10), r.Res.Handle))
|
|
|
|
return
|
|
}
|
|
|
|
// func (r *Report) ResourceTranslationParts() (resource string, ref *Ref, path []*Ref) {
|
|
// ref = r.Ref()
|
|
// path = nil
|
|
// resource = fmt.Sprintf(types.ReportResourceTranslationTpl(), types.ReportResourceTranslationType, firstOkString(strconv.FormatUint(r.Res.ID, 10), r.Res.Handle))
|
|
|
|
// return
|
|
// }
|
|
|
|
func (r *Report) AddReportBlock(res *types.ReportBlock) *ReportBlock {
|
|
p := &ReportBlock{
|
|
base: &base{},
|
|
}
|
|
|
|
p.Res = res
|
|
r.Blocks = append(r.Blocks, p)
|
|
|
|
return p
|
|
}
|
|
|
|
func (r *Report) SysID() uint64 {
|
|
return r.Res.ID
|
|
}
|
|
|
|
func (r *Report) encodeTranslations() ([]*ResourceTranslation, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
// FindReport looks for the workflow in the resource set
|
|
func FindReport(rr InterfaceSet, ii Identifiers) (ns *types.Report) {
|
|
var wfRes *Report
|
|
|
|
rr.Walk(func(r Interface) error {
|
|
wr, ok := r.(*Report)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
|
|
if wr.Identifiers().HasAny(ii) {
|
|
wfRes = wr
|
|
}
|
|
return nil
|
|
})
|
|
|
|
// Found it
|
|
if wfRes != nil {
|
|
return wfRes.Res
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func ReportErrUnresolved(ii Identifiers) error {
|
|
return fmt.Errorf("report unresolved %v", ii.StringSlice())
|
|
}
|