diff --git a/voting-station-gui/src/polling_station_dashboard/search/SearchHandler.java b/voting-station-gui/src/polling_station_dashboard/search/SearchHandler.java index ed9f4da..24c9515 100644 --- a/voting-station-gui/src/polling_station_dashboard/search/SearchHandler.java +++ b/voting-station-gui/src/polling_station_dashboard/search/SearchHandler.java @@ -11,6 +11,7 @@ import polling_station_dashboard.search.addVoter.java.AddVoterLoader; import javafx.scene.control.Button; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; /** @@ -55,20 +56,24 @@ public class SearchHandler implements EventHandler { private void VotersCheck() throws IOException { List filters = GetFilters(); - List voters = votersFetcher.FetchVoters(filters); + List> voters = votersFetcher.FetchVoters(filters); if (voters.isEmpty()) { AddVoterAddButton(); } - else if(1==1) + else if(voters.get(0).get("EligibleToVote").equals("no")) { // founded the voter but he cant vote } - else + else if(voters.get(0).get("EligibleToVote").equals("yes")) { // founded the voter and he can vote } + else + { + throw new IOException("The given voter have no valid EligibleToVote field"); + } } @Override diff --git a/voting-station-gui/src/polling_station_dashboard/search/VotersFetcher/DummyVotersFetcher.java b/voting-station-gui/src/polling_station_dashboard/search/VotersFetcher/DummyVotersFetcher.java index a699401..39f9b94 100644 --- a/voting-station-gui/src/polling_station_dashboard/search/VotersFetcher/DummyVotersFetcher.java +++ b/voting-station-gui/src/polling_station_dashboard/search/VotersFetcher/DummyVotersFetcher.java @@ -1,16 +1,60 @@ package polling_station_dashboard.search.VotersFetcher; -import java.util.ArrayList; -import java.util.List; +import java.util.*; /** * Created by Vladimir Eliezer Tokarev on 18/06/2016. * This object used for receiving empty list of object for the logic of add voter could be tested + * is implemented in this dummy way for testing the normal gui flow */ public class DummyVotersFetcher implements VotersFetcher { + private List> dummyVoters; + + public DummyVotersFetcher() + { + this.dummyVoters = new ArrayList<>(); + + // voter that cant vote + HashMap voter1 = new HashMap<>(); + voter1.put("IDNumber", "123123123"); + voter1.put("EligibleToVote", "no"); + voter1.put("Status", "HasNotVoted"); + voter1.put("Channel", "IDCMaths"); + + // voter that can vote + HashMap voter2 = new HashMap<>(); + voter2.put("IDNumber", "234234234"); + voter2.put("EligibleToVote", "yes"); + voter2.put("Status", "HasNotVoted"); + voter2.put("Channel", "IDCPhysics"); + + this.dummyVoters.add(voter1); + this.dummyVoters.add(voter2); + } + + /** + * Gets list of filters and return all the voters from dummy voters that have those filters + * @param filters list of strings + */ @Override - public List FetchVoters(List filters) { - return new ArrayList<>(); + public List> FetchVoters(List filters) + { + List> votersWithFilters = new ArrayList<>(); + + for (String filter : filters) { + for (HashMap voter: this.dummyVoters) { + Iterator it = voter.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry pair = (Map.Entry) it.next(); + if (((String) pair.getKey()).contains(filter) || ((String) pair.getValue()).contains(filter)) { + votersWithFilters.add(voter); + break; + } + } + } + } + + return votersWithFilters; } } diff --git a/voting-station-gui/src/polling_station_dashboard/search/VotersFetcher/VotersFetcher.java b/voting-station-gui/src/polling_station_dashboard/search/VotersFetcher/VotersFetcher.java index 9dd609d..18348d7 100644 --- a/voting-station-gui/src/polling_station_dashboard/search/VotersFetcher/VotersFetcher.java +++ b/voting-station-gui/src/polling_station_dashboard/search/VotersFetcher/VotersFetcher.java @@ -1,5 +1,6 @@ package polling_station_dashboard.search.VotersFetcher; +import java.util.HashMap; import java.util.List; /** @@ -8,5 +9,5 @@ import java.util.List; */ public interface VotersFetcher { - List FetchVoters(List filters); + List> FetchVoters(List filters); } diff --git a/voting-station-gui/src/polling_station_dashboard/search/addVoter/java/AddVoterController.java b/voting-station-gui/src/polling_station_dashboard/search/addVoter/java/AddVoterController.java index cdefa88..7b84898 100644 --- a/voting-station-gui/src/polling_station_dashboard/search/addVoter/java/AddVoterController.java +++ b/voting-station-gui/src/polling_station_dashboard/search/addVoter/java/AddVoterController.java @@ -4,6 +4,8 @@ import javafx.fxml.FXML; import javafx.scene.layout.Pane; import javafx.stage.Stage; +import java.util.HashMap; + /** * Created by Vladimir Eliezer Tokarev on 11/06/2016. * This object controls the add voter panel behavior @@ -12,6 +14,7 @@ public class AddVoterController { private Stage currentStage; + public void SetStage(Stage primaryStage) { this.currentStage = primaryStage;