View Test Results.
package cs221.groupk.database;
import java.io.File;
import java.util.Date;
import cs221.groupk.common.*;
import cs221.groupk.exceptions.database.*;
/**
* Database Engine is the only class that will interact with the long-term
* storage files. DatabaseEngine has all the methods to add, remove and edit
* data, as well as maintaining the internal structor of the files on disk.
* As this file has access to all data, the security for the system will be
* dealt with internally inside this class, Exceptions informing the various
* user interfaces of problems. Much of this class is simply an interface to
* underlying classes, so this class is basically provided to give a simple
* and uniform API to write the remaining modules.<BR><BR>
* <B>Notes on using DatebaseEngine</B><BR>
* <UL>
* <LI>This class uses the information in the database to protect itself, so if
* a user is not in the database, then that user cannot edit the database.</LI>
* <UL><LI>Care must be taken with changeing users permissions / removing users
* active status else it is possible to lock the system so nobody can access
* the system</LI>
* </UL>
* <LI>When a session has finnished you <B>MUST</B> call <A HREF=
* "DatabaseEngine.html#shutDownSystem()"><CODE>shutdown</A></CODE>, this
* method performs nessesary operations on the database, flushing caches, back-up
* ect.</LI>
* </UL>
* <B>Users</B><BR>
* There are no methods provided for removing Users, a user can simply be made
* in-active. This has the same effect with regard to that users functionality
* but it means that the user is maintained at each station, so you can look
* back to see who was on which station and when, evan if that user is not
* longer employed.<BR><BR>
* <B>SaleItems and SaleItemLists</B><BR>
* The methods here are carfully selected to allow the databse to preserve
* integrety, for example a SaleItem's ID is specified by the system, so
* there is no duplication of ID's, thus it will be possible to store the data
* in a normalised form, but recreate the input data or a veriation thereof.
*
* <P><I>Code spell-checked - Chris Milner - 5th December 2000.</I><P>
*
* @author <A HREF="mailto:[email protected]">Paul Smith</A>
*/
public class DatabaseEngine implements Constants
{
/**password is the local (encrypted) copy of the entered password*/
protected String password;
/**userID is the local (encrypted) copy of the entered userID*/
protected String userID;
/**validatedUserLevel specifies the level of the person whom has been authenticated*/
protected static int validatedUserLevel = ACCESS_LEVEL_NOT_VALIDATED;
/**
* disk is a copy of the Disk used as a temporary store before data is written
* to/from the database
*/
protected Disk disk;
//########################################################################
//# Constructors
//########################################################################
/**
* Default Constructor for DatabaseEngine.
*/
public DatabaseEngine()
{
startup();
}
/**
* Over-loaded Constructor for DatabaseEngine, allowing instant validation
* using the provided user ID and password.
*/
public DatabaseEngine(String userID, String password)
throws UserValidationException
{
super();
this.password = FuncU.encryptString(password);//?
this.userID = FuncU.encryptString(userID);//?
switch (validateUser(this.userID, this.password))
{
case VALIDATION_SUCCESFULL_ALL : break;
case VALIDATION_SUCCESFULL_STATIONS : break;
case VALIDATION_SUCCESFULL_BOTTOM_STATION : break;
case VALIDATION_SUCCESFULL_TOP_STATION : break;
case VALIDATION_FAIL_NOT_AUTHORISED : break;
case VALIDATION_FAIL_NO_SUCH_USER : break;
case VALIDATION_FAIL_INVALID_PASSWORD : break;
default : break;
}
}
//########################################################################
//# Disk Operation code.
//########################################################################
/**
* disasterRecovery is a utility method for rebuilding the database should
* the file structure be compromised. By passing in the Disks the database
* can be re-created. <B>This method is as the name implies, it is a last
* resort, and should not be used unless the database HAS to be re-built.</B>
* @param File[] disks is the array of File objects pointing to Disk files
* that have been written from the stations.
* @return int 0 on success or negative error code.
* @exception InsufficientAccessPrivilegeException is thrown if the current
* user does not have sufficient access privileges for admin tasks.
* @see Constants#OPERATION_FAILED
*/
public int disasterRecovery(File[] disks)
throws InsufficientAccessPrivilegeException
{
return OPERATION_FAILED;
}
/**
* addDisk adds the specified Disk to the database. The method will fail if
* you do not have sufficient privilages to perform this action, and will
* fail if you attempt to overwrite an already added Disk (within the database).
* It is recomended that the Disk files are copied to a temp file locally
* before calling this method to speed up the updating procedure.
* @exception InsufficientAccessPrivilegeException is thrown if the current
* user does not have sufficient access privileges for admin tasks.
*/
public int addDisk(Disk disk)
throws InsufficientAccessPrivilegeException
{
return OPERATION_FAILED;
}
//########################################################################
//# SaleItem Code.
//########################################################################
/**
* addSaleItemList creates an empty SaleItemList, and returns the ID of the
* newly added SaleItemList.
* @return int SaleItemList's ID.
* @exception InsufficientAccessPrivilegeException is thrown if the current
* user does not have sufficient access privileges for admin tasks.
*/
public int addSaleItemList()
throws InsufficientAccessPrivilegeException
{
return OPERATION_FAILED;
}
/**
* addSaleItem adds the SaleItem saleItem to the SaleItemList specified by
* SaleItemListID.
* @param int SaleItemListID specifes which SaleItemList to add the new
* SaleItem to.
* @param SaleItem saleItem is the new SaleItem to be added
* @return int saleItemID.
* @exception SaleItemListIDInvalidException is thrown if the value specifed
* by SaleItemListID does not reference a SaleItemList.
* @exception SaleItemIDInvalidException is thrown if the value specifed
* by saleItem already exists.
* @exception InsufficientAccessPrivilegeException is thrown if the current
* user does not have sufficient access privalges for admin tasks.
*/
public int addSaleItem(int SaleItemListID, SaleItem saleItem)
throws SaleItemListIDInvalidException,
SaleItemIDInvalidException,
InsufficientAccessPrivilegeException
{
return OPERATION_FAILED;
}
/**
* addSaleItem creates a new SaleItem, then adds it to the specifed
* SaleItemListID.
* @param int SaleItemListID specifes which SaleItemList to add the new
* SaleItem to.
* @param String itemName is the name of the item in question.
* @param String itemDescription is a description of the new SaleItem
* @param int price is the price of the new SaleItem
* @exception SaleItemListIDInvalidException is thrown if the value specifed
* by SaleItemListID does not reference a SaleItemList.
* @exception InsufficientAccessPrivilegeException is thrown if the current
* user does not have sufficient access privalges for admin tasks.
*/
public int addSaleItem(int SaleItemListID,
String itemName,
String itemDescription,
int price)
throws SaleItemListIDInvalidException,
InsufficientAccessPrivilegeException
{
return OPERATION_FAILED;
}
/**
* getSaleItemList returns a SaleItemList, using the saleItemListID to
* return the required list.
* @param int saleItemListID is used as a lookup to retreive the required
* saleItem list.
* @return SaleItemList as specified by parameter saleItemListID.
* @exception SaleItemListIDInvalidException is thrown when a SaleItemList
* cannot be found / returned with a matching id.
* @exception InsufficientAccessPrivilegeException is thrown if the current
* user does not have sufficient access privalges for admin tasks.
*/
public SaleItemList getSaleItemList(int saleItemListID)
throws SaleItemListIDInvalidException,
InsufficientAccessPrivilegeException
{
return null;
}
/**
* getSaleItemLists returns all SaleItemList objects from the database.
* @return SaleItemList[] from the database.
* @exception InsufficientAccessPrivilegeException is thrown if the current
* user does not have sufficient access privileges for admin tasks.
*/
public SaleItemList[] getSaleItemLists()
throws InsufficientAccessPrivilegeException
{
return null;
}
/**
* getSaleItems returns a list of ALL SaleItems in the database.
* @return SaleItem[] is the array of SaleItems.
* @exception InsufficientAccessPrivilegeException is thrown if the current
* user does not have sufficient access privileges for admin tasks.
*/
public SaleItem[] getSaleItems()
throws InsufficientAccessPrivilegeException
{
return null;
}
//########################################################################
//# User Admin
//########################################################################
/**
* getUserIDs returns a list of all user IDs contianed within the database.
* @return String[] of user ID's within the database.
* @exception InsufficientAccessPrivilegeException is thrown if the current
* user does not have sufficient access privileges for admin tasks.
*/
public String[] getUserIDs()
throws InsufficientAccessPrivilegeException
{
return null;
}
/*
* getUser returns the User Object with the specified userID or throws a
* UserNotFoundException if the user cannot be found. <B>Note.</B> The User
* returned will have the userID, and password fields still encrypted.
* @param String userID of returned User.
* @exception UserNotFoundException is thrown if the user specifed with
* userID is not found within the database.
* @exception InsufficientAccessPrivilegeException is thrown if the current
* user does not have sufficient access privileges for admin tasks.
*/
/*
public User getUser(String userID)
throws UserNotFoundException,
InsufficientAccessPrivilegeException
{
return null;
}*/
/**
* getUserPassword returns the user specified by userId's password.
* @param String userID to returned password of.
* @return String decrypted password.
* @exception UserNotFoundException is thrown if the user specified with
* userID is not found within the database.
* @exception InsufficientAccessPrivilegeException is thrown if the current
* user does not have sufficient access privileges for admin tasks.
*/
public String getUserPassword(String userID)
throws UserNotFoundException,
InsufficientAccessPrivilegeException
{
return null;
}
/**
* getUserFullName returns the specified users full name.
* @param String userID to returned full name of
* @return String users full name.
* @exception UserNotFoundException is thrown if the user specified with
* userID is not found within the database.
* @exception InsufficientAccessPrivilegeException is thrown if the current
* user does not have sufficient access privileges for admin tasks.
*/
public String getUserFullName(String userID)
throws UserNotFoundException,
InsufficientAccessPrivilegeException
{
return null;
}
/**
* addUser adds the User user to the user database.
* @return int negative error code or 0 for success.
* @exception InsufficientAccessPrivilegeException is thrown if the current
* user does not have sufficient access privileges for admin tasks.
* @exception UserAlreadyExistsException is thrown when the User user's ID
* already exists.
*/
public int addUser(User user)
throws InsufficientAccessPrivilegeException,
UserAlreadyExistsException
{
return OPERATION_FAILED;
}
/**
* setUserPermissions sets the Users permissions specifed by the userID
* String. <B>Caution</B> to be used with this method as it is possible to
* lock out users.
* @param String userID of user to set permissions.
* @param boolean admin or not.
* @param boolean topStation or not.
* @param boolean bottomStation or not.
* @exception UserNotFoundException is thrown if the user specifed with
* userID is not found within the database.
* @exception InsufficientAccessPrivilegeException is thrown if the current
* user does not have sufficient access privileges for admin tasks.
*/
public void setUserPermissions(String userID,
boolean admin,
boolean topStation,
boolean bottomStation)
throws UserNotFoundException,
InsufficientAccessPrivilegeException
{
}
/**
* setUserActive sets the active value in the User specified by userID. If
* a users active property is set to false, then that user is treated as if
* they are not in the system. This would be used to keep track of which staff
* are on which station, and which staff are no longer employed.
* @param String userID of user to set active.
* @param boolean active
* @exception UserNotFoundException is thrown if the user specifed with
* userID is not found within the database.
* @exception InsufficientAccessPrivilegeException is thrown if the current
* user does not have sufficient access privileges for admin tasks.
*/
public void setUserActive(String userID, boolean active)
throws UserNotFoundException,
InsufficientAccessPrivilegeException
{
}
/**
* getUserActive
* @param String userID of user to check if active or not.
* @return boolean returns true if user is "Active", otherwise false.
* @exception UserNotFoundException is thrown if the user specifed with
* userID is not found within the database.
* @exception InsufficientAccessPrivilegeException is thrown if the current
* user does not have sufficient access privileges for admin tasks.
*/
public boolean isUserActive(String userID)
throws UserNotFoundException,
InsufficientAccessPrivilegeException
{
return false;
}
//########################################################################
//# Startup / Shutdown code.
//########################################################################
/**
* validateUser takes the user and password, then checks them against known
* /valid users. The value returned specifies if the validation was
* successfull. The values returned are those specified in Constants.
* @param int negative error code, or positive access level.
* @see Constants#VALIDATION_SUCCESFULL_ALL
* @see Constants#VALIDATION_SUCCESFULL_STATIONS
* @see Constants#VALIDATION_SUCCESFULL_BOTTOM_STATION
* @see Constants#VALIDATION_SUCCESFULL_TOP_STATION
* @see Constants#VALIDATION_FAIL_NOT_AUTHORISED
* @see Constants#VALIDATION_FAIL_NO_SUCH_USER
* @see Constants#VALIDATION_FAIL_INVALID_PASSWORD
*/
public int validateUser(String user, String pswd)
{
return validatedUserLevel;
}
/**
* shutDownSystem <B>must</B> be called to finnish session using the database.
* This method will disable further read/writes to the database - without
* re-verification - saving data, and flushing buffers and generally exiting
* gracefully.
* @return int negative error code or 0 for success.
*/
public int shutDownSystem()
{
//Set a file etc to indicate databse was correctly shutdown.
return OPERATION_FAILED;
}
/**
* startup is called from the DatabaseEngines constructor to setup a few
* things, including backing-up the database, and other admin tasks.
*/
protected void startup()
{
validatedUserLevel = ACCESS_LEVEL_NOT_VALIDATED;
//check system was shutdown correctly last time (use logs ect)
//open and load current database.
//backup current files.
//log changes, keep the Disk files ect.
}
//########################################################################
//# BoughtItem Methods.
//########################################################################
/**
* getBoughtItems gets all BoughtItems, ever. This method should be used
* with caution as there could be potentially lots of data returned.
* @return BoughtItems[] is the array of BoughtItems.
* @exception InsufficientAccessPrivilegeException is thrown if the current
* user does not have sufficient access privileges for admin tasks.
*/
public BoughtItem[] getBoughtItems()
throws InsufficientAccessPrivilegeException
{
return null;
}
/**
* getBoughtItems gets all BoughtItems, on the specifed Data.
* @param Date date of BoughtItems to retrieve.
* @return BoughtItems[] is the array of BoughtItems.
* @exception InsufficientAccessPrivilegeException is thrown if the current
* user does not have sufficient access privalges for admin tasks.
*/
public BoughtItem[] getBoughtItems(Date date)
throws InsufficientAccessPrivilegeException
{
return null;
}
/**
* getBoughtItems gets all BoughtItems, between the specifed Dates.
* @param Date startDate of BoughtItems to retrieve.
* @param Date endDate of BoughtItems to retrieve.
* @return BoughtItems[] is the array of BoughtItems.
* @exception InsufficientAccessPrivilegeException is thrown if the current
* user does not have sufficient access privileges for admin tasks.
*/
public BoughtItem[] getBoughtItems(Date startDate, Date endDate)
throws InsufficientAccessPrivilegeException
{
return null;
}
/**
* getBoughtItemCount returns the total number of BoughtItems in the
* database.
* @return int number of BoughtItems
*/
public int getBoughtItemCount()
throws InsufficientAccessPrivilegeException
{
return OPERATION_FAILED;
}
/**
* getBoughtItemCount returns the total number of BoughtItems in the
* database, on the date specified by date.
* @param Date date to get BoughtItem's count for.
* @return int number of BoughtItems
*/
public int getBoughtItemCount(Date date)
throws InsufficientAccessPrivilegeException
{
return OPERATION_FAILED;
}
/**
* getBoughtItemCount returns the total number of BoughtItems in the
* database, between the dates specified by startDate and endDate.
* @param Date startDate to get BoughtItem's count from.
* @param Date endDate to get BoughtItem's count to.
* @return int number of BoughtItems
*/
public int getBoughtItemCount(Date startDate, Date endDate)
throws InsufficientAccessPrivilegeException
{
return OPERATION_FAILED;
}
}
Page automatically generated on: 26/01/01 at: 10:48:17.