fintp_routingengine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RoutingMessage.h
Go to the documentation of this file.
1 /*
2 * FinTP - Financial Transactions Processing Application
3 * Copyright (C) 2013 Business Information Systems (Allevo) S.R.L.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>
17 * or contact Allevo at : 031281 Bucuresti, 23C Calea Vitan, Romania,
18 * phone +40212554577, office@allevo.ro <mailto:office@allevo.ro>, www.allevo.ro.
19 */
20 
21 #ifndef ROUTINGMESSAGE_H
22 #define ROUTINGMESSAGE_H
23 
24 #include <map>
25 #include <vector>
26 #include <string>
27 
28 using namespace std;
29 
30 #include "XmlUtil.h"
31 #include "XPathHelper.h"
32 #include "Collections.h"
33 
34 #include "WSRM/SequenceResponse.h"
35 
36 #include "RoutingEngineMain.h"
38 #include "RoutingMessageEvaluator.h"
39 
40 class RoutingMessage;
41 
43 {
44  public :
45 
47  {
49  XML,
51  AUTO
52  };
53 
54  bool IsTextValid() const { return m_IsTextValid; }
55  bool IsDocValid() const { return m_IsDocValid; }
56 
57  RoutingMessagePayload( XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument& doc );
58  RoutingMessagePayload( const string& doc );
59 
60  // copy ops
62  RoutingMessagePayload& operator=( const RoutingMessagePayload& source );
63 
65 
66  // set
67  void setDoc( XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument& doc );
68  void setDoc( XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* doc );
69  void setText( const string& text, RoutingMessagePayload::PayloadFormat format );
70 
71  XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* getDoc( const bool throwOnDeserialize = true );
72  const XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* const getDocConst() const;
73 
74  string getText( const RoutingMessagePayload::PayloadFormat format, const bool throwOnSerialize = true );
75  string getTextConst() const;
76 
77  RoutingMessagePayload::PayloadFormat getFormat() const { return m_Format; }
78 
80  void convert( RoutingMessagePayload::PayloadFormat format );
81 
82  private :
83 
84  XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* m_Document;
85  string m_Text;
86 
87  // control payload conversion
91 };
92 
94 {
95  public :
96 
97  typedef enum
98  {
99  MO_NONE = 0,
100  MO_BYPASSMP = 1,
101  MO_BATCH = 2,
102  MO_GENERATEID = 4,
103  MO_NOSEQ = 8,
104  MO_COMPLETE = 16,
105  MO_RBATCH = 32,
110  MO_NOREACTIVATE = 64,
115  MO_NOHEADERS = 128,
119  MO_INSERTBATCH = 256,
123  MO_MARKNOTREPLIED = 512,
127  MO_REPLYDATAGRAM = 1024
128  } MESSAGE_OPTIONS;
129 
130  RoutingMessageOptions( const string& options ){ m_Options = Parse( options ); }
131  RoutingMessageOptions( int options = RoutingMessageOptions::MO_NONE ){ m_Options = options; }
132 
133  static int Parse( const string& options );
134  static string ToString( int options );
135 
136  int getValue() const { return m_Options; }
137 
138  private :
139 
141 };
142 
144 {
145  public :
146 
147  typedef enum
148  {
150  SingleMessage
151  } REQUEST_TYPE;
152 
153  private :
154 
155  string m_MessageId, m_BatchId, m_CorrelationId, m_SessionId, m_UserId;
156  unsigned long m_Priority, m_BatchSequence, m_BatchCount;
157 
165 
166  RoutingAggregationCode m_Feedback;
167 
169 
173 
175  bool m_Fastpath, m_Bulk, m_Virtual;
176 
177  string m_TableName;
178 
180  RoutingMessageEvaluator* m_PayloadEvaluator;
181 
182  //map<string, string> loadKeywords();
183 
184  public:
185 
186  //.ctor & dtor
187  RoutingMessage();
188  RoutingMessage( const string& source );
189  RoutingMessage( const string& tableName, const string& messageId, bool delayRead );
190  RoutingMessage( const string& tableName, const string& messageId, RoutingMessage ( *messageProviderCallback )() = NULL, bool fastpath = false );
191 
192  // copy ops
193  RoutingMessage( const RoutingMessage& source );
194  RoutingMessage& operator=( const RoutingMessage& source );
195 
196  ~RoutingMessage();
197 
198  void Read();
199  // static instance specific members
200 
201  // helpers
202  static RoutingMessage::REQUEST_TYPE ParseRequestType( const string& request );
203  bool isReply();
204  bool isAck();
205  bool isNack();
206 
207  // flatten
208  string ToString( bool payloadEncoded = false );
209  string ToString( const string& payload );
210 
211  void DelayTransform( const string& transform, const string& sessionCode, const unsigned int sequence );
212  string getDelayedTransform() const { return m_DelayedTransform; }
213  string getDelayedTransformSessCode() const { return m_DelayedTransformSessionCode; }
214 
215  static string ToString( REQUEST_TYPE reqType );
216 
217  // accessors
218  void setBatchSequence( const unsigned long sequence ) { m_BatchSequence = sequence; }
219  unsigned long getBatchSequence() const { return m_BatchSequence; }
220 
221  string getOriginalMessageType() const { return m_OriginalMessageType; }
222 
223  void setOutputSession( const string& osession ) { m_SessionId = osession; }
224  string getOutputSession() const { return m_SessionId; }
225 
226  void setBatchTotalCount( const unsigned long batchcount ) { m_BatchCount = batchcount; }
227  unsigned long getBatchTotalCount() const { return m_BatchCount; }
228 
229  void setBatchTotalAmount( const string& amount ) { m_BatchAmount = amount; }
230  string getBatchTotalAmount() const { return m_BatchAmount; }
231 
232  RoutingMessageOptions::MESSAGE_OPTIONS getMessageOptions() const { return m_MessageOptions; }
233  void setMessageOptions( const RoutingMessageOptions::MESSAGE_OPTIONS options ) { m_MessageOptions = options; }
234  void setMessageOption( const RoutingMessageOptions::MESSAGE_OPTIONS option ) { m_MessageOptions = ( RoutingMessageOptions::MESSAGE_OPTIONS )( option | m_MessageOptions ); }
235 
236  string getMessageId() const { return m_MessageId; }
237  void setMessageId( const string& messageId ) { m_MessageId = messageId; }
238 
239  string getCorrelationId() const { return m_CorrelationId; }
240  string getSessionId() const { return m_SessionId; }
241 
242  string getBatchId() const { return m_BatchId; }
243  void setBatchId( const string& value ) { m_BatchId = value; }
244 
245  unsigned long getPriority() const { return m_Priority; }
246  void setPriority( const unsigned long value ) { m_Priority = value; }
247 
248  string getUserId() const { return m_UserId; }
249  void setUserId( const int userId ) { m_UserId = userId; }
250 
251  void setCorrelationId( const string& correlationId ) { m_CorrelationId = correlationId; }
252 
253  RoutingAggregationCode getAggregationCode();
254 
255  const RoutingAggregationCode& getFeedback() const { return m_Feedback; }
256  void setFeedback( const RoutingAggregationCode& feedback ) { m_Feedback = feedback; }
257 
258  string getFeedbackString() const;
259  void setFeedback( const string& feedback );
260 
261  long getRoutingSequence() const { return m_RoutingSequence; }
262  void setRoutingSequence( const long value ) { m_RoutingSequence = value; }
263 
264  bool isHeld() const { return m_HoldStatus; }
265  void setHeld( const bool value ) { m_HoldStatus = value; }
266 
267  bool isBulk() const { return m_Bulk; }
268  void setBulk( const bool value ) { m_Bulk = value; }
269 
270  bool isVirtual() const { return m_Virtual; }
271  void setVirtual( const bool value ) { m_Virtual = value; }
272 
273  bool isDuplicate() const;
274 
275  string getRequestorService() const { return m_RequestorService; }
276  void setRequestorService( const string& value ) { m_RequestorService = value; }
277 
278  string getOriginalRequestorService() const { return m_OriginalRequestorService; }
279  void setOriginalRequestorService( const string& value ) { m_OriginalRequestorService = value; }
280 
281  string getResponderService() const { return m_ResponderService; }
282  void setResponderService( const string& value ) { m_ResponderService = value; }
283 
284  string getTableName() const { return m_TableName; }
285  void setTableName( const string& value ) { m_TableName = value; }
286 
287  REQUEST_TYPE getRequestType() const { return m_RequestType; }
288  void setRequestType( const REQUEST_TYPE value ) { m_RequestType = value; }
289 
290  const RoutingMessagePayload* const getPayload() const { return m_Payload; }
291  RoutingMessagePayload* getPayload() { return m_Payload; }
292  void setPayload( const string& payload );
293  //void setPayload( XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* payload );
294 
295  RoutingMessageEvaluator* getPayloadEvaluator( const bool forceReload = false );
296  void destroyPayloadEvaluator();
297 
298  void setFastpath( const bool fastpath ) { m_Fastpath = fastpath; }
299  bool getFastpath() const { return m_Fastpath; }
300 
301  string getOriginalPayload( const RoutingMessagePayload::PayloadFormat format = RoutingMessagePayload::AUTO ) const;
302 
303  void setDelayedReplyId( const string& idValue ){ m_DelayedReplyId = idValue; }
304  string getDelayedReplyId() const { return m_DelayedReplyId; }
305 
306  friend ostream& operator << ( ostream& os, const RoutingMessage& except );
307 };
308 
309 #endif // ROUTINGMESSAGE_H