Lai,Risheng
2023-11-02 30c02e0c981b16be0918483543f4b812956c45d4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
Quintiq file version 2.0
#parent: #root
Method FilterDataOnSelectedLabels (
  shadow[KpiSnapshotSetData] queryResult,
  structured[KpiLabelValue] labelFilters,
  Boolean isLabelFilteringEnabled
) as String id:Method_GlobalStateKpiTracker_FilterDataOnSelectedLabels
{
  #keys: '[146874.0.1589192311]'
  Body:
  [*
    // Copies the source data from DataHolderSnapshotSetData to DataHolderLabelFilterdSnapshots
    // while filtering based on the selected Labels.
    filter := "";
    
    if ( not isnull( queryResult ) )
    {  
      if ( isLabelFilteringEnabled )
      {
        filters := construct( Strings );
        
        traverse( labelFilters, Elements.Label, label )
        {
          values := construct( Strings );
          traverse( label, Value, value,
                    exists( labelFilters, Elements, selected, selected = value ) )
          {
            values.Add( 'exists( object, Label, l, l.Name() = "'
                        + label.Name()
                        + '" and l.Value() = "'
                        + value.Value()
                        + '") ' );
          }
          filters.Add( '(' + values.ToString( ' or ' ) + ')' );
        }
        filter := filters.ToString( ' and ' );
        debuginfo( ' >>> Generated Label filter = ', filter );
      }
    }
    
    return filter;
  *]
}