2 # ==================================================================================
3 # Copyright (c) 2020 HCL Technologies Limited.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 # ==================================================================================
18 #include"ActionToBeSetup.h"
21 void from_json(const nlohmann::json & j, ActionToBeSetup& ref) {
23 std::cout << __PRETTY_FUNCTION__ << std::endl;
25 if (j.contains("ActionDefinition")) {
26 j.at("ActionDefinition").get_to(ref.ActionDefinition);
28 j.at("ActionID").get_to(ref.ActionID);
29 j.at("ActionType").get_to(ref.ActionType);
30 if (j.contains("SubsequentAction")) {
31 j.at("SubsequentAction").get_to(ref.m_SubsequentAction);
37 void from_json(const nlohmann::json & j, std::vector<ActionToBeSetup>& ref) {
39 std::cout << __PRETTY_FUNCTION__ << std::endl;
41 for (auto& element : j) {
43 tmp.validate_json(element);
44 for (auto& val : element.items())
46 if (val.key() == "ActionDefinition") {
48 tmp.ActionDefinition.assign(val.value().begin(), val.value().end());
51 else if (val.key() == "ActionID") {
52 tmp.ActionID = val.value();
54 else if (val.key() == "ActionType") {
55 tmp.ActionType = val.value();
57 else if (val.key() == "SubsequentAction") {
58 tmp.m_SubsequentAction.SubsequentActionType = val.value()["SubsequentActionType"];
59 tmp.m_SubsequentAction.TimeToWait = val.value()["TimeToWait"];
68 void to_json(nlohmann::json& j, const ActionToBeSetup& ref) {
71 //{"ActionDefinition", ref.ActionDefinition},
72 {"ActionID", ref.ActionID},
73 {"ActionType", ref.ActionType}//,
74 //{"SubsequentAction", {{"SubsequentActionType",ref.m_SubsequentAction.SubsequentActionType},{"TimeToWait", ref.m_SubsequentAction.TimeToWait } }}
76 if (ref.ActionDefinition.size() > 0) {
77 j["ActionDefinition"] = ref.ActionDefinition;
79 if (ref.m_SubsequentAction.SubsequentActionType.length() > 0 && ref.m_SubsequentAction.TimeToWait.length() > 0) {
80 j["SubsequentAction"] = ref.m_SubsequentAction;
85 void to_json(nlohmann::json& j, const std::vector<ActionToBeSetup>& ref) {
87 for (int i = 0; i < ref.size(); i++) {
90 {"ActionDefinition", ref[i].ActionDefinition},
91 {"ActionID", ref[i].ActionID},
92 {"ActionType", ref[i].ActionType},
93 {"SubsequentAction", {{"SubsequentActionType",ref[i].m_SubsequentAction.SubsequentActionType},{"TimeToWait", ref[i].m_SubsequentAction.TimeToWait } }}
98 for (int i = 0; i < ref.size(); i++) {
100 to_json(tmp, ref[i]);