chenqinghong
2024-05-07 3ec06a830367465068963156dcc1d8e522571c13
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
Quintiq file version 2.0
#parent: #root
StaticMethod HandleIncomingMessage (
  MPSync mpsync,
  NamedValueTree requestnvt,
  NamedValue requestNV,
  Type objectType,
  MessageIntegrationLog messagelog
)
{
  Description: 'Process incoming message to create, update or delete IO object'
  TextBody:
  [*
    sourcemessage := MPSyncUtility::ID_Source_Message();
    
    body := LibInt_NvtAccessor::FirstChildNamed( requestnvt, requestNV, MPSyncUtility::NVT_NAME_BODY() );
    
    traverse( body.Children(), Elements, nvtobjects )
    {
      
      // to process particular object type only
      traverse( nvtobjects.Children(), Elements, nvtobject, nvtobject.Name() = objectType.ShortName() )
      {
        importedobject := NamedValueTreeIO::ImportObject( requestnvt, nvtobject, objectType ).astype( IOBase );
        
        if( not isnull( importedobject ) )
        {
          // Find existing data
          mode   := importedobject.Mode();
          
          object := importedobject.MessageFindIOObject( mpsync, sourcemessage ); 
        
          if( mode = MPSyncUtility::Message_Mode_InsertUpdate() )
          {
            if( isnull( object ) )
            {
              // Assign imported object to temp object and then set to actual object
             importedobject.SetDataSource( MPSyncUtility::ID_Source_Message(), false, '' );
             temp := importedobject;
             temp.MessageLinkImportedObject( &importedobject, mpsync ); 
            }
            else
            {
              // Not to update record if its old message
              if( importedobject.Timestamp() >= object.Timestamp() )
              {
                // Update data
                object.Update( importedobject, sourcemessage );
              }
              else
              {
                messagelog.AddWarning( Translations::MPSync_MessageBasedIntegration_IgnoreOldMessage( importedobject.DefinitionName(), 
                                                                                                      importedobject.GetFunctionalKeyValues(),
                                                                                                      importedobject.Timestamp(),
                                                                                                      object.Timestamp()
                                                                                                    ) );
              }
            }
          }
          // Delete data
          else if( mode = MPSyncUtility::Message_Mode_Delete() )
          {
            if( isnull( object ) )
            {
              messagelog.AddWarning( Translations::MPSync_MessageBasedIntegration_Delete_NotExists( importedobject.DefinitionName(), 
                                                                                                    importedobject.GetFunctionalKeyValues() ) 
                                                                                                  );
            }
            else
            {
              object.Delete();
            }
          }    
          else
          {
            messagelog.AddError( Translations::MPSync_MessageBasedIntegration_UnexpectedMode( importedobject.Mode(), 
                                                                                              importedobject.DefinitionName(), 
                                                                                              importedobject.GetFunctionalKeyValues() ) 
                                                                                            );
          }
        }
      }
    }
    mpsync.LastImportTime( DateTime::ActualTime() );
  *]
}