1 /**
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0.
4 */
5
6 #include <aws/kendra/model/Document.h>
7 #include <aws/core/utils/json/JsonSerializer.h>
8 #include <aws/core/utils/HashingUtils.h>
9
10 #include <utility>
11
12 using namespace Aws::Utils::Json;
13 using namespace Aws::Utils;
14
15 namespace Aws
16 {
17 namespace kendra
18 {
19 namespace Model
20 {
21
Document()22 Document::Document() :
23 m_idHasBeenSet(false),
24 m_titleHasBeenSet(false),
25 m_blobHasBeenSet(false),
26 m_s3PathHasBeenSet(false),
27 m_attributesHasBeenSet(false),
28 m_accessControlListHasBeenSet(false),
29 m_hierarchicalAccessControlListHasBeenSet(false),
30 m_contentType(ContentType::NOT_SET),
31 m_contentTypeHasBeenSet(false)
32 {
33 }
34
Document(JsonView jsonValue)35 Document::Document(JsonView jsonValue) :
36 m_idHasBeenSet(false),
37 m_titleHasBeenSet(false),
38 m_blobHasBeenSet(false),
39 m_s3PathHasBeenSet(false),
40 m_attributesHasBeenSet(false),
41 m_accessControlListHasBeenSet(false),
42 m_hierarchicalAccessControlListHasBeenSet(false),
43 m_contentType(ContentType::NOT_SET),
44 m_contentTypeHasBeenSet(false)
45 {
46 *this = jsonValue;
47 }
48
operator =(JsonView jsonValue)49 Document& Document::operator =(JsonView jsonValue)
50 {
51 if(jsonValue.ValueExists("Id"))
52 {
53 m_id = jsonValue.GetString("Id");
54
55 m_idHasBeenSet = true;
56 }
57
58 if(jsonValue.ValueExists("Title"))
59 {
60 m_title = jsonValue.GetString("Title");
61
62 m_titleHasBeenSet = true;
63 }
64
65 if(jsonValue.ValueExists("Blob"))
66 {
67 m_blob = HashingUtils::Base64Decode(jsonValue.GetString("Blob"));
68 m_blobHasBeenSet = true;
69 }
70
71 if(jsonValue.ValueExists("S3Path"))
72 {
73 m_s3Path = jsonValue.GetObject("S3Path");
74
75 m_s3PathHasBeenSet = true;
76 }
77
78 if(jsonValue.ValueExists("Attributes"))
79 {
80 Array<JsonView> attributesJsonList = jsonValue.GetArray("Attributes");
81 for(unsigned attributesIndex = 0; attributesIndex < attributesJsonList.GetLength(); ++attributesIndex)
82 {
83 m_attributes.push_back(attributesJsonList[attributesIndex].AsObject());
84 }
85 m_attributesHasBeenSet = true;
86 }
87
88 if(jsonValue.ValueExists("AccessControlList"))
89 {
90 Array<JsonView> accessControlListJsonList = jsonValue.GetArray("AccessControlList");
91 for(unsigned accessControlListIndex = 0; accessControlListIndex < accessControlListJsonList.GetLength(); ++accessControlListIndex)
92 {
93 m_accessControlList.push_back(accessControlListJsonList[accessControlListIndex].AsObject());
94 }
95 m_accessControlListHasBeenSet = true;
96 }
97
98 if(jsonValue.ValueExists("HierarchicalAccessControlList"))
99 {
100 Array<JsonView> hierarchicalAccessControlListJsonList = jsonValue.GetArray("HierarchicalAccessControlList");
101 for(unsigned hierarchicalAccessControlListIndex = 0; hierarchicalAccessControlListIndex < hierarchicalAccessControlListJsonList.GetLength(); ++hierarchicalAccessControlListIndex)
102 {
103 m_hierarchicalAccessControlList.push_back(hierarchicalAccessControlListJsonList[hierarchicalAccessControlListIndex].AsObject());
104 }
105 m_hierarchicalAccessControlListHasBeenSet = true;
106 }
107
108 if(jsonValue.ValueExists("ContentType"))
109 {
110 m_contentType = ContentTypeMapper::GetContentTypeForName(jsonValue.GetString("ContentType"));
111
112 m_contentTypeHasBeenSet = true;
113 }
114
115 return *this;
116 }
117
Jsonize() const118 JsonValue Document::Jsonize() const
119 {
120 JsonValue payload;
121
122 if(m_idHasBeenSet)
123 {
124 payload.WithString("Id", m_id);
125
126 }
127
128 if(m_titleHasBeenSet)
129 {
130 payload.WithString("Title", m_title);
131
132 }
133
134 if(m_blobHasBeenSet)
135 {
136 payload.WithString("Blob", HashingUtils::Base64Encode(m_blob));
137 }
138
139 if(m_s3PathHasBeenSet)
140 {
141 payload.WithObject("S3Path", m_s3Path.Jsonize());
142
143 }
144
145 if(m_attributesHasBeenSet)
146 {
147 Array<JsonValue> attributesJsonList(m_attributes.size());
148 for(unsigned attributesIndex = 0; attributesIndex < attributesJsonList.GetLength(); ++attributesIndex)
149 {
150 attributesJsonList[attributesIndex].AsObject(m_attributes[attributesIndex].Jsonize());
151 }
152 payload.WithArray("Attributes", std::move(attributesJsonList));
153
154 }
155
156 if(m_accessControlListHasBeenSet)
157 {
158 Array<JsonValue> accessControlListJsonList(m_accessControlList.size());
159 for(unsigned accessControlListIndex = 0; accessControlListIndex < accessControlListJsonList.GetLength(); ++accessControlListIndex)
160 {
161 accessControlListJsonList[accessControlListIndex].AsObject(m_accessControlList[accessControlListIndex].Jsonize());
162 }
163 payload.WithArray("AccessControlList", std::move(accessControlListJsonList));
164
165 }
166
167 if(m_hierarchicalAccessControlListHasBeenSet)
168 {
169 Array<JsonValue> hierarchicalAccessControlListJsonList(m_hierarchicalAccessControlList.size());
170 for(unsigned hierarchicalAccessControlListIndex = 0; hierarchicalAccessControlListIndex < hierarchicalAccessControlListJsonList.GetLength(); ++hierarchicalAccessControlListIndex)
171 {
172 hierarchicalAccessControlListJsonList[hierarchicalAccessControlListIndex].AsObject(m_hierarchicalAccessControlList[hierarchicalAccessControlListIndex].Jsonize());
173 }
174 payload.WithArray("HierarchicalAccessControlList", std::move(hierarchicalAccessControlListJsonList));
175
176 }
177
178 if(m_contentTypeHasBeenSet)
179 {
180 payload.WithString("ContentType", ContentTypeMapper::GetNameForContentType(m_contentType));
181 }
182
183 return payload;
184 }
185
186 } // namespace Model
187 } // namespace kendra
188 } // namespace Aws
189