Refactoring the code of voter-registry according to Arbel Peled CR
parent
298dd5bf6e
commit
64ccaff508
|
@ -4,19 +4,32 @@ import meerkat.bulletinboard.BulletinBoardClient;
|
|||
|
||||
/**
|
||||
* Created by Vladimir Eliezer Tokarev on 2/19/2016.
|
||||
* Handles the the after post situation of a BulletinBoardClient
|
||||
* Handles the the after post state of VoterRegistry methods (that uses bulletinBoardClient to communicate with the server)
|
||||
*/
|
||||
public class BooleanHandler implements BulletinBoardClient.ClientCallback {
|
||||
public VoterRegistry.RegistryCallBack callback;
|
||||
|
||||
/**
|
||||
* Init BooleanHandler
|
||||
* @param callback voter registry callback object
|
||||
*/
|
||||
public BooleanHandler(VoterRegistry.RegistryCallBack callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the callback HandleResult method with passed object from bulletinBoardClient
|
||||
* @param msg the message that the bulletinBoardClient passes to the callback
|
||||
*/
|
||||
@Override
|
||||
public void handleCallback(Object msg) {
|
||||
callback.HandleResult(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the callback HandleResult method with false because the post method failed
|
||||
* @param t the exception data that have been thrown during the failure of the post method
|
||||
*/
|
||||
@Override
|
||||
public void handleFailure(Throwable t) {
|
||||
callback.HandleResult(false);
|
||||
|
|
|
@ -17,14 +17,30 @@ import static util.CollectionMessagesUtils.*;
|
|||
public class RelevantDataCallBack implements BulletinBoardClient.ClientCallback<List<BulletinBoardAPI.BulletinBoardMessage>> {
|
||||
public VoterRegistry.RegistryCallBack callback;
|
||||
|
||||
/**
|
||||
* Init BooleanHandler
|
||||
* @param callback voter registry callback object
|
||||
*/
|
||||
public RelevantDataCallBack(VoterRegistry.RegistryCallBack callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given list have tags of type GROUP_ID_TAG or else
|
||||
* @param msg List<BulletinBoardAPI.BulletinBoardMessage>
|
||||
* @return true if the messages are with GROUP_ID_TAG tags
|
||||
*/
|
||||
private boolean isAddToGroupsList(List<BulletinBoardAPI.BulletinBoardMessage> msg) {
|
||||
return msg.get(0).getMsg().getTagList().get(0).contains(RegistryTags.GROUP_ID_TAG.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the list of messages is of type GROUP_ID_TAG if it is then calls
|
||||
* HandleResult with mapping of the latest groups, else calls to HandleResult with
|
||||
* the latest tag from this list (in case of personal data)
|
||||
*
|
||||
* @param msg List<BulletinBoardAPI.BulletinBoardMessage>
|
||||
*/
|
||||
@Override
|
||||
public void handleCallback(List<BulletinBoardAPI.BulletinBoardMessage> msg) {
|
||||
List<VoterRegistryMessage> messages = ConvertToVoterRegistryMessages(msg);
|
||||
|
@ -44,6 +60,10 @@ public class RelevantDataCallBack implements BulletinBoardClient.ClientCallback<
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the callback HandleResult method with false because the post method failed
|
||||
* @param t the exception data that have been thrown during the failure of the post method
|
||||
*/
|
||||
@Override
|
||||
public void handleFailure(Throwable t) {
|
||||
callback.HandleResult(null);
|
||||
|
|
|
@ -23,7 +23,6 @@ public class SimpleRegistry implements VoterRegistry{
|
|||
|
||||
protected DigitalSignature signatory;
|
||||
protected BulletinBoardClient bulletinBoardClient ;
|
||||
protected RegistryCallBack callback;
|
||||
|
||||
public SimpleRegistry(DigitalSignature signatory, BulletinBoardClient communicator) {
|
||||
this.signatory = signatory;
|
||||
|
@ -31,7 +30,8 @@ public class SimpleRegistry implements VoterRegistry{
|
|||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return BulletinBoardMessage
|
||||
|
@ -124,7 +124,8 @@ public class SimpleRegistry implements VoterRegistry{
|
|||
List<String> GroupsActionsTags = new ArrayList<String>() {{
|
||||
add(RegistryTags.GROUP_ID_TAG + groupID.getId());
|
||||
}};
|
||||
bulletinBoardClient.readMessages(GetRelevantMessagesFilters(GroupsActionsTags), new RelevantDataCallBack(callback));
|
||||
bulletinBoardClient.readMessages(GetRelevantMessagesFilters(GroupsActionsTags),
|
||||
new RelevantDataCallBack(callback));
|
||||
}
|
||||
|
||||
public void GetPersonIDDetails(RegistryMessages.VoterID voterID, RegistryCallBack callback) {
|
||||
|
@ -132,6 +133,7 @@ public class SimpleRegistry implements VoterRegistry{
|
|||
add(RegistryTags.ID_TAG + voterID.getId());
|
||||
add(RegistryTags.VOTER_ENTRY_TAG.toString());
|
||||
}};
|
||||
bulletinBoardClient.readMessages(GetRelevantMessagesFilters(GroupsActionsTags), new PersonalDataCallBack(callback));
|
||||
bulletinBoardClient.readMessages(GetRelevantMessagesFilters(GroupsActionsTags),
|
||||
new RelevantDataCallBack(callback));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import util.RegistryTags;
|
|||
|
||||
import java.sql.Timestamp;
|
||||
import java.text.ParseException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Vladimir Eliezer Tokarev on 1/15.2016
|
||||
|
@ -70,13 +69,4 @@ public class VoterRegistryMessage {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* converts the messages tags to list of strings
|
||||
*
|
||||
* @return List of strings
|
||||
*/
|
||||
public List<String> tagsToStringList() {
|
||||
return base.getTagList();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue