f427e791c31ca8fb9e89c42859bb8aca9479a525
[ric-plt/xapp-frame-cpp.git] / src / rest / model / SubscriptionInstance.h
1 #ifndef XAPP_MODEL_SubscriptionInstance_H
2 #define XAPP_MODEL_SubscriptionInstance_H
3 #include "ModelBase.h"
4
5 namespace xapp {
6 namespace model {
7
8 struct SubscriptionInstance: ModelBase {
9     int E2EventInstanceID;
10     std::string ErrorCause;
11     std::string ErrorSource;
12     std::string TimeoutType;
13     int XappEventInstanceID;
14
15     json validator_schema = R"(
16     {
17     "$schema": "http://json-schema.org/draft-07/schema#",
18     "title": "SubscriptionInstance",
19     "description": "xApp service address and port",
20     "properties": {
21         "XappEventInstanceId": {
22             "type": "integer",
23             "minimum": 0,
24             "maximum": 65535
25         },
26         "E2EventInstanceId": {
27             "type": "integer",
28             "minimum": 0,
29             "maximum": 65535
30         },
31         "ErrorCause": {
32             "description": "Descriptive error cause. Empty string when no error.",
33             "type": "string"
34         },
35         "ErrorSource": {
36             "description": "Source of error cause.",
37             "type": "string",
38             "enum": ["SUBMGR", "RTMGR", "DBAAS", "ASN1", "E2Node"]
39         },
40         "TimeoutType": {
41             "description": "Type timeout. xApp should retry if timeout occurs.",
42             "type": "string",
43             "enum": ["E2-Timeout", "RTMGR-Timeout", "DBAAS-Timeout"]
44         }
45     },
46     "required": [
47                  "XappEventInstanceId",
48                  "E2EventInstanceId"
49                  ],
50     "type": "object"
51     })"_json;
52
53     virtual json get_validator_schema() const { return validator_schema; }
54 };
55
56 void from_json(const json& j, SubscriptionInstance& ref) {
57
58     std::cout << __PRETTY_FUNCTION__ << std::endl;
59     ref.validate_json(j);
60
61     j.at("XappEventInstanceId").get_to(ref.XappEventInstanceID);
62     j.at("E2EventInstanceId").get_to(ref.E2EventInstanceID);
63     j.at("ErrorCause").get_to(ref.ErrorCause);
64     j.at("ErrorSource").get_to(ref.ErrorSource);
65     j.at("TimeoutType").get_to(ref.TimeoutType);
66 }
67
68 void to_json(json& j, const SubscriptionInstance& ref) {
69
70     j = json {
71         {"XappEventInstanceId", ref.XappEventInstanceID},
72         {"E2EventInstanceId", ref.E2EventInstanceID},
73         {"ErrorCause", ref.ErrorCause},
74         {"ErrorSource", ref.ErrorSource},
75         {"TimeoutType", ref.TimeoutType}
76     };
77 }
78
79 using SubscriptionInstances = std::vector<SubscriptionInstance>;
80
81 } /*namespace model*/
82 } /*namespace xapp*/
83 #endif /*XAPP_MODEL_SubscriptionInstance_H*/