diff --git a/voter-registry/build.gradle b/voter-registry/build.gradle index ac67f25..8472906 100644 --- a/voter-registry/build.gradle +++ b/voter-registry/build.gradle @@ -30,7 +30,7 @@ ext { nexusPassword = project.hasProperty('nexusPassword') ? project.property('nexusPassword') : "" } -description = "Meerkat Voter Registry application" +description = "Meerkat Voter RegistryUtils application" // Your project version version = "0.0" diff --git a/voter-registry/src/main/java/meerkat/MessageValidator.java b/voter-registry/src/main/java/meerkat/MessageValidator.java index b1da884..1f5c38c 100644 --- a/voter-registry/src/main/java/meerkat/MessageValidator.java +++ b/voter-registry/src/main/java/meerkat/MessageValidator.java @@ -1,10 +1,12 @@ package meerkat; +import java.util.List; + /** * Provides the validation option for objects * @param */ -public interface MessageValidator +public interface MessageValidator > { /** * Throws ValidationError when no part of the object is valid else return the valid part diff --git a/voter-registry/src/main/java/meerkat/Registry.java b/voter-registry/src/main/java/meerkat/Registry.java index 7df5c23..5a64595 100644 --- a/voter-registry/src/main/java/meerkat/Registry.java +++ b/voter-registry/src/main/java/meerkat/Registry.java @@ -1,10 +1,10 @@ package meerkat; import com.google.protobuf.Timestamp; -import meerkat.Registry.BooleanCallBack; -import meerkat.Registry.CollectionMessagesUtils; -import meerkat.Registry.RegistryTags; -import meerkat.Registry.RelevantDataCallBack; +import meerkat.RegistryUtils.MessagesCallBack; +import meerkat.RegistryUtils.CollectionMessagesUtils; +import meerkat.RegistryUtils.RegistryTags; +import meerkat.RegistryUtils.LatestMessagesCallBack; import meerkat.bulletinboard.AsyncBulletinBoardClient; import meerkat.crypto.DigitalSignature; import meerkat.protobuf.BulletinBoardAPI.BulletinBoardMessage; @@ -70,7 +70,7 @@ public class Registry implements VoterRegistry{ .addTag(RegistryTags.VOTER_DATA_TAG + voterInfo.getInfo()) .setTimestamp(Timestamp.newBuilder().setNanos((int) System.nanoTime()).build()); - bulletinBoardClient.postMessage(CreateBulletinBoardMessage(basicMessage.build()), new BooleanCallBack(callback)); + bulletinBoardClient.postMessage(CreateBulletinBoardMessage(basicMessage.build()), new MessagesCallBack(callback)); } public void AddToGroups(VoterRegistryMessage voterGroup, RegistryCallBack callback) { @@ -85,7 +85,7 @@ public class Registry implements VoterRegistry{ basicMessage.addTag(RegistryTags.GROUP_ID_TAG + voterGroup.getGroupID(i).getId()); } - bulletinBoardClient.postMessage(CreateBulletinBoardMessage(basicMessage.build()), new BooleanCallBack(callback)); + bulletinBoardClient.postMessage(CreateBulletinBoardMessage(basicMessage.build()), new MessagesCallBack(callback)); } public void SetVoted(VoterID voterId, RegistryCallBack callback) { @@ -95,7 +95,7 @@ public class Registry implements VoterRegistry{ .addTag(RegistryTags.VOTE_ACTION_TAG) .setTimestamp(Timestamp.newBuilder().setNanos((int) System.nanoTime()).build()); - bulletinBoardClient.postMessage(CreateBulletinBoardMessage(basicMessage.build()), new BooleanCallBack(callback)); + bulletinBoardClient.postMessage(CreateBulletinBoardMessage(basicMessage.build()), new MessagesCallBack(callback)); } public void GetGroups(GroupID groupID, RegistryCallBack callback) { @@ -103,7 +103,7 @@ public class Registry implements VoterRegistry{ add(RegistryTags.GROUP_ID_TAG + groupID.getId()); }}; bulletinBoardClient.readMessages(CollectionMessagesUtils.GenerateFiltersFromTags(GroupsActionsTags), - new RelevantDataCallBack(callback, signer, signature, certificateStream)); + new LatestMessagesCallBack(callback, signer, signature, certificateStream)); } public void GetPersonIDDetails(VoterID voterID, RegistryCallBack callback) { @@ -112,6 +112,6 @@ public class Registry implements VoterRegistry{ add(RegistryTags.VOTER_ENTRY_TAG); }}; bulletinBoardClient.readMessages(CollectionMessagesUtils.GenerateFiltersFromTags(GroupsActionsTags), - new RelevantDataCallBack(callback, signer, signature, certificateStream)); + new LatestMessagesCallBack(callback, signer, signature, certificateStream)); } } diff --git a/voter-registry/src/main/java/meerkat/Registry/CollectionMessagesUtils.java b/voter-registry/src/main/java/meerkat/RegistryUtils/CollectionMessagesUtils.java similarity index 91% rename from voter-registry/src/main/java/meerkat/Registry/CollectionMessagesUtils.java rename to voter-registry/src/main/java/meerkat/RegistryUtils/CollectionMessagesUtils.java index 385df42..ea304a9 100644 --- a/voter-registry/src/main/java/meerkat/Registry/CollectionMessagesUtils.java +++ b/voter-registry/src/main/java/meerkat/RegistryUtils/CollectionMessagesUtils.java @@ -1,8 +1,7 @@ -package meerkat.Registry; +package meerkat.RegistryUtils; import com.google.protobuf.InvalidProtocolBufferException; import meerkat.protobuf.BulletinBoardAPI.*; -import meerkat.protobuf.VoterRegistry; import java.text.ParseException; import java.util.*; @@ -46,16 +45,9 @@ public abstract class CollectionMessagesUtils { */ private static boolean FirstBeforeSecond(BulletinBoardMessage message1, BulletinBoardMessage message2) throws InvalidProtocolBufferException { - try { - long firstCreationTime = VoterRegistry.VoterRegistryMessage.newBuilder() - .mergeFrom(message1.getMsg().getData()).build().getCreationMiliseconds(); - long secondCreationTime = VoterRegistry.VoterRegistryMessage.newBuilder() - .mergeFrom(message2.getMsg().getData()).build().getCreationMiliseconds(); + int firstCreationTime = message1.getMsg().getTimestamp().getNanos(); + long secondCreationTime = message2.getMsg().getTimestamp().getNanos(); return firstCreationTime < secondCreationTime; - } catch (InvalidProtocolBufferException e) { - e.printStackTrace(); - throw e; - } } /** diff --git a/voter-registry/src/main/java/meerkat/Registry/RelevantDataCallBack.java b/voter-registry/src/main/java/meerkat/RegistryUtils/LatestMessagesCallBack.java similarity index 88% rename from voter-registry/src/main/java/meerkat/Registry/RelevantDataCallBack.java rename to voter-registry/src/main/java/meerkat/RegistryUtils/LatestMessagesCallBack.java index 85e4c72..b12934a 100644 --- a/voter-registry/src/main/java/meerkat/Registry/RelevantDataCallBack.java +++ b/voter-registry/src/main/java/meerkat/RegistryUtils/LatestMessagesCallBack.java @@ -1,4 +1,4 @@ -package meerkat.Registry; +package meerkat.RegistryUtils; import com.google.common.util.concurrent.FutureCallback; import com.google.protobuf.InvalidProtocolBufferException; @@ -18,7 +18,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import static meerkat.Registry.CollectionMessagesUtils.*; +import static meerkat.RegistryUtils.CollectionMessagesUtils.*; /** * TODO : add logging @@ -26,24 +26,24 @@ import static meerkat.Registry.CollectionMessagesUtils.*; /** * Created by Vladimir Eliezer Tokarev on 2/19/2016. - * Object that handles the GetGroups or the GetPersonIDDetails of the simpleRegistry + * Gets latest data from given List */ -public class RelevantDataCallBack implements FutureCallback>, MessageValidator> { +public class LatestMessagesCallBack implements FutureCallback>, MessageValidator> { public RegistryCallBack callback; protected DigitalSignature validator; protected Crypto.Signature signature; protected InputStream certificateStream; /** - * Init BooleanCallBack + * Init MessagesCallBack * @param callback voter registry callback object * @param validator DigitalSignature object * @param signature Crypto.Signature object */ - public RelevantDataCallBack(RegistryCallBack callback, - DigitalSignature validator, - Crypto.Signature signature, - InputStream certificateStream) { + public LatestMessagesCallBack(RegistryCallBack callback, + DigitalSignature validator, + Crypto.Signature signature, + InputStream certificateStream) { this.callback = callback; this.validator = validator; this.signature = signature; diff --git a/voter-registry/src/main/java/meerkat/Registry/BooleanCallBack.java b/voter-registry/src/main/java/meerkat/RegistryUtils/MessagesCallBack.java similarity index 67% rename from voter-registry/src/main/java/meerkat/Registry/BooleanCallBack.java rename to voter-registry/src/main/java/meerkat/RegistryUtils/MessagesCallBack.java index 7a41eba..525f2b3 100644 --- a/voter-registry/src/main/java/meerkat/Registry/BooleanCallBack.java +++ b/voter-registry/src/main/java/meerkat/RegistryUtils/MessagesCallBack.java @@ -1,7 +1,6 @@ -package meerkat.Registry; +package meerkat.RegistryUtils; import com.google.common.util.concurrent.FutureCallback; -import meerkat.MessageValidator; import meerkat.VoterRegistry; /** @@ -12,14 +11,15 @@ import meerkat.VoterRegistry; * Created by Vladimir Eliezer Tokarev on 2/19/2016. * Handles the the after post state of VoterRegistry methods (that uses bulletinBoardClient to communicate with the server) */ -public class BooleanCallBack implements FutureCallback, MessageValidator { +public class MessagesCallBack implements FutureCallback +{ public VoterRegistry.RegistryCallBack callback; /** - * Init BooleanCallBack + * Init MessagesCallBack * @param callback voter registry callback object */ - public BooleanCallBack(VoterRegistry.RegistryCallBack callback) { + public MessagesCallBack(VoterRegistry.RegistryCallBack callback) { this.callback = callback; } @@ -42,15 +42,4 @@ public class BooleanCallBack implements FutureCallback, MessageValidato public void onFailure(Throwable t) { callback.HandleFailure(t); } - - /** - * always return true because there no n - * @param object object which will be checked - * @return alwyas true - * @throws ValidationError - */ - @Override - public Boolean validate(Boolean object) throws ValidationError { - return true; - } } diff --git a/voter-registry/src/main/java/meerkat/Registry/RegistryTags.java b/voter-registry/src/main/java/meerkat/RegistryUtils/RegistryTags.java similarity index 94% rename from voter-registry/src/main/java/meerkat/Registry/RegistryTags.java rename to voter-registry/src/main/java/meerkat/RegistryUtils/RegistryTags.java index 13fbadb..e0960cf 100644 --- a/voter-registry/src/main/java/meerkat/Registry/RegistryTags.java +++ b/voter-registry/src/main/java/meerkat/RegistryUtils/RegistryTags.java @@ -1,4 +1,4 @@ -package meerkat.Registry; +package meerkat.RegistryUtils; /** diff --git a/voter-registry/src/test/java/SimpleRegistryTest.java b/voter-registry/src/test/java/SimpleRegistryTest.java index e0692a4..beb4d62 100644 --- a/voter-registry/src/test/java/SimpleRegistryTest.java +++ b/voter-registry/src/test/java/SimpleRegistryTest.java @@ -2,8 +2,8 @@ import com.google.common.util.concurrent.FutureCallback; import com.google.protobuf.InvalidProtocolBufferException; import junit.framework.TestCase; import meerkat.Registry; -import meerkat.Registry.CollectionMessagesUtils; -import meerkat.Registry.RegistryTags; +import meerkat.RegistryUtils.CollectionMessagesUtils; +import meerkat.RegistryUtils.RegistryTags; import meerkat.bulletinboard.AsyncBulletinBoardClient; import meerkat.bulletinboard.ThreadedBulletinBoardClient; import meerkat.crypto.concrete.ECDSASignature; @@ -29,7 +29,7 @@ import java.util.concurrent.Semaphore; /** * Created by Vladimir Eliezer Tokarev on 1/16/2016. - * Tests the Simple Registry contents + * Tests the Simple RegistryUtils contents * NOTE: for most of this tests to pass there should run BulletinBoardServer * that should be reachable on BULLETIN_BOARD_SERVER_ADDRESS */ @@ -114,7 +114,7 @@ public class SimpleRegistryTest extends TestCase { } /** - * Initialize Registry object + * Initialize RegistryUtils object */ public void setUp() { SetSigner(); @@ -130,7 +130,7 @@ public class SimpleRegistryTest extends TestCase { try { new Registry(signer, bulletinBoardClient, certStream); } catch (Exception e) { - assert false : "While creating the Registry exception have been thrown " + e; + assert false : "While creating the RegistryUtils exception have been thrown " + e; } }