Skip to content

Commit 5622875

Browse files
committed
Add private getMaterialItem method in MetaStore
Moves duplicated code into a common method in the MetaStore.
1 parent ea43801 commit 5622875

File tree

1 file changed

+13
-15
lines changed
  • src/main/java/com/amazonaws/services/dynamodbv2/datamodeling/encryption/providers/store

1 file changed

+13
-15
lines changed

src/main/java/com/amazonaws/services/dynamodbv2/datamodeling/encryption/providers/store/MetaStore.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,7 @@ public MetaStore(final AmazonDynamoDB ddb, final String tableName,
158158

159159
@Override
160160
public EncryptionMaterialsProvider getProvider(final String materialName, final long version) {
161-
final Map<String, AttributeValue> ddbKey = new HashMap<String, AttributeValue>();
162-
ddbKey.put(DEFAULT_HASH_KEY, new AttributeValue().withS(materialName));
163-
ddbKey.put(DEFAULT_RANGE_KEY, new AttributeValue().withN(Long.toString(version)));
164-
final Map<String, AttributeValue> item = ddbGet(ddbKey);
165-
if (item == null || item.isEmpty()) {
166-
throw new IndexOutOfBoundsException("No material found: " + materialName + "#" + version);
167-
}
161+
Map<String, AttributeValue> item = getMaterialItem(materialName, version);
168162
return decryptProvider(item);
169163
}
170164

@@ -215,14 +209,7 @@ public long getVersionFromMaterialDescription(final Map<String, String> descript
215209
*/
216210
public void replicate(final String materialName, final long version, final MetaStore targetMetaStore) {
217211
try {
218-
final Map<String, AttributeValue> ddbKey = new HashMap<String, AttributeValue>();
219-
ddbKey.put(DEFAULT_HASH_KEY, new AttributeValue().withS(materialName));
220-
ddbKey.put(DEFAULT_RANGE_KEY, new AttributeValue().withN(Long.toString(version)));
221-
final Map<String, AttributeValue> item = ddbGet(ddbKey);
222-
if (item == null || item.isEmpty()) {
223-
throw new IndexOutOfBoundsException("No material found: " + materialName + "#" + version);
224-
}
225-
212+
Map<String, AttributeValue> item = getMaterialItem(materialName, version);
226213
final Map<String, AttributeValue> plainText = getPlainText(item);
227214
final Map<String, AttributeValue> encryptedText = targetMetaStore.getEncryptedText(plainText);
228215
final PutItemRequest put = new PutItemRequest().withTableName(targetMetaStore.tableName).withItem(encryptedText)
@@ -233,6 +220,17 @@ public void replicate(final String materialName, final long version, final MetaS
233220
}
234221
}
235222

223+
private Map<String, AttributeValue> getMaterialItem(final String materialName, final long version) {
224+
final Map<String, AttributeValue> ddbKey = new HashMap<String, AttributeValue>();
225+
ddbKey.put(DEFAULT_HASH_KEY, new AttributeValue().withS(materialName));
226+
ddbKey.put(DEFAULT_RANGE_KEY, new AttributeValue().withN(Long.toString(version)));
227+
final Map<String, AttributeValue> item = ddbGet(ddbKey);
228+
if (item == null || item.isEmpty()) {
229+
throw new IndexOutOfBoundsException("No material found: " + materialName + "#" + version);
230+
}
231+
return item;
232+
}
233+
236234
/**
237235
* Creates a DynamoDB Table with the correct properties to be used with a ProviderStore.
238236
*

0 commit comments

Comments
 (0)