diff --git a/bulletin-board-server/meerkat b/bulletin-board-server/meerkat index 7257000..162a2ec 100644 Binary files a/bulletin-board-server/meerkat and b/bulletin-board-server/meerkat differ diff --git a/voter-registry/src/main/java/meerkat/Registry/CollectionMessagesUtils.java b/voter-registry/src/main/java/meerkat/Registry/CollectionMessagesUtils.java index 33b8ca5..03d542c 100644 --- a/voter-registry/src/main/java/meerkat/Registry/CollectionMessagesUtils.java +++ b/voter-registry/src/main/java/meerkat/Registry/CollectionMessagesUtils.java @@ -51,7 +51,7 @@ public abstract class CollectionMessagesUtils { // iterate trough all the messages and put into the map the last updated groups actions for (int i = 0 ; i < messages.size() ; i++) { VoterRegistryMessage message = messages.get(i); - String groupId = message.GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG.toString()); + String groupId = message.GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG); VoterRegistryMessage temp = groupIdToMessage.get(groupId); if (temp != null && temp != message) { diff --git a/voter-registry/src/main/java/meerkat/Registry/RegistryTags.java b/voter-registry/src/main/java/meerkat/Registry/RegistryTags.java index 9b2ea32..3f4d36a 100644 --- a/voter-registry/src/main/java/meerkat/Registry/RegistryTags.java +++ b/voter-registry/src/main/java/meerkat/Registry/RegistryTags.java @@ -1,28 +1,17 @@ package meerkat.Registry; + /** * Created by Vladimir Eliezer Tokarev on 1/9/2016. * Have the tags for the registry messages */ -public enum RegistryTags { - - ID_TAG("ID:"), - VOTER_ENTRY_TAG("Voter Entry"), - GROUP_ID_TAG("GroupID:"), - GROUP_ACTION_TAG("Group Action:"), - ADD_TO_GROUP_TAG("Add To Group"), - ACTION_TIMESTAMP_TAG("Action timestamp: "), - VOTE_ACTION_TAG("Vote Action"); - - private final String text; - - RegistryTags(final String text){ - this.text = text; - } - - public String toString(){ - return text; - } +public abstract class RegistryTags { + public final static String ID_TAG = "ID:"; + public final static String VOTER_ENTRY_TAG = "VoterEntry:"; + public final static String GROUP_ID_TAG = "GroupID:"; + public final static String ADD_TO_GROUP_TAG = "AddToGroup:"; + public final static String ACTION_TIMESTAMP_TAG = "ActionTimestamp: "; + public final static String VOTE_ACTION_TAG = "VoteAction:"; } diff --git a/voter-registry/src/main/java/meerkat/Registry/RelevantDataCallBack.java b/voter-registry/src/main/java/meerkat/Registry/RelevantDataCallBack.java index 47308e0..8339e62 100644 --- a/voter-registry/src/main/java/meerkat/Registry/RelevantDataCallBack.java +++ b/voter-registry/src/main/java/meerkat/Registry/RelevantDataCallBack.java @@ -60,7 +60,7 @@ public class RelevantDataCallBack implements ClientCallback tags = msg.get(0).getMsg().getTagList(); for (int i = 0 ;i < tags.size(); i++) { String tag = tags.get(i); - if(tag.contains(RegistryTags.GROUP_ID_TAG.toString())) + if(tag.contains(RegistryTags.GROUP_ID_TAG)) { return true; } diff --git a/voter-registry/src/main/java/meerkat/SimpleRegistry.java b/voter-registry/src/main/java/meerkat/SimpleRegistry.java index 762a9a0..8e13e1a 100644 --- a/voter-registry/src/main/java/meerkat/SimpleRegistry.java +++ b/voter-registry/src/main/java/meerkat/SimpleRegistry.java @@ -14,6 +14,10 @@ import java.security.SignatureException; import java.util.ArrayList; import java.util.List; +/** + * TODO : add ability to use DB of certificates + */ + /** * Created by Vladimir Eliezer Tokarev on 1/8/2016. * Gives the ability to synchronously manage voters information @@ -55,26 +59,15 @@ public class SimpleRegistry implements VoterRegistry{ } } - /** - * Tries to post basicMessage and return true if its been successfully posted - * - * @param Message the massage to post - * @return true when the post was successful else false - */ - private void SafePost(BulletinBoardMessage Message, BulletinBoardClient.ClientCallback callback) { - bulletinBoardClient .postMessage(Message, callback); - } - public void AddVoter(VoterInfo voterInfo, RegistryCallBack callback) { UnsignedBulletinBoardMessage.Builder basicMessage = UnsignedBulletinBoardMessage.newBuilder(). addTag(RegistryTags.ID_TAG + voterInfo.getId().getId()) - .addTag(RegistryTags.VOTER_ENTRY_TAG.toString()) + .addTag(RegistryTags.VOTER_ENTRY_TAG) .addTag(RegistryTags.ACTION_TIMESTAMP_TAG + AccurateTimestamp.GetCurrentTimestampString()); basicMessage.setData(voterInfo.getInfoBytes()); - - SafePost(CreateBulletinBoardMessage(basicMessage.build()), new BooleanCallBack(callback)); + bulletinBoardClient.postMessage(CreateBulletinBoardMessage(basicMessage.build()), new BooleanCallBack(callback)); } public void AddToGroup(VoterGroup voterGroup, RegistryCallBack callback) { @@ -82,20 +75,20 @@ public class SimpleRegistry implements VoterRegistry{ UnsignedBulletinBoardMessage.newBuilder() .addTag(RegistryTags.ID_TAG + voterGroup.getVoterId().getId()) .addTag(RegistryTags.GROUP_ID_TAG + voterGroup.getGroupId().getId()) - .addTag(RegistryTags.GROUP_ACTION_TAG .toString() + RegistryTags.ADD_TO_GROUP_TAG) + .addTag(RegistryTags.ADD_TO_GROUP_TAG) .addTag(RegistryTags.ACTION_TIMESTAMP_TAG + AccurateTimestamp.GetCurrentTimestampString()); - SafePost(CreateBulletinBoardMessage(basicMessage.build()), new BooleanCallBack(callback)); + bulletinBoardClient.postMessage(CreateBulletinBoardMessage(basicMessage.build()), new BooleanCallBack(callback)); } public void SetVoted(VoterID voterId, RegistryCallBack callback) { UnsignedBulletinBoardMessage.Builder basicMessage = UnsignedBulletinBoardMessage.newBuilder() .addTag(RegistryTags.ID_TAG + voterId.getId()) - .addTag(RegistryTags.VOTE_ACTION_TAG.toString()) + .addTag(RegistryTags.VOTE_ACTION_TAG) .addTag(RegistryTags.ACTION_TIMESTAMP_TAG + AccurateTimestamp.GetCurrentTimestampString()); - SafePost(CreateBulletinBoardMessage(basicMessage.build()), new BooleanCallBack(callback)); + bulletinBoardClient.postMessage(CreateBulletinBoardMessage(basicMessage.build()), new BooleanCallBack(callback)); } public void GetGroups(GroupID groupID, RegistryCallBack callback) { @@ -109,7 +102,7 @@ public class SimpleRegistry implements VoterRegistry{ public void GetPersonIDDetails(VoterID voterID, RegistryCallBack callback) { List GroupsActionsTags = new ArrayList() {{ add(RegistryTags.ID_TAG + voterID.getId()); - add(RegistryTags.VOTER_ENTRY_TAG.toString()); + add(RegistryTags.VOTER_ENTRY_TAG); }}; bulletinBoardClient.readMessages(CollectionMessagesUtils.GenerateFiltersFromTags(GroupsActionsTags), new RelevantDataCallBack(callback, signer, signature, certificateStream)); diff --git a/voter-registry/src/main/java/meerkat/VoterRegistryMessage.java b/voter-registry/src/main/java/meerkat/VoterRegistryMessage.java index 51910f3..0a6285a 100644 --- a/voter-registry/src/main/java/meerkat/VoterRegistryMessage.java +++ b/voter-registry/src/main/java/meerkat/VoterRegistryMessage.java @@ -56,7 +56,7 @@ public class VoterRegistryMessage { List tags = base.getTagList(); for (int i = 0 ; i < tags.size() ; i++) { String tag = tags.get(i); - if (tag.contains(RegistryTags.ACTION_TIMESTAMP_TAG.toString())) { + if (tag.contains(RegistryTags.ACTION_TIMESTAMP_TAG)) { String[] tagParts = tag.split(" "); String timestamp = tagParts[tagParts.length - 2] + " " + tagParts[tagParts.length - 1]; @@ -66,20 +66,4 @@ public class VoterRegistryMessage { return null; } - - /** - * Checks if the given message have the ADD_TO_GROUP_TAG - * - * @return true when ADD_TO_GROUP_TAG exist else false - */ - public boolean IsGroupAdding() { - List tags = base.getTagList(); - for (int i = 0 ; i < tags.size() ; i++) { - String tag = tags.get(i); - if (tag.contains(RegistryTags.ADD_TO_GROUP_TAG.toString())) { - return true; - } - } - return false; - } } diff --git a/voter-registry/src/test/java/SimpleRegistryTest.java b/voter-registry/src/test/java/SimpleRegistryTest.java index 60ce8c3..80d7500 100644 --- a/voter-registry/src/test/java/SimpleRegistryTest.java +++ b/voter-registry/src/test/java/SimpleRegistryTest.java @@ -178,7 +178,7 @@ public class SimpleRegistryTest extends TestCase { jobSemaphore.acquire(); assertEquals(1, handler.counter ); - List tags = new ArrayList(){{ add(RegistryTags.VOTER_ENTRY_TAG.toString());}}; + List tags = new ArrayList(){{ add(RegistryTags.VOTER_ENTRY_TAG);}}; MessageFilterList filters = CollectionMessagesUtils.GenerateFiltersFromTags(tags); DummyBulletinBoardCallBackHandler bulletinHandler = new DummyBulletinBoardCallBackHandler(); bulletinBoardClient.readMessages(filters, bulletinHandler); @@ -206,7 +206,7 @@ public class SimpleRegistryTest extends TestCase { jobSemaphore.acquire(); assertEquals(1, handler.counter ); - List tags = new ArrayList(){{ add(RegistryTags.VOTE_ACTION_TAG.toString());}}; + List tags = new ArrayList(){{ add(RegistryTags.VOTE_ACTION_TAG);}}; MessageFilterList filters = CollectionMessagesUtils.GenerateFiltersFromTags(tags); DummyBulletinBoardCallBackHandler bulletinHandler = new DummyBulletinBoardCallBackHandler(); bulletinBoardClient.readMessages(filters, bulletinHandler); @@ -236,8 +236,7 @@ public class SimpleRegistryTest extends TestCase { jobSemaphore.acquire(); assertEquals(1, handler.counter); - List tags = new ArrayList(){{ add(RegistryTags.GROUP_ACTION_TAG .toString() - + RegistryTags.ADD_TO_GROUP_TAG.toString());}}; + List tags = new ArrayList(){{add(RegistryTags.ADD_TO_GROUP_TAG);}}; MessageFilterList filters = CollectionMessagesUtils.GenerateFiltersFromTags(tags); DummyBulletinBoardCallBackHandler bulletinHandler = new DummyBulletinBoardCallBackHandler(); bulletinBoardClient.readMessages(filters, bulletinHandler); @@ -305,7 +304,7 @@ public class SimpleRegistryTest extends TestCase { jobSemaphore.acquire(1); assertEquals(RegistryTags.ID_TAG + id, - personalHandler.data.GetWantedTagFromBasicMessage(RegistryTags.ID_TAG.toString())); + personalHandler.data.GetWantedTagFromBasicMessage(RegistryTags.ID_TAG)); assertEquals(data,personalHandler.data.base.getData().toStringUtf8()); } }