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

View File

@ -10,6 +10,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 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
* @param listOfMessages
* @return List<BasicMessage> G
* @param listOfMessages list of bulletin board messages
* @return List<UnsignedBulletinBoardMessage>
* @throws InvalidProtocolBufferException
*/
public static final List<ProtobufsMessages.BasicMessage> GetBasicMessagesFromBulletinBoardMessages(
public static List<BulletinBoardAPI.UnsignedBulletinBoardMessage> GetUnsignedBulletinBoardMessages(
List<BulletinBoardAPI.BulletinBoardMessage> listOfMessages) throws InvalidProtocolBufferException {
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;
return listOfMessages.stream().map(BulletinBoardAPI.BulletinBoardMessage::getMsg).collect(Collectors.toList());
}
}