1 /**
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  * SPDX-License-Identifier: Apache-2.0.
4  */
5 
6 #include <aws/rds/model/ReservedDBInstance.h>
7 #include <aws/core/utils/xml/XmlSerializer.h>
8 #include <aws/core/utils/StringUtils.h>
9 #include <aws/core/utils/memory/stl/AWSStringStream.h>
10 
11 #include <utility>
12 
13 using namespace Aws::Utils::Xml;
14 using namespace Aws::Utils;
15 
16 namespace Aws
17 {
18 namespace RDS
19 {
20 namespace Model
21 {
22 
ReservedDBInstance()23 ReservedDBInstance::ReservedDBInstance() :
24     m_reservedDBInstanceIdHasBeenSet(false),
25     m_reservedDBInstancesOfferingIdHasBeenSet(false),
26     m_dBInstanceClassHasBeenSet(false),
27     m_startTimeHasBeenSet(false),
28     m_duration(0),
29     m_durationHasBeenSet(false),
30     m_fixedPrice(0.0),
31     m_fixedPriceHasBeenSet(false),
32     m_usagePrice(0.0),
33     m_usagePriceHasBeenSet(false),
34     m_currencyCodeHasBeenSet(false),
35     m_dBInstanceCount(0),
36     m_dBInstanceCountHasBeenSet(false),
37     m_productDescriptionHasBeenSet(false),
38     m_offeringTypeHasBeenSet(false),
39     m_multiAZ(false),
40     m_multiAZHasBeenSet(false),
41     m_stateHasBeenSet(false),
42     m_recurringChargesHasBeenSet(false),
43     m_reservedDBInstanceArnHasBeenSet(false),
44     m_leaseIdHasBeenSet(false)
45 {
46 }
47 
ReservedDBInstance(const XmlNode & xmlNode)48 ReservedDBInstance::ReservedDBInstance(const XmlNode& xmlNode) :
49     m_reservedDBInstanceIdHasBeenSet(false),
50     m_reservedDBInstancesOfferingIdHasBeenSet(false),
51     m_dBInstanceClassHasBeenSet(false),
52     m_startTimeHasBeenSet(false),
53     m_duration(0),
54     m_durationHasBeenSet(false),
55     m_fixedPrice(0.0),
56     m_fixedPriceHasBeenSet(false),
57     m_usagePrice(0.0),
58     m_usagePriceHasBeenSet(false),
59     m_currencyCodeHasBeenSet(false),
60     m_dBInstanceCount(0),
61     m_dBInstanceCountHasBeenSet(false),
62     m_productDescriptionHasBeenSet(false),
63     m_offeringTypeHasBeenSet(false),
64     m_multiAZ(false),
65     m_multiAZHasBeenSet(false),
66     m_stateHasBeenSet(false),
67     m_recurringChargesHasBeenSet(false),
68     m_reservedDBInstanceArnHasBeenSet(false),
69     m_leaseIdHasBeenSet(false)
70 {
71   *this = xmlNode;
72 }
73 
operator =(const XmlNode & xmlNode)74 ReservedDBInstance& ReservedDBInstance::operator =(const XmlNode& xmlNode)
75 {
76   XmlNode resultNode = xmlNode;
77 
78   if(!resultNode.IsNull())
79   {
80     XmlNode reservedDBInstanceIdNode = resultNode.FirstChild("ReservedDBInstanceId");
81     if(!reservedDBInstanceIdNode.IsNull())
82     {
83       m_reservedDBInstanceId = Aws::Utils::Xml::DecodeEscapedXmlText(reservedDBInstanceIdNode.GetText());
84       m_reservedDBInstanceIdHasBeenSet = true;
85     }
86     XmlNode reservedDBInstancesOfferingIdNode = resultNode.FirstChild("ReservedDBInstancesOfferingId");
87     if(!reservedDBInstancesOfferingIdNode.IsNull())
88     {
89       m_reservedDBInstancesOfferingId = Aws::Utils::Xml::DecodeEscapedXmlText(reservedDBInstancesOfferingIdNode.GetText());
90       m_reservedDBInstancesOfferingIdHasBeenSet = true;
91     }
92     XmlNode dBInstanceClassNode = resultNode.FirstChild("DBInstanceClass");
93     if(!dBInstanceClassNode.IsNull())
94     {
95       m_dBInstanceClass = Aws::Utils::Xml::DecodeEscapedXmlText(dBInstanceClassNode.GetText());
96       m_dBInstanceClassHasBeenSet = true;
97     }
98     XmlNode startTimeNode = resultNode.FirstChild("StartTime");
99     if(!startTimeNode.IsNull())
100     {
101       m_startTime = DateTime(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(startTimeNode.GetText()).c_str()).c_str(), DateFormat::ISO_8601);
102       m_startTimeHasBeenSet = true;
103     }
104     XmlNode durationNode = resultNode.FirstChild("Duration");
105     if(!durationNode.IsNull())
106     {
107       m_duration = StringUtils::ConvertToInt32(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(durationNode.GetText()).c_str()).c_str());
108       m_durationHasBeenSet = true;
109     }
110     XmlNode fixedPriceNode = resultNode.FirstChild("FixedPrice");
111     if(!fixedPriceNode.IsNull())
112     {
113       m_fixedPrice = StringUtils::ConvertToDouble(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(fixedPriceNode.GetText()).c_str()).c_str());
114       m_fixedPriceHasBeenSet = true;
115     }
116     XmlNode usagePriceNode = resultNode.FirstChild("UsagePrice");
117     if(!usagePriceNode.IsNull())
118     {
119       m_usagePrice = StringUtils::ConvertToDouble(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(usagePriceNode.GetText()).c_str()).c_str());
120       m_usagePriceHasBeenSet = true;
121     }
122     XmlNode currencyCodeNode = resultNode.FirstChild("CurrencyCode");
123     if(!currencyCodeNode.IsNull())
124     {
125       m_currencyCode = Aws::Utils::Xml::DecodeEscapedXmlText(currencyCodeNode.GetText());
126       m_currencyCodeHasBeenSet = true;
127     }
128     XmlNode dBInstanceCountNode = resultNode.FirstChild("DBInstanceCount");
129     if(!dBInstanceCountNode.IsNull())
130     {
131       m_dBInstanceCount = StringUtils::ConvertToInt32(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(dBInstanceCountNode.GetText()).c_str()).c_str());
132       m_dBInstanceCountHasBeenSet = true;
133     }
134     XmlNode productDescriptionNode = resultNode.FirstChild("ProductDescription");
135     if(!productDescriptionNode.IsNull())
136     {
137       m_productDescription = Aws::Utils::Xml::DecodeEscapedXmlText(productDescriptionNode.GetText());
138       m_productDescriptionHasBeenSet = true;
139     }
140     XmlNode offeringTypeNode = resultNode.FirstChild("OfferingType");
141     if(!offeringTypeNode.IsNull())
142     {
143       m_offeringType = Aws::Utils::Xml::DecodeEscapedXmlText(offeringTypeNode.GetText());
144       m_offeringTypeHasBeenSet = true;
145     }
146     XmlNode multiAZNode = resultNode.FirstChild("MultiAZ");
147     if(!multiAZNode.IsNull())
148     {
149       m_multiAZ = StringUtils::ConvertToBool(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(multiAZNode.GetText()).c_str()).c_str());
150       m_multiAZHasBeenSet = true;
151     }
152     XmlNode stateNode = resultNode.FirstChild("State");
153     if(!stateNode.IsNull())
154     {
155       m_state = Aws::Utils::Xml::DecodeEscapedXmlText(stateNode.GetText());
156       m_stateHasBeenSet = true;
157     }
158     XmlNode recurringChargesNode = resultNode.FirstChild("RecurringCharges");
159     if(!recurringChargesNode.IsNull())
160     {
161       XmlNode recurringChargesMember = recurringChargesNode.FirstChild("RecurringCharge");
162       while(!recurringChargesMember.IsNull())
163       {
164         m_recurringCharges.push_back(recurringChargesMember);
165         recurringChargesMember = recurringChargesMember.NextNode("RecurringCharge");
166       }
167 
168       m_recurringChargesHasBeenSet = true;
169     }
170     XmlNode reservedDBInstanceArnNode = resultNode.FirstChild("ReservedDBInstanceArn");
171     if(!reservedDBInstanceArnNode.IsNull())
172     {
173       m_reservedDBInstanceArn = Aws::Utils::Xml::DecodeEscapedXmlText(reservedDBInstanceArnNode.GetText());
174       m_reservedDBInstanceArnHasBeenSet = true;
175     }
176     XmlNode leaseIdNode = resultNode.FirstChild("LeaseId");
177     if(!leaseIdNode.IsNull())
178     {
179       m_leaseId = Aws::Utils::Xml::DecodeEscapedXmlText(leaseIdNode.GetText());
180       m_leaseIdHasBeenSet = true;
181     }
182   }
183 
184   return *this;
185 }
186 
OutputToStream(Aws::OStream & oStream,const char * location,unsigned index,const char * locationValue) const187 void ReservedDBInstance::OutputToStream(Aws::OStream& oStream, const char* location, unsigned index, const char* locationValue) const
188 {
189   if(m_reservedDBInstanceIdHasBeenSet)
190   {
191       oStream << location << index << locationValue << ".ReservedDBInstanceId=" << StringUtils::URLEncode(m_reservedDBInstanceId.c_str()) << "&";
192   }
193 
194   if(m_reservedDBInstancesOfferingIdHasBeenSet)
195   {
196       oStream << location << index << locationValue << ".ReservedDBInstancesOfferingId=" << StringUtils::URLEncode(m_reservedDBInstancesOfferingId.c_str()) << "&";
197   }
198 
199   if(m_dBInstanceClassHasBeenSet)
200   {
201       oStream << location << index << locationValue << ".DBInstanceClass=" << StringUtils::URLEncode(m_dBInstanceClass.c_str()) << "&";
202   }
203 
204   if(m_startTimeHasBeenSet)
205   {
206       oStream << location << index << locationValue << ".StartTime=" << StringUtils::URLEncode(m_startTime.ToGmtString(DateFormat::ISO_8601).c_str()) << "&";
207   }
208 
209   if(m_durationHasBeenSet)
210   {
211       oStream << location << index << locationValue << ".Duration=" << m_duration << "&";
212   }
213 
214   if(m_fixedPriceHasBeenSet)
215   {
216         oStream << location << index << locationValue << ".FixedPrice=" << StringUtils::URLEncode(m_fixedPrice) << "&";
217   }
218 
219   if(m_usagePriceHasBeenSet)
220   {
221         oStream << location << index << locationValue << ".UsagePrice=" << StringUtils::URLEncode(m_usagePrice) << "&";
222   }
223 
224   if(m_currencyCodeHasBeenSet)
225   {
226       oStream << location << index << locationValue << ".CurrencyCode=" << StringUtils::URLEncode(m_currencyCode.c_str()) << "&";
227   }
228 
229   if(m_dBInstanceCountHasBeenSet)
230   {
231       oStream << location << index << locationValue << ".DBInstanceCount=" << m_dBInstanceCount << "&";
232   }
233 
234   if(m_productDescriptionHasBeenSet)
235   {
236       oStream << location << index << locationValue << ".ProductDescription=" << StringUtils::URLEncode(m_productDescription.c_str()) << "&";
237   }
238 
239   if(m_offeringTypeHasBeenSet)
240   {
241       oStream << location << index << locationValue << ".OfferingType=" << StringUtils::URLEncode(m_offeringType.c_str()) << "&";
242   }
243 
244   if(m_multiAZHasBeenSet)
245   {
246       oStream << location << index << locationValue << ".MultiAZ=" << std::boolalpha << m_multiAZ << "&";
247   }
248 
249   if(m_stateHasBeenSet)
250   {
251       oStream << location << index << locationValue << ".State=" << StringUtils::URLEncode(m_state.c_str()) << "&";
252   }
253 
254   if(m_recurringChargesHasBeenSet)
255   {
256       unsigned recurringChargesIdx = 1;
257       for(auto& item : m_recurringCharges)
258       {
259         Aws::StringStream recurringChargesSs;
260         recurringChargesSs << location << index << locationValue << ".RecurringCharge." << recurringChargesIdx++;
261         item.OutputToStream(oStream, recurringChargesSs.str().c_str());
262       }
263   }
264 
265   if(m_reservedDBInstanceArnHasBeenSet)
266   {
267       oStream << location << index << locationValue << ".ReservedDBInstanceArn=" << StringUtils::URLEncode(m_reservedDBInstanceArn.c_str()) << "&";
268   }
269 
270   if(m_leaseIdHasBeenSet)
271   {
272       oStream << location << index << locationValue << ".LeaseId=" << StringUtils::URLEncode(m_leaseId.c_str()) << "&";
273   }
274 
275 }
276 
OutputToStream(Aws::OStream & oStream,const char * location) const277 void ReservedDBInstance::OutputToStream(Aws::OStream& oStream, const char* location) const
278 {
279   if(m_reservedDBInstanceIdHasBeenSet)
280   {
281       oStream << location << ".ReservedDBInstanceId=" << StringUtils::URLEncode(m_reservedDBInstanceId.c_str()) << "&";
282   }
283   if(m_reservedDBInstancesOfferingIdHasBeenSet)
284   {
285       oStream << location << ".ReservedDBInstancesOfferingId=" << StringUtils::URLEncode(m_reservedDBInstancesOfferingId.c_str()) << "&";
286   }
287   if(m_dBInstanceClassHasBeenSet)
288   {
289       oStream << location << ".DBInstanceClass=" << StringUtils::URLEncode(m_dBInstanceClass.c_str()) << "&";
290   }
291   if(m_startTimeHasBeenSet)
292   {
293       oStream << location << ".StartTime=" << StringUtils::URLEncode(m_startTime.ToGmtString(DateFormat::ISO_8601).c_str()) << "&";
294   }
295   if(m_durationHasBeenSet)
296   {
297       oStream << location << ".Duration=" << m_duration << "&";
298   }
299   if(m_fixedPriceHasBeenSet)
300   {
301         oStream << location << ".FixedPrice=" << StringUtils::URLEncode(m_fixedPrice) << "&";
302   }
303   if(m_usagePriceHasBeenSet)
304   {
305         oStream << location << ".UsagePrice=" << StringUtils::URLEncode(m_usagePrice) << "&";
306   }
307   if(m_currencyCodeHasBeenSet)
308   {
309       oStream << location << ".CurrencyCode=" << StringUtils::URLEncode(m_currencyCode.c_str()) << "&";
310   }
311   if(m_dBInstanceCountHasBeenSet)
312   {
313       oStream << location << ".DBInstanceCount=" << m_dBInstanceCount << "&";
314   }
315   if(m_productDescriptionHasBeenSet)
316   {
317       oStream << location << ".ProductDescription=" << StringUtils::URLEncode(m_productDescription.c_str()) << "&";
318   }
319   if(m_offeringTypeHasBeenSet)
320   {
321       oStream << location << ".OfferingType=" << StringUtils::URLEncode(m_offeringType.c_str()) << "&";
322   }
323   if(m_multiAZHasBeenSet)
324   {
325       oStream << location << ".MultiAZ=" << std::boolalpha << m_multiAZ << "&";
326   }
327   if(m_stateHasBeenSet)
328   {
329       oStream << location << ".State=" << StringUtils::URLEncode(m_state.c_str()) << "&";
330   }
331   if(m_recurringChargesHasBeenSet)
332   {
333       unsigned recurringChargesIdx = 1;
334       for(auto& item : m_recurringCharges)
335       {
336         Aws::StringStream recurringChargesSs;
337         recurringChargesSs << location <<  ".RecurringCharge." << recurringChargesIdx++;
338         item.OutputToStream(oStream, recurringChargesSs.str().c_str());
339       }
340   }
341   if(m_reservedDBInstanceArnHasBeenSet)
342   {
343       oStream << location << ".ReservedDBInstanceArn=" << StringUtils::URLEncode(m_reservedDBInstanceArn.c_str()) << "&";
344   }
345   if(m_leaseIdHasBeenSet)
346   {
347       oStream << location << ".LeaseId=" << StringUtils::URLEncode(m_leaseId.c_str()) << "&";
348   }
349 }
350 
351 } // namespace Model
352 } // namespace RDS
353 } // namespace Aws
354