From 64ccaff508779b430a77b9e448b5cbc493c6e460 Mon Sep 17 00:00:00 2001 From: Vladimir Eliezer Tokarev Date: Fri, 19 Feb 2016 06:33:32 -0800 Subject: [PATCH] Refactoring the code of voter-registry according to Arbel Peled CR --- .../src/main/java/meerkat/BooleanHandler.java | 15 +++++++++++++- .../java/meerkat/RelevantDataCallBack.java | 20 +++++++++++++++++++ .../src/main/java/meerkat/SimpleRegistry.java | 10 ++++++---- .../java/meerkat/VoterRegistryMessage.java | 10 ---------- 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/voter-registry/src/main/java/meerkat/BooleanHandler.java b/voter-registry/src/main/java/meerkat/BooleanHandler.java index 20a63e9..3710fdd 100644 --- a/voter-registry/src/main/java/meerkat/BooleanHandler.java +++ b/voter-registry/src/main/java/meerkat/BooleanHandler.java @@ -4,19 +4,32 @@ import meerkat.bulletinboard.BulletinBoardClient; /** * Created by Vladimir Eliezer Tokarev on 2/19/2016. - * Handles the the after post situation of a BulletinBoardClient + * Handles the the after post state of VoterRegistry methods (that uses bulletinBoardClient to communicate with the server) */ public class BooleanHandler implements BulletinBoardClient.ClientCallback { public VoterRegistry.RegistryCallBack callback; + + /** + * Init BooleanHandler + * @param callback voter registry callback object + */ public BooleanHandler(VoterRegistry.RegistryCallBack callback) { this.callback = callback; } + /** + * Calls the callback HandleResult method with passed object from bulletinBoardClient + * @param msg the message that the bulletinBoardClient passes to the callback + */ @Override public void handleCallback(Object msg) { callback.HandleResult(msg); } + /** + * Calls the callback HandleResult method with false because the post method failed + * @param t the exception data that have been thrown during the failure of the post method + */ @Override public void handleFailure(Throwable t) { callback.HandleResult(false); diff --git a/voter-registry/src/main/java/meerkat/RelevantDataCallBack.java b/voter-registry/src/main/java/meerkat/RelevantDataCallBack.java index 0881fea..9cfa276 100644 --- a/voter-registry/src/main/java/meerkat/RelevantDataCallBack.java +++ b/voter-registry/src/main/java/meerkat/RelevantDataCallBack.java @@ -17,14 +17,30 @@ import static util.CollectionMessagesUtils.*; public class RelevantDataCallBack implements BulletinBoardClient.ClientCallback> { public VoterRegistry.RegistryCallBack callback; + /** + * Init BooleanHandler + * @param callback voter registry callback object + */ public RelevantDataCallBack(VoterRegistry.RegistryCallBack callback) { this.callback = callback; } + /** + * Checks if the given list have tags of type GROUP_ID_TAG or else + * @param msg List + * @return true if the messages are with GROUP_ID_TAG tags + */ private boolean isAddToGroupsList(List msg) { return msg.get(0).getMsg().getTagList().get(0).contains(RegistryTags.GROUP_ID_TAG.toString()); } + /** + * Checks if the list of messages is of type GROUP_ID_TAG if it is then calls + * HandleResult with mapping of the latest groups, else calls to HandleResult with + * the latest tag from this list (in case of personal data) + * + * @param msg List + */ @Override public void handleCallback(List msg) { List messages = ConvertToVoterRegistryMessages(msg); @@ -44,6 +60,10 @@ public class RelevantDataCallBack implements BulletinBoardClient.ClientCallback< } } + /** + * Calls the callback HandleResult method with false because the post method failed + * @param t the exception data that have been thrown during the failure of the post method + */ @Override public void handleFailure(Throwable t) { callback.HandleResult(null); diff --git a/voter-registry/src/main/java/meerkat/SimpleRegistry.java b/voter-registry/src/main/java/meerkat/SimpleRegistry.java index 0c277cc..d193523 100644 --- a/voter-registry/src/main/java/meerkat/SimpleRegistry.java +++ b/voter-registry/src/main/java/meerkat/SimpleRegistry.java @@ -23,7 +23,6 @@ public class SimpleRegistry implements VoterRegistry{ protected DigitalSignature signatory; protected BulletinBoardClient bulletinBoardClient ; - protected RegistryCallBack callback; public SimpleRegistry(DigitalSignature signatory, BulletinBoardClient communicator) { this.signatory = signatory; @@ -31,7 +30,8 @@ public class SimpleRegistry implements VoterRegistry{ } /** - * Creates BulletinBoardMessage with signed basicMessage and UnsignedBulletinBoardMessage that contains the basic message + * Creates BulletinBoardMessage with signed basicMessage and + * UnsignedBulletinBoardMessage that contains the basic message * * @param basicMessage BasicMessage * @return BulletinBoardMessage @@ -124,7 +124,8 @@ public class SimpleRegistry implements VoterRegistry{ List GroupsActionsTags = new ArrayList() {{ add(RegistryTags.GROUP_ID_TAG + groupID.getId()); }}; - bulletinBoardClient.readMessages(GetRelevantMessagesFilters(GroupsActionsTags), new RelevantDataCallBack(callback)); + bulletinBoardClient.readMessages(GetRelevantMessagesFilters(GroupsActionsTags), + new RelevantDataCallBack(callback)); } public void GetPersonIDDetails(RegistryMessages.VoterID voterID, RegistryCallBack callback) { @@ -132,6 +133,7 @@ public class SimpleRegistry implements VoterRegistry{ add(RegistryTags.ID_TAG + voterID.getId()); add(RegistryTags.VOTER_ENTRY_TAG.toString()); }}; - bulletinBoardClient.readMessages(GetRelevantMessagesFilters(GroupsActionsTags), new PersonalDataCallBack(callback)); + bulletinBoardClient.readMessages(GetRelevantMessagesFilters(GroupsActionsTags), + new RelevantDataCallBack(callback)); } } diff --git a/voter-registry/src/main/java/meerkat/VoterRegistryMessage.java b/voter-registry/src/main/java/meerkat/VoterRegistryMessage.java index 1d9bb73..cf594c4 100644 --- a/voter-registry/src/main/java/meerkat/VoterRegistryMessage.java +++ b/voter-registry/src/main/java/meerkat/VoterRegistryMessage.java @@ -6,7 +6,6 @@ import util.RegistryTags; import java.sql.Timestamp; import java.text.ParseException; -import java.util.List; /** * Created by Vladimir Eliezer Tokarev on 1/15.2016 @@ -70,13 +69,4 @@ public class VoterRegistryMessage { } return false; } - - /** - * converts the messages tags to list of strings - * - * @return List of strings - */ - public List tagsToStringList() { - return base.getTagList(); - } }