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"SubscriptionDetail.h"
21 void from_json(const nlohmann::json& j, SubscriptionDetail& ref) {
23 std::cout << __PRETTY_FUNCTION__ << std::endl;
26 j.at("XappEventInstanceId").get_to(ref.XappEventInstanceId);
27 j.at("EventTriggers").get_to(ref.EventTriggers);
28 j.at("ActionToBeSetupList").get_to(ref.Data);
31 void from_json(const nlohmann::json& j, std::vector<SubscriptionDetail>& ref) {
33 std::cout << __PRETTY_FUNCTION__ << std::endl;
36 for (auto& element : j) {
37 SubscriptionDetail tmp;
38 tmp.validate_json(element);
39 for (auto& val : element.items()) {
40 if (val.key() == "XappEventInstanceId") {
42 //tmp.SetXappEventInstanceId(val.value());
43 tmp.XappEventInstanceId = val.value();
46 else if (val.key() == "EventTriggers") {
47 //tmp.setEventTriggers(val.value());
48 tmp.EventTriggers.assign(val.value().begin(), val.value().end());
52 else if (val.key() == "ActionToBeSetupList") {
54 nlohmann::json tmp_j(val.value());
55 from_json(tmp_j, tmp.Data);
63 for (int i = 0; i < j.size(); i++)
65 ref[i].validate_json(j.at(i));
66 j.at(i).at("XappEventInstanceId").get_to(ref[i].XappEventInstanceId);
67 j.at(i).at("EventTriggers").get_to(ref[i].EventTriggers);
68 j.at(i).at("ActionToBeSetupList").get_to(ref[i].Data);
74 void to_json(nlohmann::json& j, const SubscriptionDetail & ref) {
77 {"XappEventInstanceId", ref.XappEventInstanceId},
78 {"EventTriggers", ref.EventTriggers}
81 to_json(tmp_j, ref.Data);
82 j["ActionToBeSetupList"] = tmp_j;
83 //for (int i = 0; i < ref.Data.size(); i++) {
84 // nlohmann::json tmp_j;
85 // to_json(tmp_j, ref.Data[i]);
86 // j["ActionToBeSetupList"] += tmp_j;
89 void to_json(nlohmann::json& j, const std::vector<SubscriptionDetail> & ref) {
90 for (int i = 0; i < ref.size(); i++)
93 to_json(tmp_j, ref[i]);