Changed the enumartion of RegistryTags to abstract class with static final strings as tags

Voter-Registry
Vladimir Eliezer Tokarev 2016-02-27 01:27:19 -08:00
parent 64a9356dc2
commit 097aad4e7b
7 changed files with 26 additions and 61 deletions

Binary file not shown.

View File

@ -51,7 +51,7 @@ public abstract class CollectionMessagesUtils {
// iterate trough all the messages and put into the map the last updated groups actions
for (int i = 0 ; i < messages.size() ; i++) {
VoterRegistryMessage message = messages.get(i);
String groupId = message.GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG.toString());
String groupId = message.GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG);
VoterRegistryMessage temp = groupIdToMessage.get(groupId);
if (temp != null && temp != message) {

View File

@ -1,28 +1,17 @@
package meerkat.Registry;
/**
* Created by Vladimir Eliezer Tokarev on 1/9/2016.
* Have the tags for the registry messages
*/
public enum RegistryTags {
ID_TAG("ID:"),
VOTER_ENTRY_TAG("Voter Entry"),
GROUP_ID_TAG("GroupID:"),
GROUP_ACTION_TAG("Group Action:"),
ADD_TO_GROUP_TAG("Add To Group"),
ACTION_TIMESTAMP_TAG("Action timestamp: "),
VOTE_ACTION_TAG("Vote Action");
private final String text;
RegistryTags(final String text){
this.text = text;
}
public String toString(){
return text;
}
public abstract class RegistryTags {
public final static String ID_TAG = "ID:";
public final static String VOTER_ENTRY_TAG = "VoterEntry:";
public final static String GROUP_ID_TAG = "GroupID:";
public final static String ADD_TO_GROUP_TAG = "AddToGroup:";
public final static String ACTION_TIMESTAMP_TAG = "ActionTimestamp: ";
public final static String VOTE_ACTION_TAG = "VoteAction:";
}

View File

@ -60,7 +60,7 @@ public class RelevantDataCallBack implements ClientCallback<List<BulletinBoardMe
List<String> tags = msg.get(0).getMsg().getTagList();
for (int i = 0 ;i < tags.size(); i++) {
String tag = tags.get(i);
if(tag.contains(RegistryTags.GROUP_ID_TAG.toString()))
if(tag.contains(RegistryTags.GROUP_ID_TAG))
{
return true;
}

View File

@ -14,6 +14,10 @@ import java.security.SignatureException;
import java.util.ArrayList;
import java.util.List;
/**
* TODO : add ability to use DB of certificates
*/
/**
* Created by Vladimir Eliezer Tokarev on 1/8/2016.
* Gives the ability to synchronously manage voters information
@ -55,26 +59,15 @@ public class SimpleRegistry implements VoterRegistry{
}
}
/**
* Tries to post basicMessage and return true if its been successfully posted
*
* @param Message the massage to post
* @return true when the post was successful else false
*/
private void SafePost(BulletinBoardMessage Message, BulletinBoardClient.ClientCallback callback) {
bulletinBoardClient .postMessage(Message, callback);
}
public void AddVoter(VoterInfo voterInfo, RegistryCallBack callback) {
UnsignedBulletinBoardMessage.Builder basicMessage =
UnsignedBulletinBoardMessage.newBuilder().
addTag(RegistryTags.ID_TAG + voterInfo.getId().getId())
.addTag(RegistryTags.VOTER_ENTRY_TAG.toString())
.addTag(RegistryTags.VOTER_ENTRY_TAG)
.addTag(RegistryTags.ACTION_TIMESTAMP_TAG + AccurateTimestamp.GetCurrentTimestampString());
basicMessage.setData(voterInfo.getInfoBytes());
SafePost(CreateBulletinBoardMessage(basicMessage.build()), new BooleanCallBack(callback));
bulletinBoardClient.postMessage(CreateBulletinBoardMessage(basicMessage.build()), new BooleanCallBack(callback));
}
public void AddToGroup(VoterGroup voterGroup, RegistryCallBack callback) {
@ -82,20 +75,20 @@ public class SimpleRegistry implements VoterRegistry{
UnsignedBulletinBoardMessage.newBuilder()
.addTag(RegistryTags.ID_TAG + voterGroup.getVoterId().getId())
.addTag(RegistryTags.GROUP_ID_TAG + voterGroup.getGroupId().getId())
.addTag(RegistryTags.GROUP_ACTION_TAG .toString() + RegistryTags.ADD_TO_GROUP_TAG)
.addTag(RegistryTags.ADD_TO_GROUP_TAG)
.addTag(RegistryTags.ACTION_TIMESTAMP_TAG + AccurateTimestamp.GetCurrentTimestampString());
SafePost(CreateBulletinBoardMessage(basicMessage.build()), new BooleanCallBack(callback));
bulletinBoardClient.postMessage(CreateBulletinBoardMessage(basicMessage.build()), new BooleanCallBack(callback));
}
public void SetVoted(VoterID voterId, RegistryCallBack callback) {
UnsignedBulletinBoardMessage.Builder basicMessage =
UnsignedBulletinBoardMessage.newBuilder()
.addTag(RegistryTags.ID_TAG + voterId.getId())
.addTag(RegistryTags.VOTE_ACTION_TAG.toString())
.addTag(RegistryTags.VOTE_ACTION_TAG)
.addTag(RegistryTags.ACTION_TIMESTAMP_TAG + AccurateTimestamp.GetCurrentTimestampString());
SafePost(CreateBulletinBoardMessage(basicMessage.build()), new BooleanCallBack(callback));
bulletinBoardClient.postMessage(CreateBulletinBoardMessage(basicMessage.build()), new BooleanCallBack(callback));
}
public void GetGroups(GroupID groupID, RegistryCallBack callback) {
@ -109,7 +102,7 @@ public class SimpleRegistry implements VoterRegistry{
public void GetPersonIDDetails(VoterID voterID, RegistryCallBack callback) {
List<String> GroupsActionsTags = new ArrayList<String>() {{
add(RegistryTags.ID_TAG + voterID.getId());
add(RegistryTags.VOTER_ENTRY_TAG.toString());
add(RegistryTags.VOTER_ENTRY_TAG);
}};
bulletinBoardClient.readMessages(CollectionMessagesUtils.GenerateFiltersFromTags(GroupsActionsTags),
new RelevantDataCallBack(callback, signer, signature, certificateStream));

View File

@ -56,7 +56,7 @@ public class VoterRegistryMessage {
List<String> tags = base.getTagList();
for (int i = 0 ; i < tags.size() ; i++) {
String tag = tags.get(i);
if (tag.contains(RegistryTags.ACTION_TIMESTAMP_TAG.toString())) {
if (tag.contains(RegistryTags.ACTION_TIMESTAMP_TAG)) {
String[] tagParts = tag.split(" ");
String timestamp = tagParts[tagParts.length - 2] + " " + tagParts[tagParts.length - 1];
@ -66,20 +66,4 @@ public class VoterRegistryMessage {
return null;
}
/**
* Checks if the given message have the ADD_TO_GROUP_TAG
*
* @return true when ADD_TO_GROUP_TAG exist else false
*/
public boolean IsGroupAdding() {
List<String> tags = base.getTagList();
for (int i = 0 ; i < tags.size() ; i++) {
String tag = tags.get(i);
if (tag.contains(RegistryTags.ADD_TO_GROUP_TAG.toString())) {
return true;
}
}
return false;
}
}

View File

@ -178,7 +178,7 @@ public class SimpleRegistryTest extends TestCase {
jobSemaphore.acquire();
assertEquals(1, handler.counter );
List<String> tags = new ArrayList<String>(){{ add(RegistryTags.VOTER_ENTRY_TAG.toString());}};
List<String> tags = new ArrayList<String>(){{ add(RegistryTags.VOTER_ENTRY_TAG);}};
MessageFilterList filters = CollectionMessagesUtils.GenerateFiltersFromTags(tags);
DummyBulletinBoardCallBackHandler bulletinHandler = new DummyBulletinBoardCallBackHandler();
bulletinBoardClient.readMessages(filters, bulletinHandler);
@ -206,7 +206,7 @@ public class SimpleRegistryTest extends TestCase {
jobSemaphore.acquire();
assertEquals(1, handler.counter );
List<String> tags = new ArrayList<String>(){{ add(RegistryTags.VOTE_ACTION_TAG.toString());}};
List<String> tags = new ArrayList<String>(){{ add(RegistryTags.VOTE_ACTION_TAG);}};
MessageFilterList filters = CollectionMessagesUtils.GenerateFiltersFromTags(tags);
DummyBulletinBoardCallBackHandler bulletinHandler = new DummyBulletinBoardCallBackHandler();
bulletinBoardClient.readMessages(filters, bulletinHandler);
@ -236,8 +236,7 @@ public class SimpleRegistryTest extends TestCase {
jobSemaphore.acquire();
assertEquals(1, handler.counter);
List<String> tags = new ArrayList<String>(){{ add(RegistryTags.GROUP_ACTION_TAG .toString()
+ RegistryTags.ADD_TO_GROUP_TAG.toString());}};
List<String> tags = new ArrayList<String>(){{add(RegistryTags.ADD_TO_GROUP_TAG);}};
MessageFilterList filters = CollectionMessagesUtils.GenerateFiltersFromTags(tags);
DummyBulletinBoardCallBackHandler bulletinHandler = new DummyBulletinBoardCallBackHandler();
bulletinBoardClient.readMessages(filters, bulletinHandler);
@ -305,7 +304,7 @@ public class SimpleRegistryTest extends TestCase {
jobSemaphore.acquire(1);
assertEquals(RegistryTags.ID_TAG + id,
personalHandler.data.GetWantedTagFromBasicMessage(RegistryTags.ID_TAG.toString()));
personalHandler.data.GetWantedTagFromBasicMessage(RegistryTags.ID_TAG));
assertEquals(data,personalHandler.data.base.getData().toStringUtf8());
}
}