Changed the RegistryTagsType to RegistryTags
The Name RegistryTags more indicativevote-registry
parent
5971e8c16e
commit
e75317efa9
|
@ -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<String> GetGroups(String id) throws CommunicationException, InvalidProtocolBufferException {
|
||||
List<Tag> GroupsActionsTags = new ArrayList<Tag>();
|
||||
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<VoterRegistryMessage> voterRegistryMessages = GetRelevantVoterRegistryMessages(GroupsActionsTags);
|
||||
|
||||
|
@ -214,18 +214,18 @@ public class SimpleRegistry {
|
|||
*/
|
||||
public List<String> GetPersonIDDetails(String id) throws CommunicationException, InvalidProtocolBufferException, ParseException {
|
||||
List<Tag> GroupsActionsTags = new ArrayList<Tag>();
|
||||
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<VoterRegistryMessage> 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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(){
|
Loading…
Reference in New Issue