Dummy Voters Fetcher fetching dummy voters
parent
c90be520fe
commit
d2c9893ccf
|
@ -11,6 +11,7 @@ import polling_station_dashboard.search.addVoter.java.AddVoterLoader;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,20 +56,24 @@ public class SearchHandler implements EventHandler {
|
||||||
private void VotersCheck() throws IOException {
|
private void VotersCheck() throws IOException {
|
||||||
List<String> filters = GetFilters();
|
List<String> filters = GetFilters();
|
||||||
|
|
||||||
List<Object> voters = votersFetcher.FetchVoters(filters);
|
List<HashMap<String,String>> voters = votersFetcher.FetchVoters(filters);
|
||||||
|
|
||||||
if (voters.isEmpty())
|
if (voters.isEmpty())
|
||||||
{
|
{
|
||||||
AddVoterAddButton();
|
AddVoterAddButton();
|
||||||
}
|
}
|
||||||
else if(1==1)
|
else if(voters.get(0).get("EligibleToVote").equals("no"))
|
||||||
{
|
{
|
||||||
// founded the voter but he cant vote
|
// founded the voter but he cant vote
|
||||||
}
|
}
|
||||||
else
|
else if(voters.get(0).get("EligibleToVote").equals("yes"))
|
||||||
{
|
{
|
||||||
// founded the voter and he can vote
|
// founded the voter and he can vote
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new IOException("The given voter have no valid EligibleToVote field");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,16 +1,60 @@
|
||||||
package polling_station_dashboard.search.VotersFetcher;
|
package polling_station_dashboard.search.VotersFetcher;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Vladimir Eliezer Tokarev on 18/06/2016.
|
* 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
|
* 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 {
|
public class DummyVotersFetcher implements VotersFetcher {
|
||||||
|
|
||||||
|
private List<HashMap<String,String>> dummyVoters;
|
||||||
|
|
||||||
|
public DummyVotersFetcher()
|
||||||
|
{
|
||||||
|
this.dummyVoters = new ArrayList<>();
|
||||||
|
|
||||||
|
// voter that cant vote
|
||||||
|
HashMap<String, String> voter1 = new HashMap<>();
|
||||||
|
voter1.put("IDNumber", "123123123");
|
||||||
|
voter1.put("EligibleToVote", "no");
|
||||||
|
voter1.put("Status", "HasNotVoted");
|
||||||
|
voter1.put("Channel", "IDCMaths");
|
||||||
|
|
||||||
|
// voter that can vote
|
||||||
|
HashMap<String, String> 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
|
@Override
|
||||||
public List<Object> FetchVoters(List<String> filters) {
|
public List<HashMap<String,String>> FetchVoters(List<String> filters)
|
||||||
return new ArrayList<>();
|
{
|
||||||
|
List<HashMap<String,String>> votersWithFilters = new ArrayList<>();
|
||||||
|
|
||||||
|
for (String filter : filters) {
|
||||||
|
for (HashMap<String, String> 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package polling_station_dashboard.search.VotersFetcher;
|
package polling_station_dashboard.search.VotersFetcher;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,5 +9,5 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public interface VotersFetcher {
|
public interface VotersFetcher {
|
||||||
|
|
||||||
List<Object> FetchVoters(List<String> filters);
|
List<HashMap<String,String>> FetchVoters(List<String> filters);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ import javafx.fxml.FXML;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Vladimir Eliezer Tokarev on 11/06/2016.
|
* Created by Vladimir Eliezer Tokarev on 11/06/2016.
|
||||||
* This object controls the add voter panel behavior
|
* This object controls the add voter panel behavior
|
||||||
|
@ -12,6 +14,7 @@ public class AddVoterController {
|
||||||
|
|
||||||
private Stage currentStage;
|
private Stage currentStage;
|
||||||
|
|
||||||
|
|
||||||
public void SetStage(Stage primaryStage)
|
public void SetStage(Stage primaryStage)
|
||||||
{
|
{
|
||||||
this.currentStage = primaryStage;
|
this.currentStage = primaryStage;
|
||||||
|
|
Loading…
Reference in New Issue