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.ByteString;
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
import meerkat.ProtobufsMessages.Tag;
|
|
||||||
import meerkat.bulletinboard.SimpleBulletinBoardClient;
|
import meerkat.bulletinboard.SimpleBulletinBoardClient;
|
||||||
import meerkat.comm.CommunicationException;
|
import meerkat.comm.CommunicationException;
|
||||||
import meerkat.crypto.Encryption;
|
import meerkat.crypto.Encryption;
|
||||||
|
@ -193,9 +192,10 @@ public class SimpleRegistry {
|
||||||
* @throws CommunicationException
|
* @throws CommunicationException
|
||||||
*/
|
*/
|
||||||
public List<String> GetPersonIDDetails(String id) throws CommunicationException, InvalidProtocolBufferException, ParseException {
|
public List<String> GetPersonIDDetails(String id) throws CommunicationException, InvalidProtocolBufferException, ParseException {
|
||||||
List<Tag> GroupsActionsTags = new ArrayList<>();
|
List<String> GroupsActionsTags = new ArrayList<String>(){{
|
||||||
GroupsActionsTags.add(Tag.newBuilder().setContent(RegistryTags.ID_TAG + " " + id).build());
|
add(RegistryTags.ID_TAG + " " + id);
|
||||||
GroupsActionsTags.add(Tag.newBuilder().setContent(RegistryTags.VOTER_ENTRY_TAG.toString()).build());
|
add(RegistryTags.VOTER_ENTRY_TAG.toString());
|
||||||
|
}};
|
||||||
|
|
||||||
List<VoterRegistryMessage> voterRegistryMessages = GetRelevantVoterRegistryMessages(GroupsActionsTags);
|
List<VoterRegistryMessage> voterRegistryMessages = GetRelevantVoterRegistryMessages(GroupsActionsTags);
|
||||||
VoterRegistryMessage LatestMessage = voterRegistryMessages.get(0);
|
VoterRegistryMessage LatestMessage = voterRegistryMessages.get(0);
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package util;
|
package util;
|
||||||
|
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
import meerkat.ProtobufsMessages;
|
|
||||||
import meerkat.VoterRegistryMessage;
|
import meerkat.VoterRegistryMessage;
|
||||||
import meerkat.protobuf.BulletinBoardAPI;
|
import meerkat.protobuf.BulletinBoardAPI;
|
||||||
|
|
||||||
|
@ -19,38 +18,34 @@ import java.util.stream.Collectors;
|
||||||
public abstract class CollectionMessagesUtils {
|
public abstract class CollectionMessagesUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts lost of BasicMessages to VoterRegistryMessags
|
* Converts lost of UnsignedBulletinBoardMessage to VoterRegistryMessags
|
||||||
* @param messages list<BasicMessages>
|
* @param messages list<VoterRegistryMessage>
|
||||||
* @return List<VoterRegistryMessage>
|
* @return List<VoterRegistryMessage>
|
||||||
*/
|
*/
|
||||||
public static List<VoterRegistryMessage> ConvertToVoterRegistryMessages(List<ProtobufsMessages.BasicMessage> messages){
|
public static List<VoterRegistryMessage> ConvertToVoterRegistryMessages(List<BulletinBoardAPI.UnsignedBulletinBoardMessage> messages){
|
||||||
List<VoterRegistryMessage> voterRegistryMessages = new ArrayList<VoterRegistryMessage>();
|
return messages.stream().map(VoterRegistryMessage::new).collect(Collectors.toList());
|
||||||
for (ProtobufsMessages.BasicMessage message : messages){
|
|
||||||
voterRegistryMessages.add(new VoterRegistryMessage(message));
|
|
||||||
}
|
|
||||||
return voterRegistryMessages;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets map of GroupId to basicMessage, where the basicMessages are the last actions for those groups
|
* Gets map of GroupId to basicMessage, where the basicMessages are the last actions for those groups
|
||||||
* @param messages List<BasicMessages>
|
* @param messages List<VoterRegistryMessage>
|
||||||
* @return Map<String, VoterRegistryMessage>
|
* @return Map{String:VoterRegistryMessage}
|
||||||
* @throws ParseException
|
* @throws ParseException
|
||||||
*/
|
*/
|
||||||
public static Map<String, VoterRegistryMessage> GetLatestGroupsActions(List<VoterRegistryMessage> messages) 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
|
// iterate trough all the messages and put into the map the last updated groups actions
|
||||||
|
|
||||||
for (int i = 0; i < messages.size(); i++) {
|
for (VoterRegistryMessage message : messages) {
|
||||||
String groupId = messages.get(i).GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG);
|
String groupId = message.GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG);
|
||||||
VoterRegistryMessage temp = groupIdToMessage.get(groupId);
|
VoterRegistryMessage temp = groupIdToMessage.get(groupId);
|
||||||
|
|
||||||
if (temp != null) {
|
if (temp != null) {
|
||||||
if (temp != messages.get(i)) {
|
if (temp != message) {
|
||||||
if (temp.GetBasicMessageActionTimestamp().before(messages.get(i).GetBasicMessageActionTimestamp())) {
|
if (temp.GetBasicMessageActionTimestamp().before(message.GetBasicMessageActionTimestamp())) {
|
||||||
groupIdToMessage.put(groupId, messages.get(i));
|
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
|
* 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>
|
* @return List<String>
|
||||||
*/
|
*/
|
||||||
public static List<String> GetListOfGroupIds(Map<String, VoterRegistryMessage> groupIdToMessage) {
|
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()) {
|
groupIdToMessage.values().stream().filter(VoterRegistryMessage::IsGroupAdding).forEach(message -> {
|
||||||
if (message.IsGroupAdding()) {
|
|
||||||
String groupId = message.GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG);
|
String groupId = message.GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG);
|
||||||
groupsIds.add(groupId);
|
groupsIds.add(groupId);
|
||||||
}
|
});
|
||||||
}
|
|
||||||
return groupsIds;
|
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