diff --git a/VotersBallot.png b/VotersBallot.png index aba8fa2..cc84024 100644 Binary files a/VotersBallot.png and b/VotersBallot.png differ diff --git a/bulletin-board-client/META-INF/MANIFEST.MF b/bulletin-board-client/META-INF/MANIFEST.MF new file mode 100644 index 0000000..e00b61f --- /dev/null +++ b/bulletin-board-client/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: meerkat.voting.gui.configuration.Converter + diff --git a/meerkat-common/src/main/proto/meerkat/BallotQuestionUIElement.proto b/meerkat-common/src/main/proto/meerkat/BallotQuestionUIElement.proto index 2ec0b9d..20a1804 100644 --- a/meerkat-common/src/main/proto/meerkat/BallotQuestionUIElement.proto +++ b/meerkat-common/src/main/proto/meerkat/BallotQuestionUIElement.proto @@ -46,6 +46,11 @@ message BallotQuestionUIElement { UIQuestion question = 3; } +message BallotQuestionsUIElements { + // for easy storing all wanted questions + repeated BallotQuestionUIElement questions = 1; +} + // Enumeration that represents the available types of questions/answers that can be enum ValueType { TEXT_TYPE = 0; diff --git a/voting-booth-gui/VotersBallot.png b/voting-booth-gui/VotersBallot.png new file mode 100644 index 0000000..992e0d5 Binary files /dev/null and b/voting-booth-gui/VotersBallot.png differ diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/Main.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/Main.java index bdd27cb..d955cc3 100644 --- a/voting-booth-gui/src/main/java/meerkat/voting/gui/Main.java +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/Main.java @@ -2,14 +2,16 @@ package meerkat.voting.gui; import javafx.application.Application; import javafx.stage.Stage; +import meerkat.protobuf.BallotQuestionUIElementOuterClass; import meerkat.voting.gui.configuration.VotingBoothConfiguration; -import meerkat.voting.gui.configuration.VotingBoothConfigurationCreator; import meerkat.voting.gui.managment.ChainBuilder; import org.json.JSONException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.FileInputStream; import java.io.IOException; +import java.net.URISyntaxException; /** @@ -20,16 +22,22 @@ import java.io.IOException; public class Main extends Application { private final Logger logger = LoggerFactory.getLogger(Main.class); - + private final String CONFIGURATION_PATH = "/configuration/configuration.bin"; /** * Creates the VotingBoothConfigurationCreator and creates configuration based on given path * @return VotingBoothVonfiguration parsed from json file * @throws IOException will be thrown if the configuraiton file doesnt exist * @throws JSONException will be thrown if the json is unvalid */ - private VotingBoothConfiguration GetConfig() throws IOException, JSONException { - VotingBoothConfigurationCreator creator = new VotingBoothConfigurationCreator(); - return creator.CreateConfiguration("/configuration/VotingBoothConfiguration.json"); + private VotingBoothConfiguration GetConfig() throws IOException, JSONException, URISyntaxException { + + + FileInputStream fis = new FileInputStream(getClass().getResource(CONFIGURATION_PATH).getPath()); + BallotQuestionUIElementOuterClass.BallotQuestionsUIElements read_questions = BallotQuestionUIElementOuterClass.BallotQuestionsUIElements.parseFrom(fis); + VotingBoothConfiguration votingBoothConfiguration = new VotingBoothConfiguration(); + votingBoothConfiguration.NameSelectionQuestion = read_questions.getQuestions(1); + votingBoothConfiguration.NameSelectionByPictureQuestion = read_questions.getQuestions(0); + return votingBoothConfiguration; } @Override diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/configuration/Converter.class b/voting-booth-gui/src/main/java/meerkat/voting/gui/configuration/Converter.class new file mode 100644 index 0000000..9f0ca81 Binary files /dev/null and b/voting-booth-gui/src/main/java/meerkat/voting/gui/configuration/Converter.class differ diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/configuration/Converter.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/configuration/Converter.java new file mode 100644 index 0000000..6913b65 --- /dev/null +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/configuration/Converter.java @@ -0,0 +1,54 @@ +package meerkat.voting.gui.configuration; + +import meerkat.protobuf.BallotQuestionUIElementOuterClass; +import org.json.JSONException; + +import java.io.FileOutputStream; +import java.io.IOException; + +/** + * Created by Vladimir Eliezer Tokarev on 11/5/2016. + * This class uses the configuration creator which converts json configuration into normal binary proto file + */ +public class Converter { + private final static String OUTPUTNAME = "configuration.bin"; + + /** + * Reads the json configuration from given path + * @return VotingBoothConfiguration object + * @throws IOException + * @throws JSONException + */ + private static VotingBoothConfiguration GetVotingBoothJsonConfiguration(String path) throws IOException, JSONException { + VotingBoothConfigurationCreator creator = new VotingBoothConfigurationCreator(); + return creator.CreateConfiguration(path); + } + + /** + * Converts the configuration file into single binary proto file and writes it to the disc + * @param configuration the configuration object + */ + private static void ConvertJsonIntoBinaryFile(VotingBoothConfiguration configuration) throws IOException { + FileOutputStream fileOutputStream = new FileOutputStream(OUTPUTNAME); + BallotQuestionUIElementOuterClass.BallotQuestionsUIElements read_questions = + BallotQuestionUIElementOuterClass + .BallotQuestionsUIElements + .newBuilder() + .addQuestions(configuration.NameSelectionByPictureQuestion) + .addQuestions(configuration.NameSelectionQuestion) + .build(); + read_questions.writeTo(fileOutputStream); + fileOutputStream.close(); + } + + public static void main(String[] args) throws InterruptedException { + System.out.println("args are: " + args); + try { + ConvertJsonIntoBinaryFile(GetVotingBoothJsonConfiguration(args[0])); + } + catch (Exception e) { + System.out.println("Exception thrown: " + e); + } + } + +} diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/configuration/META-INF/MANIFEST.MF b/voting-booth-gui/src/main/java/meerkat/voting/gui/configuration/META-INF/MANIFEST.MF new file mode 100644 index 0000000..d941df6 --- /dev/null +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/configuration/META-INF/MANIFEST.MF @@ -0,0 +1,4 @@ +Manifest-Version: 1.0 +Class-Path: meerkat.voting.gui.configuration.Converter.class +Main-Class: meerkat.voting.gui.configuration.Converter + diff --git a/voting-booth-gui/src/main/resources/configuration/configuration.bin b/voting-booth-gui/src/main/resources/configuration/configuration.bin new file mode 100644 index 0000000..13e84e1 Binary files /dev/null and b/voting-booth-gui/src/main/resources/configuration/configuration.bin differ diff --git a/voting-booth-gui/src/test/java/meerkat/voting/VotingBoothConfigurationCreatorTest.java b/voting-booth-gui/src/test/java/meerkat/voting/VotingBoothConfigurationCreatorTest.java index 22cfe6b..9072381 100644 --- a/voting-booth-gui/src/test/java/meerkat/voting/VotingBoothConfigurationCreatorTest.java +++ b/voting-booth-gui/src/test/java/meerkat/voting/VotingBoothConfigurationCreatorTest.java @@ -8,7 +8,6 @@ import org.json.JSONObject; import org.junit.Before; import org.junit.Test; -import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List;