@@ -158,13 +158,7 @@ public MetaStore(final AmazonDynamoDB ddb, final String tableName,
158
158
159
159
@ Override
160
160
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 );
168
162
return decryptProvider (item );
169
163
}
170
164
@@ -215,14 +209,7 @@ public long getVersionFromMaterialDescription(final Map<String, String> descript
215
209
*/
216
210
public void replicate (final String materialName , final long version , final MetaStore targetMetaStore ) {
217
211
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 );
226
213
final Map <String , AttributeValue > plainText = getPlainText (item );
227
214
final Map <String , AttributeValue > encryptedText = targetMetaStore .getEncryptedText (plainText );
228
215
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
233
220
}
234
221
}
235
222
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
+
236
234
/**
237
235
* Creates a DynamoDB Table with the correct properties to be used with a ProviderStore.
238
236
*
0 commit comments