Skip to content

Feature : Function Expression Defintions #59

Closed

Description

@pksorensen

We had the following expression

    "expression": "@and(equal(length(formvalue(logicalName())[idx()]['cvr']),8),isDigits(formvalue(logicalName())[idx()]['cvr']))"

and wanted to simplify the whole formvalue(logicalName())[idx()]['cvr'] into a currentCellValue function and coded this up:

public class CurrentCellValueFunction : Function
    {
        private readonly ILogger _logger;
        private readonly ManifestAccessor _validationContext;
        private readonly FormDataAccessor _formDataAccessor;
        private readonly FormValueFunction _formValueFunction;
        private readonly IdxFunction _idxFunction;
        private readonly LogicalNameFunction _logicalNameFunction;

        public CurrentCellValueFunction(
            ILogger<CurrentCellValueFunction> logger,
            ManifestAccessor validationContext,
            FormDataAccessor formDataAccessor,
            FormValueFunction formValueFunction,
            IdxFunction idxFunction,
            LogicalNameFunction logicalNameFunction) : base("currentCellValue")
        {
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));
            _validationContext = validationContext ?? throw new ArgumentNullException(nameof(validationContext));
            _formDataAccessor = formDataAccessor ?? throw new ArgumentNullException(nameof(formDataAccessor));
            _formValueFunction = formValueFunction;
            _idxFunction = idxFunction;
            _logicalNameFunction = logicalNameFunction;
        }

        public override async ValueTask<ValueContainer> ExecuteFunction(params ValueContainer[] parameters)
        {
            _logger.LogDebug("{FunctionName} entered", nameof(CurrentCellValueFunction));
             
            try
            {  
                
                //currentCellValue = formvalue(logicalName())[idx()]['cvr']

                var logicalName = await _logicalNameFunction.ExecuteFunction();
                var idx = await _idxFunction.ExecuteFunction();
                var formvalue = await _formValueFunction.ExecuteFunction(logicalName);

                var currentCell = formvalue[idx.GetValue<int>()][_validationContext.CurrentAttributeLogicalName];

                return currentCell;

            }
            catch (Exception ex)
            {
                _logger.LogDebug(ex,"{FunctionName} failed", nameof(CurrentCellValueFunction));
                throw;
            }
        }
    }

however it bascially could have been automated in the framework to do Function expression Definitions:

services.AddFunctionExpresssionDefinition("currentCellValue", "@formvalue(logicalName())[idx()][attributeLogicalName()]")

or

services.AddFunctionExpresssionDefinition("currentCellValue", "formvalue(logicalName())[idx()][attributeLogicalName()]")

Activity

  1. added
    enhancement
    on Dec 23, 2021
  2. added a commit that references this issue on Feb 28, 2022
    0efcfad
  3. linked a pull request that will close this issueTst/metadata function #75on Feb 28, 2022
  4. github-actions commented on Mar 18, 2022

    @github-actions

    🎉 This issue has been resolved in version 4.0.0-dev.1 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

  5. github-actions commented on Aug 23, 2022

    @github-actions

    🎉 This issue has been resolved in version 4.0.0 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions