hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
PocoJSONReducingOutputMessageConvertor.cpp
Go to the documentation of this file.
2 #include "Exceptions.hpp"
3 #include <Poco/JSON/JSONException.h>
4 #include "PocoJSONExtractor.hpp"
5 #include "PocoJSONBuilder.hpp"
6 
7 namespace HCE {
8 
9 namespace reduce_convertors {
10 
11 using namespace Poco;
12 using namespace std;
13 using namespace HCE::reduce_types;
14 
16 }
17 
19 }
20 
21 SharedPtr<ReducingOutputMessage> PocoJSONReducingOutputMessageConvertor::
23 {
24  try{
25  PocoJSONExtractor pocoJSONExtractor(json);
26  types::MessageType processingType =
27  static_cast<types::MessageType>(pocoJSONExtractor.extractAsInt(PROCESSING_TYPE_NAME));
28  int ttl = pocoJSONExtractor.extractAsInt(TTL_NAME);
29  string body = pocoJSONExtractor.extractAsString(BODY_NAME);
30  int processingErrorCode = pocoJSONExtractor.extractAsInt(PROCESSING_ERROR_CODE_NAME);
31  int processingElapsedTime = pocoJSONExtractor.extractAsInt(PROCESSING_ELAPSED_TIME_NAME);
32  string processingErrorMsg = pocoJSONExtractor.extractAsString(PROCESSING_ERROR_MSG_NAME);
33 
34  return SharedPtr<ReducingOutputMessage>(new ReducingOutputMessage(processingType, ttl,
35  body, processingErrorCode, processingErrorMsg, processingElapsedTime));
36  }
37  catch(JSON::JSONException& e){
38  throw reduce::WrongJSONStructureException(e.displayText());
39  }
40  catch(Exception& e){
41  throw reduce::WrongJSONStructureException(e.displayText());
42  }
43 }
44 
46  const SharedPtr<ReducingOutputMessage> & message)
47 {
48  try{
49  PocoJSONBuilder pocoJSONBuilder;
50 
51  pocoJSONBuilder.add(PROCESSING_TYPE_NAME, static_cast<int>(message->getProcessingType()));
52  pocoJSONBuilder.add(TTL_NAME, message->getTTL());
53  pocoJSONBuilder.add(BODY_NAME, message->getBody());
54  pocoJSONBuilder.add(PROCESSING_ERROR_CODE_NAME, message->getProcessingErrorCode());
55  pocoJSONBuilder.add(PROCESSING_ERROR_MSG_NAME, message->getProcessingErrorMsg());
56  pocoJSONBuilder.add(PROCESSING_ELAPSED_TIME_NAME, message->getProcessingElapsedTime());
57 
58  return pocoJSONBuilder.build();
59  }
60  catch(std::exception& e){
62  }
63 }
64 
65 
66 }
67 }