Refactoring the code of voter-registry according to Arbel Peled CR
parent
bb4cc5b087
commit
298dd5bf6e
|
@ -0,0 +1,24 @@
|
|||
package meerkat;
|
||||
|
||||
import meerkat.bulletinboard.BulletinBoardClient;
|
||||
|
||||
/**
|
||||
* Created by Vladimir Eliezer Tokarev on 2/19/2016.
|
||||
* Handles the the after post situation of a BulletinBoardClient
|
||||
*/
|
||||
public class BooleanHandler implements BulletinBoardClient.ClientCallback {
|
||||
public VoterRegistry.RegistryCallBack callback;
|
||||
public BooleanHandler(VoterRegistry.RegistryCallBack callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleCallback(Object msg) {
|
||||
callback.HandleResult(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleFailure(Throwable t) {
|
||||
callback.HandleResult(false);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package meerkat;
|
||||
|
||||
import meerkat.bulletinboard.BulletinBoardClient;
|
||||
import meerkat.protobuf.BulletinBoardAPI;
|
||||
import util.RegistryTags;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static util.CollectionMessagesUtils.*;
|
||||
|
||||
/**
|
||||
* Created by Vladimir Eliezer Tokarev on 2/19/2016.
|
||||
* Object that handles the GetGroups or the GetPersonIDDetails of the simpleRegistry
|
||||
*/
|
||||
public class RelevantDataCallBack implements BulletinBoardClient.ClientCallback<List<BulletinBoardAPI.BulletinBoardMessage>> {
|
||||
public VoterRegistry.RegistryCallBack callback;
|
||||
|
||||
public RelevantDataCallBack(VoterRegistry.RegistryCallBack callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
private boolean isAddToGroupsList(List<BulletinBoardAPI.BulletinBoardMessage> msg) {
|
||||
return msg.get(0).getMsg().getTagList().get(0).contains(RegistryTags.GROUP_ID_TAG.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleCallback(List<BulletinBoardAPI.BulletinBoardMessage> msg) {
|
||||
List<VoterRegistryMessage> messages = ConvertToVoterRegistryMessages(msg);
|
||||
|
||||
if(isAddToGroupsList(msg)){
|
||||
try {
|
||||
Map<String, VoterRegistryMessage> map = GetLatestGroupsActions(messages);
|
||||
callback.HandleResult(GetListOfGroupIds(map));
|
||||
} catch (ParseException e) {
|
||||
callback.HandleResult(null);
|
||||
}
|
||||
}
|
||||
try {
|
||||
callback.HandleResult(GetLatestMessage(messages));
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleFailure(Throwable t) {
|
||||
callback.HandleResult(null);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue