diff --git a/bulletin-board-server/meerkat b/bulletin-board-server/meerkat index 1b73e91..7257000 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 c52f071..33b8ca5 100644 --- a/voter-registry/src/main/java/meerkat/Registry/CollectionMessagesUtils.java +++ b/voter-registry/src/main/java/meerkat/Registry/CollectionMessagesUtils.java @@ -7,11 +7,7 @@ import meerkat.protobuf.BulletinBoardAPI.MessageFilter; import meerkat.protobuf.BulletinBoardAPI.MessageFilterList; import java.text.ParseException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; +import java.util.*; /** * TODO: add logging to this utils @@ -34,9 +30,13 @@ public abstract class CollectionMessagesUtils { * @param messages list * @return List */ - public static List ConvertToVoterRegistryMessages( - List messages){ - return messages.stream().map(VoterRegistryMessage::new).collect(Collectors.toList()); + public static List ConvertToVoterRegistryMessages(List messages){ + List voterMessages = new ArrayList<>(); + for (int i = 0 ; i < messages.size() ; i++) + { + voterMessages.add(new VoterRegistryMessage(messages.get(i))); + } + return voterMessages; } /** @@ -71,11 +71,13 @@ public abstract class CollectionMessagesUtils { */ public static List GetListOfGroupIds(Map groupIdToMessage) { List groupsIds = new ArrayList<>(); - - groupIdToMessage.values().stream().filter(VoterRegistryMessage::IsGroupAdding).forEach(message -> { + Iterator entries = groupIdToMessage.entrySet().iterator(); + while (entries.hasNext()) { + Map.Entry tuple = (Map.Entry) entries.next(); + VoterRegistryMessage message = (VoterRegistryMessage) tuple.getValue(); String groupId = message.GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG.toString()); groupsIds.add(groupId); - }); + } return groupsIds; } diff --git a/voter-registry/src/main/java/meerkat/Registry/RelevantDataCallBack.java b/voter-registry/src/main/java/meerkat/Registry/RelevantDataCallBack.java index c6cff8f..47308e0 100644 --- a/voter-registry/src/main/java/meerkat/Registry/RelevantDataCallBack.java +++ b/voter-registry/src/main/java/meerkat/Registry/RelevantDataCallBack.java @@ -79,6 +79,7 @@ public class RelevantDataCallBack implements ClientCallback msg) { try { List messages = ConvertToVoterRegistryMessages(validate(msg)); + if(isAddToGroupsList(msg)) { Map map = GetLatestGroupsActions(messages); List groupsOfUser = GetListOfGroupIds(map); diff --git a/voter-registry/src/test/java/SimpleRegistryTest.java b/voter-registry/src/test/java/SimpleRegistryTest.java index 9b75d29..60ce8c3 100644 --- a/voter-registry/src/test/java/SimpleRegistryTest.java +++ b/voter-registry/src/test/java/SimpleRegistryTest.java @@ -2,15 +2,17 @@ import com.google.protobuf.InvalidProtocolBufferException; import junit.framework.TestCase; import meerkat.Registry.CollectionMessagesUtils; import meerkat.Registry.RegistryTags; -import meerkat.VoterRegistry; import meerkat.SimpleRegistry; -import meerkat.protobuf.VoterRegistry.*; import meerkat.VoterRegistryMessage; import meerkat.bulletinboard.BulletinBoardClient; import meerkat.bulletinboard.ThreadedBulletinBoardClient; import meerkat.crypto.concrete.ECDSASignature; import meerkat.protobuf.BulletinBoardAPI.BulletinBoardMessage; import meerkat.protobuf.BulletinBoardAPI.MessageFilterList; +import meerkat.protobuf.VoterRegistry.GroupID; +import meerkat.protobuf.VoterRegistry.VoterGroup; +import meerkat.protobuf.VoterRegistry.VoterID; +import meerkat.protobuf.VoterRegistry.VoterInfo; import meerkat.protobuf.Voting; import java.io.InputStream; @@ -45,7 +47,7 @@ public class SimpleRegistryTest extends TestCase { public static String KEYFILE_PASSWORD = "secret"; Semaphore jobSemaphore; - class DummyRegistryCallBackHandler implements VoterRegistry.RegistryCallBack{ + class DummyRegistryCallBackHandler implements meerkat.VoterRegistry.RegistryCallBack{ public int counter; public T data; @@ -167,7 +169,8 @@ public class SimpleRegistryTest extends TestCase { String id = new BigInteger(130, random).toString(32); String data = new BigInteger(130, random).toString(32); - VoterInfo voterInfo = VoterInfo.newBuilder().setId(VoterID.newBuilder().setId(id)).setInfo(data).build(); + VoterInfo voterInfo = VoterInfo.newBuilder(). + setId(VoterID.newBuilder().setId(id)).setInfo(data).build(); SimpleRegistry registry = new SimpleRegistry(signer, bulletinBoardClient, certStream); registry.AddVoter(voterInfo, handler); @@ -223,7 +226,8 @@ public class SimpleRegistryTest extends TestCase { String voterId = new BigInteger(130, random).toString(32); String groupId = new BigInteger(130, random).toString(32); - VoterGroup voterInfo = VoterGroup.newBuilder().setVoterId(VoterID.newBuilder().setId(voterId)) + VoterGroup voterInfo = VoterGroup.newBuilder() + .setVoterId(VoterID.newBuilder().setId(voterId)) .setGroupId(GroupID.newBuilder().setId(groupId)).build(); SimpleRegistry registry = new SimpleRegistry(signer, bulletinBoardClient, certStream); @@ -256,7 +260,8 @@ public class SimpleRegistryTest extends TestCase { String voterId = new BigInteger(130, random).toString(32); String groupId = new BigInteger(130, random).toString(32); - VoterGroup voterInfo = VoterGroup.newBuilder().setVoterId(VoterID.newBuilder().setId(voterId)) + VoterGroup voterInfo = VoterGroup.newBuilder() + .setVoterId(VoterID.newBuilder().setId(voterId)) .setGroupId(GroupID.newBuilder().setId(groupId)).build(); this.certStream = getClass().getResourceAsStream(CERT1_PEM_EXAMPLE); @@ -285,7 +290,8 @@ public class SimpleRegistryTest extends TestCase { String id = new BigInteger(130, random).toString(32); String data = new BigInteger(130, random).toString(32); - VoterInfo voterInfo = VoterInfo.newBuilder().setId(VoterID.newBuilder().setId(id)).setInfo(data).build(); + VoterInfo voterInfo = VoterInfo.newBuilder(). + setId(VoterID.newBuilder().setId(id)).setInfo(data).build(); SimpleRegistry registry = new SimpleRegistry(signer, bulletinBoardClient, certStream); registry.AddVoter(voterInfo, handler); @@ -296,9 +302,11 @@ public class SimpleRegistryTest extends TestCase { DummyRegistryCallBackHandler personalHandler = new DummyRegistryCallBackHandler<>(); registry.GetPersonIDDetails(VoterID.newBuilder().setId(id).build(), personalHandler); - jobSemaphore.acquire(); + + jobSemaphore.acquire(1); assertEquals(RegistryTags.ID_TAG + id, personalHandler.data.GetWantedTagFromBasicMessage(RegistryTags.ID_TAG.toString())); assertEquals(data,personalHandler.data.base.getData().toStringUtf8()); } } +