cafe.main
Class MainGuiHandler

java.lang.Object
  extended by cafe.main.MainGuiHandler
All Implemented Interfaces:
UserInterfaceEvent

public class MainGuiHandler
extends java.lang.Object
implements UserInterfaceEvent

This class connects GUI with Database and Authentication components

Version:
0.2
Author:
Markus Penttila

Constructor Summary
MainGuiHandler(Database db, CoffeeTouch main, AuthenticationSettings authSettings)
          Constructs a new instance of this class and creates Authentication instance.
 
Method Summary
 boolean authenticateUser(java.lang.String username, java.lang.String password)
          Authenticates an user's CS department username and password by calling UserAuthentication interface's authenticateUser method.
 CancelProduct cancelProductExport(UserInfo user)
          Cancels the last export transaction from the given user.
 void deleteFingerprint(int id)
          Deletes a certain fingerprint (data) from the database and fingerprint cache by calling Database interface's deleteFingerprint and CoffeeTouch's deleteFingerprint methods.
 void exportProduct(UserInfo user, ExportProduct product)
          Marks an export transaction to the given user and product by calling Database interface's exportProduct method.
 ImportProduct[] getAlerts()
          Returns a list of all products that have an alert set.
 ProductGroup[] getProductGroups()
          Returns a list of all product groups.
 ExportProduct[] getProductList()
          Returns a list of all exportable products.
 void importProduct(UserInfo user, ImportProduct product, double amount)
          Marks an import transaction to the given user and product by calling Database interface's importProduct method.
 void insertAlert(ImportProduct product)
          Inserts an alert to the given product to the database by calling Database interface's insertAlert method.
 UserInfo loadUser(java.lang.String username)
          Loads an user's information from the database based on the CS dep. username given as an argument.
 void removeAlert(ImportProduct product)
          Removes the alert from the given product by calling Database interface's removeAlert method.
 void saveUser(UserInfo user)
          Saves an UserInfo instance describing a certain user to the database by calling Database interface's saveUser method.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MainGuiHandler

public MainGuiHandler(Database db,
                      CoffeeTouch main,
                      AuthenticationSettings authSettings)
Constructs a new instance of this class and creates Authentication instance.

Parameters:
db - reference to a class that implemens database interface
main - reference to main class
authSettings - settings to be passed on to Authentication
Method Detail

authenticateUser

public boolean authenticateUser(java.lang.String username,
                                java.lang.String password)
Authenticates an user's CS department username and password by calling UserAuthentication interface's authenticateUser method.

Specified by:
authenticateUser in interface UserInterfaceEvent
Parameters:
username - user's username
password - user's password
Returns:
true if username and password match, false if the do not.

cancelProductExport

public CancelProduct cancelProductExport(UserInfo user)
Cancels the last export transaction from the given user. Calls Database interface's cancelProductExport method. If a database error occurs, calls CoffeeTouch's displayDBError method.

Specified by:
cancelProductExport in interface UserInterfaceEvent
Parameters:
user - the user whose transaction will be cancelled
Returns:
information about the cancelled product. null if such transaction could not be found.

deleteFingerprint

public void deleteFingerprint(int id)
Deletes a certain fingerprint (data) from the database and fingerprint cache by calling Database interface's deleteFingerprint and CoffeeTouch's deleteFingerprint methods. If a database exception occurs, calls CoffeeTouch's displayDBError method.

Specified by:
deleteFingerprint in interface UserInterfaceEvent
Parameters:
id - the id of the fingerprint that will be deleted

exportProduct

public void exportProduct(UserInfo user,
                          ExportProduct product)
Marks an export transaction to the given user and product by calling Database interface's exportProduct method. If a database exception occurs, calls CoffeeTouch's displayDBError.

Specified by:
exportProduct in interface UserInterfaceEvent
Parameters:
user - the current user exporting a product
product - the product to be exported

getAlerts

public ImportProduct[] getAlerts()
Returns a list of all products that have an alert set. Gets the list by calling Database interface's getAlerts method. If a database exception occurs, calls CoffeeTouch's displayDBError.

Specified by:
getAlerts in interface UserInterfaceEvent
Returns:
list of products as ImportProduct instances.

getProductGroups

public ProductGroup[] getProductGroups()
Returns a list of all product groups. Gets the list by calling Database interface's getProductGroups method. If a database exception occurs, calls CoffeeTouch's displayDBError.

Specified by:
getProductGroups in interface UserInterfaceEvent
Returns:
the list of ProductGroup instances

getProductList

public ExportProduct[] getProductList()
Returns a list of all exportable products. Gets the list by calling Database interface's getProductList method. If a database error occurs, calls CoffeeTouch's displayDBError method.

Specified by:
getProductList in interface UserInterfaceEvent
Returns:
the list containing all exportable products

importProduct

public void importProduct(UserInfo user,
                          ImportProduct product,
                          double amount)
Marks an import transaction to the given user and product by calling Database interface's importProduct method. If a database error occurs, calls CoffeeTouch's displayDBError method.

Specified by:
importProduct in interface UserInterfaceEvent
Parameters:
user - the current user importing a product
product - the product to be imported
amount - the amount (size) of the imported product

insertAlert

public void insertAlert(ImportProduct product)
Inserts an alert to the given product to the database by calling Database interface's insertAlert method. If a database error occurs, calls CoffeeTouch's displayDBError method.

Specified by:
insertAlert in interface UserInterfaceEvent
Parameters:
product - the product that will receive the alert

loadUser

public UserInfo loadUser(java.lang.String username)
Loads an user's information from the database based on the CS dep. username given as an argument. Calls Database interface's loadUser(username) method. If a database error occurs, calls CoffeeTouch's displayDBError method.

Specified by:
loadUser in interface UserInterfaceEvent
Parameters:
username - the username of the user to be loaded
Returns:
a UserInfo instance containing a user's information.

removeAlert

public void removeAlert(ImportProduct product)
Removes the alert from the given product by calling Database interface's removeAlert method. If a database error occurs, calls CoffeeTouch's displayDBError method.

Specified by:
removeAlert in interface UserInterfaceEvent
Parameters:
product - the product whose alert will be dismissed

saveUser

public void saveUser(UserInfo user)
Saves an UserInfo instance describing a certain user to the database by calling Database interface's saveUser method.

Specified by:
saveUser in interface UserInterfaceEvent
Parameters:
user - UserInfo to be stored