yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
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
64
Quintiq file version 2.0
#parent: #root
Method ProcessDataFromQI (
  NamedValueTree responseNVT_i,
  String integratorID_i
) as LibDIF_IntegrationDataset
{
  Description: 'Trigger ProcessDataFromQI using the QIntegrator(-route) with the provided ID.'
  TextBody:
  [*
    // Retrieve the data from the Body of the replied NVT.
    bodyNode := responseNVT_i.Root().Child( responseNVT_i.GetHandle( "Body" ) );
    
    // Remove the appendix "As3DSpace" from the IntegratorID if applicable.
    integratorID := ifexpr( integratorID_i.EndsWith( LibDIF_IntegrationDataset::AS_3DSPACE() ), 
                            integratorID_i.SubString( 0, integratorID_i.Length() - LibDIF_IntegrationDataset::AS_3DSPACE().Length() ),
                            integratorID_i ); 
    
    // See if the response is 'raw' JSON or a NVT.
    if( LibDIF_PlatformAPICall::IsRawResponse( responseNVT_i ) )
    {
      // See if the data should be processed.
      doProcess := this.DoNotProcessDataFromQI().Find( integratorID ) < 0;
      if( doProcess )
      {
        // Get the JSON-data from the body and parse it.
        json := JSON::Parse( bodyNode.GetValueAsString() );
    
        // Call the method that must be overridden and implemented at the Implementation Level.
        if( this.DoProcessDataFromQI( json, integratorID ) )
        {
          // All OK...
        }
        else
        {
          // Raise an error if the QIntegrator(-route) was not found.
          LibDIF_Util::Error( this.DefinitionName() + ".DoProcessDataFromQI( json_i, integratorID_i ) is not implemented for QIntegrator(-route) | IntegratorID = '" + integratorID + "'. "
                            + "Either implement the method for the IntegratorID, or add the IntegratorID to method DoNotProcessDataFromQI()." );
        }
      }
    }
    else
    {
      datasetNode := bodyNode.Child( responseNVT_i.GetHandle( this.DefinitionName() ) );
      
      // Import the NVT as a temporary instance of the Integration-dataset that owns the imported integration objects.
      tempIntegrationDataset := NamedValueTreeIO::ImportObject( responseNVT_i, datasetNode, typeofexpression( this ) );
      
      // Call the method that must be overridden and implemented at the Implementation Level.
      if( this.DoProcessDataFromQI( tempIntegrationDataset, integratorID ) )
      {
        // All OK...
      }
      else
      {
        // Raise an error if the QIntegrator(-route) was not found.
        LibDIF_Util::Error( this.DefinitionName() + ".DoProcessDataFromQI( tempIntegrationDataset_i ) is not implemented for QIntegrator(-route) | IntegratorID = '" + integratorID + "'" );
      }
    }
    
    // Return a stream that can be reacted on.
    return this;
  *]
}