Changed the SimpleRegistry to work with UnsignedBulletinBoardMessage

The basicMessage is not needed
Voter-Registry
Vladimir Eliezer Tokarev 2016-01-22 07:47:39 -08:00
parent 0d8e522e93
commit 1815863746
2 changed files with 16 additions and 23 deletions

View File

@ -2,7 +2,6 @@ package meerkat;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.InvalidProtocolBufferException;
import meerkat.ProtobufsMessages.BasicMessage;
import meerkat.ProtobufsMessages.Tag; import meerkat.ProtobufsMessages.Tag;
import meerkat.bulletinboard.SimpleBulletinBoardClient; import meerkat.bulletinboard.SimpleBulletinBoardClient;
import meerkat.comm.CommunicationException; import meerkat.comm.CommunicationException;
@ -60,13 +59,13 @@ public class SimpleRegistry {
* @param tags the tags based on which the messages will be filtered * @param tags the tags based on which the messages will be filtered
* @return List<BulletinBoardAPI.BulletinBoardMessage> * @return List<BulletinBoardAPI.BulletinBoardMessage>
*/ */
private List<BulletinBoardAPI.BulletinBoardMessage> GetRelevantMessages(List<Tag> tags) { private List<BulletinBoardAPI.BulletinBoardMessage> GetRelevantMessages(List<String> tags) {
BulletinBoardAPI.MessageFilterList.Builder filters = BulletinBoardAPI.MessageFilterList.Builder filters =
BulletinBoardAPI.MessageFilterList.newBuilder(); BulletinBoardAPI.MessageFilterList.newBuilder();
for (Tag tag : tags) { for (String tag : tags) {
BulletinBoardAPI.MessageFilter.Builder idFilter = BulletinBoardAPI.MessageFilter.Builder idFilter =
BulletinBoardAPI.MessageFilter.newBuilder().setTag(tag.getContent()); BulletinBoardAPI.MessageFilter.newBuilder().setTag(tag);
filters.addFilter(idFilter); filters.addFilter(idFilter);
} }
@ -79,9 +78,10 @@ public class SimpleRegistry {
* @param tags list of tags that will be used as filters * @param tags list of tags that will be used as filters
* @return List<VoterRegistryMessage> * @return List<VoterRegistryMessage>
*/ */
private List<VoterRegistryMessage> GetRelevantVoterRegistryMessages(List<Tag> tags) throws InvalidProtocolBufferException { private List<VoterRegistryMessage> GetRelevantVoterRegistryMessages(List<String> tags) throws InvalidProtocolBufferException {
List<BulletinBoardAPI.BulletinBoardMessage> relevantMessages = GetRelevantMessages(tags); List<BulletinBoardAPI.BulletinBoardMessage> relevantMessages = GetRelevantMessages(tags);
List<BasicMessage> messages = CollectionMessagesUtils.GetBasicMessagesFromBulletinBoardMessages(relevantMessages); List<BulletinBoardAPI.UnsignedBulletinBoardMessage> messages =
CollectionMessagesUtils.GetUnsignedBulletinBoardMessages(relevantMessages);
return CollectionMessagesUtils.ConvertToVoterRegistryMessages(messages); return CollectionMessagesUtils.ConvertToVoterRegistryMessages(messages);
} }
@ -169,10 +169,11 @@ public class SimpleRegistry {
* @throws CommunicationException, InvalidProtocolBufferException * @throws CommunicationException, InvalidProtocolBufferException
*/ */
public List<String> GetGroups(String id) throws CommunicationException, InvalidProtocolBufferException { public List<String> GetGroups(String id) throws CommunicationException, InvalidProtocolBufferException {
List<Tag> GroupsActionsTags = new ArrayList<>(); List<String> GroupsActionsTags = new ArrayList<String>(){{
GroupsActionsTags.add(Tag.newBuilder().setContent(RegistryTags.ID_TAG + " " + id).build()); add(RegistryTags.ID_TAG + " " + id);
GroupsActionsTags.add(Tag.newBuilder().setContent(RegistryTags.GROUP_ACTION_TAG + " " + RegistryTags.REMOVE_FROM_GROUP_TAG).build()); add(RegistryTags.GROUP_ACTION_TAG + " " + RegistryTags.REMOVE_FROM_GROUP_TAG);
GroupsActionsTags.add(Tag.newBuilder().setContent(RegistryTags.GROUP_ACTION_TAG + " " + RegistryTags.ADD_TO_GROUP_TAG).build()); add(RegistryTags.GROUP_ACTION_TAG + " " + RegistryTags.ADD_TO_GROUP_TAG);
}};
List<VoterRegistryMessage> voterRegistryMessages = GetRelevantVoterRegistryMessages(GroupsActionsTags); List<VoterRegistryMessage> voterRegistryMessages = GetRelevantVoterRegistryMessages(GroupsActionsTags);

View File

@ -10,6 +10,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
/** /**
* Created by Vladimir Eliezer Tokarev on 1/15/2016. * Created by Vladimir Eliezer Tokarev on 1/15/2016.
@ -77,21 +78,12 @@ public abstract class CollectionMessagesUtils {
/** /**
* Gets all the basic messages from bulletin board messages * Gets all the basic messages from bulletin board messages
* @param listOfMessages * @param listOfMessages list of bulletin board messages
* @return List<BasicMessage> G * @return List<UnsignedBulletinBoardMessage>
* @throws InvalidProtocolBufferException * @throws InvalidProtocolBufferException
*/ */
public static final List<ProtobufsMessages.BasicMessage> GetBasicMessagesFromBulletinBoardMessages( public static List<BulletinBoardAPI.UnsignedBulletinBoardMessage> GetUnsignedBulletinBoardMessages(
List<BulletinBoardAPI.BulletinBoardMessage> listOfMessages) throws InvalidProtocolBufferException { List<BulletinBoardAPI.BulletinBoardMessage> listOfMessages) throws InvalidProtocolBufferException {
return listOfMessages.stream().map(BulletinBoardAPI.BulletinBoardMessage::getMsg).collect(Collectors.toList());
List<ProtobufsMessages.BasicMessage> basicMessages = new ArrayList<ProtobufsMessages.BasicMessage>();
for (BulletinBoardAPI.BulletinBoardMessage bulletinBoardMessage : listOfMessages){
ProtobufsMessages.BasicMessage.Builder basicMessage =
ProtobufsMessages.BasicMessage.newBuilder().mergeFrom(bulletinBoardMessage.getMsg().getData());
basicMessages.add(basicMessage.build());
}
return basicMessages;
} }
} }