Changed the SimpleRegistry to work with UnsignedBulletinBoardMessage
The basicMessage is not neededVoter-Registry
parent
0d8e522e93
commit
1815863746
|
@ -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);
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue