Changed the SimpleRegistry file
started to implement the different methods of this class (such as created basic messages)vote-registry
parent
05871a2ea7
commit
51b9f9decd
|
@ -8,19 +8,18 @@ public abstract class RegistryTagTypes {
|
||||||
|
|
||||||
private RegistryTagTypes(){}
|
private RegistryTagTypes(){}
|
||||||
|
|
||||||
// The ID tag
|
public static final String ID_TAG = "ID:";
|
||||||
public static final String ID_TYPE = "ID:";
|
|
||||||
|
|
||||||
// The Voter Entry Tag
|
public static final String VOTER_ENTRY_TAG = "Voter Entry";
|
||||||
public static final String VOTER_ENTRY_TAG = "Voter Entry:";
|
|
||||||
|
|
||||||
// THE Group ID Tag
|
|
||||||
public static final String GROUP_ID_TAG = "Group ID:";
|
public static final String GROUP_ID_TAG = "Group ID:";
|
||||||
|
|
||||||
// The Group Action Tag
|
|
||||||
public static final String GROUP_ACTION_TAG = "Group Action:";
|
public static final String GROUP_ACTION_TAG = "Group Action:";
|
||||||
|
|
||||||
// The Vote Action Tag
|
public static final String REMOVE_FROM_GROUP_TAG = "Remove From Group";
|
||||||
public static final String VOTE_ACTION_TAG = "Vote Action:";
|
|
||||||
|
public static final String ADD_TO_GROUP_TAG = "Add To Group";
|
||||||
|
|
||||||
|
public static final String VOTE_ACTION_TAG = "Vote Action";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,18 @@
|
||||||
package meerkat;
|
package meerkat;
|
||||||
import meerkat.ProtobufsMessages.*;
|
|
||||||
import meerkat.comm.CommunicationException;
|
|
||||||
|
|
||||||
|
import com.google.protobuf.*;
|
||||||
|
import meerkat.ProtobufsMessages.BasicMessage;
|
||||||
|
import meerkat.ProtobufsMessages.BulletinBoardMessage;
|
||||||
|
import meerkat.ProtobufsMessages.Tag;
|
||||||
|
import meerkat.bulletinboard.BulletinBoardClient;
|
||||||
|
import meerkat.comm.CommunicationException;
|
||||||
|
import meerkat.crypto.DigitalSignature;
|
||||||
|
import meerkat.protobuf.BulletinBoardAPI;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Vladimir Eliezer Tokarev on 1/8/2016.
|
* Created by Vladimir Eliezer Tokarev on 1/8/2016.
|
||||||
|
@ -11,92 +21,230 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class SimpleRegistry {
|
public class SimpleRegistry {
|
||||||
|
|
||||||
public SimpleRegistry(){
|
protected DigitalSignature signatory;
|
||||||
// inits the encoding object
|
|
||||||
// inits the connection data
|
protected BulletinBoardClient communicator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param signatory implements the DigitalSignature interface
|
||||||
|
* @param communicator implements the BulletinBoardClient interface
|
||||||
|
*/
|
||||||
|
public SimpleRegistry(DigitalSignature signatory, BulletinBoardClient communicator){
|
||||||
|
this.signatory = signatory;
|
||||||
|
this.communicator = communicator;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to add new voter to the bulletin-board
|
* Adds new voter to the bulletin-board
|
||||||
* @param voterID
|
* @param voterID
|
||||||
* @param personalData for example residence location
|
* @param personalData for example residence location
|
||||||
* @throws throws CommunicationException
|
* @throws throws CommunicationException
|
||||||
* @return true if the adding action succeeded else return false
|
* @return void
|
||||||
*/
|
|
||||||
public boolean AddVoter(String voterID, String personalData) throws CommunicationException {
|
|
||||||
/**
|
|
||||||
* try:
|
|
||||||
* Create basic message for adding new voter
|
|
||||||
* Create bulletin board message using CreateBulletinBoardMessage
|
|
||||||
* use SimpleBulletinBoardClient.PostMessage to send the message
|
|
||||||
* return true
|
|
||||||
* catch exception:
|
|
||||||
* return false
|
|
||||||
*/
|
*/
|
||||||
|
public void AddVoter(String voterID, String personalData) throws CommunicationException {
|
||||||
|
Tag.Builder idTag = Tag.newBuilder();
|
||||||
|
idTag.setContent(RegistryTagTypes.ID_TAG + " " + voterID);
|
||||||
|
|
||||||
|
Tag.Builder voterEntryTag = Tag.newBuilder();
|
||||||
|
voterEntryTag.setContent(RegistryTagTypes.VOTER_ENTRY_TAG);
|
||||||
|
|
||||||
|
BasicMessage.Builder basicMessage = BasicMessage.newBuilder();
|
||||||
|
basicMessage.setData(ByteString.copyFrom(personalData.getBytes()));
|
||||||
|
basicMessage.addTag(idTag);
|
||||||
|
basicMessage.addTag(voterEntryTag);
|
||||||
|
|
||||||
|
communicator.postMessage(CreateBulletinBoardMessage(basicMessage), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries adding given voter to given group
|
* Adding given voter to given group
|
||||||
* @param voterID
|
* @param voterID
|
||||||
* @param groupID
|
* @param groupID
|
||||||
* @throws CommunicationException
|
* @throws CommunicationException
|
||||||
* @return true if the adding action succeeded else return false
|
* @return true if the adding action succeeded else return false
|
||||||
*/
|
*/
|
||||||
public boolean AddToGroup(String voterID, String groupID) throws CommunicationException {
|
public void AddToGroup(String voterID, String groupID) throws CommunicationException {
|
||||||
/**
|
Tag.Builder idTag = Tag.newBuilder();
|
||||||
* try:
|
idTag.setContent(RegistryTagTypes.ID_TAG + " " + voterID);
|
||||||
* Create basic message for adding the given voter to the wanted group
|
|
||||||
* Create bulletin board message using CreateBulletinBoardMessage
|
Tag.Builder groupIDTag = Tag.newBuilder();
|
||||||
* use SimpleBulletinBoardClient.PostMessage to send the message
|
groupIDTag.setContent(RegistryTagTypes.GROUP_ID_TAG + " " + groupID);
|
||||||
* return true
|
|
||||||
* catch exception:
|
Tag.Builder actionTag = Tag.newBuilder();
|
||||||
* return false
|
actionTag.setContent(RegistryTagTypes.GROUP_ACTION_TAG + " " + RegistryTagTypes.ADD_TO_GROUP_TAG);
|
||||||
*/
|
|
||||||
|
BasicMessage.Builder basicMessage = BasicMessage.newBuilder();
|
||||||
|
basicMessage.addTag(idTag);
|
||||||
|
basicMessage.addTag(groupIDTag);
|
||||||
|
basicMessage.addTag(actionTag);
|
||||||
|
|
||||||
|
communicator.postMessage(CreateBulletinBoardMessage(basicMessage), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries remove given voter from given group
|
* Removes given voter from given group
|
||||||
* @param voterID
|
* @param voterID
|
||||||
* @param groupID
|
* @param groupID
|
||||||
* @return true if the removing action succeeded else return false
|
* @return true if the removing action succeeded else return false
|
||||||
* @throws CommunicationException
|
* @throws CommunicationException
|
||||||
*/
|
*/
|
||||||
public boolean RemoveFromGroup(String voterID, String groupID) throws CommunicationException {
|
public void RemoveFromGroup(String voterID, String groupID) throws CommunicationException {
|
||||||
/**
|
Tag.Builder idTag = Tag.newBuilder();
|
||||||
* try:
|
idTag.setContent(RegistryTagTypes.ID_TAG + " " + voterID);
|
||||||
* Create basic message for removing the given voter from the wanted group
|
|
||||||
* Create bulletin board message using CreateBulletinBoardMessage
|
Tag.Builder groupIDTag = Tag.newBuilder();
|
||||||
* use SimpleBulletinBoardClient.PostMessage to send the message
|
groupIDTag.setContent(RegistryTagTypes.GROUP_ID_TAG + " " + groupID);
|
||||||
* return true
|
|
||||||
* catch exception:
|
Tag.Builder actionTag = Tag.newBuilder();
|
||||||
* return false
|
actionTag.setContent(RegistryTagTypes.GROUP_ACTION_TAG + " " + RegistryTagTypes.REMOVE_FROM_GROUP_TAG);
|
||||||
*/
|
|
||||||
|
BasicMessage.Builder basicMessage = BasicMessage.newBuilder();
|
||||||
|
basicMessage.addTag(idTag);
|
||||||
|
basicMessage.addTag(groupIDTag);
|
||||||
|
basicMessage.addTag(actionTag);
|
||||||
|
|
||||||
|
communicator.postMessage(CreateBulletinBoardMessage(basicMessage), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to set that the voter have voted
|
* Sets that the voter have voted
|
||||||
* @param id
|
* @param id
|
||||||
* @return true if the set voted succeded else false
|
* @return true if the set voted succeded else false
|
||||||
* @throws CommunicationException
|
* @throws CommunicationException
|
||||||
*/
|
*/
|
||||||
public boolean SetVoted(String id) throws CommunicationException {
|
public void SetVoted(String id) throws CommunicationException {
|
||||||
/**
|
Tag.Builder idTag = Tag.newBuilder();
|
||||||
* try:
|
idTag.setContent(RegistryTagTypes.ID_TAG + " " + id);
|
||||||
* Create basic message set voted
|
|
||||||
* Create bulletin board message using CreateBulletinBoardMessage
|
Tag.Builder voteAction = Tag.newBuilder();
|
||||||
* use SimpleBulletinBoardClient.PostMessage to send the message
|
voteAction.setContent(RegistryTagTypes.VOTE_ACTION_TAG);
|
||||||
* return true
|
|
||||||
* catch exception:
|
BasicMessage.Builder basicMessage = BasicMessage.newBuilder();
|
||||||
* return false
|
basicMessage.addTag(idTag);
|
||||||
*/
|
basicMessage.addTag(voteAction);
|
||||||
|
|
||||||
|
communicator.postMessage(CreateBulletinBoardMessage(basicMessage), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Craetes bulletin board message from basic message (with the signatures parts)
|
* Creates bulletin board message from basic message (with the signatures parts)
|
||||||
* @param basicMessage array of bytes
|
* @param basicMessage BasicMessage.Builder
|
||||||
* @return
|
* @return BulletinBoardAPI.BulletinBoardMessage
|
||||||
*/
|
*/
|
||||||
private byte[] CreateBulletinBoardMessage(byte[] basicMessage) {
|
private BulletinBoardAPI.BulletinBoardMessage CreateBulletinBoardMessage(BasicMessage.Builder basicMessage) {
|
||||||
|
BulletinBoardMessage.Builder bulletinBoardmessage = BulletinBoardMessage.newBuilder();
|
||||||
|
Message encodableMessage = new Message() {
|
||||||
|
@Override
|
||||||
|
public Parser<? extends Message> getParserForType() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder newBuilderForType() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder toBuilder() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeTo(CodedOutputStream output) throws IOException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSerializedSize() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ByteString toByteString() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] toByteArray() {
|
||||||
|
return new byte[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeTo(OutputStream output) throws IOException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeDelimitedTo(OutputStream output) throws IOException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Message getDefaultInstanceForType() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> findInitializationErrors() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getInitializationErrorString() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Descriptors.Descriptor getDescriptorForType() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<Descriptors.FieldDescriptor, Object> getAllFields() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasOneof(Descriptors.OneofDescriptor oneof) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Descriptors.FieldDescriptor getOneofFieldDescriptor(Descriptors.OneofDescriptor oneof) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasField(Descriptors.FieldDescriptor field) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getField(Descriptors.FieldDescriptor field) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRepeatedFieldCount(Descriptors.FieldDescriptor field) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getRepeatedField(Descriptors.FieldDescriptor field, int index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UnknownFieldSet getUnknownFields() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isInitialized() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* encode the basic message
|
* encode the basic message
|
||||||
* create bulletin board message
|
* create bulletin board message
|
||||||
|
|
Loading…
Reference in New Issue