How to create BE lint rules
 
Forums / SmartComponent Library - Developer Forum / How to create BE lint rules

How to create BE lint rules

5 posts, 0 answered
  1. Carl Verbiest
    Carl Verbiest avatar
    59 posts
    Registered:
    12 Oct 2018
    18 Oct 2019
    Link to this post

    Note: By now I already have an answer to most questions I pose here.
    I'm still posting because

    1. I'd like some sanity check of the way I'm approaching this
    2. If valid, the answers I found might be useful for someone else.

    We have some rules concerning Business entities

    Examples
    * some fields should be present in entity temp-tables
    * some fields should not be present in entity temp-tables
    * all uniquely indexed fields should be initial ?
    * ...

    We would like those checks done before saving a BE
    We would like the ability to run the same checks in batch, possible through unit checks.
    Similar to sonar lint rules we'd like a mechanism to mark rule violations as intentional.
    e.g. field that should normally be present is left out intentionally

    The rules would be mostly custom, although I can image there could be some rules that are generally accepted, e.g.temp-table should have a unique index.

    Can we have some general provisions in the BED / BEDGM for this or should we write a custom plugin for that ? Currently, going for the custom plugin approach

    If done by a custom plugin are there fields/tables in the bedgm data structure we can safely use to mark violations as intentional ? Can we use the *properties tables for that ?

    Is there a save event that has a cancellable eventargs ? Currently, subscribing to BusinessEntityDatasetController:BeforeFileSave

    Code fragments from our plugin.


        method public void Startup (dataset for dsBusinessEntity bind,
                                    poController as BusinessEntityDatasetController,
                                    poForm as BusinessEntityDesignerForm,
                                    poToolbar as UltraToolbarsManager):

            this-object:Form = poForm .
            this-object:Controller = poController .

            if valid-object(this-object:Controller)
            then this-object:Controller:BeforeFileSave:subscribe(this-object:BeforeFileSaveHandler).

             /* trimmed */   
        end method .

        method public void BeforeFileSaveHandler(caller as progress.lang.object, e AS CancelableFileEventArgs):

            define variable hDs as handle no-undo.
            hDs = dataset dsBusinessEntity:handle.

            new be.cce.SmartTools.BusinessEntityDesigner.Validator.CceDesignValidation(DATASET-HANDLE hDs BIND):PerformChecks().

        end method.

        method public void Shutdown ():

            if valid-object(this-object:Controller)
            then this-object:Controller:BeforeFileSave:unsubscribe(this-object:BeforeFileSaveHandler).
            this-object:Form = ?.
            this-object:Controller = ?.

        end method .




  2. Mike Fechner
    Mike Fechner avatar
    319 posts
    Registered:
    14 Sep 2016
    18 Oct 2019 in reply to Carl Verbiest
    Link to this post
    I strongly suggest NOT to prevent saving of the .bedgm file in any case! Saving the file does not mean the developer is done with his task - he might just save an intermediate result because he's switching to a different task (like end of work day) temporarily. Permissive validation should only be implemented when calling a task done (per-commit?) or generating code.

    The BeforeFileSave event of the BusinessEntityDatasetController is cancelable. However the intention of this event was to implement SCM checkout. And not validation. But you probably may use it and ignore the intended use. 

    You can  use the ....Properties tables can be used to store any information you want.

    The Consultingwerk.BusinessEntityDesigner.Plugins.JavaScriptSafeNameValidationPlugin plugin can be used as an example for code-validation implemented as a plugin.
  3. Carl Verbiest
    Carl Verbiest avatar
    59 posts
    Registered:
    12 Oct 2018
    21 Oct 2019 in reply to Mike Fechner
    Link to this post
    I strongly agree not to prevent saving but I'd have a dialog with the issues and a save-anyway option.
    It would be great if we could have some "Sonarlint on the fly" type of view in the BED than I could do without dialogs.
  4. Mike Fechner
    Mike Fechner avatar
    319 posts
    Registered:
    14 Sep 2016
    21 Oct 2019 in reply to Carl Verbiest
    Link to this post
    A plugin has access to the Business Entity Designer Form. So it could gain access to the UltraDockManager and add any view you need.

    If you expect more support from our end there, please provide details in an enhancement request. 
  5. Carl Verbiest
    Carl Verbiest avatar
    59 posts
    Registered:
    12 Oct 2018
    21 Oct 2019 in reply to Mike Fechner
    Link to this post
    I'll start with a test that shows a dialog screen.
    The test will be invoked either on save or by clicking a button in the toolbar.

5 posts, 0 answered