1 /**
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  * SPDX-License-Identifier: Apache-2.0.
4  */
5 
6 #include <aws/ssm/model/OpsAggregator.h>
7 #include <aws/core/utils/json/JsonSerializer.h>
8 
9 #include <utility>
10 
11 using namespace Aws::Utils::Json;
12 using namespace Aws::Utils;
13 
14 namespace Aws
15 {
16 namespace SSM
17 {
18 namespace Model
19 {
20 
OpsAggregator()21 OpsAggregator::OpsAggregator() :
22     m_aggregatorTypeHasBeenSet(false),
23     m_typeNameHasBeenSet(false),
24     m_attributeNameHasBeenSet(false),
25     m_valuesHasBeenSet(false),
26     m_filtersHasBeenSet(false),
27     m_aggregatorsHasBeenSet(false)
28 {
29 }
30 
OpsAggregator(JsonView jsonValue)31 OpsAggregator::OpsAggregator(JsonView jsonValue) :
32     m_aggregatorTypeHasBeenSet(false),
33     m_typeNameHasBeenSet(false),
34     m_attributeNameHasBeenSet(false),
35     m_valuesHasBeenSet(false),
36     m_filtersHasBeenSet(false),
37     m_aggregatorsHasBeenSet(false)
38 {
39   *this = jsonValue;
40 }
41 
operator =(JsonView jsonValue)42 OpsAggregator& OpsAggregator::operator =(JsonView jsonValue)
43 {
44   if(jsonValue.ValueExists("AggregatorType"))
45   {
46     m_aggregatorType = jsonValue.GetString("AggregatorType");
47 
48     m_aggregatorTypeHasBeenSet = true;
49   }
50 
51   if(jsonValue.ValueExists("TypeName"))
52   {
53     m_typeName = jsonValue.GetString("TypeName");
54 
55     m_typeNameHasBeenSet = true;
56   }
57 
58   if(jsonValue.ValueExists("AttributeName"))
59   {
60     m_attributeName = jsonValue.GetString("AttributeName");
61 
62     m_attributeNameHasBeenSet = true;
63   }
64 
65   if(jsonValue.ValueExists("Values"))
66   {
67     Aws::Map<Aws::String, JsonView> valuesJsonMap = jsonValue.GetObject("Values").GetAllObjects();
68     for(auto& valuesItem : valuesJsonMap)
69     {
70       m_values[valuesItem.first] = valuesItem.second.AsString();
71     }
72     m_valuesHasBeenSet = true;
73   }
74 
75   if(jsonValue.ValueExists("Filters"))
76   {
77     Array<JsonView> filtersJsonList = jsonValue.GetArray("Filters");
78     for(unsigned filtersIndex = 0; filtersIndex < filtersJsonList.GetLength(); ++filtersIndex)
79     {
80       m_filters.push_back(filtersJsonList[filtersIndex].AsObject());
81     }
82     m_filtersHasBeenSet = true;
83   }
84 
85   if(jsonValue.ValueExists("Aggregators"))
86   {
87     Array<JsonView> aggregatorsJsonList = jsonValue.GetArray("Aggregators");
88     for(unsigned aggregatorsIndex = 0; aggregatorsIndex < aggregatorsJsonList.GetLength(); ++aggregatorsIndex)
89     {
90       m_aggregators.push_back(aggregatorsJsonList[aggregatorsIndex].AsObject());
91     }
92     m_aggregatorsHasBeenSet = true;
93   }
94 
95   return *this;
96 }
97 
Jsonize() const98 JsonValue OpsAggregator::Jsonize() const
99 {
100   JsonValue payload;
101 
102   if(m_aggregatorTypeHasBeenSet)
103   {
104    payload.WithString("AggregatorType", m_aggregatorType);
105 
106   }
107 
108   if(m_typeNameHasBeenSet)
109   {
110    payload.WithString("TypeName", m_typeName);
111 
112   }
113 
114   if(m_attributeNameHasBeenSet)
115   {
116    payload.WithString("AttributeName", m_attributeName);
117 
118   }
119 
120   if(m_valuesHasBeenSet)
121   {
122    JsonValue valuesJsonMap;
123    for(auto& valuesItem : m_values)
124    {
125      valuesJsonMap.WithString(valuesItem.first, valuesItem.second);
126    }
127    payload.WithObject("Values", std::move(valuesJsonMap));
128 
129   }
130 
131   if(m_filtersHasBeenSet)
132   {
133    Array<JsonValue> filtersJsonList(m_filters.size());
134    for(unsigned filtersIndex = 0; filtersIndex < filtersJsonList.GetLength(); ++filtersIndex)
135    {
136      filtersJsonList[filtersIndex].AsObject(m_filters[filtersIndex].Jsonize());
137    }
138    payload.WithArray("Filters", std::move(filtersJsonList));
139 
140   }
141 
142   if(m_aggregatorsHasBeenSet)
143   {
144    Array<JsonValue> aggregatorsJsonList(m_aggregators.size());
145    for(unsigned aggregatorsIndex = 0; aggregatorsIndex < aggregatorsJsonList.GetLength(); ++aggregatorsIndex)
146    {
147      aggregatorsJsonList[aggregatorsIndex].AsObject(m_aggregators[aggregatorsIndex].Jsonize());
148    }
149    payload.WithArray("Aggregators", std::move(aggregatorsJsonList));
150 
151   }
152 
153   return payload;
154 }
155 
156 } // namespace Model
157 } // namespace SSM
158 } // namespace Aws
159