fintp_base
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RoutingMessageEvaluator.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 ROUTINGMESSAGEEVALUATOR_H
22 #define ROUTINGMESSAGEEVALUATOR_H
23 
24 #include <map>
25 #include <vector>
26 #include <string>
27 
28 using namespace std;
29 
30 #ifdef WIN32
31 #include <windows.h>
32 #endif
33 
34 #include "XmlUtil.h"
35 #include "XPathHelper.h"
36 #include "Collections.h"
37 #include "RoutingAggregationCode.h"
38 #include "RoutingKeyword.h"
39 
40 #include "WSRM/SequenceResponse.h"
41 
42 #define FEEDBACK_PROVIDER_COUNT 8
43 #define INTERNALXMLPAYLOAD_FIELDCOUNT 20
44 
45 //TODO rework this dependency
46 class RoutingMessage;
47 class Plugin;
48 
50 {
51  public :
52  enum Fields
53  {
54  SENDER = 0,
55  RECEIVER = 1,
56  MESSAGETYPE = 2,
57  MUR = 3, //TTC
58  FINCOPY = 4,//Service
59  //IOIDENTIFIER = 5, // va fi scos
60  TRN = 5, //reference
61  CURRENCY = 6,
62  AMOUNT = 7,
63  VALUEDATE = 8,
64  RELATEDREF = 9,//RelRef
65  IBAN = 10,//DbtAccount
66  SEQ = 11,
67  MAXSEQ = 12,
68  IBANPL = 13,//CdtAccount
69  SENDERCORR = 14,//OrdBank
70  RECEIVERCORR = 15,//BenBank
71 
72  //STATUS = 18,
73  ORGTXID = 16,//OrigRef
74  REASONCODE = 17,
75  ORGINSTRID = 18,
76  OBATCHID = 19,
77  };
78 
79  private :
80  static const string m_FieldNames[ INTERNALXMLPAYLOAD_FIELDCOUNT ];
81 
82  public :
83  static string getFieldName( const int field );
84 };
85 
87 {
88 
89  public:
90 
92  {
93  SAA_METHOD_MQID = 100,
94  SAA_METHOD_TRN = 101,
95  SAA_METHOD_CORRELID = 102
96  };
97 
99  {
100  METHOD_MQID = 150,
101  METHOD_TRN = 151,
102  METHOD_CORRELID = 152
103  };
104 
106  {
107  TMETHOD_MQID = 200,
108  TMETHOD_MIR = 201,
109  TMETHOD_CORRELID = 202
110  };
111 
112  static string ToString( const SAAACKMethod method )
113  {
114  switch( method )
115  {
117  return "TRN";
119  return "MQID";
121  return "CORRELID";
122  default :
123  throw invalid_argument( "SAA ACK method is invalid" );
124  }
125  }
126 
127  static string ToString( const SwiftACKMethod method )
128  {
129  switch( method )
130  {
132  return "TRN";
134  return "MQID";
136  return "CORRELID";
137  default :
138  throw invalid_argument( "SWIFT ACK method is invalid" );
139  }
140  }
141 
142  static string ToString( const TFDACKMethod method )
143  {
144  switch( method )
145  {
147  return "MIR";
149  return "MQID";
151  return "CORRELID";
152  default :
153  throw invalid_argument( "TFD ACK method is invalid" );
154  }
155  }
156 };
157 
159 {
160  public :
161 
162 #if defined( TESTDLL_EXPORT ) || defined ( TESTDLL_IMPORT )
163  friend class RoutingPayloadEvalTest;
164 #endif
165 
167  {
178  SWIFTSTS
179  };
180 
182  {
183  FEEDBACKPROVIDER_FTP = 0,
184  FEEDBACKPROVIDER_MQ = 1,
185  FEEDBACKPROVIDER_TFD = 2,
186  FEEDBACKPROVIDER_UNK = 3
187  };
188 
189  static const string FEEDBACKFTP_ACK;
190  static const string FEEDBACKFTP_APPROVED;
191  static const string FEEDBACKFTP_CSMAPPROVED;
192  static const string FEEDBACKFTP_RJCT;
193  static const string FEEDBACKFTP_REACT;
194  static const string FEEDBACKFTP_MSG;
195  static const string FEEDBACKFTP_LATERJCT;
196  static const string FEEDBACKFTP_REFUSE;
197  static const string FEEDBACKFTP_LOSTRFD;
198  static const string FEEDBACKFTP_NOREACT;
199 
200  static const string AGGREGATIONTOKEN_FTPID;
201  static const string AGGREGATIONTOKEN_FTPCODE;
202  static const string AGGREGATIONTOKEN_SAACODE;
203  static const string AGGREGATIONTOKEN_TFDCODE;
204  static const string AGGREGATIONTOKEN_SWIFTCODE;
205  static const string AGGREGATIONTOKEN_MIR;
206  static const string AGGREGATIONTOKEN_MQID;
207  static const string AGGREGATIONTOKEN_MQCODE;
208  static const string AGGREGATIONTOKEN_PAYLOAD;
209  static const string AGGREGATIONTOKEN_REQUESTOR;
210  static const string AGGREGATIONTOKEN_BATCHID;
211  static const string AGGREGATIONTOKEN_OBATCHID;
212  static const string AGGREGATIONTOKEN_BATCHSEQ;
213  static const string AGGREGATIONTOKEN_TRN;
214  static const string AGGREGATIONTOKEN_OSESSION;
215  static const string AGGREGATIONTOKEN_ISESSION;
216  static const string AGGREGATIONTOKEN_ISSUER;
217  //same as AGGREGATIONTOKEN_FTPID but used to override bussines message info
218  static const string AGGREGATIONTOKEN_CORRELID;
219 
220  protected :
221 
222  static const string m_FeedbackProviders[ FEEDBACK_PROVIDER_COUNT ];
223  static const string m_FeedbackTokens[ FEEDBACK_PROVIDER_COUNT ];
224  static const string m_FeedbackIds[ FEEDBACK_PROVIDER_COUNT ];
225 
230  map< string, string > m_Fields;
231 
238  map< string, string > m_XPathFields;
239 
244 
248  map< string, string > m_KeywordMappings;
249 
254 
258  static bool m_MarkACHApproved;
259 
260 #ifdef WIN32
261  static map<Plugin*, HMODULE> m_RegisteredPlugins;
262 #else
263  static map<Plugin*, void*> m_RegisteredPlugins;
264 #endif
265 
266  protected :
267 
270  bool m_Valid;
271  string m_Namespace;
272 
273  virtual string internalToString() = 0;
274  string internalGetField( const int field );
275  string internalGetField( const string& field );
276 
277  RoutingMessageEvaluator& operator=( const RoutingMessageEvaluator& source );
279  RoutingMessageEvaluator( const XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* document, RoutingMessageEvaluator::EvaluatorType evaluatorType );
280 
281  XALAN_CPP_NAMESPACE_QUALIFIER XercesDocumentWrapper *m_DocumentWrapper;
282  XALAN_CPP_NAMESPACE_QUALIFIER XalanDocument *m_XalanDocument;
283  const XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *m_Document;
284 
285  void setNamespace( const string& namespaceValue ){ m_Namespace = namespaceValue; }
286 
287  static string getOriginalRef( const string& reference, const string& batchId );
288  static string getBatchType( const string& batchId, const string& tableName = "BATCHJOBS", const string& sender = "" );
289 
290  private:
291 
292  static string (*m_GetOriginalRefFunction)( const string& reference, const string& batchId );
293  static string (*m_GetBatchTypeFunction)( const string& batchId, const string& tableName, const string& sender );
294  virtual string getMessageType() = 0;
295 
296  public:
297 
298  static void setGetOriginalRefFunction( string (*function)( const string& reference, const string& batchId ) );
299  static void setGetBatchTypeFunction( string (*function)(const string& batchId, const string& tableName, const string& sender) );
300 
301  //Keyword operations
302  void setKeywordMappings( const map<string, string> keywordMappings ) { m_KeywordMappings = keywordMappings; }
303 
304  const vector<string> getKeywordNames();
305  static void setKeywords( const RoutingKeywordCollection& keywords );
306  void setIsoTypes( const bool isoMessageType ) { m_IsoMessageType = isoMessageType; }
307 
308  string GetKeywordXPath( const string& messageType, const string& keyword );
309  string EvaluateKeywordValue( const string& messageType, const string& value, const string& keyword, const string& field = "value" );
310  pair< string, RoutingKeyword::EVALUATOR_TYPE > Evaluate( const string& value, const string& keyword, const string& field );
311 
312  static void setSwiftACKMethod( const string& method )
313  {
314  if ( method == "TRN" )
315  m_SwiftACKMethod = CorrelationOptions::METHOD_TRN;
316  else if ( method == "CORRELID" )
317  m_SwiftACKMethod = CorrelationOptions::METHOD_CORRELID;
318  else m_SwiftACKMethod = CorrelationOptions::METHOD_MQID;
319  }
320 
321  static void setSAAACKMethod( const string& method )
322  {
323  if ( method == "TRN" )
324  m_SAAACKMethod = CorrelationOptions::SAA_METHOD_TRN;
325  else if ( method == "CORRELID" )
327  else m_SAAACKMethod = CorrelationOptions::SAA_METHOD_MQID;
328  }
329 
330  static void setTFDACKMethod( const string& method )
331  {
332  if ( method == "MQID" )
333  m_TFDACKMethod = CorrelationOptions::TMETHOD_MQID;
334  else if ( method == "CORRELID" )
335  m_TFDACKMethod = CorrelationOptions::TMETHOD_CORRELID;
336  else m_TFDACKMethod = CorrelationOptions::TMETHOD_MIR;
337  }
338 
339  static void setMarkApproved( bool markAchApproved ){ m_MarkACHApproved = markAchApproved; }
340 
341  static string getSAAACKMethod() { return CorrelationOptions::ToString( m_SAAACKMethod ); }
342  static string getSwiftACKMethod() { return CorrelationOptions::ToString( m_SwiftACKMethod ); }
343  static string getTFDACKMethod() { return CorrelationOptions::ToString( m_TFDACKMethod ); }
344 
345  static void ReadEvaluators( const string& location );
346  static void EvaluatorsCleanup();
347 
348  static RoutingMessageEvaluator::FeedbackProvider getProviderById( const string& coorelId );
349  static RoutingMessageEvaluator::FeedbackProvider getProviderByCode( const string& code );
350  static RoutingMessageEvaluator::FeedbackProvider getProviderByName( const string& coorelName );
351 
352  static string getNamespaceByMessageType( const string& messageType );
353 
354  static RoutingAggregationCode composeFeedback( const string& correlId, const string& errorCode, RoutingMessageEvaluator::FeedbackProvider );
355  static string serializeFeedback( const RoutingAggregationCode& feedback );
356 
357  static RoutingMessageEvaluator* getEvaluator( const XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* document );
358  static RoutingMessageEvaluator::EvaluatorType Parse( const string& evaluatorType );
359 
360  // returns true if the message is in SWIFT XML Format and can be evaluated
361  bool CheckPayloadType( RoutingMessageEvaluator::EvaluatorType payloadtype ) const { return m_EvaluatorType == payloadtype; }
362 
363  static bool isIso( const string& msgNamespace );
364 
365  virtual bool isIso() const { return false; }
366 
367  bool isBusinessFormat() const;
368 
369  bool isValid() const { return m_Valid; }
370  void setValid( const bool validStatus ) { m_Valid = validStatus; }
371 
372  string ToString();
373  string getField( const int field );
374  string getField( const string& field );
375  string getCustomXPath( const string& xpath, const bool noCache = false );
376 
377  string getNamespace() const { return m_Namespace; }
378 
379  virtual const RoutingAggregationCode& getAggregationCode( const RoutingAggregationCode& feedback ) = 0;
380  virtual RoutingAggregationCode getBusinessAggregationCode()
381  {
382  return RoutingAggregationCode();
383  }
384 
385  virtual FinTP::NameValueCollection getAddParams( const string& ref )
386  {
387  return FinTP::NameValueCollection();
388  }
389 
390  virtual bool isReply() = 0;
391  virtual bool isAck() = 0;
392  virtual bool isNack() = 0;
393  virtual bool isAck( const string ns )
394  {
395  if ( ns.length() == 0 )
396  return isAck();
397  return ( isAck() && ( ns == m_Namespace ) );
398  }
399  virtual bool isNack( const string ns )
400  {
401  if ( ns.length() == 0 )
402  return isNack();
403  return ( isNack() && ( ns == m_Namespace ) );
404  }
405  virtual bool isBatch() = 0;
406 
407  virtual bool updateRelatedMessages() { return false; }
408  virtual bool isOriginalIncomingMessage() { return false; }
409  virtual bool isDD() { return false; }
410  virtual bool isID() { return false; }
411  virtual string getIssuer() { return ""; }
412 
413  virtual string getOverrideFeedback() { return ""; }
414  virtual string getOverrideFeedbackId() { return ""; }
416 
417  const XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* getDocument() const { return m_Document; }
418  RoutingMessageEvaluator::EvaluatorType getEvaluatorType() const { return m_EvaluatorType; }
419 
420  // standards version
421  virtual wsrm::SequenceResponse* getSequenceResponse() = 0;
422 
423  // Visitor method on message
424  virtual void UpdateMessage( RoutingMessage* message );
425 
426  virtual bool checkReactivation(){ return true; }
427  virtual bool delayReply() { return false; }
428 
429  virtual ~RoutingMessageEvaluator();
430 };
431 
432 extern "C"
433 {
434  class Plugin
435  {
436  private:
437  const std::string m_Name;
438  const std::string m_Version;
439  public:
440  Plugin( const std::string& name, const std::string& version ): m_Name( name ), m_Version( version ){}
441  const std::string& getName() { return m_Name; }
442  const std::string& getVersion() { return m_Version; }
443  virtual bool hasNamespace( const string& aNamespace ) = 0;
444  virtual RoutingMessageEvaluator* newInstance( const XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* document ) = 0;
445  };
446 
447  typedef Plugin* ( *getPlugin )( void );
448 }
449 #endif //ROUTINGMESSAGEEVALUATOR_H