lazhen
2025-01-09 8afe90b633046db39042aada36b88193062f8cff
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
Quintiq file version 2.0
#parent: #root
Method MessageReceiveSetRemoved (NamedValueTree nvt_i)
{
  Description:
  [*
    Handle and process the message received of type set removed
    (1) This method will be overridden for the HierarchyChannel in order to disallow set removal
  *]
  TextBody:
  [*
    sourceKind := LibInt_MessageAccessor::GetHeaderPropertyAsString( nvt_i, LibDMF_CommunicationChannel::HEADER_SOURCEKIND() );
    sourceName := LibInt_MessageAccessor::GetHeaderPropertyAsString( nvt_i, LibDMF_CommunicationChannel::HEADER_SOURCENAME() );
    
    // LastUpdated can be missing when the message is received from an IF-system.
    lastUpdated := ifexpr( LibInt_MessageAccessor::HasHeaderProperty( nvt_i, LibDMF_CommunicationChannel::HEADER_LAST_UPDATED() ),
                           LibInt_MessageAccessor::GetHeaderPropertyAsDateTime( nvt_i, LibDMF_CommunicationChannel::HEADER_LAST_UPDATED() ),
                           DateTime::MinDateTime() );
    
    root := this.CommunicationChannelRoot();
    
    // Retrieve IntegrationEvent.
    event := root.EventGetLast( sourceKind, sourceName );
    
    // Log the Activity
    root.EventLogActivity( event, "Instantiate data" );
    
    // For checking if error
    allowable := true;
    
    // TODO: disallow hierarchy
    if( this.IsHierarchyChannel() )
    {
      // temporarily allowed for testing
      //allowable := false;
    }
    
    if( this.CommunicationChannelRoot().IsDataManager() and allowable )
    {
      systemOnChannel := this.GetSystemOnChannel( sourceKind, sourceName );
      gp  := this.CommunicationChannelRoot().GlobalParameters();
    
      // the set must exists
      set := this.GetSet( nvt_i, true );
    
      // set should not be null for removal
      if( not isnull( set ))
      {
        // TODO: send error message if set not owned by SoC
    
        // before sending, delete all the objects, so that the sync will replace with empty set
        set.DeleteObjects();
    
        // Check if the data is 'sane' and can be send to Systems that are interested in it.
        feedbacks := construct( Strings );
        canSend   := set.DoSanityCheck( feedbacks );
    
        if( canSend )
        {
          // End of event (for Interface System messages)
          root.EventComplete( event );
    
          // Send the data to the Systems that are interested in it.
          set.SendToInterestedSystems( LibDMF_CommunicationChannel::MESSAGETYPE_SETREMOVED() );
        }
        else
        {
          root.EventLogActivityWarning( event,
                                        "Cannot send data to interested Systems. Reason(s) :" + String::NewLine() + feedbacks.Concatenate( String::NewLine() ) );
        }
    
        // remove set for the settype after sending
        set.Delete();
      }
      else
      {
        errorMessage := "Cannot remove set in Data Manager. Reason: Set " + set.Name() + " does not exist in Data Manager."
    
        root.EventLogActivityWarning( event, errorMessage );
    
        // Signal error: set not found
        this.MessageSendErrorToSystem( LibDMF_CommunicationChannel::MESSAGETYPE_SETCREATED(), errorMessage, systemOnChannel, gp.DM_DatasetKind(), gp.DM_DatasetName() );
    
        root.EventComplete( event );
      }
    }
    else if( not this.CommunicationChannelRoot().IsDataManager() and allowable )
    {
      data := this.DataInstantiateInChannelOfSystem( nvt_i );
    
      // RequestID is never needed for SetCreated and SetRemoved
      requestID := LibDMF_CommunicationChannel::REQUEST_NO_ID();
    
      // In a System the generic data must be transformed into the target data structure.
      activityInfo := ifexpr( requestID <> LibDMF_CommunicationChannel::REQUEST_NO_ID(), ", RequestID = " + requestID, "" );
      root.EventLogActivity( event, "Synchronize data" + activityInfo );
    
      // Provide the RequestID to the System so it can take action on it if required.
      this.DataSynchronizeToSystem( data, lastUpdated, requestID );
    
      // The data in the Channel can be deleted again.
      traverse( data, Elements, object )
      {
        object.Delete();
      }
    }
  *]
}