Added the validation that the answers given are valid strings and pictures
parent
e440bb3e76
commit
fbc1707b37
|
@ -1,6 +1,12 @@
|
||||||
package meerkat.voting.gui.configuration;
|
package meerkat.voting.gui.configuration;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import javafx.embed.swing.SwingFXUtils;
|
||||||
import meerkat.protobuf.BallotQuestionUIElementOuterClass;
|
import meerkat.protobuf.BallotQuestionUIElementOuterClass;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Vladimir Eliezer Tokarev on 10/1/2016.
|
* Created by Vladimir Eliezer Tokarev on 10/1/2016.
|
||||||
* This object contains all the questions and configurations needed for the voting-booth-gui work
|
* This object contains all the questions and configurations needed for the voting-booth-gui work
|
||||||
|
@ -28,6 +34,24 @@ public class VotingBoothConfiguration {
|
||||||
BallotQuestionUIElementOuterClass.ValueType.forNumber(NameSelectionQuestion.getAnswers().getAnswersType()) == null ){
|
BallotQuestionUIElementOuterClass.ValueType.forNumber(NameSelectionQuestion.getAnswers().getAnswersType()) == null ){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// Check that all the given answers are valid bte strings that can be converted into strings
|
||||||
|
for (ByteString answer: NameSelectionQuestion.getAnswers().getAnswers().getAnswersList()){
|
||||||
|
try {
|
||||||
|
String strAnswer = answer.toStringUtf8();
|
||||||
|
} catch (Exception e){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Check that all given byteStrings that are pictures can be converted into pictures
|
||||||
|
for (ByteString answer :NameSelectionByPictureQuestion.getAnswers().getAnswers().getAnswersList()){
|
||||||
|
try {
|
||||||
|
BufferedImage bufferedImage = ImageIO.read(answer.newInput());
|
||||||
|
SwingFXUtils.toFXImage(bufferedImage, null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue