limj
2023-10-24 93652435728de839582440eefd5122c281181d35
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Quintiq file version 2.0
#parent: #root
Method ConvertNvtToShadowSnapshotSetData (
  NamedValueTree nvt
) as shadow[KpiSnapshotSetData] id:Method_GlobalStateKpiTracker_ConvertNvtToShadowSnapshotSetData
{
  #keys: '[136398.1.783148550]'
  Body:
  [*
    // Converts the query-result NamedValueTree to a shadow-KpiSnapshotSetData enclosure.
    set := KpiTracker.KpiSnapshotSetData( relshadow );
    
    // Define handles.
    setDataHandle  := nvt.GetHandle( "KpiSnapshotSetData" );
    snapshotHandle := nvt.GetHandle( "KpiSnapshotData" );
    kpivalueHandle := nvt.GetHandle( "KpiValueData" );
    labelHandle    := nvt.GetHandle( "KpiLabelData" );
    serverDtHandle := nvt.GetHandle( "ServerDateTime" );
    planDtHandle   := nvt.GetHandle( "PlanDateTime" );
    nameHandle     := nvt.GetHandle( 'Name' );
    valueHandle    := nvt.GetHandle( 'Value' );
    retentionHandle:= nvt.GetHandle( 'RetentionPolicyIdentification' );
    sourceDatasetMDSIDHandle := nvt.GetHandle( 'SourceDatasetMDSID' );
    
    // Get to the real root (the setData).
    root           := nvt.Root();
    setData        := root.Child( setDataHandle );
    
    // Each child of setData is a SnapshotData.
    traverse( setData.Children( snapshotHandle ), Elements, snapshotNvt )
    {
      snapshot := set.SnapshotData( relnew );
      snapshot.ServerDateTime ( snapshotNvt.Child( serverDtHandle ).GetValueAsDateTime() );
      snapshot.PlanDateTime   ( snapshotNvt.Child( planDtHandle ).GetValueAsDateTime() );
      snapshot.RetentionPolicyIdentification( snapshotNvt.Child( retentionHandle ).GetValueAsString() );
      snapshot.SourceDatasetMDSID( snapshotNvt.Child( sourceDatasetMDSIDHandle ).GetValueAsKey() );
    
      // Labels
      labels := construct( Strings );
      labeldata := selectsortedset( snapshotNvt.Children( labelHandle ), Elements, label, true, label.Child( nameHandle ).GetValueAsString() );
      traverse( labeldata, Elements, labelNvt )
      {
        label := snapshot.Label( relnew );
        label.Name( labelNvt.Child( nameHandle ).GetValueAsString() );
        label.Value( labelNvt.Child( valueHandle ).GetValueAsString() );
        labels.Add( label.Name() + ": " + label.Value() );
      }
      
      // Kpi values
      traverse( snapshotNvt.Children( kpivalueHandle ), Elements, valueNvt )
      {
        val := snapshot.Value( relnew );
        val.Name( valueNvt.Child( nameHandle ).GetValueAsString() );
        val.Value( valueNvt.Child( valueHandle ).GetValueAsReal() );
        val.UI_SnapshotLabels( labels.ToString( ";" ) );
      }
    
    }
    
    return &set;
  *]
  ReturnsOwning: true
}