diff --git a/voter-registry/src/main/java/meerkat/SimpleRegistry.java b/voter-registry/src/main/java/meerkat/SimpleRegistry.java index d425619..d841929 100644 --- a/voter-registry/src/main/java/meerkat/SimpleRegistry.java +++ b/voter-registry/src/main/java/meerkat/SimpleRegistry.java @@ -11,7 +11,7 @@ import meerkat.protobuf.BulletinBoardAPI; import meerkat.protobuf.Crypto; import util.AccurateTimestamp; import util.CollectionMessagesUtils; -import util.Tags; +import util.RegistryTags; import java.io.IOException; import java.text.ParseException; @@ -111,9 +111,9 @@ public class SimpleRegistry { */ public void AddVoter(String voterID, String personalData) throws CommunicationException, IOException { Tag.Builder[] tags = GetTagsArrayInLength(3); - tags[0].setContent(Tags.ID_TAG + " " + voterID); - tags[1].setContent(Tags.VOTER_ENTRY_TAG.toString()); - tags[2].setContent(Tags.ACTION_TIMESTAMP_TAG + " " + AccurateTimestamp.GetCurrentTimestampString()); + tags[0].setContent(RegistryTags.ID_TAG + " " + voterID); + tags[1].setContent(RegistryTags.VOTER_ENTRY_TAG.toString()); + tags[2].setContent(RegistryTags.ACTION_TIMESTAMP_TAG + " " + AccurateTimestamp.GetCurrentTimestampString()); BasicMessage.Builder basicMessage = BasicMessage.newBuilder().addTag(tags[0]).addTag(tags[1]).addTag(tags[1]); basicMessage.setData(ByteString.copyFrom(personalData.getBytes())); @@ -131,10 +131,10 @@ public class SimpleRegistry { */ public void AddToGroup(String voterID, String groupID) throws CommunicationException, IOException { Tag.Builder[] tags = GetTagsArrayInLength(4); - tags[0].setContent(Tags.ID_TAG + " " + voterID); - tags[1].setContent(Tags.GROUP_ID_TAG + " " + groupID); - tags[2].setContent(Tags.GROUP_ACTION_TAG + " " + Tags.ADD_TO_GROUP_TAG); - tags[3].setContent(Tags.ACTION_TIMESTAMP_TAG + " " + AccurateTimestamp.GetCurrentTimestampString()); + tags[0].setContent(RegistryTags.ID_TAG + " " + voterID); + tags[1].setContent(RegistryTags.GROUP_ID_TAG + " " + groupID); + tags[2].setContent(RegistryTags.GROUP_ACTION_TAG + " " + RegistryTags.ADD_TO_GROUP_TAG); + tags[3].setContent(RegistryTags.ACTION_TIMESTAMP_TAG + " " + AccurateTimestamp.GetCurrentTimestampString()); BasicMessage.Builder basicMessage = BasicMessage.newBuilder().addTag(tags[0]).addTag(tags[1]).addTag(tags[2]).addTag(tags[3]); @@ -152,10 +152,10 @@ public class SimpleRegistry { */ public void RemoveFromGroup(String voterID, String groupID) throws CommunicationException, IOException { Tag.Builder[] tags = GetTagsArrayInLength(4); - tags[0].setContent(Tags.ID_TAG + " " + voterID); - tags[1].setContent(Tags.GROUP_ID_TAG + " " + groupID); - tags[2].setContent(Tags.GROUP_ACTION_TAG + " " + Tags.REMOVE_FROM_GROUP_TAG); - tags[3].setContent(Tags.ACTION_TIMESTAMP_TAG + " " + AccurateTimestamp.GetCurrentTimestampString()); + tags[0].setContent(RegistryTags.ID_TAG + " " + voterID); + tags[1].setContent(RegistryTags.GROUP_ID_TAG + " " + groupID); + tags[2].setContent(RegistryTags.GROUP_ACTION_TAG + " " + RegistryTags.REMOVE_FROM_GROUP_TAG); + tags[3].setContent(RegistryTags.ACTION_TIMESTAMP_TAG + " " + AccurateTimestamp.GetCurrentTimestampString()); BasicMessage.Builder basicMessage = BasicMessage.newBuilder().addTag(tags[0]).addTag(tags[1]).addTag(tags[2]).addTag(tags[3]); @@ -172,9 +172,9 @@ public class SimpleRegistry { */ public void AddVoter(String id) throws CommunicationException, IOException { Tag.Builder[] tags = GetTagsArrayInLength(3); - tags[0].setContent(Tags.ID_TAG + " " + id); - tags[1].setContent(Tags.VOTE_ACTION_TAG.toString()); - tags[2].setContent(Tags.ACTION_TIMESTAMP_TAG + " " + AccurateTimestamp.GetCurrentTimestampString()); + tags[0].setContent(RegistryTags.ID_TAG + " " + id); + tags[1].setContent(RegistryTags.VOTE_ACTION_TAG.toString()); + tags[2].setContent(RegistryTags.ACTION_TIMESTAMP_TAG + " " + AccurateTimestamp.GetCurrentTimestampString()); BasicMessage.Builder basicMessage = BasicMessage.newBuilder().addTag(tags[0]).addTag(tags[1]).addTag(tags[2]); @@ -191,9 +191,9 @@ public class SimpleRegistry { */ public List GetGroups(String id) throws CommunicationException, InvalidProtocolBufferException { List GroupsActionsTags = new ArrayList(); - GroupsActionsTags.add(Tag.newBuilder().setContent(Tags.ID_TAG + " " + id).build()); - GroupsActionsTags.add(Tag.newBuilder().setContent(Tags.GROUP_ACTION_TAG + " " + Tags.REMOVE_FROM_GROUP_TAG).build()); - GroupsActionsTags.add(Tag.newBuilder().setContent(Tags.GROUP_ACTION_TAG + " " + Tags.ADD_TO_GROUP_TAG).build()); + GroupsActionsTags.add(Tag.newBuilder().setContent(RegistryTags.ID_TAG + " " + id).build()); + GroupsActionsTags.add(Tag.newBuilder().setContent(RegistryTags.GROUP_ACTION_TAG + " " + RegistryTags.REMOVE_FROM_GROUP_TAG).build()); + GroupsActionsTags.add(Tag.newBuilder().setContent(RegistryTags.GROUP_ACTION_TAG + " " + RegistryTags.ADD_TO_GROUP_TAG).build()); List voterRegistryMessages = GetRelevantVoterRegistryMessages(GroupsActionsTags); @@ -214,18 +214,18 @@ public class SimpleRegistry { */ public List GetPersonIDDetails(String id) throws CommunicationException, InvalidProtocolBufferException, ParseException { List GroupsActionsTags = new ArrayList(); - GroupsActionsTags.add(Tag.newBuilder().setContent(Tags.ID_TAG + " " + id).build()); - GroupsActionsTags.add(Tag.newBuilder().setContent(Tags.VOTER_ENTRY_TAG.toString()).build()); + GroupsActionsTags.add(Tag.newBuilder().setContent(RegistryTags.ID_TAG + " " + id).build()); + GroupsActionsTags.add(Tag.newBuilder().setContent(RegistryTags.VOTER_ENTRY_TAG.toString()).build()); List voterRegistryMessages = GetRelevantVoterRegistryMessages(GroupsActionsTags); VoterRegistryMessage LatestMessage = voterRegistryMessages.get(0); for (VoterRegistryMessage message : voterRegistryMessages) { - if (LatestMessage.GetBasicMessageActionTimestamp().before(message.GetBasicMessageActionTimestamp()) { + if (message.GetBasicMessageActionTimestamp().before(LatestMessage.GetBasicMessageActionTimestamp())) { LatestMessage = message; } } - return Arrays.asList(LatestMessage.GetWantedTagFromBasicMessage(Tags.ID_TAG), LatestMessage.base.getData().toString()); + return Arrays.asList(LatestMessage.GetWantedTagFromBasicMessage(RegistryTags.ID_TAG), LatestMessage.base.getData().toString()); } } diff --git a/voter-registry/src/main/java/meerkat/VoterRegistryMessage.java b/voter-registry/src/main/java/meerkat/VoterRegistryMessage.java index 6426b9c..1115e4f 100644 --- a/voter-registry/src/main/java/meerkat/VoterRegistryMessage.java +++ b/voter-registry/src/main/java/meerkat/VoterRegistryMessage.java @@ -1,7 +1,7 @@ package meerkat; import util.AccurateTimestamp; -import util.Tags; +import util.RegistryTags; import java.sql.Timestamp; import java.text.ParseException; @@ -23,7 +23,7 @@ public class VoterRegistryMessage { * @param tagName * @return string */ - public String GetWantedTagFromBasicMessage(Tags tagName){ + public String GetWantedTagFromBasicMessage(RegistryTags tagName){ for (ProtobufsMessages.Tag tag : base.getTagList()) { if ( tag.getContent().contains(tagName.toString())) { return tag.getContent(); @@ -39,7 +39,7 @@ public class VoterRegistryMessage { */ public Timestamp GetBasicMessageActionTimestamp() throws ParseException { for (ProtobufsMessages.Tag tag : base.getTagList()) { - if ( tag.getContent().contains(Tags.ACTION_TIMESTAMP_TAG.toString())) { + if ( tag.getContent().contains(RegistryTags.ACTION_TIMESTAMP_TAG.toString())) { String[] tagParts = tag.getContent().split(" "); String timestamp = tagParts[tagParts.length - 1]; return AccurateTimestamp.GetTimestampFromString(timestamp); @@ -55,7 +55,7 @@ public class VoterRegistryMessage { */ public boolean IsGroupAdding() { for (ProtobufsMessages.Tag tag : base.getTagList()) { - if ( tag.getContent().contains(Tags.ADD_TO_GROUP_TAG.toString())) { + if ( tag.getContent().contains(RegistryTags.ADD_TO_GROUP_TAG.toString())) { return true; } } diff --git a/voter-registry/src/main/java/util/CollectionMessagesUtils.java b/voter-registry/src/main/java/util/CollectionMessagesUtils.java index 620f8bb..50ba0bd 100644 --- a/voter-registry/src/main/java/util/CollectionMessagesUtils.java +++ b/voter-registry/src/main/java/util/CollectionMessagesUtils.java @@ -43,7 +43,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++) { - String groupId = messages.get(i).GetWantedTagFromBasicMessage(Tags.GROUP_ID_TAG); + String groupId = messages.get(i).GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG); VoterRegistryMessage temp = groupIdToMessage.get(groupId); if (temp != null) { @@ -68,7 +68,7 @@ public abstract class CollectionMessagesUtils { for (VoterRegistryMessage message : groupIdToMessage.values()) { if (message.IsGroupAdding()) { - String groupId = message.GetWantedTagFromBasicMessage(Tags.GROUP_ID_TAG); + String groupId = message.GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG); groupsIds.add(groupId); } } diff --git a/voter-registry/src/main/java/util/RegistryTagTypes.java b/voter-registry/src/main/java/util/RegistryTags.java similarity index 85% rename from voter-registry/src/main/java/util/RegistryTagTypes.java rename to voter-registry/src/main/java/util/RegistryTags.java index 815290b..1769ee0 100644 --- a/voter-registry/src/main/java/util/RegistryTagTypes.java +++ b/voter-registry/src/main/java/util/RegistryTags.java @@ -4,7 +4,7 @@ package util; * Created by Vladimir Eliezer Tokarev on 1/9/2016. * Have the tags for the registry messages */ -public enum Tags { +public enum RegistryTags { ID_TAG("ID:"), VOTER_ENTRY_TAG("Voter Entry"), @@ -17,8 +17,8 @@ public enum Tags { private final String text; - Tags(final String text){ - this.text = text + RegistryTags(final String text){ + this.text = text; } public String toString(){