Skip to content
26 changes: 13 additions & 13 deletions adapter/controller_decorator.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package adapter

import (
"context"
"encoding/json"
"fmt"
"log/slog"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -59,16 +59,16 @@ func (c *controllerFunction) Decorate(db *db.DBSyncClient, _ *easyjson.JSON) eas
}

children := getChildrenUUIDSByLinkTypeRemote(db, c.id, lt)
return easyjson.JSONFromArray(children)
return easyjson.NewJSON(children)
case "getFromJPGQL":
query := ""
if len(c.args) > 0 {
query = c.args[0]
}
if uuids, err := db.Query.JPGQLCtraQuery(c.id, query); err == nil {
return easyjson.JSONFromArray(uuids)
return easyjson.NewJSON(uuids)
}
return easyjson.JSONFromArray([]string{})
return easyjson.NewJSON([]string{})
case "getFromFPLInBase64":
query := ""
if len(c.args) > 0 {
Expand Down Expand Up @@ -96,15 +96,15 @@ func (c *controllerFunction) Decorate(db *db.DBSyncClient, _ *easyjson.JSON) eas
}
}
// --------------------------------------------------------------------------
return easyjson.JSONFromArray(uuids)
return easyjson.NewJSON(uuids)
}
return easyjson.JSONFromArray([]string{})
return easyjson.NewJSON([]string{})
case "getInOutLinkTypes":
out := getInOutLinkTypes(db, c.id)
return easyjson.JSONFromArray(out)
return easyjson.NewJSON(out)
case "getOutLinkTypes":
out := getOutLinkTypes(db, c.id)
return easyjson.JSONFromArray(out)
return easyjson.NewJSON(out)
case "getLinksByType":
if len(c.args) != 1 {
return easyjson.NewJSON("invalid arguments")
Expand Down Expand Up @@ -153,7 +153,7 @@ func parseDecorators(objectID string, payload *easyjson.JSON) map[string]control
case _FUNCTION:
f, args, err := extractFunctionAndArgs(value)
if err != nil {
slog.Warn(err.Error())
logger.GetLogger().Warn(context.TODO(), err.Error())
continue
}

Expand All @@ -163,7 +163,7 @@ func parseDecorators(objectID string, payload *easyjson.JSON) map[string]control
args: args,
}
default:
slog.Warn("parse decorator: unknown decorator", "decorator", decorator)
logger.GetLogger().Warnf(context.TODO(), "parse decorator: unknown decorator=%s", decorator)
}
}

Expand Down Expand Up @@ -239,7 +239,7 @@ func parseArguments(s string) ([]string, error) {
return nil, fmt.Errorf("unbalanced parentheses in arguments")
}

// Добавляем последний аргумент
// Add last argument
if currentArg.Len() > 0 {
args = append(args, strings.TrimSpace(currentArg.String()))
}
Expand All @@ -255,7 +255,7 @@ func getChildrenLinkDataRemote(db *db.DBSyncClient, id, filterLinkType string, f

data, err := db.Graph.VertexRead(id, true)
if err != nil {
logger.Logln(logger.ErrorLevel, err.Error())
logger.GetLogger().Error(context.TODO(), err.Error())
return easyjson.NewJSONObject()
}

Expand Down Expand Up @@ -292,7 +292,7 @@ func getChildrenUUIDSByLinkTypeRemote(db *db.DBSyncClient, id, filterLinkType st

data, err := db.Graph.VertexRead(id, true)
if err != nil {
logger.Logln(logger.ErrorLevel, err.Error())
logger.GetLogger().Error(context.TODO(), err.Error())
return result
}

Expand Down
7 changes: 4 additions & 3 deletions adapter/decorators/in_out_link_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package decorators

import (
"context"
"strings"

"github.com/foliagecp/easyjson"
Expand All @@ -27,7 +28,7 @@ func inOutLinkTypes(_ sf.StatefunExecutor, ctx *sf.StatefunContextProcessor) {

data, err := db.Graph.VertexRead(ctx.Self.ID, true)
if err != nil {
logger.Logln(logger.ErrorLevel, err.Error())
logger.GetLogger().Error(context.TODO(), err.Error())
return
}

Expand Down Expand Up @@ -76,8 +77,8 @@ func inOutLinkTypes(_ sf.StatefunExecutor, ctx *sf.StatefunContextProcessor) {
}

resp := easyjson.NewJSONObject()
resp.SetByPath("in", easyjson.JSONFromArray(in))
resp.SetByPath("out", easyjson.JSONFromArray(out))
resp.SetByPath("in", easyjson.NewJSON(in))
resp.SetByPath("out", easyjson.NewJSON(out))
okResponse(ctx, resp)
}

Expand Down
4 changes: 3 additions & 1 deletion adapter/decorators/links_by_type.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package decorators

import (
"context"

"github.com/foliagecp/sdk/statefun/logger"
sf "github.com/foliagecp/sdk/statefun/plugins"
"github.com/foliagecp/ui-app-lib/internal/common"
Expand Down Expand Up @@ -39,7 +41,7 @@ func linksByType(_ sf.StatefunExecutor, ctx *sf.StatefunContextProcessor) {
db := common.MustDBClient(ctx.Request)
data, err := db.Graph.VertexRead(ctx.Self.ID, true)
if err != nil {
logger.Logln(logger.ErrorLevel, err.Error())
logger.GetLogger().Error(context.TODO(), err.Error())
return
}

Expand Down
7 changes: 4 additions & 3 deletions adapter/decorators/types_navigation.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package decorators

import (
"context"
"encoding/json"
"log/slog"
"sort"

"github.com/foliagecp/sdk/embedded/graph/crud"
"github.com/foliagecp/sdk/statefun/logger"
sf "github.com/foliagecp/sdk/statefun/plugins"
"github.com/foliagecp/ui-app-lib/internal/common"
)
Expand Down Expand Up @@ -133,7 +134,7 @@ func typesNavigation(_ sf.StatefunExecutor, ctx *sf.StatefunContextProcessor) {
if ok := typeBody.PathExists("object_ids"); ok {
var typeObjects []string
if err := json.Unmarshal(typeBody.GetByPath("object_ids").ToBytes(), &typeObjects); err != nil {
slog.Warn(err.Error())
logger.GetLogger().Warn(context.TODO(), err.Error())
}

for _, v := range typeObjects {
Expand Down Expand Up @@ -239,7 +240,7 @@ func inOutTypes(ctx *sf.StatefunContextProcessor, id string) []string {

link, err := db.CMDB.TypesLinkRead(objectID, id)
if err != nil {
slog.Error(err.Error())
logger.GetLogger().Error(context.TODO(), err.Error())
continue
}

Expand Down
42 changes: 21 additions & 21 deletions adapter/statefun.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package adapter
import (
"context"
"fmt"
"log/slog"
"strings"
"sync"
"time"
Expand All @@ -12,6 +11,7 @@ import (
"github.com/foliagecp/sdk/clients/go/db"
"github.com/foliagecp/sdk/embedded/graph/crud"
"github.com/foliagecp/sdk/statefun"
"github.com/foliagecp/sdk/statefun/logger"
sfplugins "github.com/foliagecp/sdk/statefun/plugins"
"github.com/foliagecp/sdk/statefun/system"
"github.com/foliagecp/ui-app-lib/adapter/decorators"
Expand Down Expand Up @@ -44,7 +44,7 @@ func controllerObjectOnTriggerWindowUpdater(runtime *statefun.Runtime) {
for objectUUI, updatePayload := range controllerObjectOnTriggerWindowUpdaterTasks {
err := runtime.Signal(sfplugins.AutoSignalSelect, inStatefun.CONTROLLER_OBJECT_UPDATE, objectUUI, updatePayload, nil)
if err != nil {
slog.Warn(err.Error())
logger.GetLogger().Warn(context.TODO(), err.Error())
}
}
clear(controllerObjectOnTriggerWindowUpdaterTasks)
Expand All @@ -56,11 +56,11 @@ func controllerObjectOnTriggerWindowUpdater(runtime *statefun.Runtime) {
}

func RegisterFunctions(runtime *statefun.Runtime) {
statefun.NewFunctionType(runtime, inStatefun.CONTROLLER_START, StartController, *statefun.NewFunctionTypeConfig())
statefun.NewFunctionType(runtime, inStatefun.CONTROLLER_CLEAR, ClearController, *statefun.NewFunctionTypeConfig())
statefun.NewFunctionType(runtime, inStatefun.CONTROLLER_OBJECT_UPDATE, UpdateControllerObject, *statefun.NewFunctionTypeConfig())
statefun.NewFunctionType(runtime, inStatefun.CONTROLLER_OBJECT_TRIGGER, ControllerObjectTrigger, *statefun.NewFunctionTypeConfig())
statefun.NewFunctionType(runtime, inStatefun.CONTROLLER_CONSTRUCT, ControllerConstruct, *statefun.NewFunctionTypeConfig().SetAllowedRequestProviders(sfplugins.AutoRequestSelect))
statefun.NewFunctionType(runtime, inStatefun.CONTROLLER_START, StartController, *statefun.NewFunctionTypeConfig().SetIdChannelSize(100))
statefun.NewFunctionType(runtime, inStatefun.CONTROLLER_CLEAR, ClearController, *statefun.NewFunctionTypeConfig().SetIdChannelSize(100))
statefun.NewFunctionType(runtime, inStatefun.CONTROLLER_OBJECT_UPDATE, UpdateControllerObject, *statefun.NewFunctionTypeConfig().SetIdChannelSize(100))
statefun.NewFunctionType(runtime, inStatefun.CONTROLLER_OBJECT_TRIGGER, ControllerObjectTrigger, *statefun.NewFunctionTypeConfig().SetIdChannelSize(100))
statefun.NewFunctionType(runtime, inStatefun.CONTROLLER_CONSTRUCT, ControllerConstruct, *statefun.NewFunctionTypeConfig().SetAllowedRequestProviders(sfplugins.AutoRequestSelect).SetIdChannelSize(100))

decorators.Register(runtime)

Expand Down Expand Up @@ -152,14 +152,14 @@ func StartController(_ sfplugins.StatefunExecutor, ctx *sfplugins.StatefunContex

if err := cmdb.ObjectsLinkCreate(self.ID, caller.ID, caller.ID, []string{}); err != nil {
if !common.ErrorAlreadyExists(err) {
slog.Warn("failed to create objects link between controller and session", "err", err.Error())
logger.GetLogger().Warnf(context.TODO(), "failed to create objects link between controller and session, err=%v", err.Error())
return
}
}

if err := cmdb.ObjectsLinkCreate(caller.ID, self.ID, self.ID, []string{}); err != nil {
if !common.ErrorAlreadyExists(err) {
slog.Warn("failed to create objects link between session and controller", "err", err.Error())
logger.GetLogger().Warnf(context.TODO(), "failed to create objects link between session and controller, err=%v", err.Error())
return
}
}
Expand All @@ -174,14 +174,14 @@ func StartController(_ sfplugins.StatefunExecutor, ctx *sfplugins.StatefunContex
objectType, err := common.ObjectType(cmdb, objectUUID)
if err != nil {
if !common.ErrorAlreadyExists(err) {
slog.Warn("failed to find uuid type", "err", err.Error())
logger.GetLogger().Warnf(context.TODO(), "failed to find uuid type, err=%v", err.Error())
return
}
}

if err := cmdb.TypesLinkCreate(inStatefun.CONTROLLER_OBJECT_TYPE, objectType, inStatefun.CONTROLLER_SUBJECT_TYPE, []string{}); err != nil {
if !common.ErrorAlreadyExists(err) {
slog.Warn("failed to create types link between controller object and uuid", "err", err.Error())
logger.GetLogger().Warn(context.TODO(), "failed to create types link between controller object and uuid", err.Error())
return
}
}
Expand Down Expand Up @@ -347,7 +347,7 @@ func StartController(_ sfplugins.StatefunExecutor, ctx *sfplugins.StatefunContex
// if it's different send update to controller
func UpdateControllerObject(_ sfplugins.StatefunExecutor, ctx *sfplugins.StatefunContextProcessor) {
controllerObjectID := ctx.Self.ID
slog.Info("Update controller object", "id", controllerObjectID)
logger.GetLogger().Infof(context.TODO(), "Update controller object, id=%s", controllerObjectID)

var body *easyjson.JSON
var parentControllerID string
Expand All @@ -371,21 +371,21 @@ func UpdateControllerObject(_ sfplugins.StatefunExecutor, ctx *sfplugins.Statefu

if err := cmdb.ObjectCreate(controllerObjectID, inStatefun.CONTROLLER_OBJECT_TYPE, controllerObjectBody); err != nil {
if !common.ErrorAlreadyExists(err) {
slog.Warn("failed to create controller object", "err", err.Error())
logger.GetLogger().Warnf(context.TODO(), "failed to create controller object, err=%s", err.Error())
return
}
}

if err := cmdb.ObjectsLinkCreate(controllerObjectID, realObjectID, "uiapplib_"+realObjectID, []string{}); err != nil {
if !common.ErrorAlreadyExists(err) {
slog.Warn("failed to create objects link between controller object and uuid", "err", err.Error())
logger.GetLogger().Warnf(context.TODO(), "failed to create objects link between controller object and uuid, err=%s", err.Error())
return
}
}

if err := cmdb.ObjectsLinkCreate(parentControllerID, controllerObjectID, controllerObjectID, []string{}); err != nil {
if !common.ErrorAlreadyExists(err) {
slog.Warn("failed to create objects link between controller and controller object", "err", err.Error())
logger.GetLogger().Warnf(context.TODO(), "failed to create objects link between controller and controller object, err=%s", err.Error())
return
}
}
Expand All @@ -395,7 +395,7 @@ func UpdateControllerObject(_ sfplugins.StatefunExecutor, ctx *sfplugins.Statefu
} else {
parentUUID, ok := body.GetByPath("parent").AsString()
if !ok {
slog.Warn("empty controller id")
logger.GetLogger().Warn(context.TODO(), "empty controller id")
return
}
parentControllerID = parentUUID
Expand All @@ -405,7 +405,7 @@ func UpdateControllerObject(_ sfplugins.StatefunExecutor, ctx *sfplugins.Statefu

controllerBody, err := ctx.Domain.Cache().GetValueJSON(parentControllerID)
if err != nil {
slog.Error(err.Error())
logger.GetLogger().Error(context.TODO(), err.Error())
return
}

Expand Down Expand Up @@ -462,16 +462,16 @@ func UpdateControllerObject(_ sfplugins.StatefunExecutor, ctx *sfplugins.Statefu
subscribers := getChildrenUUIDSByLinkTypeLocal(ctx, parentControllerID, inStatefun.SUBSCRIBER_TYPE)

if len(forceUpdateSessionId) == 0 {
slog.Info("Send update to subscribers", "subscribers", subscribers)
logger.GetLogger().Infof(context.TODO(), "Send update to subscribers=%v", subscribers)
for _, subID := range subscribers {
if err := egress.SendToSessionEgress(ctx, subID, &updateReply); err != nil {
slog.Warn(err.Error())
logger.GetLogger().Warn(context.TODO(), err.Error())
}
}
} else {
slog.Info("Send update to force update requested session only", "subscribers", subscribers)
logger.GetLogger().Infof(context.TODO(), "Send update to force update requested session only, subscribers=%v", subscribers)
if err := egress.SendToSessionEgress(ctx, forceUpdateSessionId, &updateReply); err != nil {
slog.Warn(err.Error())
logger.GetLogger().Warn(context.TODO(), err.Error())
}
}
// ------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion adapter/statefun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (s *adapterTestSuite) Test_StartController_Correct() {
payload := easyjson.NewJSONObject()
payload.SetByPath("name", easyjson.NewJSON(controllerName))
payload.SetByPath("declaration", controllerDeclaration)
payload.SetByPath("uuids", easyjson.JSONFromArray(uuids))
payload.SetByPath("uuids", easyjson.NewJSON(uuids))

err = s.Signal(sfplugins.AutoSignalSelect, typename, controllerID, &payload, nil)
s.Require().NoError(err)
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ go 1.21.1

require (
github.com/foliagecp/easyjson v0.1.7
github.com/foliagecp/sdk v0.1.7-cachejson-hotfix-2
github.com/foliagecp/sdk v0.1.7-dev08072025.0.20251024102811-464daa79e017
github.com/google/uuid v1.6.0
github.com/stretchr/testify v1.11.1
)

require (
github.com/PaesslerAG/gval v1.2.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/dot v1.6.1 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
github.com/klauspost/compress v1.17.7 // indirect
Expand All @@ -28,6 +30,7 @@ require (
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/time v0.5.0 // indirect
Expand Down
Loading
Loading