qlik-oss / enigma-go

Go library for consuming Qlik's Associative Engine.
MIT License
39 stars 12 forks source link

chartObject.GetProperties() is missing many chart properties #246

Closed wvkehoe closed 2 years ago

wvkehoe commented 2 years ago

Description

It appears that the GetProperties and GetFullPropertyTree methods on a chart object do not return all of the properties of the chart.

Steps to Reproduce

  1. Create (or find) and app that has at least one sheet and one chart
  2. Make sure the chart has a title property value
  3. Use a program that looks as follows to loop through all the sheets and all the charts of each sheet to obtain the properties of each chart (before calling the function, open a new enigma doc session on the app and pass the "doc" object to the function)
func GetAllChartProperties(ctx context, doc *enigma,doc) {
        sheetListObject, e := doc.CreateSessionObject(ctx, &enigma.GenericObjectProperties{
        Info:             &enigma.NxInfo{Type: "SheetList"},
        AppObjectListDef: &enigma.AppObjectListDef{Type: "sheet", Data: sheetContents},
    })
    sheetListObjectLayout, e := sheetListObject.GetLayout(ctx)
    if e != nil {
           fmt.Printf("error obtaining sheetList object:", e.Error())
           return
    }
    if sheetListObjectLayout != nil && sheetListObjectLayout.AppObjectList != nil {
        for _, sh := range sheetListObjectLayout.AppObjectList.Items {
            shID := sh.Info.Id
            shObj, err := doc.GetObject(ctx, shID)
            var shData models.QSheetData
            e := json.Unmarshal(sh.Data, &shData)
            if e != nil {
                fmt.Printf("error unmarshalling sheet data %s:", e.Error())
                continue
            }
            var sheetChartRefs []string
            for _, ch := range shData.Charts {
                // get the details of this chart
                chartObj, e := doc.GetObject(ctx, ch.Name)
                if err != nil {
                                     fmt.Printf("error getting chart object '%s': %s", ch.Name, e.Error())
                                     continue
                } else {
                        chartProps, err := chartObj.GetProperties(ctx)
                                     // EXAMINE chartProps IN DEBUGGER HERE AND NOTE THE ABSENCE OF title, subtitle, etc. properties
                                 }
                         }
                 }
        }
}
Expected behavior

It is expected to find properties like title, subtitle, footnote, etc. but these properties are not included in the results of the chartObject.GetProperties method call.

Actual behavior

The results of the chartObj.GetProperties call includes content as shown below: Screen Shot 2022-02-16 at 9 01 43 AM

Environment

MacOS Big Sur 11.6.1, enigma-go v3.2.0

Operating system
[ ] Windows
[x] OSX
[ ] Linux

Versions

wennmo commented 2 years ago

Hi @wvkehoe, the GetProperties and GetFullPropertyTree functions will only return properties that are defined by engine i.e. properties that are part of the engine JSON-RPC specification.

For custom properties that are set by e.g. the sense-client you will need to use the GetPropertiesRaw or GetFullPropertyTreeRaw functions instead. https://pkg.go.dev/github.com/qlik-oss/enigma-go#GenericObject.GetPropertiesRaw

There is an example for this as well here

wvkehoe commented 2 years ago

@wennmo Thanks for the follow-up. I was able to use GetPropertiesRaw with this type unmarshal structure:

type customObjectProperties struct {
    enigma.GenericObjectProperties
    Title    string `json:"title"`
    Subtitle string `json:"subtitle"`
    Footnote string `json:"footnote"`
}

to obtain the title, subtitle and footnote for each chart.
Unfortunately, when I try to do a similar approach with using GetPropertiesRaw on a sheet object to get its ownerId, publish status, creation and modified date using the following unmarshal structure, I don't get any results (just emty strings and :

type customSheetProperties struct {
    enigma.GenericObjectProperties
    OwnerId      string `json:"ownerId"`
    Published    bool   `json:"published"`
    CreatedDate  string `json:"createdDate"`
    ModifiedDate string `json:"modifiedDate"`
}

Do you know where I can find the documentation on custom sheet properties?

wennmo commented 2 years ago

Ok, great that it lead to some progress 👍

The properties defined by the client on a sheet (and other objects) should be documented on qlik.dev.

If you want to take a closer look at what properties that are returned from engine for a specific object/call you can also log the traffic in enigma-go. There is an example for how to enable logging here

wennmo commented 2 years ago

Hi @wvkehoe, can we consider this issue resolved?

wennmo commented 2 years ago

Closing issue for now, since there are no remaining questions. Feel free to reopen or create a new issue if needed.