From efc2bd7501851b742e996146a2aed3ee248d1936 Mon Sep 17 00:00:00 2001 From: Simon Bussmann Date: Fri, 11 Dec 2020 10:57:58 +0100 Subject: [PATCH] added support of controling the behavoir of the program from the cli Start application with: -Dmotto for mottoVoting -Dadding for addingPhase -Dvoting for votingPhase --- .../controller/VotingController.java | 69 +++++++++---------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/github/cato447/AbizeitungVotingSystem/controller/VotingController.java b/src/main/java/com/github/cato447/AbizeitungVotingSystem/controller/VotingController.java index d1ac09d..9f7406d 100644 --- a/src/main/java/com/github/cato447/AbizeitungVotingSystem/controller/VotingController.java +++ b/src/main/java/com/github/cato447/AbizeitungVotingSystem/controller/VotingController.java @@ -6,6 +6,7 @@ import com.github.cato447.AbizeitungVotingSystem.helper.RandomNumber; import com.github.cato447.AbizeitungVotingSystem.repositories.*; import com.github.cato447.AbizeitungVotingSystem.table.TableAction; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.stereotype.Controller; @@ -23,9 +24,17 @@ import java.util.*; @Controller public class VotingController { - private boolean votingPhase; - private boolean mottoPhase; - private boolean addingPhase; + + @Value("motto") + String motto; + @Value("adding") + String adding; + @Value("voting") + String voting; + + private boolean votingPhase = false; + private boolean mottoPhase = false; + private boolean addingPhase = false; private static final Logger LOGGER = LogManager.getLogger(VotingController.class); private TableAction tableAction = new TableAction(); @@ -54,52 +63,42 @@ public class VotingController { @PostConstruct public void init() { - try { - String votingPhaseConfig = System.getProperty("votingPhase"); - if (votingPhaseConfig.equalsIgnoreCase("true")) { + if (motto != null){ + mottoPhase = true; + } else if (adding != null){ + addingPhase = true; + } else if (voting != null){ votingPhase = true; } - String mottoPhaseConfig = System.getProperty("mottoPhase"); - if (mottoPhaseConfig.equalsIgnoreCase("true")) { - mottoPhase = true; - } - - String addingPhaseConfig = System.getProperty("addingPhase"); - if (addingPhaseConfig.equalsIgnoreCase("true")){ - addingPhase = true; - } - } catch (Exception e){ - - } // //TODO: TESTING REMOVE ON SHIPPING // votingPhase = false; // mottoPhase = true; // addingPhase = false; - LOGGER.info("Program started with arguments: votingPhase="+ votingPhase + " mottoPhase=" + mottoPhase + " addingPhase=" + addingPhase); + LOGGER.info("Program started with arguments: votingPhase="+ votingPhase + " mottoPhase=" + mottoPhase + " addingPhase=" + addingPhase); - if (voterRepository.findAll().size() == 0) { - tableAction.setUpVoters(voterRepository); - LOGGER.info("Voters successfully set up"); - } + if (voterRepository.findAll().size() == 0) { + tableAction.setUpVoters(voterRepository); + LOGGER.info("Voters successfully set up"); + } - if (categoryRepository.findAll().size() == 0) { - tableAction.setUpCategories(categoryRepository); - LOGGER.info("Categories successfully set up"); - } + if (categoryRepository.findAll().size() == 0) { + tableAction.setUpCategories(categoryRepository); + LOGGER.info("Categories successfully set up"); + } - if (mottoRepository.findAll().size() == 0){ - tableAction.setUpMottos(mottoRepository); - LOGGER.info("Mottos successfully set up"); - } + if (mottoRepository.findAll().size() == 0){ + tableAction.setUpMottos(mottoRepository); + LOGGER.info("Mottos successfully set up"); + } - if (candidateRepository.findAll().size() == 0 && votingPhase == true && possibleCandidateRepository.findAll().size() != 0) { - tableAction.setUpCandidates(possibleCandidateRepository, candidateRepository); - LOGGER.info("Candidates successfully set up"); + if (candidateRepository.findAll().size() == 0 && votingPhase == true && possibleCandidateRepository.findAll().size() != 0) { + tableAction.setUpCandidates(possibleCandidateRepository, candidateRepository); + LOGGER.info("Candidates successfully set up"); + } } - } @RequestMapping("/") public String WelcomeSite() {