diff --git a/voter-registry/src/main/java/util/MessagesUtils.java b/voter-registry/src/main/java/util/MessagesUtils.java new file mode 100644 index 0000000..d98c0d4 --- /dev/null +++ b/voter-registry/src/main/java/util/MessagesUtils.java @@ -0,0 +1,51 @@ +package util; + +import com.google.protobuf.InvalidProtocolBufferException; +import meerkat.ProtobufsMessages; +import meerkat.protobuf.BulletinBoardAPI; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by Dasha on 1/15/2016. + */ +public abstract class MessagesUtils { + + /** + * Gets all the basic messages from bulletin board messages + * @param listOfMessages + * @return List G + * @throws InvalidProtocolBufferException + */ + public static final List GetBasicMessagesFromBulletinBoardMessages( + List listOfMessages) throws InvalidProtocolBufferException { + + List basicMessages = new ArrayList(); + + for (BulletinBoardAPI.BulletinBoardMessage bulletinBoardMessage : listOfMessages){ + ProtobufsMessages.BasicMessage.Builder basicMessage = + ProtobufsMessages.BasicMessage.newBuilder().mergeFrom(bulletinBoardMessage.getMsg().getData()); + basicMessages.add(basicMessage.build()); + } + + return basicMessages; + } + + /** + * Gets the wanted tag from given basic message + * @param message + * @param tagName + * @return string + */ + public static final String GetWantedTagFromBasicMessage(ProtobufsMessages.BasicMessage message, Tags tagName){ + List tags = message.getTagList(); + + for (ProtobufsMessages.Tag tag : tags) { + if ( tag.getContent().contains(tagName.toString())) { + return tag.getContent(); + } + } + return null; + } +}