Re-organized the voter-registry
Since there no need for basicMessage i have removed it, and changed few methods to be in language level 7Voter-Registry
parent
dfc5bf4b24
commit
89bac8d346
File diff suppressed because it is too large
Load Diff
|
@ -2,7 +2,6 @@ package meerkat;
|
|||
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import meerkat.ProtobufsMessages.Tag;
|
||||
import meerkat.bulletinboard.SimpleBulletinBoardClient;
|
||||
import meerkat.comm.CommunicationException;
|
||||
import meerkat.crypto.Encryption;
|
||||
|
@ -193,9 +192,10 @@ public class SimpleRegistry {
|
|||
* @throws CommunicationException
|
||||
*/
|
||||
public List<String> GetPersonIDDetails(String id) throws CommunicationException, InvalidProtocolBufferException, ParseException {
|
||||
List<Tag> GroupsActionsTags = new ArrayList<>();
|
||||
GroupsActionsTags.add(Tag.newBuilder().setContent(RegistryTags.ID_TAG + " " + id).build());
|
||||
GroupsActionsTags.add(Tag.newBuilder().setContent(RegistryTags.VOTER_ENTRY_TAG.toString()).build());
|
||||
List<String> GroupsActionsTags = new ArrayList<String>(){{
|
||||
add(RegistryTags.ID_TAG + " " + id);
|
||||
add(RegistryTags.VOTER_ENTRY_TAG.toString());
|
||||
}};
|
||||
|
||||
List<VoterRegistryMessage> voterRegistryMessages = GetRelevantVoterRegistryMessages(GroupsActionsTags);
|
||||
VoterRegistryMessage LatestMessage = voterRegistryMessages.get(0);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package util;
|
||||
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import meerkat.ProtobufsMessages;
|
||||
import meerkat.VoterRegistryMessage;
|
||||
import meerkat.protobuf.BulletinBoardAPI;
|
||||
|
||||
|
@ -19,38 +18,34 @@ import java.util.stream.Collectors;
|
|||
public abstract class CollectionMessagesUtils {
|
||||
|
||||
/**
|
||||
* Converts lost of BasicMessages to VoterRegistryMessags
|
||||
* @param messages list<BasicMessages>
|
||||
* Converts lost of UnsignedBulletinBoardMessage to VoterRegistryMessags
|
||||
* @param messages list<VoterRegistryMessage>
|
||||
* @return List<VoterRegistryMessage>
|
||||
*/
|
||||
public static List<VoterRegistryMessage> ConvertToVoterRegistryMessages(List<ProtobufsMessages.BasicMessage> messages){
|
||||
List<VoterRegistryMessage> voterRegistryMessages = new ArrayList<VoterRegistryMessage>();
|
||||
for (ProtobufsMessages.BasicMessage message : messages){
|
||||
voterRegistryMessages.add(new VoterRegistryMessage(message));
|
||||
}
|
||||
return voterRegistryMessages;
|
||||
public static List<VoterRegistryMessage> ConvertToVoterRegistryMessages(List<BulletinBoardAPI.UnsignedBulletinBoardMessage> messages){
|
||||
return messages.stream().map(VoterRegistryMessage::new).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets map of GroupId to basicMessage, where the basicMessages are the last actions for those groups
|
||||
* @param messages List<BasicMessages>
|
||||
* @return Map<String, VoterRegistryMessage>
|
||||
* @param messages List<VoterRegistryMessage>
|
||||
* @return Map{String:VoterRegistryMessage}
|
||||
* @throws ParseException
|
||||
*/
|
||||
public static Map<String, VoterRegistryMessage> GetLatestGroupsActions(List<VoterRegistryMessage> messages) throws ParseException {
|
||||
|
||||
Map<String, VoterRegistryMessage> groupIdToMessage = new HashMap<String, VoterRegistryMessage>();
|
||||
Map<String, VoterRegistryMessage> groupIdToMessage = new HashMap<>();
|
||||
|
||||
// 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(RegistryTags.GROUP_ID_TAG);
|
||||
for (VoterRegistryMessage message : messages) {
|
||||
String groupId = message.GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG);
|
||||
VoterRegistryMessage temp = groupIdToMessage.get(groupId);
|
||||
|
||||
if (temp != null) {
|
||||
if (temp != messages.get(i)) {
|
||||
if (temp.GetBasicMessageActionTimestamp().before(messages.get(i).GetBasicMessageActionTimestamp())) {
|
||||
groupIdToMessage.put(groupId, messages.get(i));
|
||||
if (temp != message) {
|
||||
if (temp.GetBasicMessageActionTimestamp().before(message.GetBasicMessageActionTimestamp())) {
|
||||
groupIdToMessage.put(groupId, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,18 +56,16 @@ public abstract class CollectionMessagesUtils {
|
|||
|
||||
/**
|
||||
* Gets list of groups ids of the basicMessages that carried the adding to group tag
|
||||
* @param groupIdToMessage Map<String, BasicMessage>
|
||||
* @param groupIdToMessage Map<String, VoterRegistryMessage>
|
||||
* @return List<String>
|
||||
*/
|
||||
public static List<String> GetListOfGroupIds(Map<String, VoterRegistryMessage> groupIdToMessage) {
|
||||
List<String> groupsIds = new ArrayList<String>();
|
||||
List<String> groupsIds = new ArrayList<>();
|
||||
|
||||
for (VoterRegistryMessage message : groupIdToMessage.values()) {
|
||||
if (message.IsGroupAdding()) {
|
||||
String groupId = message.GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG);
|
||||
groupsIds.add(groupId);
|
||||
}
|
||||
}
|
||||
groupIdToMessage.values().stream().filter(VoterRegistryMessage::IsGroupAdding).forEach(message -> {
|
||||
String groupId = message.GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG);
|
||||
groupsIds.add(groupId);
|
||||
});
|
||||
return groupsIds;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
package meerkat;
|
||||
|
||||
option java_outer_classname = "ProtobufsMessages";
|
||||
|
||||
message Tag {
|
||||
required string content = 1;
|
||||
}
|
||||
|
||||
message BasicMessage {
|
||||
repeated Tag tag = 1;
|
||||
optional bytes data = 2;
|
||||
}
|
Loading…
Reference in New Issue