Skip to content

Commit

Permalink
Apicompliance 1288 - Open App (#419)
Browse files Browse the repository at this point in the history
Changes for API compliance with latest Sense version
  • Loading branch information
DnlLrssn authored Aug 17, 2023
1 parent c52c5e8 commit 2545f65
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 87 deletions.
2 changes: 1 addition & 1 deletion scenario/changesheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (settings ChangeSheetSettings) Execute(sessionState *session.State, actionS

// Get or create current selection object
sessionState.QueueRequest(func(ctx context.Context) error {
if _, err := uplink.CurrentApp.GetCurrentSelections(sessionState, actionState); err != nil {
if _, err := uplink.CurrentApp.GetCurrentSelections(sessionState, actionState, true); err != nil {
return errors.WithStack(err)
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion scenario/createbookmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (settings CreateBookmarkSettings) Execute(sessionState *session.State, acti

// Get or create current selection object
sessionState.QueueRequest(func(ctx context.Context) error {
if _, err := uplink.CurrentApp.GetCurrentSelections(sessionState, actionState); err != nil {
if _, err := uplink.CurrentApp.GetCurrentSelections(sessionState, actionState, true); err != nil {
return errors.WithStack(err)
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion scenario/generateodag.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func GenerateOdag(sessionState *session.State, settings GenerateOdagSettings, ac
func MakeOdagRequest(sessionState *session.State, actionState *action.State, odagLinkBindings []structs.OdagLinkBinding, host string, odagEndpoint OdagEndpointConfiguration, odagLinkId string, postObject structs.IOdagPostRequest, connection *enigmahandlers.SenseUplink) error {
var currentSelections *senseobjects.CurrentSelections
var err error
if currentSelections, err = connection.CurrentApp.GetCurrentSelections(sessionState, actionState); err != nil {
if currentSelections, err = connection.CurrentApp.GetCurrentSelections(sessionState, actionState, true); err != nil {
return errors.WithStack(err)
}

Expand Down
10 changes: 10 additions & 0 deletions scenario/openapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ func (openApp OpenAppSettings) Execute(sessionState *session.State, actionState
return errors.WithStack(err)
}, actionState, true, "")

sessionState.QueueRequest(func(ctx context.Context) error {
_, err := uplink.Global.AllowCreateApp(ctx)
return errors.WithStack(err)
}, actionState, true, "")

sessionState.QueueRequest(func(ctx context.Context) error {
_, err := uplink.CurrentApp.Doc.GetScriptEx(ctx)
return errors.WithStack(err)
}, actionState, true, "")

for i := 0; i < 2; i++ {
sessionState.QueueRequestRaw(uplink.CurrentApp.Doc.GetAppPropertiesRaw, actionState, true, "failed to get AppProperties")
}
Expand Down
43 changes: 24 additions & 19 deletions senseobjects/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,6 @@ func (app *App) GetVariableList(sessionState SessionState, actionState *action.S
return nil, errors.WithStack(err)
}

if err := sessionState.SendRequest(actionState, app.variablelist.UpdateProperties); err != nil {
return nil, errors.WithStack(err)
}

// update variable list layout when variable list has a change event
onVariableListChanged := func(ctx context.Context, actionState *action.State) error {
return errors.WithStack(app.variablelist.UpdateLayout(ctx))
Expand Down Expand Up @@ -193,10 +189,6 @@ func (app *App) GetAppsPropsList(sessionState SessionState, actionState *action.
return nil, errors.WithStack(err)
}

if err := sessionState.SendRequest(actionState, app.appPropsList.UpdateProperties); err != nil {
return nil, errors.WithStack(err)
}

if err := sessionState.SendRequest(actionState, func(ctx context.Context) error {
return app.appPropsList.UpdateLayout(ctx, app.Doc, sessionState, actionState)
}); err != nil {
Expand Down Expand Up @@ -457,8 +449,15 @@ func (app *App) GetFieldList(sessionState SessionState, actionState *action.Stat
}

// GetCurrentSelections create current selection session object and add to list
func (app *App) GetCurrentSelections(sessionState SessionState, actionState *action.State) (*CurrentSelections, error) {
func (app *App) GetCurrentSelections(sessionState SessionState, actionState *action.State, requestData bool) (*CurrentSelections, error) {
if app.currentSelections != nil {
if requestData && app.currentSelections.enigmaObject != nil {
if f := sessionState.GetEventFunc(app.currentSelections.enigmaObject.Handle); f != nil {
if err := f(sessionState.BaseContext(), actionState); err != nil {
return app.currentSelections, errors.WithStack(err)
}
}
}
return app.currentSelections, nil
}

Expand All @@ -475,20 +474,26 @@ func (app *App) GetCurrentSelections(sessionState SessionState, actionState *act
return nil, errors.WithStack(err)
}

// Get layout
if err := sessionState.SendRequest(actionState, app.currentSelections.UpdateProperties); err != nil {
return nil, errors.WithStack(err)
}
if err := sessionState.SendRequest(actionState, app.currentSelections.UpdateLayout); err != nil {
return nil, errors.WithStack(err)
}

var once sync.Once
// update currentSelection layout when object is changed
onCurrentSelectionChanged := func(ctx context.Context, actionState *action.State) error {
var err error
once.Do(func() {
err = sessionState.SendRequest(actionState, app.currentSelections.UpdateProperties)
})
if err != nil {
return errors.WithStack(err)
}
return errors.WithStack(app.currentSelections.UpdateLayout(ctx))
}
sessionState.RegisterEvent(app.currentSelections.enigmaObject.Handle,
onCurrentSelectionChanged, nil, true)

if requestData {
if err := onCurrentSelectionChanged(sessionState.BaseContext(), actionState); err != nil {
return nil, errors.WithStack(err)
}
}

sessionState.RegisterEvent(app.currentSelections.enigmaObject.Handle, onCurrentSelectionChanged, nil, true)

return app.currentSelections, nil
}
Expand Down
34 changes: 0 additions & 34 deletions senseobjects/appspropslist.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
type (
AppPropsList struct {
enigmaObject *enigma.GenericObject
properties *enigma.GenericObjectProperties
layout *enigma.GenericObjectLayout
items map[string]*enigma.GenericObject

Expand Down Expand Up @@ -53,39 +52,6 @@ func CreateAppPropsListObject(ctx context.Context, doc *enigma.Doc) (*AppPropsLi
}, nil
}

// UpdateProperties of AppPropsList
func (appPropsList *AppPropsList) UpdateProperties(ctx context.Context) error {
if appPropsList.enigmaObject == nil {
return errors.Errorf("AppPropsList enigma object is nil")
}
propertiesRaw, err := appPropsList.enigmaObject.GetEffectivePropertiesRaw(ctx)
if err != nil {
return errors.WithStack(err)
}

var properties enigma.GenericObjectProperties
err = json.Unmarshal(propertiesRaw, &properties)
if err != nil {
return errors.Wrap(err, "Failed to unmarshal AppPopsList properties")
}

appPropsList.setProperties(&properties)
return nil
}

func (appPropsList *AppPropsList) setProperties(properties *enigma.GenericObjectProperties) {
appPropsList.mu.Lock()
defer appPropsList.mu.Unlock()
appPropsList.properties = properties
}

// Properties of AppPropsList
func (appPropsList *AppPropsList) Properties() *enigma.GenericObjectProperties {
appPropsList.mu.Lock()
defer appPropsList.mu.Unlock()
return appPropsList.properties
}

// UpdateLayout of AppPropsList
func (appPropsList *AppPropsList) UpdateLayout(ctx context.Context, doc *enigma.Doc, sessionState SessionState, actionState *action.State) error {
if appPropsList.enigmaObject == nil {
Expand Down
1 change: 1 addition & 0 deletions senseobjects/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type (
onClose func(),
failOnError bool)
DeRegisterEvent(handle int)
GetEventFunc(handle int) func(ctx context.Context, actionState *action.State) error
LogDebugf(format string, args ...interface{})
LogDetail(level logger.LogLevel, msg, detail string)
LogError(err error)
Expand Down
33 changes: 2 additions & 31 deletions senseobjects/variablelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package senseobjects

import (
"context"
"github.com/goccy/go-json"
"sync"

"github.com/goccy/go-json"

"github.com/pkg/errors"
"github.com/qlik-oss/enigma-go/v4"
)
Expand All @@ -14,7 +15,6 @@ type (
VariableList struct {
enigmaObject *enigma.GenericObject
layout *enigma.GenericObjectLayout
properties *enigma.GenericObjectProperties

mutex sync.Mutex
}
Expand Down Expand Up @@ -74,32 +74,3 @@ func (variableList *VariableList) setLayout(layout *enigma.GenericObjectLayout)

variableList.layout = layout
}

// UpdateProperties get and set properties for VariableList
func (variableList *VariableList) UpdateProperties(ctx context.Context) error {
if variableList.enigmaObject == nil {
return errors.Errorf("variableList enigma object is nil")
}

propertiesRaw, err := variableList.enigmaObject.GetEffectivePropertiesRaw(ctx)
if err != nil {
return errors.Wrapf(err, "Failed to unmarshal variableList properties")
}

var properties enigma.GenericObjectProperties
err = json.Unmarshal(propertiesRaw, &properties)
if err != nil {
return errors.Wrap(err, "Failed to unmarshal variableList properties")
}

variableList.setProperties(&properties)

return nil
}

func (variableList *VariableList) setProperties(properties *enigma.GenericObjectProperties) {
variableList.mutex.Lock()
defer variableList.mutex.Unlock()

variableList.properties = properties
}
11 changes: 11 additions & 0 deletions session/sessionstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,17 @@ func (state *State) RegisterEvent(handle int,
})
}

// GetEvent for handle
func (state *State) GetEventFunc(handle int) func(ctx context.Context, actionState *action.State) error {
state.eventMu.Lock()
defer state.eventMu.Unlock()
event, exist := state.events[handle]
if exist && event != nil {
return event.F
}
return nil
}

// DeRegisterEvents for handles in list
func (state *State) DeRegisterEvents(handles []int) {
state.eventMu.Lock()
Expand Down

0 comments on commit 2545f65

Please sign in to comment.