/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mytime.gui.model;
import com.microsoft.sqlserver.jdbc.SQLServerException;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.beans.property.IntegerProperty;
import javafx.scene.Node;
import javafx.scene.Scene;
import mytime.be.Group;
import mytime.be.Location;
import mytime.be.Person;
import mytime.bll.BLLManager;
import mytime.bll.TransactionException;
/**
*
* @author Stefan-VpcEB3J1E
*/
public class Model
{
private static Model INSTANCE;
private BLLManager bllMgr;
private Scene managerScene;
private Scene loginManScene;
private Model()
{
try
{
bllMgr = new BLLManager();
} catch (IOException ex)
{
ex.printStackTrace();
}
}
public static Model getInstance()
{
if (INSTANCE == null)
{
INSTANCE = new Model();
}
return INSTANCE;
}
/**
* Gets all the locations without the groups and persons
*
* @return
* @throws SQLException
*/
public List<Location> getAllLocations() throws SQLException
{
return bllMgr.getAllLocations();
}
/**
* Gets a location with groups and persons.
*
* @param id
* @return
* @throws SQLServerException
*/
public Location getSelectedLocation(int locationid) throws SQLException
{
return bllMgr.getSelectedLocation(locationid);
}
/**
* Documents volunteer-hours in the database. Method is called to store
* hours worked by given volunteer-id at given guild-id. The date when this
* method is called is also saved in the database
*
* @param volunteerid
* @param guildid
* @param hours
* @throws SQLException
*/
public void addHoursForVolunteer(int volunteerid, int guildid, int hours) throws SQLException
{
bllMgr.addHoursForVolunteer(volunteerid, guildid, hours);
}
/**
* Returns a list of guilds at a certain location which the given volunteer
* is a member of
*
* @param c
* @param volunteerid
* @param locationid
* @return
*/
public List<Group> getAMembersGuildsAtLocation(int volunteerid, int locationid) throws SQLException
{
return bllMgr.getAMembersGuildsAtLocation(volunteerid, locationid);
}
public BLLManager getBllManager()
{
return bllMgr;
}
/**
* Gets a List of all the groups a person document hours into.
*
* @param personId
* @return
* @throws SQLException
*/
public List<Group> getAllGroupsForPerson(int personId) throws SQLException
{
return bllMgr.getAllGroupsForPerson(personId);
}
/**
* Save the chosen location on the pc, so you dont have to choose everytime
* you open the application
*
* @param location
* @throws IOException
*/
public void saveLocationLocally(int locationid) throws IOException
{
bllMgr.saveLocationLocally(locationid);
}
/**
* Gets the store location
*
* @return
* @throws IOException
*/
public int getLocalLocation() throws IOException
{
return bllMgr.getLocalLocation();
}
/**
* @return all volunteers
* @throws SQLException
*/
public List<Person> getAllVolunteers() throws SQLException
{
return bllMgr.getAllVolunteers();
}
/**
* Creates and adds volunteer to the database
*
* @param name
* @param email
* @param phonenumber
* @throws SQLException
*/
public Person createVolunteer(String firstname, String lastname, String email, String phonenumber, String description, String profilepicture, int... groupid) throws SQLException, TransactionException
{
return bllMgr.createVolunteer(firstname, lastname, email, phonenumber, description, profilepicture, groupid);
}
public void setManagerScene(Scene scene)
{
this.managerScene = scene;
}
public Scene getManagerScene()
{
return managerScene;
}
/**
* @return all groups stored in the database
* @throws SQLException
*/
public List<Group> getAllGroups() throws SQLException
{
return bllMgr.getAllGroups();
}
/**
* Updates the information of a person.
* @param person
*/
public void updatePerson(Person person) throws SQLException
{
bllMgr.updatePerson(person);
}
public void setLoginManScene(Scene scene)
{
this.loginManScene = scene;
}
public Scene getLoginManScene()
{
return loginManScene;
}
/**
* Assign person to group (Volunteer to guild)
* @param person
* @param group
* @throws SQLException
*/
public void addPersonToGroup(Person person, Group group) throws SQLException
{
bllMgr.addPersonToGroup(person, group);
}
/**
* Removes a person from a group
* @param person
* @param group
* @throws SQLException
*/
public void removePersonFromGroup(Person person, Group group) throws SQLException
{
bllMgr.removePersonFromGroup(person, group);
}
/**
* @param query
* @return filters any list of nodes which has person userdata and returns the filtered list
*/
public List<Node> filterAnyListOfNodes(String query, List<Node> fullList)
{
//System.out.println(bllMgr.filterList(query, loginPersonNodes));
return bllMgr.filterList(query, fullList);
}
/**
* Get sum of hours worked in each guild by one volunteer
* @param person
* @param groupAmount
* @return int[guild id][hours]
* @throws SQLException
*/
public int[][] getHoursWorkedInEachGuildOnByPerson(Person person, int groupAmount) throws SQLException
{
return bllMgr.getHoursWorkedInEachGuildOnByPerson(person, groupAmount);
}
}