votingPhase can now be toggled from jar

Use -DvotingPhase={boolean} to set value (Defaults to false)
This commit is contained in:
2020-12-08 23:32:20 +01:00
parent 9bf9f8acdc
commit 5204322f40

View File

@@ -26,7 +26,8 @@ import java.util.*;
@Controller @Controller
public class VotingController { public class VotingController {
private Boolean candidatesAdded = true;
private boolean votingPhase = false;
private static final Logger LOGGER = LogManager.getLogger(VotingController.class); private static final Logger LOGGER = LogManager.getLogger(VotingController.class);
private TableAction tableAction = new TableAction(); private TableAction tableAction = new TableAction();
@@ -52,6 +53,17 @@ public class VotingController {
@PostConstruct @PostConstruct
public void init() { public void init() {
try {
String mode = System.getProperty("votingPhase");
if (mode.equalsIgnoreCase("true")) {
votingPhase = true;
} else {
votingPhase = false;
}
} catch (Exception e){
votingPhase = false;
}
if (voterRepository.findAll().size() == 0) { if (voterRepository.findAll().size() == 0) {
tableAction.setUpVoters(voterRepository); tableAction.setUpVoters(voterRepository);
LOGGER.info("Voters successfully set up"); LOGGER.info("Voters successfully set up");
@@ -62,10 +74,11 @@ public class VotingController {
LOGGER.info("Categories successfully set up"); LOGGER.info("Categories successfully set up");
} }
if (candidateRepository.findAll().size() == 0 && candidatesAdded == true && possibleCandidateRepository.findAll().size()!=0) { if (candidateRepository.findAll().size() == 0 && votingPhase == true && possibleCandidateRepository.findAll().size() != 0) {
tableAction.setUpCandidates(possibleCandidateRepository, candidateRepository); tableAction.setUpCandidates(possibleCandidateRepository, candidateRepository);
LOGGER.info("Candidates successfully set up"); LOGGER.info("Candidates successfully set up");
} }
LOGGER.info(votingPhase);
} }
@RequestMapping("/") @RequestMapping("/")
@@ -91,7 +104,7 @@ public class VotingController {
if (voter.getVote_status()) { if (voter.getVote_status()) {
LOGGER.warn(name + " has already voted"); LOGGER.warn(name + " has already voted");
return "errors/alreadyVoted.html"; return "errors/alreadyVoted.html";
} else if (voter.getCandidatesubmit_status() && candidatesAdded == false) { } else if (voter.getCandidatesubmit_status() && votingPhase == false) {
LOGGER.warn(name + " has already submitted its candidates"); LOGGER.warn(name + " has already submitted its candidates");
return "errors/alreadysubmittedcandidates.html"; return "errors/alreadysubmittedcandidates.html";
} else { } else {
@@ -117,7 +130,7 @@ public class VotingController {
switch (tableAction.checkToken(name, code, authCodesRepository)) { switch (tableAction.checkToken(name, code, authCodesRepository)) {
case "matched": case "matched":
LOGGER.warn("matched"); LOGGER.warn("matched");
if(candidatesAdded) { if (votingPhase) {
List<Category> categories = categoryRepository.findAll(); List<Category> categories = categoryRepository.findAll();
model.addAttribute("categories", categories); model.addAttribute("categories", categories);
model.addAttribute("name", name); model.addAttribute("name", name);