IValidationCustomMappings.FillByAttributes

Syntax

FillByAttributes;

Description

The FillByAttributes method automatically fills in the mapping collection.

Comments

The method should be called after setting mapping in validation rule. Mappings are made based on the set expression and only for the attributes with matching identifiers.

Example

Executing the example requires that the repository contains time series databases with the TSDB and SDB_VALID identifiers. Both time series databases should contain attributes of series with the same identifiers. The TSDB database should also contain a validation rule of the Compare by Expression type with the VALID_CUSTOM identifier.

Add links to the Cubes, Dimensions system assemblies. Metabase, Ms.

Sub UserProc;
Var
    mb: IMetabase;
    TSDBExt, TSDBVal: IMetabaseObjectDescriptor;
    ValidObj: IMetabaseObject;
    ValidFilter: IValidationFilter;
    Custom: IValidationCustom;
    Mappings: IValidationCustomMappings;
    Map: IValidationCustomMapping;
    Transform: IMsFormulaTransform;
    Formula: IMsFormula;
    Det: IMsDeterministicTransform;
    Inputs: IMsFormulaTransformVariables;
    TransformVar: IMsFormulaTransformVariable;
    Tree: IMsFormulaTransformSlicesTree;
    Slice: IMsFormulaTransformSlice;
    Term: IMsFormulaTerm;
    i, j: Integer;
    Binding: IValidationCustomDimensionsBinding;
    ValidExecSett: IValidationExecuteSettings;
    ValidExecRun: IValidationExecRun;
Begin
    mb := MetabaseClass.Active;
    // Get compared time series database (TSDB 1)
    TSDBVal := Mb.ItemById("TSDB");
    // Get time series database used for comparison (TSDB 2)
    TSDBExt := Mb.ItemById("TSDB_VALID");
    // Get validation rule
    ValidObj := Mb.ItemByIdNamespace("VALID_CUSTOM", TSDBVal.Key).Edit;
    ValidFilter := ValidObj As IValidationFilter;
    ValidFilter.Kind := ValidationDetailsKind.Custom;
    // Get rule parameters
    Custom := ValidFilter.Details As IValidationCustom;
    // Get rule calculation parameters
    Transform := Custom.Transform;
    Formula := Transform.FormulaItem(0);
    Formula.Kind := MsFormulaKind.Deterministic;
    Det := Formula.Method As IMsDeterministicTransform;
    // Get collection of input variables
    Inputs := Transform.Inputs;
    // Add input variable from TSDB 2
    TransformVar := Inputs.Add(TSDBExt.Bind As IVariableStub);
    Tree := TransformVar.SlicesTree(TransformVar);
    Slice := Tree.CreateSlice(1);
    Term := Det.Operands.Add(Slice);
    // Add variable to expression
    Det.Expression.AsString := Term.TermToInnerText;
    // Add input variable from TSDB 1
    TransformVar := Transform.Inputs.Add(TSDBVal.Bind As IVariableStub);
    Tree := TransformVar.SlicesTree(TransformVar);
    Slice := Tree.CreateSlice(1);
    Term := Det.Operands.Add(Slice);
    // Form final expression with both variables
    Det.Expression.AsString := Det.Expression.AsString + ">" + Term.TermToInnerText;
    // Get attribute mapping parameters
    Mappings := Custom.Mappings;
    // Clear existing mappings
    Mappings.Clear;
    // Execute automatic mapping
    Mappings.FillByAttributes;
    // Display information about performed mappings
    For i := 0 To Mappings.Count - 1 Do
        Debug.WriteLine("Mapping #" + (i + 1).ToString);
        Map := Mappings.Item(i);
        Debug.Indent;
        // Search through all dimension bindings
        For j := 0 To Map.ValidationStub.DimensionCount - 1 Do
            Binding := Map.FindByValidationDimKey((Map.ValidationStub.Dimension(j) As IMetabaseObject).Key);
            Debug.WriteLine("Binding #" + (j + 1).ToString);
            Debug.Indent;
            Debug.WriteLine("Dimension from external data source: " + Binding.ExternalDim.Name);
            Debug.WriteLine("Dimension from data source used for validation: " + Binding.ValidationDim.Name);
            Debug.Unindent;
        End For;
        Debug.Unindent;
    End For;
    // Save changes of validation rule
    ValidObj.Save;
    // Execute rule
    ValidExecSett := New ValidationExecuteSettings.Create;
    ValidExecRun := ValidFilter.Execute(ValidExecSett);
End Sub UserProc;

After executing the example calculation expression is set for validation rule and it is based on series from two different time series databases. Dimensions of two different time series databases are mapped automatically.

See also:

IValidationCustomMappings