The new object which creates protobuf from jason working
							parent
							
								
									80a0a2fc2c
								
							
						
					
					
						commit
						55279e2e3d
					
				|  | @ -16,11 +16,14 @@ import java.util.ArrayList; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.Scanner; | import java.util.Scanner; | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| /** | /** | ||||||
|  * Created by Vladimir Eliezer Tokarev on 10/4/2016. |  * Created by Vladimir Eliezer Tokarev on 10/4/2016. | ||||||
|  * This class creates QuestionBallotUIElement from given configuration file |  * This class creates QuestionBallotUIElement from given configuration file | ||||||
|  */ |  */ | ||||||
| class VotingBoothConfigurationCreator { | class VotingBoothConfigurationCreator { | ||||||
|  |     private int CURRENT_NUMBER_OF_QUESTIONS_REPRESENTED_TO_VOTER = 2 ; | ||||||
|     /** |     /** | ||||||
|      * Creates VotingBoothConfiguarion object form file that given as paramter |      * Creates VotingBoothConfiguarion object form file that given as paramter | ||||||
|      * @param configPath the path to the json configuration |      * @param configPath the path to the json configuration | ||||||
|  | @ -30,13 +33,19 @@ class VotingBoothConfigurationCreator { | ||||||
|         VotingBoothConfiguration config = new VotingBoothConfiguration(); |         VotingBoothConfiguration config = new VotingBoothConfiguration(); | ||||||
|         JSONArray array = this.getJsonFromPath(configPath); |         JSONArray array = this.getJsonFromPath(configPath); | ||||||
| 
 | 
 | ||||||
|         if (array.length() > 2) { |         if (array.length() > CURRENT_NUMBER_OF_QUESTIONS_REPRESENTED_TO_VOTER) { | ||||||
|             throw new IOException("The configration has to many questions datas"); |             throw new IOException("The configration has to many questions datas"); | ||||||
|         } else { |         } else { | ||||||
|             BallotQuestionUIElementOuterClass.BallotQuestionUIElement ballotQuestionUIElement = this.convertJSONObjToBallotQuestion(array.getJSONObject(0)); |             try { | ||||||
|             config.NameSelectionQuestion = ballotQuestionUIElement; |                 BallotQuestionUIElementOuterClass.BallotQuestionUIElement ballotQuestionUIElement = this.convertJSONObjToBallotQuestion(array.getJSONObject(0)); | ||||||
|             ballotQuestionUIElement = this.convertJSONObjToBallotQuestion(array.getJSONObject(1)); |                 config.NameSelectionQuestion = ballotQuestionUIElement; | ||||||
|             config.NameSelectionByPictureQuestion = ballotQuestionUIElement; | 
 | ||||||
|  |                 ballotQuestionUIElement = this.convertJSONObjToBallotQuestion(array.getJSONObject(1)); | ||||||
|  |                 config.NameSelectionByPictureQuestion = ballotQuestionUIElement; | ||||||
|  |             } | ||||||
|  |             catch (JSONException e) { | ||||||
|  |                 e.printStackTrace(); | ||||||
|  |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return config; |         return config; | ||||||
|  | @ -77,19 +86,21 @@ class VotingBoothConfigurationCreator { | ||||||
|             byteStrings.add(this.convertToByteStringBasedOnType(answersType, answersValues.getString(i))); |             byteStrings.add(this.convertToByteStringBasedOnType(answersType, answersValues.getString(i))); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         // Create the UIQuestion and set the values parsed from jason
 | ||||||
|         BallotQuestionUIElementOuterClass.UIQuestion uiQuestion = BallotQuestionUIElementOuterClass.UIQuestion.newBuilder() |         BallotQuestionUIElementOuterClass.UIQuestion uiQuestion = BallotQuestionUIElementOuterClass.UIQuestion.newBuilder() | ||||||
|                 .setQuestionType(questionType) |                 .setQuestionType(questionType) | ||||||
|                 .setQuestion(BallotQuestionUIElementOuterClass.Question.newBuilder() |                 .setQuestion(BallotQuestionUIElementOuterClass.Question.newBuilder() | ||||||
|                         .setQuestion(questionValue)) |                         .setQuestion(questionValue)) | ||||||
|                 .build(); |                 .build(); | ||||||
| 
 | 
 | ||||||
|  |         // Create UIAnswers and set the values parsed from jason
 | ||||||
|         BallotQuestionUIElementOuterClass.UIAnswers.Builder uiAnswersBuilder = BallotQuestionUIElementOuterClass.UIAnswers.newBuilder() |         BallotQuestionUIElementOuterClass.UIAnswers.Builder uiAnswersBuilder = BallotQuestionUIElementOuterClass.UIAnswers.newBuilder() | ||||||
|                 .setAnswersType(answersType); |                 .setAnswersType(answersType); | ||||||
|  |         BallotQuestionUIElementOuterClass.ListOfAnswers.Builder listOfAnswers = BallotQuestionUIElementOuterClass.ListOfAnswers.newBuilder(); | ||||||
|         for(ByteString byteString : byteStrings){ |         for(ByteString byteString : byteStrings){ | ||||||
|             uiAnswersBuilder.setAnswers(BallotQuestionUIElementOuterClass.ListOfAnswers.newBuilder() |             listOfAnswers.addAnswers(byteString); | ||||||
|                                         .addAnswers(byteString)); |  | ||||||
|         } |         } | ||||||
| 
 |         uiAnswersBuilder.setAnswers(listOfAnswers); | ||||||
| 
 | 
 | ||||||
|         return BallotQuestionUIElementOuterClass.BallotQuestionUIElement.newBuilder() |         return BallotQuestionUIElementOuterClass.BallotQuestionUIElement.newBuilder() | ||||||
|                 .setQuestion(uiQuestion) |                 .setQuestion(uiQuestion) | ||||||
|  | @ -98,8 +109,6 @@ class VotingBoothConfigurationCreator { | ||||||
|                 .build(); |                 .build(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|     /** |     /** | ||||||
|      * Tries to get convert the given question to ByteString else throws excetion |      * Tries to get convert the given question to ByteString else throws excetion | ||||||
|      * @param questionType the type of the question (can be 0 - text, 1 - audio, 2 - image) |      * @param questionType the type of the question (can be 0 - text, 1 - audio, 2 - image) | ||||||
|  |  | ||||||
|  | @ -19,11 +19,11 @@ | ||||||
|       "randomize": true, |       "randomize": true, | ||||||
|       "question": { |       "question": { | ||||||
|         "type": 0, |         "type": 0, | ||||||
|         "question": "Select candidate picture." |         "questionValue": "Select candidate picture." | ||||||
|       }, |       }, | ||||||
|       "answers": { |       "answers": { | ||||||
|         "type": 2, |         "type": 2, | ||||||
|         "answers": [ |         "answersValue": [ | ||||||
|           "/F:/vova/meerkat/meerkat-java/voting-booth-gui/src/main/resources/images/GeorgeBush.png", |           "/F:/vova/meerkat/meerkat-java/voting-booth-gui/src/main/resources/images/GeorgeBush.png", | ||||||
|           "/F:/vova/meerkat/meerkat-java/voting-booth-gui/src/main/resources/images/MichaelJackson.png", |           "/F:/vova/meerkat/meerkat-java/voting-booth-gui/src/main/resources/images/MichaelJackson.png", | ||||||
|           "/F:/vova/meerkat/meerkat-java/voting-booth-gui/src/main/resources/images/AntonioBanderass.png" |           "/F:/vova/meerkat/meerkat-java/voting-booth-gui/src/main/resources/images/AntonioBanderass.png" | ||||||
		Loading…
	
		Reference in New Issue