From 68caeee114bf63269b2ee88eff744e10e40787f1 Mon Sep 17 00:00:00 2001 From: Vladimir Eliezer Tokarev Date: Sat, 23 Jan 2016 05:51:41 -0800 Subject: [PATCH] Changed the SimpleRegistry The new Simple Registry works according to the RegistryInstance interface --- .../main/java/meerkat/RegistryInstance.java | 12 ++++++------ .../src/main/java/meerkat/SimpleRegistry.java | 19 +++++++++++-------- .../java/util/CollectionMessagesUtils.java | 5 +++-- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/voter-registry/src/main/java/meerkat/RegistryInstance.java b/voter-registry/src/main/java/meerkat/RegistryInstance.java index 7fa4f40..857a7e7 100644 --- a/voter-registry/src/main/java/meerkat/RegistryInstance.java +++ b/voter-registry/src/main/java/meerkat/RegistryInstance.java @@ -14,7 +14,7 @@ public interface RegistryInstance { * @param callBack when the adding voter done callBack.HandleVoterAdded will be called * @return void */ - abstract void AddVoter(String voterID, String personalData, RegistryCallBack callBack); + void AddVoter(String voterID, String personalData, RegistryCallBack callBack); /** * Adding given voter to given group @@ -24,7 +24,7 @@ public interface RegistryInstance { * @param callBack when the adding voter done callBack.HandleVoterAddedToGroup will be called * @return true if the adding action succeeded else return false */ - abstract void AddToGroup(String voterID, String groupID, RegistryCallBack callBack); + void AddToGroup(String voterID, String groupID, RegistryCallBack callBack); /** * Removes given voter from given group @@ -34,7 +34,7 @@ public interface RegistryInstance { * @param callBack when the adding voter done callBack.HandleVoterRemovedFromGroup will be called * @return true if the removing action succeeded else return false */ - abstract void RemoveFromGroup(String voterID, String groupID, RegistryCallBack callBack); + void RemoveFromGroup(String voterID, String groupID, RegistryCallBack callBack); /** * Sets that the voter have voted @@ -43,7 +43,7 @@ public interface RegistryInstance { * @param callBack when the adding voter done callBack.HandleSetVoted will be called * @return true if the set voted succeed else false */ - abstract void SetVoted(String id, RegistryCallBack callBack); + void SetVoted(String id, RegistryCallBack callBack); /** * Requests all the groups that the given id voter is in @@ -52,7 +52,7 @@ public interface RegistryInstance { * @param callBack when the adding voter done callBack.HandleVoterGroups will be called * @return list of groups ids (or names), if the method fails its empty */ - abstract void GetGroups(String id, RegistryCallBack callBack); + void GetGroups(String id, RegistryCallBack callBack); /** * Retrieves list of strings that represents voter @@ -61,6 +61,6 @@ public interface RegistryInstance { * @param callBack when the adding voter done callBack.HandleVoterInfo will be called * @return list of strings (empty list if the lookup failed) */ - abstract void GetPersonIDDetails(String id, RegistryCallBack callBack); + void GetPersonIDDetails(String id, RegistryCallBack callBack); } diff --git a/voter-registry/src/main/java/meerkat/SimpleRegistry.java b/voter-registry/src/main/java/meerkat/SimpleRegistry.java index 9a7962b..41e4eb3 100644 --- a/voter-registry/src/main/java/meerkat/SimpleRegistry.java +++ b/voter-registry/src/main/java/meerkat/SimpleRegistry.java @@ -23,7 +23,6 @@ import static util.CollectionMessagesUtils.*; public class SimpleRegistry implements RegistryInstance{ protected Encryption signatory; - protected SimpleBulletinBoardClient communicator; public SimpleRegistry(Encryption signatory, SimpleBulletinBoardClient communicator) { @@ -31,8 +30,12 @@ public class SimpleRegistry implements RegistryInstance{ this.communicator = communicator; } + private List wantedInformation; + private boolean methodSucceeded; + /** * Creates BulletinBoardMessage with signed basicMessage and UnsignedBulletinBoardMessage that contains the basic message + * * @param basicMessage BasicMessage * @return BulletinBoardAPI.BulletinBoardMessage */ @@ -42,7 +45,7 @@ public class SimpleRegistry implements RegistryInstance{ BulletinBoardAPI.BulletinBoardMessage.newBuilder(); Crypto.RerandomizableEncryptedMessage encryptedMessage = - signatory.encrypt(basicMessage, signatory.generateRandomness(new Random())); + signatory.encrypt(basicMessage, signatory.generateRandomness(new Random())); Crypto.Signature.Builder messageSignature = Crypto.Signature.newBuilder(); messageSignature.mergeFrom(encryptedMessage); @@ -52,7 +55,7 @@ public class SimpleRegistry implements RegistryInstance{ return bulletinBoardMessage.build(); } catch (IOException e) { - return null; + return null; } } @@ -94,7 +97,7 @@ public class SimpleRegistry implements RegistryInstance{ * @param Message the massage to post * @return true when the post was successful else false */ - private boolean SafePost(BulletinBoardAPI.BulletinBoardMessage Message){ + private boolean SafePost(BulletinBoardAPI.BulletinBoardMessage Message) { try { communicator.postMessage(Message); return true; @@ -149,7 +152,7 @@ public class SimpleRegistry implements RegistryInstance{ public void GetGroups(String id, RegistryCallBack callback) { try { - List GroupsActionsTags = new ArrayList(){{ + List GroupsActionsTags = new ArrayList() {{ add(RegistryTags.ID_TAG + " " + id); add(RegistryTags.GROUP_ACTION_TAG + " " + RegistryTags.REMOVE_FROM_GROUP_TAG); add(RegistryTags.GROUP_ACTION_TAG + " " + RegistryTags.ADD_TO_GROUP_TAG); @@ -166,13 +169,13 @@ public class SimpleRegistry implements RegistryInstance{ public void GetPersonIDDetails(String id, RegistryCallBack callback) { try { - List GroupsActionsTags = new ArrayList(){{ + List GroupsActionsTags = new ArrayList() {{ add(RegistryTags.ID_TAG + " " + id); add(RegistryTags.VOTER_ENTRY_TAG.toString()); }}; - List voterRegistryMessages = GetRelevantVoterRegistryMessages(GroupsActionsTags); + List voterRegistryMessages = GetRelevantVoterRegistryMessages(GroupsActionsTags); - VoterRegistryMessage LatestMessage = GetLatestMessage(voterRegistryMessages); + VoterRegistryMessage LatestMessage = GetLatestMessage(voterRegistryMessages); callback.HandleVoterInfo(LatestMessage.tagsToStringList()); } catch (InvalidProtocolBufferException | ParseException e) { diff --git a/voter-registry/src/main/java/util/CollectionMessagesUtils.java b/voter-registry/src/main/java/util/CollectionMessagesUtils.java index 3f1b496..3586014 100644 --- a/voter-registry/src/main/java/util/CollectionMessagesUtils.java +++ b/voter-registry/src/main/java/util/CollectionMessagesUtils.java @@ -18,11 +18,12 @@ import java.util.stream.Collectors; public abstract class CollectionMessagesUtils { /** - * Converts lost of UnsignedBulletinBoardMessage to VoterRegistryMessags + * Converts lost of UnsignedBulletinBoardMessage to VoterRegistryMessages * @param messages list * @return List */ - public static List ConvertToVoterRegistryMessages(List messages){ + public static List ConvertToVoterRegistryMessages( + List messages){ return messages.stream().map(VoterRegistryMessage::new).collect(Collectors.toList()); }