Changed the SimpleRegistry

The new Simple Registry works according to the RegistryInstance interface
Voter-Registry
Vladimir Eliezer Tokarev 2016-01-23 05:51:41 -08:00
parent c30ea072f2
commit 68caeee114
3 changed files with 20 additions and 16 deletions

View File

@ -14,7 +14,7 @@ public interface RegistryInstance {
* @param callBack when the adding voter done callBack.HandleVoterAdded will be called
* @return void
*/
abstract void AddVoter(String voterID, String personalData, RegistryCallBack callBack);
void AddVoter(String voterID, String personalData, RegistryCallBack callBack);
/**
* Adding given voter to given group
@ -24,7 +24,7 @@ public interface RegistryInstance {
* @param callBack when the adding voter done callBack.HandleVoterAddedToGroup will be called
* @return true if the adding action succeeded else return false
*/
abstract void AddToGroup(String voterID, String groupID, RegistryCallBack callBack);
void AddToGroup(String voterID, String groupID, RegistryCallBack callBack);
/**
* Removes given voter from given group
@ -34,7 +34,7 @@ public interface RegistryInstance {
* @param callBack when the adding voter done callBack.HandleVoterRemovedFromGroup will be called
* @return true if the removing action succeeded else return false
*/
abstract void RemoveFromGroup(String voterID, String groupID, RegistryCallBack callBack);
void RemoveFromGroup(String voterID, String groupID, RegistryCallBack callBack);
/**
* Sets that the voter have voted
@ -43,7 +43,7 @@ public interface RegistryInstance {
* @param callBack when the adding voter done callBack.HandleSetVoted will be called
* @return true if the set voted succeed else false
*/
abstract void SetVoted(String id, RegistryCallBack callBack);
void SetVoted(String id, RegistryCallBack callBack);
/**
* Requests all the groups that the given id voter is in
@ -52,7 +52,7 @@ public interface RegistryInstance {
* @param callBack when the adding voter done callBack.HandleVoterGroups will be called
* @return list of groups ids (or names), if the method fails its empty
*/
abstract void GetGroups(String id, RegistryCallBack callBack);
void GetGroups(String id, RegistryCallBack callBack);
/**
* Retrieves list of strings that represents voter
@ -61,6 +61,6 @@ public interface RegistryInstance {
* @param callBack when the adding voter done callBack.HandleVoterInfo will be called
* @return list of strings (empty list if the lookup failed)
*/
abstract void GetPersonIDDetails(String id, RegistryCallBack callBack);
void GetPersonIDDetails(String id, RegistryCallBack callBack);
}

View File

@ -23,7 +23,6 @@ import static util.CollectionMessagesUtils.*;
public class SimpleRegistry implements RegistryInstance{
protected Encryption signatory;
protected SimpleBulletinBoardClient communicator;
public SimpleRegistry(Encryption signatory, SimpleBulletinBoardClient communicator) {
@ -31,8 +30,12 @@ public class SimpleRegistry implements RegistryInstance{
this.communicator = communicator;
}
private List<String> wantedInformation;
private boolean methodSucceeded;
/**
* Creates BulletinBoardMessage with signed basicMessage and UnsignedBulletinBoardMessage that contains the basic message
*
* @param basicMessage BasicMessage
* @return BulletinBoardAPI.BulletinBoardMessage
*/
@ -42,7 +45,7 @@ public class SimpleRegistry implements RegistryInstance{
BulletinBoardAPI.BulletinBoardMessage.newBuilder();
Crypto.RerandomizableEncryptedMessage encryptedMessage =
signatory.encrypt(basicMessage, signatory.generateRandomness(new Random()));
signatory.encrypt(basicMessage, signatory.generateRandomness(new Random()));
Crypto.Signature.Builder messageSignature = Crypto.Signature.newBuilder();
messageSignature.mergeFrom(encryptedMessage);
@ -52,7 +55,7 @@ public class SimpleRegistry implements RegistryInstance{
return bulletinBoardMessage.build();
} catch (IOException e) {
return null;
return null;
}
}
@ -94,7 +97,7 @@ public class SimpleRegistry implements RegistryInstance{
* @param Message the massage to post
* @return true when the post was successful else false
*/
private boolean SafePost(BulletinBoardAPI.BulletinBoardMessage Message){
private boolean SafePost(BulletinBoardAPI.BulletinBoardMessage Message) {
try {
communicator.postMessage(Message);
return true;
@ -149,7 +152,7 @@ public class SimpleRegistry implements RegistryInstance{
public void GetGroups(String id, RegistryCallBack callback) {
try {
List<String> GroupsActionsTags = new ArrayList<String>(){{
List<String> GroupsActionsTags = new ArrayList<String>() {{
add(RegistryTags.ID_TAG + " " + id);
add(RegistryTags.GROUP_ACTION_TAG + " " + RegistryTags.REMOVE_FROM_GROUP_TAG);
add(RegistryTags.GROUP_ACTION_TAG + " " + RegistryTags.ADD_TO_GROUP_TAG);
@ -166,13 +169,13 @@ public class SimpleRegistry implements RegistryInstance{
public void GetPersonIDDetails(String id, RegistryCallBack callback) {
try {
List<String> GroupsActionsTags = new ArrayList<String>(){{
List<String> GroupsActionsTags = new ArrayList<String>() {{
add(RegistryTags.ID_TAG + " " + id);
add(RegistryTags.VOTER_ENTRY_TAG.toString());
}};
List<VoterRegistryMessage> voterRegistryMessages = GetRelevantVoterRegistryMessages(GroupsActionsTags);
List<VoterRegistryMessage> voterRegistryMessages = GetRelevantVoterRegistryMessages(GroupsActionsTags);
VoterRegistryMessage LatestMessage = GetLatestMessage(voterRegistryMessages);
VoterRegistryMessage LatestMessage = GetLatestMessage(voterRegistryMessages);
callback.HandleVoterInfo(LatestMessage.tagsToStringList());
} catch (InvalidProtocolBufferException | ParseException e) {

View File

@ -18,11 +18,12 @@ import java.util.stream.Collectors;
public abstract class CollectionMessagesUtils {
/**
* Converts lost of UnsignedBulletinBoardMessage to VoterRegistryMessags
* Converts lost of UnsignedBulletinBoardMessage to VoterRegistryMessages
* @param messages list<VoterRegistryMessage>
* @return List<VoterRegistryMessage>
*/
public static List<VoterRegistryMessage> ConvertToVoterRegistryMessages(List<BulletinBoardAPI.UnsignedBulletinBoardMessage> messages){
public static List<VoterRegistryMessage> ConvertToVoterRegistryMessages(
List<BulletinBoardAPI.UnsignedBulletinBoardMessage> messages){
return messages.stream().map(VoterRegistryMessage::new).collect(Collectors.toList());
}