1 /**
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  * SPDX-License-Identifier: Apache-2.0.
4  */
5 
6 #include <aws/workdocs/model/Principal.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 WorkDocs
17 {
18 namespace Model
19 {
20 
Principal()21 Principal::Principal() :
22     m_idHasBeenSet(false),
23     m_type(PrincipalType::NOT_SET),
24     m_typeHasBeenSet(false),
25     m_rolesHasBeenSet(false)
26 {
27 }
28 
Principal(JsonView jsonValue)29 Principal::Principal(JsonView jsonValue) :
30     m_idHasBeenSet(false),
31     m_type(PrincipalType::NOT_SET),
32     m_typeHasBeenSet(false),
33     m_rolesHasBeenSet(false)
34 {
35   *this = jsonValue;
36 }
37 
operator =(JsonView jsonValue)38 Principal& Principal::operator =(JsonView jsonValue)
39 {
40   if(jsonValue.ValueExists("Id"))
41   {
42     m_id = jsonValue.GetString("Id");
43 
44     m_idHasBeenSet = true;
45   }
46 
47   if(jsonValue.ValueExists("Type"))
48   {
49     m_type = PrincipalTypeMapper::GetPrincipalTypeForName(jsonValue.GetString("Type"));
50 
51     m_typeHasBeenSet = true;
52   }
53 
54   if(jsonValue.ValueExists("Roles"))
55   {
56     Array<JsonView> rolesJsonList = jsonValue.GetArray("Roles");
57     for(unsigned rolesIndex = 0; rolesIndex < rolesJsonList.GetLength(); ++rolesIndex)
58     {
59       m_roles.push_back(rolesJsonList[rolesIndex].AsObject());
60     }
61     m_rolesHasBeenSet = true;
62   }
63 
64   return *this;
65 }
66 
Jsonize() const67 JsonValue Principal::Jsonize() const
68 {
69   JsonValue payload;
70 
71   if(m_idHasBeenSet)
72   {
73    payload.WithString("Id", m_id);
74 
75   }
76 
77   if(m_typeHasBeenSet)
78   {
79    payload.WithString("Type", PrincipalTypeMapper::GetNameForPrincipalType(m_type));
80   }
81 
82   if(m_rolesHasBeenSet)
83   {
84    Array<JsonValue> rolesJsonList(m_roles.size());
85    for(unsigned rolesIndex = 0; rolesIndex < rolesJsonList.GetLength(); ++rolesIndex)
86    {
87      rolesJsonList[rolesIndex].AsObject(m_roles[rolesIndex].Jsonize());
88    }
89    payload.WithArray("Roles", std::move(rolesJsonList));
90 
91   }
92 
93   return payload;
94 }
95 
96 } // namespace Model
97 } // namespace WorkDocs
98 } // namespace Aws
99