/*
* 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.dal;
import com.microsoft.sqlserver.jdbc.SQLServerException;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import mytime.be.Group;
import mytime.be.Location;
import mytime.be.Person;
import mytime.be.Volunteer;
import mytime.bll.TransactionException;
import mytime.dal.controller.FileoutputController;
import mytime.dal.controller.GuildController;
import mytime.dal.controller.IFileoutput;
import mytime.dal.controller.IGuild;
import mytime.dal.controller.ILocation;
import mytime.dal.controller.IVolunteer;
import mytime.dal.controller.LocationController;
import mytime.dal.controller.VolunteerController;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/**
*
* @author Stefan-VpcEB3J1E
*/
public class DALFacade
{
private final IVolunteer volunteerController;
private final IGuild guildController;
private final ILocation locationController;
private final IFileoutput fileoutController;
private static DALFacade INSTANCE;
private DALFacade() throws IOException
{
volunteerController = new VolunteerController();
guildController = new GuildController();
locationController = new LocationController();
fileoutController = new FileoutputController();
}
public static DALFacade getInstance() throws IOException
{
if (INSTANCE == null)
{
INSTANCE = new DALFacade();
}
return INSTANCE;
}
/**
* Gets all the volunteers in a group
*
* @return
* @throws SQLException
*/
public List<Person> getAllVolunteersInGuild(Group group) throws SQLException
{
return volunteerController.getAllVolunteersInGuild(group);
}
/**
* 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 volunteerController.createVolunteer(firstname, lastname, email, phonenumber, description, profilepicture, groupid);
}
/**
* Creates and adds guild to the database
*
* @param name
* @param locationId
* @throws SQLException
*/
public Group createGuild(String name, int locationId) throws SQLException
{
return guildController.createGuild(name, locationId);
}
/**
* Returns a list of all locations stored in database
*
* @return
*/
public List<Location> getAllLocations() throws SQLException
{
return guildController.getAllLocations();
}
// /**
// * Returns all guilds at a given location
// * @param location
// * @return
// * @throws SQLException
// */
// public List<Group> getAllGuildsAtLocation(Location location) throws SQLException
// {
// return guildController.getAllGuildsAtLocation(location);
// }
/**
* Gets the location with groups and persons by id
*
* @param locationId
* @return
* @throws SQLServerException
*/
public Location getSelectedLocation(int locationid) throws SQLException
{
return locationController.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
{
volunteerController.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 guildController.getAMembersGuildsAtLocation(volunteerid, locationid);
}
/**
* @param volunteerid
* @return the amount of hours one volunteer has worked in total, as an int.
* The volunteer is defined by id
* @throws SQLException
*/
public int getTotalHoursOneVolunteer(int volunteerid) throws SQLException
{
return volunteerController.getTotalHoursOneVolunteer(volunteerid);
}
/**
* @param volunteerid
* @param guildid
* @return amount of hours one person worked on one guild, as an int.
* @throws SQLException
*/
public int getHoursWorkedOnOneGuildByVolunteer(int volunteerid, int guildid) throws SQLException
{
return volunteerController.getHoursWorkedOnOneGuildByVolunteer(volunteerid, guildid);
}
/**
*
* @param volunteerid
* @return amount of hours one person worked on one guild, as an int.
* @throws SQLException
*/
public List<Integer> getArrayOfAvailableGuildsForVolunteer(int volunteerid) throws SQLException
{
return guildController.getArrayOfAvailableGuildsForVolunteer(volunteerid);
}
/**
* Assign a volunteer to a guild
*
* @param volunteerid
* @param guildid
* @throws SQLException
*/
public void addVolunteerToGuild(int volunteerid, int guildid) throws SQLException
{
volunteerController.addVolunteerToGuild(volunteerid, guildid);
}
/**
* @param volunteerid
* @return a list of all the groups a person is assigned to
* @throws SQLException
*/
public List<Group> getAllGroupsForPerson(int volunteerid) throws SQLException
{
return guildController.getAllGroupsForPerson(volunteerid);
}
/**
* Undoes the last documented hours for the current person logged in.
*
* @throws SQLException if there hadn't been done a transaction.
*/
public void undoLastDocumentedHours() throws SQLException
{
volunteerController.undoLastDocumentedHours();
}
/**
* 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
{
locationController.saveLocationLocally(locationid);
}
/**
* Gets the store location
*
* @return
* @throws IOException
*/
public int getLocalLocation() throws IOException
{
return locationController.getLocalLocation();
}
/**
* @return all volunteers
* @throws SQLException
*/
public List<Person> getAllVolunteers() throws SQLException
{
return volunteerController.getAllVolunteers();
}
/**
* Deletes a volunteer from the database
*
* @param volunteerid
* @throws SQLException
*/
public void deleteVolunteer(Person p) throws SQLException
{
volunteerController.deleteVolunteer(p);
}
/**
* Undo the last deleted person.
*
* @return
* @throws SQLException
*/
public Person undoLastDeletedPerson() throws SQLException
{
return volunteerController.undoLastDeletedPerson();
}
/**
* Clears the saved location on this computer.
*
* @throws IOException
*/
public void clearLocationLocally() throws IOException
{
locationController.clearLocationLocally();
}
/**
* @return all groups stored in the database
* @throws SQLException
*/
public List<Group> getAllGroups() throws SQLException
{
return guildController.getAllGroups();
}
/**
* Updates the information of a person.
*
* @param person
*/
public void updatePerson(Person person) throws SQLException
{
volunteerController.updatePerson(person);
}
/**
* Assign person to group (Volunteer to guild)
*
* @param person
* @param group
* @throws SQLException
*/
public void addVolunteerToGuild(Person person, Group group) throws SQLException
{
volunteerController.addVolunteerToGuild(person.getId().get(), group.getId().get());
}
/**
* Removes a person from a group
*
* @param person
* @param group
* @throws SQLException
*/
public void removePersonFromGroup(Person person, Group group) throws SQLException
{
volunteerController.removePersonFromGroup(person, group);
}
/**
* 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 volunteerController.getHoursWorkedInEachGuildOnByPerson(person, groupAmount);
}
/**
* Method for saving a the spreadsheet as a XLS document.
*
* @param generateXlsDocument Spreadsheet
* @param selectedFile Destination file to save to.
*/
public void saveXlsDocument(HSSFWorkbook generateXlsDocument, File selectedFile)
{
fileoutController.saveXlsDocument(generateXlsDocument, selectedFile);
}
}