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 * @param callBack when the adding voter done callBack.HandleVoterAdded will be called
* @return void * @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 * 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 * @param callBack when the adding voter done callBack.HandleVoterAddedToGroup will be called
* @return true if the adding action succeeded else return false * @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 * 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 * @param callBack when the adding voter done callBack.HandleVoterRemovedFromGroup will be called
* @return true if the removing action succeeded else return false * @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 * 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 * @param callBack when the adding voter done callBack.HandleSetVoted will be called
* @return true if the set voted succeed else false * @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 * 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 * @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 * @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 * 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 * @param callBack when the adding voter done callBack.HandleVoterInfo will be called
* @return list of strings (empty list if the lookup failed) * @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{ public class SimpleRegistry implements RegistryInstance{
protected Encryption signatory; protected Encryption signatory;
protected SimpleBulletinBoardClient communicator; protected SimpleBulletinBoardClient communicator;
public SimpleRegistry(Encryption signatory, SimpleBulletinBoardClient communicator) { public SimpleRegistry(Encryption signatory, SimpleBulletinBoardClient communicator) {
@ -31,8 +30,12 @@ public class SimpleRegistry implements RegistryInstance{
this.communicator = communicator; this.communicator = communicator;
} }
private List<String> wantedInformation;
private boolean methodSucceeded;
/** /**
* Creates BulletinBoardMessage with signed basicMessage and UnsignedBulletinBoardMessage that contains the basic message * Creates BulletinBoardMessage with signed basicMessage and UnsignedBulletinBoardMessage that contains the basic message
*
* @param basicMessage BasicMessage * @param basicMessage BasicMessage
* @return BulletinBoardAPI.BulletinBoardMessage * @return BulletinBoardAPI.BulletinBoardMessage
*/ */
@ -94,7 +97,7 @@ public class SimpleRegistry implements RegistryInstance{
* @param Message the massage to post * @param Message the massage to post
* @return true when the post was successful else false * @return true when the post was successful else false
*/ */
private boolean SafePost(BulletinBoardAPI.BulletinBoardMessage Message){ private boolean SafePost(BulletinBoardAPI.BulletinBoardMessage Message) {
try { try {
communicator.postMessage(Message); communicator.postMessage(Message);
return true; return true;
@ -149,7 +152,7 @@ public class SimpleRegistry implements RegistryInstance{
public void GetGroups(String id, RegistryCallBack callback) { public void GetGroups(String id, RegistryCallBack callback) {
try { try {
List<String> GroupsActionsTags = new ArrayList<String>(){{ List<String> GroupsActionsTags = new ArrayList<String>() {{
add(RegistryTags.ID_TAG + " " + id); add(RegistryTags.ID_TAG + " " + id);
add(RegistryTags.GROUP_ACTION_TAG + " " + RegistryTags.REMOVE_FROM_GROUP_TAG); add(RegistryTags.GROUP_ACTION_TAG + " " + RegistryTags.REMOVE_FROM_GROUP_TAG);
add(RegistryTags.GROUP_ACTION_TAG + " " + RegistryTags.ADD_TO_GROUP_TAG); add(RegistryTags.GROUP_ACTION_TAG + " " + RegistryTags.ADD_TO_GROUP_TAG);
@ -166,7 +169,7 @@ public class SimpleRegistry implements RegistryInstance{
public void GetPersonIDDetails(String id, RegistryCallBack callback) { public void GetPersonIDDetails(String id, RegistryCallBack callback) {
try { try {
List<String> GroupsActionsTags = new ArrayList<String>(){{ List<String> GroupsActionsTags = new ArrayList<String>() {{
add(RegistryTags.ID_TAG + " " + id); add(RegistryTags.ID_TAG + " " + id);
add(RegistryTags.VOTER_ENTRY_TAG.toString()); add(RegistryTags.VOTER_ENTRY_TAG.toString());
}}; }};

View File

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