Skip to content

Functional Test Cases for Document DDB API and Surface API Review 2 comments #3843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
* {@snippet :
* // CustomAttributeConverterProvider.create() is an example for some Custom converter provider
* EnhancedDocument enhancedDocumentWithCustomConverter = EnhancedDocument.builder().attributeConverterProviders
* (CustomAttributeConverterProvider.create(), AttributeConverterProvide.defaultProvider())
* .putWithType("customObject", customObject, EnhancedType.of(CustomClass.class))
* (CustomAttributeConverterProvider.create(), AttributeConverterProvide.defaultProvider()
* .put("customObject", customObject, EnhancedType.of(CustomClass.class))
* .build();
*}
* <p>Enhanced Document can be created with Json as input using Static factory method.In this case it used
Expand Down Expand Up @@ -143,7 +143,7 @@ static Builder builder() {
* <p>
* <b>Retrieving String Type for a document</b>
* {@snippet :
* Custom resultCustom = document.get("key", EnhancedType.of(Custom.class));
* String resultCustom = document.get("key", EnhancedType.of(String.class));
* }
* <b>Retrieving Custom Type for which Convertor Provider was defined while creating the document</b>
* {@snippet :
Expand All @@ -166,6 +166,31 @@ static Builder builder() {
*/
<T> T get(String attributeName, EnhancedType<T> type);

/**
* Returns the value of the specified attribute in the current document as a specified class type; or null if the
* attribute either doesn't exist or the attribute value is null.
* <p>
* <b>Retrieving String Type for a document</b>
* {@snippet :
* String resultCustom = document.get("key", String.class);
* }
* <b>Retrieving Custom Type for which Convertor Provider was defined while creating the document</b>
* {@snippet :
* Custom resultCustom = document.get("key", Custom.class);
* }
* <p>
* Note :
* This API should not be used to retrieve values of List and Map types.
* Instead, getList and getMap APIs should be used to retrieve attributes of type List and Map, respectively.
* </p>
* @param attributeName Name of the attribute.
* @param clazz Class type of value.
* @param <T> The type of the attribute value.
* @return Attribute value of type T
* }
*/
<T> T get(String attributeName, Class<T> clazz);

/**
* Gets the String value of specified attribute in the document.
*
Expand Down Expand Up @@ -212,8 +237,8 @@ static Builder builder() {
/**
* Gets the Set of String values of the given attribute in the current document.
* @param attributeName Name of the attribute.
* @return value of the specified attribute in the current document as a set of SdkBytes; or null if the attribute either
* doesn't exist or the attribute value is null.
* @return value of the specified attribute in the current document as a set of SdkBytes;
* or null if the attribute doesn't exist.
*/
Set<SdkBytes> getBytesSet(String attributeName);

Expand All @@ -223,8 +248,8 @@ static Builder builder() {
* @param attributeName Name of the attribute.
* @param type {@link EnhancedType} of Type T.
* @param <T> Type T of List elements
* @return value of the specified attribute in the current document as a list of type T; or null if the
* attribute either doesn't exist or the attribute value is null.
* @return value of the specified attribute in the current document as a list of type T,
* or null if the attribute does not exist.
*/

<T> List<T> getList(String attributeName, EnhancedType<T> type);
Expand Down Expand Up @@ -259,10 +284,13 @@ static Builder builder() {
* Gets the {@link Boolean} value for the specified attribute.
*
* @param attributeName Name of the attribute.
* @return value of the specified attribute in the current document as a non-null Boolean.
* @return value of the specified attribute in the current document as a Boolean representation; or null if the attribute
* either doesn't exist or the attribute value is null.
* @throws RuntimeException
* if either the attribute doesn't exist or if the attribute
* value cannot be converted into a boolean value.
* if the attribute value cannot be converted to a Boolean representation.
* Note that the Boolean representation of 0 and 1 in Numbers and "0" and "1" in Strings is false and true,
* respectively.
*
*/
Boolean getBoolean(String attributeName);

Expand All @@ -276,7 +304,7 @@ static Builder builder() {
* @param attributeName Name of the attribute.
* @return value of the specified attribute in the current document as a List of {@link AttributeValue}
*/
List<AttributeValue> getUnknownTypeList(String attributeName);
List<AttributeValue> getListOfUnknownType(String attributeName);

/**
* Retrieves a Map with String keys and corresponding AttributeValue objects as values for a specified attribute in a
Expand All @@ -287,7 +315,7 @@ static Builder builder() {
* @param attributeName Name of the attribute.
* @return value of the specified attribute in the current document as a {@link AttributeValue}
*/
Map<String, AttributeValue> getUnknownTypeMap(String attributeName);
Map<String, AttributeValue> getMapOfUnknownType(String attributeName);

/**
*
Expand Down Expand Up @@ -350,7 +378,7 @@ interface Builder {
* @param value The boolean value that needs to be set.
* @return Builder instance to construct a {@link EnhancedDocument}
*/
Builder putBoolean(String attributeName, Boolean value);
Builder putBoolean(String attributeName, boolean value);

/**
* Appends an attribute of name attributeName with a null value.
Expand Down Expand Up @@ -414,11 +442,33 @@ interface Builder {
* provider.
* Example:
{@snippet :
EnhancedDocument.builder().putWithType("customKey", customValue, EnhancedType.of(CustomClass.class));
* }
* EnhancedDocument.builder().put("customKey", customValue, EnhancedType.of(CustomClass.class));
*}
* Use {@link #putString(String, String)} or {@link #putNumber(String, Number)} for inserting simple value types of
* attributes.
* Use {@link #putList(String, List, EnhancedType)} or {@link #putMapOfType(String, Map, EnhancedType, EnhancedType)} for
* Use {@link #putList(String, List, EnhancedType)} or {@link #putMap(String, Map, EnhancedType, EnhancedType)} for
* inserting collections of attribute values.
* Note that the attribute converter provider added to the DocumentBuilder must provide the converter for the class T
* that is to be inserted.
@param attributeName the name of the attribute to be added to the document.
@param value the value to set.
@param type the Enhanced type of the value to set.
@return a builder instance to construct a {@link EnhancedDocument}.
@param <T> the type of the value to set.
*/
<T> Builder put(String attributeName, T value, EnhancedType<T> type);

/**
* Appends an attribute named {@code attributeName} with a value of Class type T.
* Use this method to insert attribute values of custom types that have attribute converters defined in a converter
* provider.
* Example:
{@snippet :
* EnhancedDocument.builder().put("customKey", customValue, CustomClass.class);
*}
* Use {@link #putString(String, String)} or {@link #putNumber(String, Number)} for inserting simple value types of
* attributes.
* Use {@link #putList(String, List, EnhancedType)} or {@link #putMap(String, Map, EnhancedType, EnhancedType)} for
* inserting collections of attribute values.
* Note that the attribute converter provider added to the DocumentBuilder must provide the converter for the class T
* that is to be inserted.
Expand All @@ -428,7 +478,7 @@ interface Builder {
@return a builder instance to construct a {@link EnhancedDocument}.
@param <T> the type of the value to set.
*/
<T> Builder putWithType(String attributeName, T value, EnhancedType<T> type);
<T> Builder put(String attributeName, T value, Class<T> type);

/**
* Appends an attribute with the specified name and a Map containing keys and values of {@link EnhancedType} K
Expand All @@ -437,14 +487,14 @@ interface Builder {
* values.
* <p>For example, to insert a map with String keys and Long values:
* {@snippet :
* EnhancedDocument.builder().putMapOfType("stringMap", mapWithStringKeyNumberValue, EnhancedType.of(String.class),
* EnhancedDocument.builder().putMap("stringMap", mapWithStringKeyNumberValue, EnhancedType.of(String.class),
* EnhancedType.of(String.class), EnhancedType.of(Long.class))
* }
*}
* <p>For example, to insert a map of String Key and Custom Values:
* {@snippet :
* EnhancedDocument.builder().putMapOfType("customMap", mapWithStringKeyCustomValue, EnhancedType.of(String.class),
* EnhancedDocument.builder().putMap("customMap", mapWithStringKeyCustomValue, EnhancedType.of(String.class),
* EnhancedType.of(String.class), EnhancedType.of(Custom.class))
* }
*}
* Note that the AttributeConverterProvider added to the DocumentBuilder should provide the converter for the classes
* K and V that
* are to be inserted.
Expand All @@ -454,7 +504,7 @@ interface Builder {
* @param valueType Enhanced type of Value class.
* @return Builder instance to construct a {@link EnhancedDocument}
*/
<K, V> Builder putMapOfType(String attributeName, Map<K, V> value, EnhancedType<K> keyType, EnhancedType<V> valueType);
<K, V> Builder putMap(String attributeName, Map<K, V> value, EnhancedType<K> keyType, EnhancedType<V> valueType);

/**
Appends an attribute to the document builder with the specified name and value of a JSON document in string format.
Expand All @@ -464,6 +514,15 @@ interface Builder {
*/
Builder putJson(String attributeName, String json);


/**
* Removes a previously appended attribute.
* This can be used where a previously added attribute to the Builder is no longer needed.
* @param attributeName The attribute that needs to be removed.
* @return Builder instance to construct a {@link EnhancedDocument}
*/
Builder remove(String attributeName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the use case for this? Do we support this in v1?

Copy link
Contributor Author

@joviegas joviegas Mar 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its there in V1 as removeAttribute,

By Providing remove we can do following oldDocument.toBuilder().remove("attr1").build() this will remove attr1 from the


/**
* Appends collection of attributeConverterProvider to the document builder. These
* AttributeConverterProvider will be used to convert any given key to custom type T.
Expand Down
Loading