From 298dd5bf6eec1376581934221d225ccd6d3641f2 Mon Sep 17 00:00:00 2001 From: Vladimir Eliezer Tokarev Date: Fri, 19 Feb 2016 06:18:28 -0800 Subject: [PATCH] Refactoring the code of voter-registry according to Arbel Peled CR --- .../src/main/java/meerkat/BooleanHandler.java | 24 +++++++++ .../java/meerkat/RelevantDataCallBack.java | 51 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 voter-registry/src/main/java/meerkat/BooleanHandler.java create mode 100644 voter-registry/src/main/java/meerkat/RelevantDataCallBack.java diff --git a/voter-registry/src/main/java/meerkat/BooleanHandler.java b/voter-registry/src/main/java/meerkat/BooleanHandler.java new file mode 100644 index 0000000..20a63e9 --- /dev/null +++ b/voter-registry/src/main/java/meerkat/BooleanHandler.java @@ -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); + } +} diff --git a/voter-registry/src/main/java/meerkat/RelevantDataCallBack.java b/voter-registry/src/main/java/meerkat/RelevantDataCallBack.java new file mode 100644 index 0000000..0881fea --- /dev/null +++ b/voter-registry/src/main/java/meerkat/RelevantDataCallBack.java @@ -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> { + public VoterRegistry.RegistryCallBack callback; + + public RelevantDataCallBack(VoterRegistry.RegistryCallBack callback) { + this.callback = callback; + } + + private boolean isAddToGroupsList(List msg) { + return msg.get(0).getMsg().getTagList().get(0).contains(RegistryTags.GROUP_ID_TAG.toString()); + } + + @Override + public void handleCallback(List msg) { + List messages = ConvertToVoterRegistryMessages(msg); + + if(isAddToGroupsList(msg)){ + try { + Map 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); + } +}