hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
PocoJSONReducingInputMessageConvertor.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 
12 using namespace Poco;
13 using namespace std;
14 using namespace HCE::reduce_types;
15 
17 }
18 
20 }
21 
22 SharedPtr<ReducingInputMessage> PocoJSONReducingInputMessageConvertor::
23  convertToReducingInputMessageFrom(const std::string & json)
24 {
25  try{
26  PocoJSONExtractor pocoJSONExtractor(json);
27  types::MessageType processingType =
28  static_cast<types::MessageType>(pocoJSONExtractor.extractAsInt(PROCESSING_TYPE_NAME));
29  int ttl = pocoJSONExtractor.extractAsInt(TTL_NAME);
30  string body = pocoJSONExtractor.extractAsString(BODY_NAME);
31 
32  return SharedPtr<ReducingInputMessage>(new ReducingInputMessage(processingType, ttl, body));
33  }
34  catch(JSON::JSONException& e){
35  throw reduce::WrongJSONStructureException(e.displayText());
36  }
37  catch(Exception& e){
38  throw reduce::WrongJSONStructureException(e.displayText());
39  }
40 }
41 
43  const SharedPtr<ReducingInputMessage> & inputMessage)
44 {
45  try{
46  PocoJSONBuilder pocoJSONBuilder;
47  pocoJSONBuilder.add(PROCESSING_TYPE_NAME, static_cast<int>(inputMessage->getProcessingType()));
48  pocoJSONBuilder.add(TTL_NAME, inputMessage->getTTL());
49  pocoJSONBuilder.add(BODY_NAME, inputMessage->getBody());
50 
51  return pocoJSONBuilder.build();
52  }
53  catch(std::exception& e){
55  }
56 }
57 
58 }
59 }