GetScenarioResult.cc 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * Copyright 2009-2017 Alibaba Cloud All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <alibabacloud/ccc/model/GetScenarioResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::CCC;
  19. using namespace AlibabaCloud::CCC::Model;
  20. GetScenarioResult::GetScenarioResult() :
  21. ServiceResult()
  22. {}
  23. GetScenarioResult::GetScenarioResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. GetScenarioResult::~GetScenarioResult()
  29. {}
  30. void GetScenarioResult::parse(const std::string &payload)
  31. {
  32. Json::Reader reader;
  33. Json::Value value;
  34. reader.parse(payload, value);
  35. setRequestId(value["RequestId"].asString());
  36. auto scenarioNode = value["Scenario"];
  37. if(!scenarioNode["Id"].isNull())
  38. scenario_.id = scenarioNode["Id"].asString();
  39. if(!scenarioNode["Name"].isNull())
  40. scenario_.name = scenarioNode["Name"].asString();
  41. if(!scenarioNode["Description"].isNull())
  42. scenario_.description = scenarioNode["Description"].asString();
  43. if(!scenarioNode["Type"].isNull())
  44. scenario_.type = scenarioNode["Type"].asString();
  45. if(!scenarioNode["IsTemplate"].isNull())
  46. scenario_.isTemplate = scenarioNode["IsTemplate"].asString() == "true";
  47. auto allSurveysNode = scenarioNode["Surveys"]["Survey"];
  48. for (auto scenarioNodeSurveysSurvey : allSurveysNode)
  49. {
  50. Scenario::Survey surveyObject;
  51. if(!scenarioNodeSurveysSurvey["Id"].isNull())
  52. surveyObject.id = scenarioNodeSurveysSurvey["Id"].asString();
  53. if(!scenarioNodeSurveysSurvey["Name"].isNull())
  54. surveyObject.name = scenarioNodeSurveysSurvey["Name"].asString();
  55. if(!scenarioNodeSurveysSurvey["Description"].isNull())
  56. surveyObject.description = scenarioNodeSurveysSurvey["Description"].asString();
  57. if(!scenarioNodeSurveysSurvey["Role"].isNull())
  58. surveyObject.role = scenarioNodeSurveysSurvey["Role"].asString();
  59. if(!scenarioNodeSurveysSurvey["Round"].isNull())
  60. surveyObject.round = std::stoi(scenarioNodeSurveysSurvey["Round"].asString());
  61. if(!scenarioNodeSurveysSurvey["BeebotId"].isNull())
  62. surveyObject.beebotId = scenarioNodeSurveysSurvey["BeebotId"].asString();
  63. auto allIntentsNode = allSurveysNode["Intents"]["IntentNode"];
  64. for (auto allSurveysNodeIntentsIntentNode : allIntentsNode)
  65. {
  66. Scenario::Survey::IntentNode intentsObject;
  67. if(!allSurveysNodeIntentsIntentNode["NodeId"].isNull())
  68. intentsObject.nodeId = allSurveysNodeIntentsIntentNode["NodeId"].asString();
  69. if(!allSurveysNodeIntentsIntentNode["IntentId"].isNull())
  70. intentsObject.intentId = allSurveysNodeIntentsIntentNode["IntentId"].asString();
  71. surveyObject.intents.push_back(intentsObject);
  72. }
  73. scenario_.surveys.push_back(surveyObject);
  74. }
  75. auto allVariablesNode = scenarioNode["Variables"]["KeyValuePair"];
  76. for (auto scenarioNodeVariablesKeyValuePair : allVariablesNode)
  77. {
  78. Scenario::KeyValuePair keyValuePairObject;
  79. if(!scenarioNodeVariablesKeyValuePair["Key"].isNull())
  80. keyValuePairObject.key = scenarioNodeVariablesKeyValuePair["Key"].asString();
  81. if(!scenarioNodeVariablesKeyValuePair["Value"].isNull())
  82. keyValuePairObject.value = scenarioNodeVariablesKeyValuePair["Value"].asString();
  83. scenario_.variables.push_back(keyValuePairObject);
  84. }
  85. auto strategyNode = scenarioNode["Strategy"];
  86. if(!strategyNode["Id"].isNull())
  87. scenario_.strategy.id = strategyNode["Id"].asString();
  88. if(!strategyNode["Name"].isNull())
  89. scenario_.strategy.name = strategyNode["Name"].asString();
  90. if(!strategyNode["Description"].isNull())
  91. scenario_.strategy.description = strategyNode["Description"].asString();
  92. if(!strategyNode["Type"].isNull())
  93. scenario_.strategy.type = strategyNode["Type"].asString();
  94. if(!strategyNode["StartTime"].isNull())
  95. scenario_.strategy.startTime = std::stol(strategyNode["StartTime"].asString());
  96. if(!strategyNode["EndTime"].isNull())
  97. scenario_.strategy.endTime = std::stol(strategyNode["EndTime"].asString());
  98. if(!strategyNode["RepeatBy"].isNull())
  99. scenario_.strategy.repeatBy = strategyNode["RepeatBy"].asString();
  100. if(!strategyNode["MaxAttemptsPerDay"].isNull())
  101. scenario_.strategy.maxAttemptsPerDay = std::stoi(strategyNode["MaxAttemptsPerDay"].asString());
  102. if(!strategyNode["MinAttemptInterval"].isNull())
  103. scenario_.strategy.minAttemptInterval = std::stoi(strategyNode["MinAttemptInterval"].asString());
  104. if(!strategyNode["Customized"].isNull())
  105. scenario_.strategy.customized = strategyNode["Customized"].asString();
  106. if(!strategyNode["RoutingStrategy"].isNull())
  107. scenario_.strategy.routingStrategy = strategyNode["RoutingStrategy"].asString();
  108. if(!strategyNode["FollowUpStrategy"].isNull())
  109. scenario_.strategy.followUpStrategy = strategyNode["FollowUpStrategy"].asString();
  110. if(!strategyNode["IsTemplate"].isNull())
  111. scenario_.strategy.isTemplate = strategyNode["IsTemplate"].asString() == "true";
  112. auto allWorkingTimeNode = strategyNode["WorkingTime"]["TimeFrame"];
  113. for (auto strategyNodeWorkingTimeTimeFrame : allWorkingTimeNode)
  114. {
  115. Scenario::Strategy::TimeFrame timeFrameObject;
  116. if(!strategyNodeWorkingTimeTimeFrame["BeginTime"].isNull())
  117. timeFrameObject.beginTime = strategyNodeWorkingTimeTimeFrame["BeginTime"].asString();
  118. if(!strategyNodeWorkingTimeTimeFrame["EndTime"].isNull())
  119. timeFrameObject.endTime = strategyNodeWorkingTimeTimeFrame["EndTime"].asString();
  120. scenario_.strategy.workingTime.push_back(timeFrameObject);
  121. }
  122. auto allRepeatDays = strategyNode["RepeatDays"]["Integer"];
  123. for (auto value : allRepeatDays)
  124. scenario_.strategy.repeatDays.push_back(value.asString());
  125. if(!value["Success"].isNull())
  126. success_ = value["Success"].asString() == "true";
  127. if(!value["Code"].isNull())
  128. code_ = value["Code"].asString();
  129. if(!value["Message"].isNull())
  130. message_ = value["Message"].asString();
  131. if(!value["HttpStatusCode"].isNull())
  132. httpStatusCode_ = std::stoi(value["HttpStatusCode"].asString());
  133. }
  134. std::string GetScenarioResult::getMessage()const
  135. {
  136. return message_;
  137. }
  138. int GetScenarioResult::getHttpStatusCode()const
  139. {
  140. return httpStatusCode_;
  141. }
  142. std::string GetScenarioResult::getCode()const
  143. {
  144. return code_;
  145. }
  146. bool GetScenarioResult::getSuccess()const
  147. {
  148. return success_;
  149. }
  150. GetScenarioResult::Scenario GetScenarioResult::getScenario()const
  151. {
  152. return scenario_;
  153. }