3
0

Fixup envoy codegen

This commit is contained in:
Tomaž Jerman 2021-09-20 12:45:45 +02:00
parent 16f789bdb4
commit 3ba9c61986
8 changed files with 161 additions and 4 deletions

View File

@ -11,7 +11,6 @@ package service
import (
"context"
"github.com/cortezaproject/corteza-server/automation/types"
"github.com/cortezaproject/corteza-server/pkg/actionlog"

View File

@ -14,7 +14,6 @@ package service
import (
"context"
"github.com/cortezaproject/corteza-server/compose/types"
"github.com/cortezaproject/corteza-server/pkg/actionlog"

View File

@ -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()

View File

@ -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())
}

View File

@ -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
}

View File

@ -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

View File

@ -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
}

View File

@ -11,7 +11,6 @@ package service
import (
"context"
"github.com/cortezaproject/corteza-server/system/types"
"github.com/cortezaproject/corteza-server/pkg/actionlog"