Changed the type of the message validator and reformated the classes in an appropriate way.
							parent
							
								
									d9272c9f94
								
							
						
					
					
						commit
						9828832553
					
				|  | @ -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" | ||||
|  |  | |||
|  | @ -1,10 +1,12 @@ | |||
| package meerkat; | ||||
| 
 | ||||
| import java.util.List; | ||||
| 
 | ||||
| /** | ||||
|  * Provides the validation option for objects | ||||
|  * @param <T> | ||||
|  */ | ||||
| public interface MessageValidator<T> | ||||
| public interface MessageValidator <T extends List<?>> | ||||
| { | ||||
|     /** | ||||
|      * Throws ValidationError when no part of the object is valid else return the valid part | ||||
|  |  | |||
|  | @ -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)); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -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; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | @ -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,21 +26,21 @@ 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<BulletinBoardMessage> | ||||
|  */ | ||||
| public class RelevantDataCallBack implements FutureCallback<List<BulletinBoardMessage>>, MessageValidator<List<BulletinBoardMessage>> { | ||||
| public class LatestMessagesCallBack implements FutureCallback<List<BulletinBoardMessage>>, MessageValidator<List<BulletinBoardMessage>> { | ||||
|     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, | ||||
|     public LatestMessagesCallBack(RegistryCallBack callback, | ||||
|                                   DigitalSignature validator, | ||||
|                                   Crypto.Signature signature, | ||||
|                                   InputStream certificateStream) { | ||||
|  | @ -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<Boolean>, MessageValidator<Boolean> { | ||||
| public class MessagesCallBack implements FutureCallback<Boolean> | ||||
| { | ||||
|     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<Boolean>, 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; | ||||
|     } | ||||
| } | ||||
|  | @ -1,4 +1,4 @@ | |||
| package meerkat.Registry; | ||||
| package meerkat.RegistryUtils; | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  | @ -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; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue