Added configuration validation
parent
ca89514c97
commit
e440bb3e76
|
@ -62,6 +62,9 @@ dependencies {
|
||||||
// Jar that creates barcodes
|
// Jar that creates barcodes
|
||||||
compile group: 'net.sourceforge.barbecue', name: 'barbecue', version: '1.5-beta1'
|
compile group: 'net.sourceforge.barbecue', name: 'barbecue', version: '1.5-beta1'
|
||||||
|
|
||||||
|
// Json configuration parsing for the test
|
||||||
|
testCompile group: 'org.json', name: 'json', version: '20160810'
|
||||||
|
|
||||||
testCompile 'junit:junit:4.+'
|
testCompile 'junit:junit:4.+'
|
||||||
|
|
||||||
runtime 'org.codehaus.groovy:groovy:2.4.+'
|
runtime 'org.codehaus.groovy:groovy:2.4.+'
|
||||||
|
|
|
@ -8,5 +8,28 @@ import meerkat.protobuf.BallotQuestionUIElementOuterClass;
|
||||||
public class VotingBoothConfiguration {
|
public class VotingBoothConfiguration {
|
||||||
public BallotQuestionUIElementOuterClass.BallotQuestionUIElement NameSelectionQuestion;
|
public BallotQuestionUIElementOuterClass.BallotQuestionUIElement NameSelectionQuestion;
|
||||||
public BallotQuestionUIElementOuterClass.BallotQuestionUIElement NameSelectionByPictureQuestion;
|
public BallotQuestionUIElementOuterClass.BallotQuestionUIElement NameSelectionByPictureQuestion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks that the configuration that have been given is valud
|
||||||
|
* @return true if the configuration was valid else false
|
||||||
|
*/
|
||||||
|
public boolean IsConfigurationValid(){
|
||||||
|
// check that both the ballot questions really exists
|
||||||
|
if (this.NameSelectionByPictureQuestion == null || this.NameSelectionQuestion == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// check that both the questions answers exists
|
||||||
|
if (this.NameSelectionQuestion.getAnswers().getAnswers().getAnswersList() == null ||
|
||||||
|
this.NameSelectionByPictureQuestion.getAnswers().getAnswers().getAnswersList() == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// check that both the types of the questions answers are supported
|
||||||
|
if (BallotQuestionUIElementOuterClass.ValueType.forNumber(NameSelectionByPictureQuestion.getAnswers().getAnswersType()) == null ||
|
||||||
|
BallotQuestionUIElementOuterClass.ValueType.forNumber(NameSelectionQuestion.getAnswers().getAnswersType()) == null ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,8 @@ public class ChainBuilder {
|
||||||
WelcomeSplashLoader welcomeSplashLoader = new WelcomeSplashLoader(primaryStage, configuration);
|
WelcomeSplashLoader welcomeSplashLoader = new WelcomeSplashLoader(primaryStage, configuration);
|
||||||
TwoWayNode welcomeSplashController = welcomeSplashLoader.GetWelcomeSplash();
|
TwoWayNode welcomeSplashController = welcomeSplashLoader.GetWelcomeSplash();
|
||||||
welcomeSplashController.SetVotersBallot(votersBallot);
|
welcomeSplashController.SetVotersBallot(votersBallot);
|
||||||
|
// Calling the update method for the splash controller to run its graphics changes
|
||||||
|
welcomeSplashController.UpdateNode();
|
||||||
|
|
||||||
StraightChannelSectionLoader straightChannelSectionLoader = new StraightChannelSectionLoader(primaryStage, configuration);
|
StraightChannelSectionLoader straightChannelSectionLoader = new StraightChannelSectionLoader(primaryStage, configuration);
|
||||||
TwoWayNode straightChannelSectionController = straightChannelSectionLoader.GetStraightChannelSection();
|
TwoWayNode straightChannelSectionController = straightChannelSectionLoader.GetStraightChannelSection();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package meerkat.voting.gui.panels.welcome_splash;
|
package meerkat.voting.gui.panels.welcome_splash;
|
||||||
|
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.input.MouseEvent;
|
import javafx.scene.input.MouseEvent;
|
||||||
import meerkat.voting.gui.managment.TwoWayNode;
|
import meerkat.voting.gui.managment.TwoWayNode;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -13,6 +14,10 @@ import org.slf4j.LoggerFactory;
|
||||||
public class WelcomeSplashController extends TwoWayNode {
|
public class WelcomeSplashController extends TwoWayNode {
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(WelcomeSplashController.class);
|
private final Logger logger = LoggerFactory.getLogger(WelcomeSplashController.class);
|
||||||
|
private final String INVALID_CONFIGURATION_ERROR_TEXT = "The given configuration is invalid please run this voting booth with different configuraiton.";
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Label ErrorPanel;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void StartVotingProcess(MouseEvent mousePressed) {
|
private void StartVotingProcess(MouseEvent mousePressed) {
|
||||||
|
@ -25,6 +30,18 @@ public class WelcomeSplashController extends TwoWayNode {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void UpdateNode() {
|
public void UpdateNode() {
|
||||||
// There is no questions relevant to this panel so this method does nothing
|
if (this.config == null || !this.config.IsConfigurationValid()){
|
||||||
|
RepresentErrorToVoter(INVALID_CONFIGURATION_ERROR_TEXT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the given string to user in ErrorLabel
|
||||||
|
* @param message is the error string to represent to the user
|
||||||
|
*/
|
||||||
|
private void RepresentErrorToVoter(String message) {
|
||||||
|
ErrorPanel.setText(message);
|
||||||
|
this.currentStage.show();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,5 +95,10 @@
|
||||||
</GridPane>
|
</GridPane>
|
||||||
</children>
|
</children>
|
||||||
</GridPane>
|
</GridPane>
|
||||||
|
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="3">
|
||||||
|
<center>
|
||||||
|
<Label fx:id="ErrorPanel" maxHeight="30.0" maxWidth="500.0" minHeight="30.0" minWidth="500.0" prefHeight="30.0" prefWidth="500.0" BorderPane.alignment="CENTER" />
|
||||||
|
</center>
|
||||||
|
</BorderPane>
|
||||||
</children>
|
</children>
|
||||||
</GridPane>
|
</GridPane>
|
||||||
|
|
Loading…
Reference in New Issue