Skip to content

Commit 2793699

Browse files
committed
Surface API Review - Review comments
1 parent 278e27f commit 2793699

File tree

5 files changed

+64
-27
lines changed

5 files changed

+64
-27
lines changed

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/document/EnhancedDocument.java

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,50 @@
3737
*
3838
* TODO : Add some examples in the Java Doc after API Surface review.
3939
*/
40+
41+
/**
42+
* The Document API interface for DynamoDB provides operations for working with unstructured data. This includes data with no
43+
* fixed schema, data that can't be modeled using rigid types, or data that has a flexible schema. This interface defines
44+
* methods for accessing a Document and provides constructor methods for instantiating a Document object. You can use the
45+
* Document object to read and write data to DynamoDB using the EnhancedDynamoDB client.
46+
* se the methods defined in this interface to perform operations such as adding, retrieving, updating, and deleting data. For
47+
* example, you can use the {@code putItem} method to add an item to a DynamoDB table, or the {@code getItem} method to
48+
* retrieve an item from a table.
49+
* To use the Document API, you must first create an instance of the EnhancedDynamoDB client. Then, you can use the methods
50+
* defined in this interface to interact with the data stored in DynamoDB.
51+
* {@code Example Usage:}
52+
* <pre>{@code
53+
* EnhancedDynamoDbClient enhancedClient = EnhancedDynamoDbClient.builder()
54+
*
55+
* markdown
56+
*
57+
* .dynamoDbClient(dynamoDbClient)
58+
*
59+
* markdown
60+
*
61+
* .build();
62+
*
63+
* // Create a new Document object
64+
* Document document = Document.create();
65+
* // Add an item to the Document
66+
* document.put("key", "value");
67+
* // Write the item to DynamoDB using the EnhancedDynamoDB client
68+
* enhancedClient.putItem(PutItemEnhancedRequest.builder("tableName").item(document).build());
69+
* // Retrieve the item from DynamoDB
70+
* GetItemEnhancedResponse<Document> response = enhancedClient.getItem(GetItemEnhancedRequest.builder("tableName")
71+
*
72+
* less
73+
*
74+
* .key(Collections.singletonMap("partitionKey", "partitionValue"))
75+
*
76+
* markdown
77+
*
78+
* .build());
79+
*
80+
* // Get the item from the response
81+
* Document retrievedItem = response.item();
82+
* }</pre>
83+
* */
4084
@SdkPublicApi
4185
public interface EnhancedDocument {
4286

@@ -234,7 +278,7 @@ static Builder builder() {
234278
* @return value of the specified attribute in the current document as a map of string-to-<code>T</code>'s; or null if the
235279
* attribute either doesn't exist or the attribute value is null.
236280
*/
237-
<T> Map<String, T> getMap(String attributeName, EnhancedType<T> type);
281+
<T> Map<String, T> getMapOfType(String attributeName, EnhancedType<T> type);
238282

239283
/**
240284
* Convenience method to return the specified attribute in the current item as a (copy of) map of
@@ -288,24 +332,15 @@ <T extends Number> Map<String, T> getMapOfNumbers(String attributeName,
288332
String getJson(String attributeName);
289333

290334
/**
291-
* Gets the JSON document value as pretty Json string for the specified attribute.
292-
*
293-
* @param attributeName Name of the attribute.
294-
* @return value of the specified attribute in the current document as a JSON string with pretty indentation; or null if the
295-
* attribute either doesn't exist or the attribute value is null.
296-
*/
297-
String getJsonPretty(String attributeName);
298-
299-
/**
300-
* Gets the {@link Boolean} value for the specified attribute.
335+
* Gets the boolean value for the specified attribute.
301336
*
302337
* @param attributeName Name of the attribute.
303338
* @return value of the specified attribute in the current document as a non-null Boolean.
304339
* @throws RuntimeException
305340
* if either the attribute doesn't exist or if the attribute
306341
* value cannot be converted into a boolean value.
307342
*/
308-
Boolean getBoolean(String attributeName);
343+
boolean getBoolean(String attributeName);
309344

310345
/**
311346
* Gets the value as Object for a given attribute in the current document.

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/document/DefaultEnhancedDocument.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public List<?> getList(String attributeName) {
206206
}
207207

208208
@Override
209-
public <T> Map<String, T> getMap(String attributeName, EnhancedType<T> type) {
209+
public <T> Map<String, T> getMapOfType(String attributeName, EnhancedType<T> type) {
210210
validateConverter(type);
211211
AttributeValue attributeValue = attributeValueMap.get(attributeName);
212212
if (attributeValue == null || !attributeValue.hasM()) {
@@ -275,13 +275,7 @@ public String getJson(String attributeName) {
275275
}
276276

277277
@Override
278-
public String getJsonPretty(String attributeName) {
279-
//TODO : Implementation in next revision or next PR.
280-
throw new UnsupportedOperationException("Currently unsupported");
281-
}
282-
283-
@Override
284-
public Boolean getBoolean(String attributeName) {
278+
public boolean getBoolean(String attributeName) {
285279
return getBool(attributeName);
286280
}
287281

services-custom/dynamodb-enhanced/src/test/java/software/amazon/awssdk/enhanced/dynamodb/document/DefaultEnhancedDocumentTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ void multipleGetterForDocument(){
402402
Map<String , BigDecimal> bigDecimalMap = new LinkedHashMap<>();
403403
bigDecimalMap.put("k1", BigDecimal.valueOf(3));
404404
bigDecimalMap.put("k2", BigDecimal.valueOf(9));
405-
assertThat(document.getMap("simpleMap", EnhancedType.of(BigDecimal.class))).isEqualTo(bigDecimalMap);
405+
assertThat(document.getMapOfType("simpleMap", EnhancedType.of(BigDecimal.class))).isEqualTo(bigDecimalMap);
406406
assertThat(document.getMapAsDocument("nestedDoc").getStringSet("innerKey")).isEqualTo(getStringSet(STRINGS_ARRAY));
407407
assertThat(document.getTypeOf("nullKey")).isNull();
408408
}

services-custom/dynamodb-enhanced/src/test/java/software/amazon/awssdk/enhanced/dynamodb/functionaltests/document/APISurfaceAreaReview.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ void createTableSchema() {
117117
.build());
118118

119119

120+
121+
122+
120123
/**
121124
* Creating SCHEMA with Primary and secondary keys
122125
*/
@@ -189,6 +192,7 @@ void enhancedDocDefaultSimpleAttributes() {
189192
Stream.of(SdkBytes.fromUtf8String("a")).collect(Collectors.toSet()))
190193
.build();
191194

195+
192196
/**
193197
*{
194198
* "HashKey":"abcdefg123",
@@ -285,6 +289,10 @@ void generic_access_to_enhancedDcoument_attributes() {
285289

286290
// Extracting Custom Object\
287291
CustomClassForDocumentAPI customAttr = customDoc.get("custom_attr", EnhancedType.of(CustomClassForDocumentAPI.class));
292+
293+
294+
customDoc.get("custom_attr");
295+
288296
System.out.println("customAttr " +customAttr);
289297
assertThat(customAttr).isEqualTo(customObject);
290298

@@ -341,13 +349,14 @@ void putSimpleDocumentWithSimpleValues() {
341349
}
342350

343351
/**
344-
*- Does EnhancedDocument.Builder needs add(key, Object, attributeConverterProvider)
352+
*- Does EnhancedDocument.Builder needs add(key, Object, attributeConverterProvider) ==> Not required , since at the time
353+
* of building the User can pass AttributeCOnverters using addAttributeConveters
345354
*
346355
* - Should we refer bytes as binary or byte in apis example addBinary(byte[] byte) or addByte(byte[] byte)
347356
*
348357
* - Map<String, Object> getRawMap(String attributeName); ==> Can we remove the use of Object ? <Zoe>
349358
*
350-
* - getJsonPretty. Do we actually need this?
359+
* - getJsonPretty. Do we actually need this? ==> removed
351360
*
352361
* - Object get(String attributeName); ==> Do we need this
353362
* - We don't have jsonPretty utility elsewhere. Do we need it?

services-custom/dynamodb-enhanced/src/test/java/software/amazon/awssdk/enhanced/dynamodb/mapper/DocumentTableSchemaTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ private static EnhancedDocument getAnonymousEnhancedDocument() {
187187
@Override
188188
public List<?> getList(String attributeName) {return null;}
189189
@Override
190-
public <T> Map<String, T> getMap(String attributeName, EnhancedType<T> type) {return null;}
190+
public <T> Map<String, T> getMapOfType(String attributeName, EnhancedType<T> type) {return null;}
191191
@Override
192192
public <T extends Number> Map<String, T> getMapOfNumbers(String attributeName, Class<T> valueType) {return null;}
193193
@Override
@@ -196,10 +196,9 @@ private static EnhancedDocument getAnonymousEnhancedDocument() {
196196
public EnhancedDocument getMapAsDocument(String attributeName) {return null;}
197197
@Override
198198
public String getJson(String attributeName) {return null;}
199+
199200
@Override
200-
public String getJsonPretty(String attributeName) {return null;}
201-
@Override
202-
public Boolean getBoolean(String attributeName) {return null;}
201+
public boolean getBoolean(String attributeName) {return false;}
203202
@Override
204203
public Object get(String attributeName) {return null;}
205204
@Override

0 commit comments

Comments
 (0)