Changed the usage of json configuration
For now we use an binary file which contains all the protobuf ballot quesitons. However there is a problem, the jar that suppose to convert json into binary configuraiton file doesnt work.android-scanner
parent
c4e0e5f56d
commit
d6ea9412e3
BIN
VotersBallot.png
BIN
VotersBallot.png
Binary file not shown.
Before Width: | Height: | Size: 954 B After Width: | Height: | Size: 953 B |
|
@ -0,0 +1,3 @@
|
||||||
|
Manifest-Version: 1.0
|
||||||
|
Main-Class: meerkat.voting.gui.configuration.Converter
|
||||||
|
|
|
@ -46,6 +46,11 @@ message BallotQuestionUIElement {
|
||||||
UIQuestion question = 3;
|
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
|
// Enumeration that represents the available types of questions/answers that can be
|
||||||
enum ValueType {
|
enum ValueType {
|
||||||
TEXT_TYPE = 0;
|
TEXT_TYPE = 0;
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 954 B |
|
@ -2,14 +2,16 @@ package meerkat.voting.gui;
|
||||||
|
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
import meerkat.protobuf.BallotQuestionUIElementOuterClass;
|
||||||
import meerkat.voting.gui.configuration.VotingBoothConfiguration;
|
import meerkat.voting.gui.configuration.VotingBoothConfiguration;
|
||||||
import meerkat.voting.gui.configuration.VotingBoothConfigurationCreator;
|
|
||||||
import meerkat.voting.gui.managment.ChainBuilder;
|
import meerkat.voting.gui.managment.ChainBuilder;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,16 +22,22 @@ import java.io.IOException;
|
||||||
public class Main extends Application {
|
public class Main extends Application {
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(Main.class);
|
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
|
* Creates the VotingBoothConfigurationCreator and creates configuration based on given path
|
||||||
* @return VotingBoothVonfiguration parsed from json file
|
* @return VotingBoothVonfiguration parsed from json file
|
||||||
* @throws IOException will be thrown if the configuraiton file doesnt exist
|
* @throws IOException will be thrown if the configuraiton file doesnt exist
|
||||||
* @throws JSONException will be thrown if the json is unvalid
|
* @throws JSONException will be thrown if the json is unvalid
|
||||||
*/
|
*/
|
||||||
private VotingBoothConfiguration GetConfig() throws IOException, JSONException {
|
private VotingBoothConfiguration GetConfig() throws IOException, JSONException, URISyntaxException {
|
||||||
VotingBoothConfigurationCreator creator = new VotingBoothConfigurationCreator();
|
|
||||||
return creator.CreateConfiguration("/configuration/VotingBoothConfiguration.json");
|
|
||||||
|
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
|
@Override
|
||||||
|
|
Binary file not shown.
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
Manifest-Version: 1.0
|
||||||
|
Class-Path: meerkat.voting.gui.configuration.Converter.class
|
||||||
|
Main-Class: meerkat.voting.gui.configuration.Converter
|
||||||
|
|
Binary file not shown.
|
@ -8,7 +8,6 @@ import org.json.JSONObject;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
Loading…
Reference in New Issue