Quintiq file version 2.0
|
#parent: #root
|
StaticMethod HandleIncomingMessage (
|
MPSync mpsync,
|
NamedValueTree requestnvt,
|
NamedValue requestNV,
|
MessageIntegrationLog messagelog
|
)
|
{
|
Description: 'Process incoming message to create, update or delete IO object'
|
TextBody:
|
[*
|
syncidgenerator := mpsync.GetSyncIDGenerator();
|
sourcemessage := MPSyncUtility::ID_Source_Message();
|
|
// Pre-process data to handle MPSyncID type index duplicates, assign unique ID
|
mpsyncidhandle := requestnvt.GetHandle( IOBase::ATTRIBUTENAME_MPSyncID() );
|
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() = typeof( IORouting ).ShortName() )
|
{
|
// Get latest MPSyncID and add to NVT
|
nvtobject.AddChild( mpsyncidhandle, syncidgenerator.GetRoutingSyncID() );
|
importedobject := NamedValueTreeIO::ImportObject( requestnvt, nvtobject, typeof( IORouting ) ).astype( IORouting );
|
|
if( not isnull( importedobject ) )
|
{
|
// Find existing data
|
mode := importedobject.Mode();
|
object := select( mpsync, IORouting, io,
|
io.DataSource() = sourcemessage
|
and io.ID() = importedobject.ID()
|
);
|
|
if( mode = MPSyncUtility::Message_Mode_InsertUpdate() )
|
{
|
if( isnull( object ) )
|
{
|
// Assign imported object as real instance
|
importedobject.SetDataSource( MPSyncUtility::ID_Source_Message(), false, '' );
|
mpsync.IORouting( relinsert, &importedobject );
|
}
|
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() )
|
);
|
}
|
}
|
}
|
}
|
*]
|
}
|