public class LibraryManager extends Object
LibraryManagerFacade
interface providing
the business logic functions for the Virtual Library. Data access is
mediated by DAO objects, which are instantiated using Spring dependency
injection.Constructor and Description |
---|
LibraryManager() |
Modifier and Type | Method and Description |
---|---|
ArrayList<Book> |
authorSearch(String authorLastName)
Returns a list including all {org.sourceforge.vlibrary.user.domain.Author}s with the the given
last name.
|
boolean |
bookExists(long book)
Determines whether or not there is a book with the given id.
|
void |
cancelRequest(long reader,
long book)
Cancels a pending request for a book and sends confirmation email to
the reader canceling the request.
|
void |
createAuthorIds(ArrayList<Author> authors)
Walks input ArrayList, looking up and setting ID properties for
each Author in the list.
|
Book |
createBook(Book book,
ArrayList<Subject> subjects,
ArrayList<Author> authors)
Creates a book in the database and associates the given lists of
subjects and authors with the book.
|
void |
createBookAuthors(Book book,
ArrayList<Author> authors)
Sets the authors for the given book.
|
void |
createBookSubjects(Book book,
ArrayList<Subject> subjects)
Sets the subjects for the given book.
|
void |
createSubjectIds(ArrayList<Subject> subjects)
Walks the input ArrayList of
Subject instances, looking up and
setting ID properties for each Subject in the list. |
boolean |
deskPhoneExists(String deskPhone)
Determines whether or not there is a reader with the given
desk phone.
|
ArrayList<Book> |
dump()
Returns an ArrayList of
Book instances consisting of all books
in the library. |
void |
forgotPassword(String uid,
String email)
Validates that
uid exists and has email as
email address of record, then resets the associated password to a
randomly generated string and sends the reader an email with the new
password. |
ArrayList<Author> |
getAuthors(Book book)
Returns an ArrayList of Author} instances including the authors
of the given book.
|
ArrayList<Location> |
getLocations()
Returns an ArrayList including all currently defined locations.
|
long |
getPossessor(long book)
Queries the transaction table to determine the whereabouts of a book.
|
ReaderDAO |
getReaderDAO() |
long |
getReaderID(String firstName,
String lastName)
Returns the ID of a reader with the given first and last name, if
there is such a reader, throwing
LibraryException if
there is no reader with the given name. |
ArrayList<Reader> |
getReaders()
Returns an
ArrayList of Reader instances including
all currently registered Virtual Library readers. |
ArrayList<Subject> |
getSubjects()
Returns an ArrayList including all subjects currently defined in the
Virtual Library.
|
ArrayList<Subject> |
getSubjects(Book book)
Returns an ArrayList including all subjects currently defined in the
Virtual Library.
|
List<LibraryTransaction> |
getTransactions(long book)
Gets the entire transaction history for a book and returns
an ArrayList of
LibraryTransaction instances. |
void |
insertReader(Reader reader)
Inserts a record corresponding to the given reader into the database.
|
boolean |
isUserIDValid(long id)
Determines whether or not the given ID corresponds to a reader.
|
boolean |
isUserIDValid(String UID)
Determines whether or not the given UID (user id) belongs to a reader.
|
boolean |
isUserValidByPhone(String phoneNo)
Determines whether or not the supplied desk phone number belongs to a
reader.
|
Map |
lookupBook(String isbn)
Looks up the book indicated by the ISBN with SRU/SRW provider, returning
a Map of key-value pairs expressing attributes of the book.
|
ArrayList<Book> |
ownerSearch(long owner)
Returns an ArrayList of
Book instances consisting of all books
that are owned by the reader with the given ID. |
void |
processCheckin(long reader,
long book,
long location)
Processes book checkin transaction.
|
void |
processCheckout(long reader,
long book,
long location)
Processes book checkout transaction.
|
BookMoveTransaction |
processExchange(long reader,
long book,
String transactionType,
long location)
Processes a book checkin or checkout transaction.
|
void |
processRequest(long reader,
long book,
long location)
Processes book request transaction.
|
boolean |
readerExists(long id)
Determines whether or not there is a reader with the given ID.
|
boolean |
readerExists(String firstName,
String lastName)
Determines whether or not there is a reader with the given first and
last name.
|
boolean |
requestPending(long reader,
long book)
Determines whether or not a reader has a request pending for a book.
|
void |
resetPassword(String user,
String newPwd)
Resets a user's password.
|
Book |
retrieveBook(long bookID)
Returns the book with the given ID, or
null if there is no
such book. |
Reader |
retrieveByUid(String uid)
Retrieves a
Reader by user id (UID). |
long |
retrieveIDByPhone(String phoneNo)
Returns the ID of the reader who has the given desk phone.
|
Reader |
retrieveReader(long id)
Returns a fully populated
Reader corresponding to the
reader having the given ID. |
LibraryTransaction |
retrieveTransaction(long id)
Returns the
LibraryTransaction with the given transaction id. |
void |
setAuthorDAO(AuthorDAO authorDAO) |
void |
setBookDAO(BookDAO bookDAO) |
void |
setCrypto(Crypto crypto)
Used for Spring Dependency Injection
|
void |
setLibraryTransactionDAO(LibraryTransactionDAO libraryTransactionDAO) |
void |
setLocationDAO(LocationDAO locationDAO) |
void |
setMailWorker(MailWorker mailWorker) |
void |
setReaderDAO(ReaderDAO readerDAO) |
void |
setResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource resourceBundleMessageSource)
Used for Spring Dependency Injection
|
void |
setSruSrwClientInterface(SruSrwClientInterface sruClient)
Used for Spring Dependency Injection
|
void |
setSubjectDAO(SubjectDAO subjectDAO) |
ArrayList<Book> |
subjectAndSearch(ArrayList subjects)
|
ArrayList<Book> |
subjectOrSearch(ArrayList<Subject> subjects)
|
ArrayList<Book> |
titleSearch(String title)
Returns an ArrayList of
Book instances consisting of all books
having the given title. |
void |
updateBook(Book book)
Updates the database record associated with
book with the
properties that the given instance has. |
void |
updateReader(Reader reader)
Updates the database record associated with
reader with the
properties that the given instance has. |
public void setResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource resourceBundleMessageSource)
public void setMailWorker(MailWorker mailWorker)
mailWorker
- The mailWorker to set.public void setAuthorDAO(AuthorDAO authorDAO)
authorDAO
- The authorDAO to set.public void setBookDAO(BookDAO bookDAO)
bookDAO
- The bookDAO to set.public void setReaderDAO(ReaderDAO readerDAO)
readerDAO
- The readerDAO to set.public ReaderDAO getReaderDAO()
public void setSubjectDAO(SubjectDAO subjectDAO)
subjectDAO
- The subjectDAO to set.public void setLibraryTransactionDAO(LibraryTransactionDAO libraryTransactionDAO)
libraryTransactionDAO
- The libraryTransactionDAO to set.public void setCrypto(Crypto crypto)
public void setLocationDAO(LocationDAO locationDAO)
subjectDAO
- The subjectDAO to set.public void setSruSrwClientInterface(SruSrwClientInterface sruClient)
public ArrayList<Subject> getSubjects() throws LibraryException
LibraryException
- if an error occurs retrieving the list of
subjectspublic void createSubjectIds(ArrayList<Subject> subjects) throws LibraryException
Subject
instances, looking up and
setting ID properties for each Subject in the list. Lookup is based on
the description property. If a Subject is not found, a new entry is
inserted into the database and the ID of the newly created record is
assigned to the instance.subjects
- ArrayList of SubjectsLibraryException
- if a data access error occurspublic ArrayList<Location> getLocations() throws LibraryException
LibraryException
- if an error occurs retrieving the list of
subjectspublic boolean isUserValidByPhone(String phoneNo) throws LibraryException
phoneNo
- phone number to validateLibraryException
- if a data access error occurs validating
the phone numberpublic long retrieveIDByPhone(String phoneNo) throws LibraryException
Returns the ID of the reader who has the given desk phone.
Returns0
if there is no reader with the given desk
phone.phoneNo
- the desk phone to look upLibraryException
- if a data access error occurspublic boolean isUserIDValid(long id) throws LibraryException
id
- ID to validateLibraryException
- if a data access error occurs looking up the IDpublic boolean isUserIDValid(String UID) throws LibraryException
id
- UID to validateLibraryException
- if a data access error occurs looking up
the UIDpublic boolean readerExists(String firstName, String lastName) throws LibraryException
firstName
- first namelastName
- last nameLibraryException
- if a data access error occurspublic boolean readerExists(long id) throws LibraryException
id
- the ID to validateLibraryException
- if a data access error occurspublic boolean deskPhoneExists(String deskPhone) throws LibraryException
deskPhone
- the phone number to validateLibraryException
- if a data access error occurspublic ArrayList<Reader> getReaders() throws LibraryException
ArrayList
of Reader
instances including
all currently registered Virtual Library readers.LibraryException
- if a data access error occurspublic LibraryTransaction retrieveTransaction(long id) throws LibraryException
LibraryTransaction
with the given transaction id.id
- the ID of the transaction to retrieveLibraryException
- if a data access error occurs retrieving the
transactionpublic ArrayList<Book> authorSearch(String authorLastName) throws LibraryException
authorLastName
- the last name to look upLibraryException
- if a data access error occurspublic ArrayList<Book> subjectOrSearch(ArrayList<Subject> subjects) throws LibraryException
Book
instances consisting of all books
associated with one or more of the Subject
s in the input array.subjects
- list of subjectsLibraryException
- if a data access error occurspublic ArrayList<Book> subjectAndSearch(ArrayList subjects) throws LibraryException
Book
instances consisting of all books
that are associated with all of the Subject
s
in the input array.subjects
- list of subjectsLibraryException
- if a data access error occurspublic ArrayList<Book> ownerSearch(long owner) throws LibraryException
Book
instances consisting of all books
that are owned by the reader with the given ID.owner
- ID of ownerLibraryException
- if a data access error occurspublic ArrayList<Book> titleSearch(String title) throws LibraryException
Book
instances consisting of all books
having the given title.title
- title to look forLibraryException
- if a data access error occurspublic ArrayList<Book> dump() throws LibraryException
Book
instances consisting of all books
in the library.LibraryException
- if a data access error occurspublic Reader retrieveByUid(String uid) throws LibraryException
Retrieves a Reader
by user id (UID).
Returns null
if the supplied uid is not associated
with a reader in the datablase.
uid
- the UID of the reader to lookupLibraryException
- if a data access error occurspublic ArrayList<Author> getAuthors(Book book) throws LibraryException
book
- the bookLibraryException
- if a data access error occurspublic ArrayList<Subject> getSubjects(Book book) throws LibraryException
LibraryException
- if an error occurs retrieving the list of
subjectspublic BookMoveTransaction processExchange(long reader, long book, String transactionType, long location) throws LibraryException
BookMoveTransaction
representing
the transaction.
Delegates to one of #processCheckin(long, long)
or
#processCheckout(long, long)
, depending on the
transactionType
, which must be either
Contants.CHECKIN
or Contants.CHECKOUT
.
reader
- the id of the reader initiating the transactionbook
- the id of the book being checked in or outtransactionType
- transaction type - must be either
Contants.CHECKIN
or Contants.CHECKOUT
location
- the location of the checkin or checkoutLibraryException
- if an error occurs processing the transaction,
or if the parameters are not validpublic boolean bookExists(long book) throws LibraryException
book
- id to checkLibraryException
public long getReaderID(String firstName, String lastName) throws LibraryException
Returns the ID of a reader with the given first and last name, if
there is such a reader, throwing LibraryException
if
there is no reader with the given name.
Does not check for uniqueness - i.e., if there is more than one reader with the given first and last name, no exception is generated.
firstName
- the first name of the readerlastName
- the last name of the readerLibraryException
- if no such reader exists or a data access
error occurs looking up the readerpublic void createAuthorIds(ArrayList<Author> authors) throws LibraryException
authors
- = ArrayList of AuthorsLibraryException
public Book retrieveBook(long bookID) throws LibraryException
null
if there is no
such book.bookID
- the ID of the bookBook
instance with the given IDLibraryException
- if a data access error occurspublic Reader retrieveReader(long id) throws LibraryException
Reader
corresponding to the
reader having the given ID. Returns null
if there is no
such reader.id
- the ID to lookupReader
instanceLibraryException
- f a data access error occurspublic void createBookAuthors(Book book, ArrayList<Author> authors) throws LibraryException
book
- the book to attach authors toauthors
- the authors of the bookLibraryException
- if an error occurs accessing the database or
the ID of the given Book does not correspond to a book in the databasepublic void createBookSubjects(Book book, ArrayList<Subject> subjects) throws LibraryException
book
- the book to attach subjects tosubjects
- the subjects of the bookLibraryException
- if an error occurs accessing the database or
the ID of the given Book does not correspond to a book in the databasepublic Book createBook(Book book, ArrayList<Subject> subjects, ArrayList<Author> authors) throws LibraryException
Creates a book in the database and associates the given lists of
subjects and authors with the book. Authors and subjects are created
in the database if they do not already exist. Returns a new
Book
instance with the ID set to the database ID of the
newly created book.
The supplied book must have minimally a title and isbn, otherwise a LibraryException is thrown.
book
- the book to createsubjects
- the subjects to associate with the bookauthors
- the authors of the bookBook
instance with the ID of the newly created
bookLibraryException
- if the supplied book does not have sufficient
data or a database access error occurspublic void updateBook(Book book) throws LibraryException
book
with the
properties that the given instance has. Uses the ID property to locate
the record to update. If the ID does not correspond to a book in the
database, a LibraryException
is thrown.book
- the book to updateLibraryException
- if the book does not exist, or a data access
error occurspublic void insertReader(Reader reader) throws LibraryException
Inserts a record corresponding to the given reader into the database.
Ignores the ID field on input, but sets this field to the value of the database ID of the newly created reader.
Throws LibraryException
if the reader is missing
first name, last name, email or desk phone properties; or if the email
or desk phone already exist in the database.
reader
- the reader to addLibraryException
- if the reader is a duplicate, is missing data,
or a data access error occurspublic void updateReader(Reader reader) throws LibraryException
reader
with the
properties that the given instance has. Uses the ID property to locate
the record to update. If the ID does not correspond to a reader in the
database, a LibraryException
is thrown.reader
- the reader to updateLibraryException
- if the reader does not exist, or a data access
error occurspublic void processCheckin(long reader, long book, long location) throws LibraryException
Processes book checkin transaction.
Records the checkin in the transaction table and sends email notifications to current requesters.
Allows redundant checkins - i.e., a book that is already checked in can be checked in again.
book
- the id of the book being checked inreader
- the id of the reader checking in the booklocation
- the id of the location of the transactionLibraryException
- if an error occurs recording the checkin or
sending notificationspublic void processCheckout(long reader, long book, long location) throws LibraryException
Processes book checkout transaction.
Records the checkout in the transaction table and sends email notifications to current requesters.
book
- the id of the book being checked outreader
- the id of the reader checking out the booklocation
- the id of the location of the transactionLibraryException
- if an error occurs recording the checkout or
sending notificationspublic long getPossessor(long book) throws LibraryException
CHECKED_IN.
If there are no transactions associated with the book, then the book's owner is assumed to have the book, so the owner's ID is returned in this case.
book
- the id of the book being soughtLibraryException
- will be thrown if the book does not exist
or a data access error occurspublic void processRequest(long reader, long book, long location) throws Exception
The algorithm works as follows: First, we get a list of all copies of the given book whose last known location is the given location. If there are no such copies, BookNotFoundAtLocationException is thrown. If the reader has a pending request for one of these copies, DuplicateRequestException is thrown. If any are checked in, BookAwaitingPickupException is thrown. Otherwise, a request is created for each of the copies and the current possessor of each is notified.
book
- the id of the book being requestedreader
- the id of the reader making the requestlocation
- the location where the book is being requestedLibraryException
- if an error occurs processing the
transactionDuplicateRequestException
- if the requester already has a
request pending for the bookReaderNotFoundException
- if the reader
is not
foundException
public boolean requestPending(long reader, long book) throws LibraryException
reader
- the ID of the readerbook
- the ID of the bookreader
has a request
pending for the book with ID book
; false otherwiseLibraryException
- if a data access error occurspublic void cancelRequest(long reader, long book) throws LibraryException
reader
- the ID of the reader canceling the requestbook
- the ID of the bookLibraryException
- if the reader or book does not exist, or if
there is an error canceling the requestpublic List<LibraryTransaction> getTransactions(long book) throws LibraryException
LibraryTransaction
instances.book
- id of the book to retrieve transactions forLibraryException
- if a data access error occurspublic void resetPassword(String user, String newPwd) throws LibraryException
Fails silently if the user does not exist.
user
- UID of the usernewPwd
- new passwordLibraryException
- if an error occurs resetting the passwordpublic void forgotPassword(String uid, String email) throws LibraryException
uid
exists and has email
as
email address of record, then resets the associated password to a
randomly generated string and sends the reader an email with the new
password.uid
- UID to reset password foremail
- = email address - for confirmation and message targetLibraryException
- if the uid
is not found or if an
error occurs resetting the password or sending the notificationpublic Map lookupBook(String isbn) throws LibraryException
Constants.BOOKTITLE Constants.BOOKSUBJECTSLIST Constants.BOOKAUTHOR Constants.BOOKPUBLISHER Constants.BOOKDATEAll keys are mapped to String values, except Constants.BOOKSUBJECTSLIST which maps to a List of Strings.
isbn
- ISBN of the bookLibraryException
- if the isbn
is not found or if an error occursCopyright © 2003-2017 The Virtual Library Team. All Rights Reserved.