Add simple dispatch functions for resend making dispatch logic easier to read. make dispatch methods protected for more direct testing.
@@ -242,13 +242,8 @@ public class TransactionManagerImpl implements TransactionManager {
return new SendResponse(encodedKey);
}
- @Override
- public ResendResponse resend(ResendRequest request) {
-
- final byte[] publicKeyData = base64Codec.decode(request.getPublicKey());
- PublicKey recipientPublicKey = PublicKey.from(publicKeyData);
- if (request.getType() == ResendRequestType.ALL) {
+ protected ResendResponse resendAll(PublicKey recipientPublicKey) {
int offset = 0;
while (offset < encryptedTransactionDAO.transactionCount()) {
@@ -309,10 +304,9 @@ public class TransactionManagerImpl implements TransactionManager {
}
return new ResendResponse();
- } else {
+ }
- final byte[] hashKey = base64Codec.decode(request.getKey());
- final MessageHash messageHash = new MessageHash(hashKey);
+ protected ResendResponse resendIndividual(PublicKey recipientPublicKey,MessageHash messageHash) {
final EncryptedTransaction encryptedTransaction =
encryptedTransactionDAO
@@ -334,6 +328,24 @@ public class TransactionManagerImpl implements TransactionManager {
returnValue = payloadEncoder.forRecipient(payload, recipientPublicKey);
}
return new ResendResponse(payloadEncoder.encode(returnValue));
+
+ }
+
+ @Override
+ public ResendResponse resend(ResendRequest request) {
+
+ final byte[] publicKeyData = base64Codec.decode(request.getPublicKey());
+ PublicKey recipientPublicKey = PublicKey.from(publicKeyData);
+
+ if (request.getType() == ResendRequestType.ALL) {
+ return resendAll(recipientPublicKey);
+
+ } else {
+
+ final byte[] hashKey = base64Codec.decode(request.getKey());
+ final MessageHash messageHash = new MessageHash(hashKey);
+ return resendIndividual(recipientPublicKey,messageHash);
+
}
}
