RIC-641 Fixing client/server model definitions and adding client and server API
[ric-plt/xapp-frame-cpp.git] / src / model / SubscriptionInstance.cpp
1 /*
2 # ==================================================================================
3 # Copyright (c) 2020 HCL Technologies Limited.
4 #
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
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
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 # ==================================================================================
17 */
18 #include"SubscriptionInstance.h"
19 namespace xapp {
20         namespace model {
21                 void from_json(const nlohmann::json& j, SubscriptionInstance& ref) {
22
23                         std::cout << __PRETTY_FUNCTION__ << std::endl;
24                         ref.validate_json(j);
25
26                         j.at("XappEventInstanceId").get_to(ref.XappEventInstanceId);
27                         j.at("E2EventInstanceId").get_to(ref.E2EventInstanceId);
28                         j.at("ErrorCause").get_to(ref.ErrorCause);
29                         j.at("ErrorSource").get_to(ref.ErrorSource);
30                         j.at("TimeoutType").get_to(ref.TimeoutType);
31                 }
32                 void from_json(const nlohmann::json& j, std::vector<SubscriptionInstance>& ref) {
33
34                         std::cout << __PRETTY_FUNCTION__ << std::endl;
35                         for (auto& element : j) {
36                                 SubscriptionInstance tmp;
37                                 tmp.validate_json(element);
38                                 for (auto& val : element.items())
39                                 {
40
41
42                                         if (val.key() == "XappEventInstanceId") {
43
44                                                 tmp.XappEventInstanceId = val.value();
45
46                                         }
47                                         else if (val.key() == "E2EventInstanceId") {
48                                                 tmp.E2EventInstanceId = val.value();
49                                         }
50                                         else if (val.key() == "ErrorCause") {
51                                                 tmp.ErrorCause = val.value();
52                                         }
53                                         else if (val.key() == "ErrorSource") {
54                                                 tmp.ErrorSource = val.value();
55                                         }
56                                         else if (val.key() == "TimeoutType") {
57                                                 tmp.TimeoutType = val.value();
58                                         }
59
60
61                                 }
62                                 ref.push_back(tmp);
63
64
65                         }
66
67
68                 }
69
70                 void to_json(nlohmann::json& j, const SubscriptionInstance& ref) {
71
72                         j = nlohmann::json{
73                                 {"XappEventInstanceId", ref.XappEventInstanceId},
74                                 {"E2EventInstanceId", ref.E2EventInstanceId},
75                                 {"ErrorCause", ref.ErrorCause},
76                                 {"ErrorSource", ref.ErrorSource},
77                                 {"TimeoutType", ref.TimeoutType}
78                         };
79                 }
80                 void to_json(nlohmann::json& j, const std::vector<SubscriptionInstance>& ref) {
81
82
83                         for (int i = 0; i < ref.size(); i++)
84                         {
85
86                                 nlohmann::json tmp = nlohmann::json{
87                                 {"XappEventInstanceId", ref[i].XappEventInstanceId},
88                                 {"E2EventInstanceId", ref[i].E2EventInstanceId},
89                                 {"ErrorCause", ref[i].ErrorCause},
90                                 {"ErrorSource", ref[i].ErrorSource},
91                                 {"TimeoutType", ref[i].TimeoutType}
92                                 };
93                                 j.push_back(tmp);
94                         }
95                 }
96         }
97 }