diff --git a/aws-lambda-java-events/pom.xml b/aws-lambda-java-events/pom.xml
index 3640bf06..7089866d 100644
--- a/aws-lambda-java-events/pom.xml
+++ b/aws-lambda-java-events/pom.xml
@@ -62,6 +62,11 @@
+ * An item-centric description of an unique event within a stream.
+ *
+ * The main body of the stream item, containing all of the
+ * DynamoDB-specific fields.
+ *
+ * A globally unique identifier for the event that was recorded in this
+ * stream record.
+ *
+ * A globally unique identifier for the event that was recorded in this
+ * stream record.
+ *
+ * A globally unique identifier for the event that was recorded in this
+ * stream record.
+ *
+ * The type of data modification that was performed on the DynamoDB table:
+ *
+ *
+ *
+ *
+ *
+ *
+ * @param eventName
+ * The type of data modification that was performed on the DynamoDB
+ * table:INSERT
- a new item was added to the table.
+ * MODIFY
- one or more of the item's attributes were updated.
+ * REMOVE
- the item was deleted from the table
+ *
+ * INSERT
- a new item was added to the table.
+ *
+ * MODIFY
- one or more of the item's attributes were
+ * updated.
+ *
+ * REMOVE
- the item was deleted from the table
+ *
+ * The type of data modification that was performed on the DynamoDB table: + *
+ *
+ * INSERT
- a new item was added to the table.
+ *
+ * MODIFY
- one or more of the item's attributes were updated.
+ *
+ * REMOVE
- the item was deleted from the table
+ *
+ * INSERT
- a new item was added to the table.
+ *
+ * MODIFY
- one or more of the item's attributes were
+ * updated.
+ *
+ * REMOVE
- the item was deleted from the table
+ *
+ * The type of data modification that was performed on the DynamoDB table: + *
+ *
+ * INSERT
- a new item was added to the table.
+ *
+ * MODIFY
- one or more of the item's attributes were updated.
+ *
+ * REMOVE
- the item was deleted from the table
+ *
+ * INSERT
- a new item was added to the table.
+ *
+ * MODIFY
- one or more of the item's attributes were
+ * updated.
+ *
+ * REMOVE
- the item was deleted from the table
+ *
+ * The type of data modification that was performed on the DynamoDB table: + *
+ *
+ * INSERT
- a new item was added to the table.
+ *
+ * MODIFY
- one or more of the item's attributes were updated.
+ *
+ * REMOVE
- the item was deleted from the table
+ *
+ * INSERT
- a new item was added to the table.
+ *
+ * MODIFY
- one or more of the item's attributes were
+ * updated.
+ *
+ * REMOVE
- the item was deleted from the table
+ *
+ * The type of data modification that was performed on the DynamoDB table: + *
+ *
+ * INSERT
- a new item was added to the table.
+ *
+ * MODIFY
- one or more of the item's attributes were updated.
+ *
+ * REMOVE
- the item was deleted from the table
+ *
+ * INSERT
- a new item was added to the table.
+ *
+ * MODIFY
- one or more of the item's attributes were
+ * updated.
+ *
+ * REMOVE
- the item was deleted from the table
+ *
+ * The version number of the stream record format. Currently, this is + * 1.0. + *
+ * + * @param eventVersion + * The version number of the stream record format. Currently, this is + * 1.0. + */ + public void setEventVersion(String eventVersion) { + record.setEventVersion(eventVersion); + } + + /** + *+ * The version number of the stream record format. Currently, this is + * 1.0. + *
+ * + * @return The version number of the stream record format. Currently, this + * is 1.0. + */ + public String getEventVersion() { + return record.getEventVersion(); + } + + /** + *+ * The version number of the stream record format. Currently, this is + * 1.0. + *
+ * + * @param eventVersion + * The version number of the stream record format. Currently, this is + * 1.0. + * @return Returns a reference to this object so that method calls can be + * chained together. + */ + public ItemRecord withEventVersion(String eventVersion) { + setEventVersion(eventVersion); + return this; + } + + /** + *+ * The AWS service from which the stream record originated. For DynamoDB + * Streams, this is aws:dynamodb. + *
+ * + * @param eventSource + * The AWS service from which the stream record originated. For + * DynamoDB Streams, this is aws:dynamodb. + */ + public void setEventSource(String eventSource) { + record.setEventSource(eventSource); + } + + /** + *+ * The AWS service from which the stream record originated. For DynamoDB + * Streams, this is aws:dynamodb. + *
+ * + * @return The AWS service from which the stream record originated. For + * DynamoDB Streams, this is aws:dynamodb. + */ + public String getEventSource() { + return record.getEventSource(); + } + + /** + *+ * The AWS service from which the stream record originated. For DynamoDB + * Streams, this is aws:dynamodb. + *
+ * + * @param eventSource + * The AWS service from which the stream record originated. For + * DynamoDB Streams, this is aws:dynamodb. + * @return Returns a reference to this object so that method calls can be + * chained together. + */ + public ItemRecord withEventSource(String eventSource) { + setEventSource(eventSource); + return this; + } + + /** + *+ * The region in which the GetRecords request was received. + *
+ * + * @param awsRegion + * The region in which the GetRecords request was received. + */ + public void setAwsRegion(String awsRegion) { + record.setAwsRegion(awsRegion); + } + + /** + *+ * The region in which the GetRecords request was received. + *
+ * + * @return The region in which the GetRecords request was received. + */ + public String getAwsRegion() { + return record.getAwsRegion(); + } + + /** + *+ * The region in which the GetRecords request was received. + *
+ * + * @param awsRegion + * The region in which the GetRecords request was received. + * @return Returns a reference to this object so that method calls can be + * chained together. + */ + public ItemRecord withAwsRegion(String awsRegion) { + setAwsRegion(awsRegion); + return this; + } + + /** + *+ * The main body of the stream item, containing all of the + * DynamoDB-specific fields. + *
+ * + * @param streamItem + * The main body of the stream item, containing all of the + * DynamoDB-specific fields. + */ + public void setStreamItem(StreamItem streamItem) { + this.streamItem = streamItem; + this.record.setDynamodb(null); + } + + /** + *+ * The main body of the stream item, containing all of the + * DynamoDB-specific fields. + *
+ * + * @return The main body of the stream item, containing all of the + * DynamoDB-specific fields. + */ + public StreamItem getStreamItem() { + if (streamItem == null) + streamItem = new StreamItem(record.getDynamodb()); + return streamItem; + } + + /** + *+ * The main body of the stream item, containing all of the + * DynamoDB-specific fields. + *
+ * + * @param dynamodb + * The main body of the stream item, containing all of the + * DynamoDB-specific fields. + * @return Returns a reference to this object so that method calls can be + * chained together. + */ + public ItemRecord withStreamItem(StreamItem streamItem) { + setStreamItem(streamItem); + return this; + } + + /** + * Returns a string representation of this object; useful for testing and + * debugging. + * + * @return A string representation of this object. + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("{"); + if (getEventID() != null) + sb.append("EventID: " + getEventID() + ","); + if (getEventName() != null) + sb.append("EventName: " + getEventName() + ","); + if (getEventVersion() != null) + sb.append("EventVersion: " + getEventVersion() + ","); + if (getEventSource() != null) + sb.append("EventSource: " + getEventSource() + ","); + if (getAwsRegion() != null) + sb.append("AwsRegion: " + getAwsRegion() + ","); + if (getStreamItem() != null) + sb.append("StreamItem: " + getStreamItem()); + sb.append("}"); + return sb.toString(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + + if (obj instanceof ItemRecord == false) + return false; + ItemRecord other = (ItemRecord) obj; + if (other.getEventID() == null ^ this.getEventID() == null) + return false; + if (other.getEventID() != null + && other.getEventID().equals(this.getEventID()) == false) + return false; + if (other.getEventName() == null ^ this.getEventName() == null) + return false; + if (other.getEventName() != null + && other.getEventName().equals(this.getEventName()) == false) + return false; + if (other.getEventVersion() == null ^ this.getEventVersion() == null) + return false; + if (other.getEventVersion() != null + && other.getEventVersion().equals(this.getEventVersion()) == false) + return false; + if (other.getEventSource() == null ^ this.getEventSource() == null) + return false; + if (other.getEventSource() != null + && other.getEventSource().equals(this.getEventSource()) == false) + return false; + if (other.getAwsRegion() == null ^ this.getAwsRegion() == null) + return false; + if (other.getAwsRegion() != null + && other.getAwsRegion().equals(this.getAwsRegion()) == false) + return false; + if (other.getStreamItem() == null ^ this.getStreamItem() == null) + return false; + if (other.getStreamItem() != null + && other.getStreamItem().equals(this.getStreamItem()) == false) + return false; + return true; + } + + @Override + public int hashCode() { + final int prime = 31; + int hashCode = 1; + + hashCode = prime * hashCode + + ((getEventID() == null) ? 0 : getEventID().hashCode()); + hashCode = prime * hashCode + + ((getEventName() == null) ? 0 : getEventName().hashCode()); + hashCode = prime + * hashCode + + ((getEventVersion() == null) ? 0 : getEventVersion() + .hashCode()); + hashCode = prime + * hashCode + + ((getEventSource() == null) ? 0 : getEventSource().hashCode()); + hashCode = prime * hashCode + + ((getAwsRegion() == null) ? 0 : getAwsRegion().hashCode()); + hashCode = prime * hashCode + + ((getStreamItem() == null) ? 0 : getStreamItem().hashCode()); + return hashCode; + } + + @Override + public ItemRecord clone() { + try { + return (ItemRecord) super.clone(); + } catch (CloneNotSupportedException e) { + throw new IllegalStateException( + "Got a CloneNotSupportedException from Object.clone() " + + "even though we're Cloneable!", e); + } + } +} \ No newline at end of file diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/document/StreamItem.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/document/StreamItem.java new file mode 100644 index 00000000..97900cc3 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/document/StreamItem.java @@ -0,0 +1,775 @@ +/* + * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package com.amazonaws.services.lambda.runtime.events.document; + +import static com.amazonaws.services.dynamodbv2.document.internal.InternalUtils.toSimpleMapValue; + +import java.io.Serializable; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import com.amazonaws.services.dynamodbv2.document.Item; +import com.amazonaws.services.dynamodbv2.document.KeyAttribute; +import com.amazonaws.services.dynamodbv2.document.PrimaryKey; +import com.amazonaws.services.dynamodbv2.model.StreamRecord; +import com.amazonaws.services.dynamodbv2.model.StreamViewType; + +/** + *+ * An item-centric description of a single data modification that was performed + * on an item in a DynamoDB table using the DynamoDB Document API. + *
+ */ +public class StreamItem implements Serializable, Cloneable { + private static final long serialVersionUID = 1L; + + /** + * The underlying low-level stream record on which this stream item is + * built. + */ + private final StreamRecord record; + + /** + * Internal cache to provide the behavior of access by reference instead of + * by value. + */ + private PrimaryKey primaryKey; + private Item newImage; + private Item oldImage; + + public StreamItem(StreamRecord record) { + this.record = record == null ? new StreamRecord() : record; + } + + public StreamItem() { + this(new StreamRecord()); // a placeholder + } + + /** + *+ * The primary key(s) for the DynamoDB item that was modified. + *
+ * + * @return The primary key(s) for the DynamoDB item that was modified. + */ + public PrimaryKey getPrimaryKey() { + if (primaryKey == null) { + Map+ * The primary key(s) for the DynamoDB item that was modified. + *
+ * + * @param primaryKey + * The primary key(s) for the DynamoDB item that was + * modified. + */ + public void setPrimaryKey(PrimaryKey primaryKey) { + this.primaryKey = primaryKey; + record.clearKeysEntries(); + } + + /** + *+ * The primary key(s) for the DynamoDB item that was modified. + *
+ * + * @param primaryKey + * The primary key(s) for the DynamoDB item that was modified. + * @return Returns a reference to this object so that method calls can be + * chained together. + */ + public StreamItem withPrimaryKey(PrimaryKey primaryKey) { + setPrimaryKey(primaryKey); + return this; + } + + public StreamItem addKeysEntry(String attrName, Object value) { + PrimaryKey pk = this.getPrimaryKey(); + if (pk.hasComponent(attrName)) + throw new IllegalArgumentException("Duplicated keys (" + attrName + + ") are provided."); + pk.addComponent(attrName, value); + return this; + } + + /** + * Removes all the entries added into Keys. <p> Returns a reference to + * this object so that method calls can be chained together. + */ + public StreamItem clearKeysEntries() { + this.primaryKey = null; + record.clearKeysEntries(); + return this; + } + + /** + *+ * The item in the DynamoDB table as it appeared after it was modified. + *
+ * + * @return The item in the DynamoDB table as it appeared after it was + * modified. + */ + public Item getNewImage() { + if (newImage == null) { + newImage = Item.fromMap(toSimpleMapValue(record.getNewImage())); + record.clearNewImageEntries(); + } + return newImage; + } + + /** + *+ * The item in the DynamoDB table as it appeared after it was modified. + *
+ * + * @param newImage + * The item in the DynamoDB table as it appeared after it was + * modified. + */ + public void setNewImage(Item newImage) { + this.newImage = newImage; + record.clearNewImageEntries(); + } + + /** + *+ * The item in the DynamoDB table as it appeared after it was modified. + *
+ * + * @param newImage + * The item in the DynamoDB table as it appeared after it was + * modified. + * @return Returns a reference to this object so that method calls can be + * chained together. + */ + public StreamItem withNewImage(Item newImage) { + setNewImage(newImage); + return this; + } + + public StreamItem addNewImageEntry(String key, Object value) { + Item newImage = this.getNewImage(); + if (newImage.hasAttribute(key)) + throw new IllegalArgumentException("Duplicated keys (" + key + + ") are provided."); + newImage.with(key, value); + return this; + } + + /** + * Removes all the entries added into NewImage. <p> Returns a reference + * to this object so that method calls can be chained together. + */ + public StreamItem clearNewImageEntries() { + this.newImage = null; + record.clearNewImageEntries(); + return this; + } + + /** + *+ * The item in the DynamoDB table as it appeared before it was modified. + *
+ * + * @return The item in the DynamoDB table as it appeared before it was + * modified. + */ + public Item getOldImage() { + if (oldImage == null) { + oldImage = Item.fromMap(toSimpleMapValue(record.getOldImage())); + record.clearOldImageEntries(); + } + return oldImage; + } + + /** + *+ * The item in the DynamoDB table as it appeared before it was modified. + *
+ * + * @param oldImage + * The item in the DynamoDB table as it appeared before it was + * modified. + */ + public void setOldImage(Item oldImage) { + this.oldImage = oldImage; + record.clearOldImageEntries(); + } + + /** + *+ * The item in the DynamoDB table as it appeared before it was modified. + *
+ * + * @param oldImage + * The item in the DynamoDB table as it appeared before it was + * modified. + * @return Returns a reference to this object so that method calls can be + * chained together. + */ + public StreamItem withOldImage(Item oldImage) { + setOldImage(oldImage); + return this; + } + + public StreamItem addOldImageEntry(String key, Object value) { + Item oldImage = this.getOldImage(); + if (oldImage.hasAttribute(key)) + throw new IllegalArgumentException("Duplicated keys (" + key + + ") are provided."); + oldImage.with(key, value); + return this; + } + + /** + * Removes all the entries added into OldImage. <p> Returns a reference + * to this object so that method calls can be chained together. + */ + public StreamItem clearOldImageEntries() { + this.oldImage = null; + return this; + } + + /** + *+ * The sequence number of the stream record. + *
+ * + * @param sequenceNumber + * The sequence number of the stream record. + */ + public void setSequenceNumber(String sequenceNumber) { + record.setSequenceNumber(sequenceNumber); + } + + /** + *+ * The sequence number of the stream record. + *
+ * + * @return The sequence number of the stream record. + */ + public String getSequenceNumber() { + return record.getSequenceNumber(); + } + + /** + *+ * The sequence number of the stream record. + *
+ * + * @param sequenceNumber + * The sequence number of the stream record. + * @return Returns a reference to this object so that method calls can be + * chained together. + */ + public StreamItem withSequenceNumber(String sequenceNumber) { + setSequenceNumber(sequenceNumber); + return this; + } + + /** + *+ * The size of the stream record, in bytes. + *
+ * + * @param sizeBytes + * The size of the stream record, in bytes. + */ + public void setSizeBytes(Long sizeBytes) { + record.setSizeBytes(sizeBytes); + } + + /** + *+ * The size of the stream record, in bytes. + *
+ * + * @return The size of the stream record, in bytes. + */ + public Long getSizeBytes() { + return record.getSizeBytes(); + } + + /** + *+ * The size of the stream record, in bytes. + *
+ * + * @param sizeBytes + * The size of the stream record, in bytes. + * @return Returns a reference to this object so that method calls can be + * chained together. + */ + public StreamItem withSizeBytes(Long sizeBytes) { + setSizeBytes(sizeBytes); + return this; + } + + /** + *+ * The type of data from the modified DynamoDB item that was captured in + * this stream record: + *
+ *
+ * KEYS_ONLY
- only the key attributes of the modified item.
+ *
+ * NEW_IMAGE
- the entire item, as it appears after it was
+ * modified.
+ *
+ * OLD_IMAGE
- the entire item, as it appeared before it was
+ * modified.
+ *
+ * NEW_AND_OLD_IMAGES
— both the new and the old item images of
+ * the item.
+ *
+ * KEYS_ONLY
- only the key attributes of the
+ * modified item.
+ *
+ * NEW_IMAGE
- the entire item, as it appears after
+ * it was modified.
+ *
+ * OLD_IMAGE
- the entire item, as it appeared
+ * before it was modified.
+ *
+ * NEW_AND_OLD_IMAGES
— both the new and the old
+ * item images of the item.
+ *
+ * The type of data from the modified DynamoDB item that was captured in + * this stream record: + *
+ *
+ * KEYS_ONLY
- only the key attributes of the modified item.
+ *
+ * NEW_IMAGE
- the entire item, as it appears after it was
+ * modified.
+ *
+ * OLD_IMAGE
- the entire item, as it appeared before it was
+ * modified.
+ *
+ * NEW_AND_OLD_IMAGES
— both the new and the old item images of
+ * the item.
+ *
+ * KEYS_ONLY
- only the key attributes of the modified
+ * item.
+ *
+ * NEW_IMAGE
- the entire item, as it appears after it
+ * was modified.
+ *
+ * OLD_IMAGE
- the entire item, as it appeared before
+ * it was modified.
+ *
+ * NEW_AND_OLD_IMAGES
— both the new and the old item
+ * images of the item.
+ *
+ * The type of data from the modified DynamoDB item that was captured in + * this stream record: + *
+ *
+ * KEYS_ONLY
- only the key attributes of the modified item.
+ *
+ * NEW_IMAGE
- the entire item, as it appears after it was
+ * modified.
+ *
+ * OLD_IMAGE
- the entire item, as it appeared before it was
+ * modified.
+ *
+ * NEW_AND_OLD_IMAGES
— both the new and the old item images of
+ * the item.
+ *
+ * KEYS_ONLY
- only the key attributes of the
+ * modified item.
+ *
+ * NEW_IMAGE
- the entire item, as it appears after
+ * it was modified.
+ *
+ * OLD_IMAGE
- the entire item, as it appeared
+ * before it was modified.
+ *
+ * NEW_AND_OLD_IMAGES
— both the new and the old
+ * item images of the item.
+ *
+ * The type of data from the modified DynamoDB item that was captured in + * this stream record: + *
+ *
+ * KEYS_ONLY
- only the key attributes of the modified item.
+ *
+ * NEW_IMAGE
- the entire item, as it appears after it was
+ * modified.
+ *
+ * OLD_IMAGE
- the entire item, as it appeared before it was
+ * modified.
+ *
+ * NEW_AND_OLD_IMAGES
— both the new and the old item images of
+ * the item.
+ *
+ * KEYS_ONLY
- only the key attributes of the
+ * modified item.
+ *
+ * NEW_IMAGE
- the entire item, as it appears after
+ * it was modified.
+ *
+ * OLD_IMAGE
- the entire item, as it appeared
+ * before it was modified.
+ *
+ * NEW_AND_OLD_IMAGES
— both the new and the old
+ * item images of the item.
+ *
+ * The type of data from the modified DynamoDB item that was captured in + * this stream record: + *
+ *
+ * KEYS_ONLY
- only the key attributes of the modified item.
+ *
+ * NEW_IMAGE
- the entire item, as it appears after it was
+ * modified.
+ *
+ * OLD_IMAGE
- the entire item, as it appeared before it was
+ * modified.
+ *
+ * NEW_AND_OLD_IMAGES
— both the new and the old item images of
+ * the item.
+ *
+ * KEYS_ONLY
- only the key attributes of the
+ * modified item.
+ *
+ * NEW_IMAGE
- the entire item, as it appears after
+ * it was modified.
+ *
+ * OLD_IMAGE
- the entire item, as it appeared
+ * before it was modified.
+ *
+ * NEW_AND_OLD_IMAGES
— both the new and the old
+ * item images of the item.
+ *