Adding JsonSchema parser implementation for simulator and Updating Raml Parser.
[platform/upstream/iotivity.git] / service / simulator / ramlparser / raml / model / Action.cpp
1 /******************************************************************\r
2  *\r
3  * Copyright 2015 Samsung Electronics All Rights Reserved.\r
4  *\r
5  *\r
6  *\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  *\r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  *\r
19  ******************************************************************/\r
20 \r
21 #include "Action.h"\r
22 \r
23 namespace RAML\r
24 {\r
25     ActionType Action::getType() const\r
26     {\r
27         return m_type;\r
28     }\r
29     void Action::setType(const ActionType &type)\r
30     {\r
31         m_type = type;\r
32     }\r
33     std::string Action::getDescription() const\r
34     {\r
35         return m_description;\r
36     }\r
37     void Action::setDescription(const std::string &description)\r
38     {\r
39         m_description = description;\r
40     }\r
41     std::map<std::string, HeaderPtr > const &Action::getHeaders() const\r
42     {\r
43         return m_headers;\r
44     }\r
45     void Action::setHeader(const std::string &headerName, const HeaderPtr &header)\r
46     {\r
47         m_headers[headerName] = header;\r
48     }\r
49     std::map<std::string, QueryParameterPtr > const &Action::getQueryParameters()const\r
50     {\r
51         return m_queryParameters;\r
52     }\r
53     void Action::setQueryParameter(const std::string &paramName,\r
54                                    const QueryParameterPtr &queryParameter)\r
55     {\r
56         m_queryParameters[paramName] = queryParameter;\r
57     }\r
58     RequestResponseBodyPtr Action::getRequestBody(const std::string &bodyType)\r
59     {\r
60         return m_requestBody[bodyType];\r
61     }\r
62 \r
63     std::map<std::string, RequestResponseBodyPtr> const &Action::getRequestBody() const\r
64     {\r
65         return m_requestBody;\r
66     }\r
67     void Action::setRequestBody(const std::string &typeName)\r
68     {\r
69         m_requestBody[typeName] = std::make_shared<RequestResponseBody>(typeName);\r
70     }\r
71 \r
72     void Action::setRequestBody(const std::string &typeName , const RequestResponseBodyPtr &body)\r
73     {\r
74         m_requestBody[typeName] = body;\r
75     }\r
76     ResponsePtr Action::getResponse(const std::string &responseCode)\r
77     {\r
78         return m_responses[responseCode];\r
79     }\r
80 \r
81     std::map<std::string, ResponsePtr> const &Action::getResponses() const\r
82     {\r
83         return m_responses;\r
84     }\r
85     void Action::setResponse(const std::string &responseCode, const ResponsePtr &response)\r
86     {\r
87         m_responses[responseCode] = response;\r
88     }\r
89 \r
90     std::list<std::string> const &Action::getProtocols() const\r
91     {\r
92         return m_protocols;\r
93     }\r
94     void Action::setProtocol(const std::string &protocol)\r
95     {\r
96         m_protocols.push_back(protocol);\r
97     }\r
98     std::map<std::string, UriParameterPtr > const &Action::getBaseUriParameters() const\r
99     {\r
100         return m_baseUriParameters;\r
101     }\r
102     void Action::setBaseUriParameter(const std::string &paramName ,\r
103                                      const UriParameterPtr &baseUriParameter)\r
104     {\r
105         m_baseUriParameters[paramName] = baseUriParameter;\r
106     }\r
107 \r
108     std::list<std::string> const &Action::getTraits() const\r
109     {\r
110         return m_trait;\r
111     }\r
112     void Action::setTrait(const std::string &trait)\r
113     {\r
114         m_trait.push_back(trait);\r
115     }\r
116     void Action::readAction(const ActionType actionType, const YAML::Node &yamlNode)\r
117     {\r
118         m_type = actionType;\r
119         for ( YAML::const_iterator it = yamlNode.begin(); it != yamlNode.end(); ++it )\r
120         {\r
121             std::string key = READ_NODE_AS_STRING(it->first);\r
122 \r
123             if (key == Keys::Description)\r
124                 setDescription(READ_NODE_AS_STRING(it->second));\r
125             else if (key == Keys::Responses)\r
126             {\r
127                 YAML::Node responseNode = it->second;\r
128                 for ( YAML::const_iterator tt = responseNode.begin(); tt != responseNode.end(); ++tt )\r
129                 {\r
130                     std::string responseCode = READ_NODE_AS_STRING(tt->first);\r
131                     setResponse(responseCode, std::make_shared<Response>(tt->second, m_includeResolver));\r
132                 }\r
133             }\r
134             else if (key == Keys::Headers)\r
135             {\r
136                 YAML::Node paramNode = it->second;\r
137                 for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt )\r
138                 {\r
139                     setHeader(READ_NODE_AS_STRING(tt->first), std::make_shared<Header>(tt->second));\r
140                 }\r
141             }\r
142             else if (key == Keys::QueryParameters)\r
143             {\r
144                 YAML::Node paramNode = it->second;\r
145                 for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt )\r
146                 {\r
147                     setQueryParameter(READ_NODE_AS_STRING(tt->first), std::make_shared<QueryParameter>(tt->second));\r
148                 }\r
149             }\r
150             else if (key == Keys::Protocols)\r
151             {\r
152                 YAML::Node protocolNode = it->second;\r
153                 for ( YAML::const_iterator tt = protocolNode.begin(); tt != protocolNode.end(); ++tt )\r
154                 {\r
155                     setProtocol(READ_NODE_AS_STRING(*tt));\r
156                 }\r
157             }\r
158             else if (key == Keys::BaseUriParameters)\r
159             {\r
160                 YAML::Node paramNode = it->second;\r
161                 for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt )\r
162                 {\r
163                     setBaseUriParameter(READ_NODE_AS_STRING(tt->first), std::make_shared<UriParameter>(tt->second));\r
164                 }\r
165             }\r
166             else if (key == Keys::Body)\r
167             {\r
168                 YAML::Node responseBody = it->second;\r
169 \r
170                 for ( YAML::const_iterator tt = responseBody.begin(); tt != responseBody.end(); ++tt )\r
171                 {\r
172                     std::string type = READ_NODE_AS_STRING(tt->first);\r
173                     setRequestBody(type, std::make_shared<RequestResponseBody>(type, tt->second, m_includeResolver));\r
174                 }\r
175             }\r
176             else if (key == Keys::IsTrait)\r
177             {\r
178                 YAML::Node traitNode = it->second;\r
179                 for ( YAML::const_iterator tt = traitNode.begin(); tt != traitNode.end(); ++tt )\r
180                 {\r
181                     setTrait(READ_NODE_AS_STRING(*tt));\r
182                 }\r
183             }\r
184         }\r
185     }\r
186 \r
187 };\r
188 \r