From 3ba9c619863a336e9beccebdd4115d1e4e41e876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Jerman?= Date: Mon, 20 Sep 2021 12:45:45 +0200 Subject: [PATCH] Fixup envoy codegen --- automation/service/locale.gen.go | 1 - compose/service/locale.gen.go | 1 - .../resource-resource_translation.go.tpl | 2 +- pkg/envoy/resource/report.go | 109 ++++++++++++++++++ .../resource/resource_translation.gen.go | 14 +++ .../resource_translation_parse.gen.go | 12 ++ ...ource_translation_references_system.gen.go | 25 ++++ system/service/locale.gen.go | 1 - 8 files changed, 161 insertions(+), 4 deletions(-) create mode 100644 pkg/envoy/resource/report.go create mode 100644 pkg/envoy/resource/resource_translation_references_system.gen.go diff --git a/automation/service/locale.gen.go b/automation/service/locale.gen.go index 510fc74df..26c97ce89 100644 --- a/automation/service/locale.gen.go +++ b/automation/service/locale.gen.go @@ -11,7 +11,6 @@ package service import ( "context" - "github.com/cortezaproject/corteza-server/automation/types" "github.com/cortezaproject/corteza-server/pkg/actionlog" diff --git a/compose/service/locale.gen.go b/compose/service/locale.gen.go index fc5e4db1d..e4fd7ce62 100644 --- a/compose/service/locale.gen.go +++ b/compose/service/locale.gen.go @@ -14,7 +14,6 @@ package service import ( "context" - "github.com/cortezaproject/corteza-server/compose/types" "github.com/cortezaproject/corteza-server/pkg/actionlog" diff --git a/pkg/codegen-v3/assets/templates/gocode/envoy/resource-resource_translation.go.tpl b/pkg/codegen-v3/assets/templates/gocode/envoy/resource-resource_translation.go.tpl index 4210d4701..580d1df0c 100644 --- a/pkg/codegen-v3/assets/templates/gocode/envoy/resource-resource_translation.go.tpl +++ b/pkg/codegen-v3/assets/templates/gocode/envoy/resource-resource_translation.go.tpl @@ -14,7 +14,7 @@ import ( {{ $Component := .Component }} {{ $Resource := .Resource }} {{ $GoType := printf "types.%s" .Resource }} -func (r *{{export $Component}}{{$Resource}}) EncodeTranslations() ([]*ResourceTranslation, error) { +func (r *{{if not (eq $Component "system")}}{{export $Component}}{{ end }}{{$Resource}}) EncodeTranslations() ([]*ResourceTranslation, error) { out := make([]*ResourceTranslation, 0, 10) rr := r.Res.EncodeTranslations() diff --git a/pkg/envoy/resource/report.go b/pkg/envoy/resource/report.go new file mode 100644 index 000000000..aa453fc20 --- /dev/null +++ b/pkg/envoy/resource/report.go @@ -0,0 +1,109 @@ +package resource + +import ( + "fmt" + "strconv" + + "github.com/cortezaproject/corteza-server/system/types" +) + +type ( + Report struct { + *base + Res *types.Report + + Sources []*ReportSource + Projections []*ReportProjection + } + + ReportSource struct { + *base + Res *types.ReportDataSource + } + + ReportProjection struct { + *base + Res *types.ReportProjection + } +) + +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) AddReportSource(res *types.ReportDataSource) *ReportSource { + s := &ReportSource{ + base: &base{}, + } + + s.Res = res + r.Sources = append(r.Sources, s) + + return s +} + +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) AddReportProjection(res *types.ReportProjection) *ReportProjection { + p := &ReportProjection{ + base: &base{}, + } + + p.Res = res + r.Projections = append(r.Projections, 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()) +} diff --git a/pkg/envoy/resource/resource_translation.gen.go b/pkg/envoy/resource/resource_translation.gen.go index 1c09c8195..11bac24bf 100644 --- a/pkg/envoy/resource/resource_translation.gen.go +++ b/pkg/envoy/resource/resource_translation.gen.go @@ -13,6 +13,7 @@ package resource // - compose.module.yaml // - compose.namespace.yaml // - compose.page.yaml +// - system.report.yaml import ( systemTypes "github.com/cortezaproject/corteza-server/system/types" @@ -87,3 +88,16 @@ func (r *ComposePage) EncodeTranslations() ([]*ResourceTranslation, error) { return append(out, tmp...), err } + +func (r *Report) EncodeTranslations() ([]*ResourceTranslation, error) { + out := make([]*ResourceTranslation, 0, 10) + + rr := r.Res.EncodeTranslations() + rr.SetLanguage(defaultLanguage) + res, ref, pp := r.ResourceTranslationParts() + out = append(out, NewResourceTranslation(systemTypes.FromLocale(rr), res, ref, pp...)) + + tmp, err := r.encodeTranslations() + return append(out, tmp...), err + +} diff --git a/pkg/envoy/resource/resource_translation_parse.gen.go b/pkg/envoy/resource/resource_translation_parse.gen.go index 6cba461fc..eb6c3f232 100644 --- a/pkg/envoy/resource/resource_translation_parse.gen.go +++ b/pkg/envoy/resource/resource_translation_parse.gen.go @@ -13,11 +13,13 @@ package resource // - compose.module.yaml // - compose.namespace.yaml // - compose.page.yaml +// - system.report.yaml import ( "fmt" automationTypes "github.com/cortezaproject/corteza-server/automation/types" composeTypes "github.com/cortezaproject/corteza-server/compose/types" + systemTypes "github.com/cortezaproject/corteza-server/system/types" "strings" ) @@ -131,6 +133,16 @@ func ParseResourceTranslation(res string) (string, *Ref, []*Ref, error) { ) return composeTypes.PageResourceTranslationType, ref, pp, err + case systemTypes.ReportResourceTranslationType: + if len(path) != 1 { + return "", nil, nil, fmt.Errorf("expecting 1 reference components in path, got %d", len(path)) + } + ref, pp, err := SystemReportResourceTranslationReferences( + // report + path[0], + ) + return systemTypes.ReportResourceTranslationType, ref, pp, err + } // return unhandled resource as-is diff --git a/pkg/envoy/resource/resource_translation_references_system.gen.go b/pkg/envoy/resource/resource_translation_references_system.gen.go new file mode 100644 index 000000000..c781bd5ed --- /dev/null +++ b/pkg/envoy/resource/resource_translation_references_system.gen.go @@ -0,0 +1,25 @@ +package resource + +// This file is auto-generated. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// + +// Definitions file that controls how this file is generated: +// - system.report.yaml + +import ( + "github.com/cortezaproject/corteza-server/system/types" +) + +// SystemReportResourceTranslationReferences generates Locale references +// +// Resources with "envoy: false" are skipped +// +// This function is auto-generated +func SystemReportResourceTranslationReferences(report string) (res *Ref, pp []*Ref, err error) { + res = &Ref{ResourceType: types.ReportResourceType, Identifiers: MakeIdentifiers(report)} + + return +} diff --git a/system/service/locale.gen.go b/system/service/locale.gen.go index aaefefcd8..3a02e18cf 100644 --- a/system/service/locale.gen.go +++ b/system/service/locale.gen.go @@ -11,7 +11,6 @@ package service import ( "context" - "github.com/cortezaproject/corteza-server/system/types" "github.com/cortezaproject/corteza-server/pkg/actionlog"