From 40663c65b83b8751123a3bdf37cd2f0d16eb0f30 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Tue, 15 Nov 2016 12:49:30 +0200 Subject: [PATCH] Bug 17712: Add new Koha::Exceptions To describe problems or notes to availability, we will be using Koha::Exceptions. This patch adds many useful Koha::Exceptions that we can use for this purpose. --- Koha/Exceptions.pm | 27 ++++++++++++++- Koha/Exceptions/Biblio.pm | 32 +++++++++++++++++ Koha/Exceptions/Checkout.pm | 66 +++++++++++++++++++++++++++++++++++ Koha/Exceptions/Hold.pm | 47 +++++++++++++++++++++++++ Koha/Exceptions/Item.pm | 84 +++++++++++++++++++++++++++++++++++++++++++++ Koha/Exceptions/ItemType.pm | 18 ++++++++++ Koha/Exceptions/Patron.pm | 66 +++++++++++++++++++++++++++++++++++ 7 files changed, 339 insertions(+), 1 deletion(-) create mode 100644 Koha/Exceptions/Biblio.pm create mode 100644 Koha/Exceptions/Checkout.pm create mode 100644 Koha/Exceptions/Hold.pm create mode 100644 Koha/Exceptions/Item.pm create mode 100644 Koha/Exceptions/ItemType.pm create mode 100644 Koha/Exceptions/Patron.pm diff --git a/Koha/Exceptions.pm b/Koha/Exceptions.pm index dd8647b..1cceddc 100644 --- a/Koha/Exceptions.pm +++ b/Koha/Exceptions.pm @@ -9,6 +9,11 @@ use Exception::Class ( description => 'Something went wrong!', }, + 'Koha::Exceptions::BadParameter' => { + isa => 'Koha::Exceptions::Exception', + description => 'A bad parameter was given', + fields => ['parameter'], + }, 'Koha::Exceptions::DuplicateObject' => { isa => 'Koha::Exceptions::Exception', description => 'Same object already exists', @@ -17,9 +22,29 @@ use Exception::Class ( isa => 'Koha::Exceptions::Exception', description => 'The default value cannot be deleted' }, + 'Koha::Exceptions::InvalidDate' => { + isa => 'Koha::Exceptions::Exception', + description => "Date is invalid.", + fields => ["date"], + }, 'Koha::Exceptions::MissingParameter' => { isa => 'Koha::Exceptions::Exception', - description => 'A required parameter is missing' + description => 'A required parameter is missing', + fields => ["parameter"], + }, + 'Koha::Exceptions::AuthenticationRequired' => { + isa => 'Koha::Exceptions::Exception', + description => 'Auhtentication is required.', + }, + 'Koha::Exceptions::NoPermission' => { + isa => 'Koha::Exceptions::Exception', + description => 'No permission to access this resource.', + fields => ["required_permissions"] + }, + 'Koha::Exceptions::NotImplemented' => { + isa => 'Koha::Exceptions::Exception', + description => 'A subroutine is not implemented', + fields => ["subroutine"] }, # Virtualshelves exceptions 'Koha::Exceptions::Virtualshelves::DuplicateObject' => { diff --git a/Koha/Exceptions/Biblio.pm b/Koha/Exceptions/Biblio.pm new file mode 100644 index 0000000..21ea965 --- /dev/null +++ b/Koha/Exceptions/Biblio.pm @@ -0,0 +1,32 @@ +package Koha::Exceptions::Biblio; + +use Modern::Perl; + +use Exception::Class ( + + 'Koha::Exceptions::Biblio' => { + description => 'Something went wrong!', + }, + 'Koha::Exceptions::Biblio::AnotherItemCheckedOut' => { + isa => 'Koha::Exceptions::Biblio', + description => "Another item from same biblio already checked out.", + fields => ["itemnumbers"], + }, + 'Koha::Exceptions::Biblio::CheckedOut' => { + isa => 'Koha::Exceptions::Biblio', + description => "Biblio is already checked out for patron.", + fields => ['biblionumber'], + }, + 'Koha::Exceptions::Biblio::NoAvailableItems' => { + isa => 'Koha::Exceptions::Biblio', + description => "Biblio does not have any available items.", + }, + 'Koha::Exceptions::Biblio::NotFound' => { + isa => 'Koha::Exceptions::Biblio', + description => "Biblio not found.", + fields => ['biblionumber'], + }, + +); + +1; diff --git a/Koha/Exceptions/Checkout.pm b/Koha/Exceptions/Checkout.pm new file mode 100644 index 0000000..611c338 --- /dev/null +++ b/Koha/Exceptions/Checkout.pm @@ -0,0 +1,66 @@ +package Koha::Exceptions::Checkout; + +use Modern::Perl; + +use Exception::Class ( + + 'Koha::Exceptions::Checkout' => { + description => 'Something went wrong!', + }, + 'Koha::Exceptions::Checkout::DueDateBeforeNow' => { + isa => 'Koha::Exceptions::Checkout', + description => 'Given due date is already in the past.', + fields => ["duedate", "now"], + }, + 'Koha::Exceptions::Checkout::Fee' => { + isa => 'Koha::Exceptions::Checkout', + description => "There are checkout fees.", + fields => ["amount"], + }, + 'Koha::Exceptions::Checkout::InvalidDueDate' => { + isa => 'Koha::Exceptions::Checkout', + description => 'Given due date is invalid.', + fields => ["duedate"], + }, + 'Koha::Exceptions::Checkout::MaximumCheckoutsReached' => { + isa => 'Koha::Exceptions::Checkout', + description => "Maximum number of checkouts have been reached, or none allowed.", + fields => ["max_checkouts_allowed", "current_checkout_count"], + }, + 'Koha::Exceptions::Checkout::MaximumOnsiteCheckoutsReached' => { + isa => 'Koha::Exceptions::Checkout', + description => "Maximum number of on-site checkouts have been reached.", + fields => ["max_onsite_checkouts", "current_onsite_checkouts"], + }, + 'Koha::Exceptions::Checkout::NoMoreRenewals' => { + isa => 'Koha::Exceptions::Checkout', + description => "No more renewals are allowed.", + }, + 'Koha::Exceptions::Checkout::NoRenewalForOnsiteCheckouts' => { + isa => 'Koha::Exceptions::Checkout', + description => "On-site checkouts cannot be renewed.", + }, + 'Koha::Exceptions::Checkout::OnsiteCheckoutsDisabled' => { + isa => 'Koha::Exceptions::Checkout', + description => "On-site checkouts are disabled.", + }, + 'Koha::Exceptions::Checkout::OnsiteCheckoutWillBeSwitched' => { + isa => 'Koha::Exceptions::Checkout', + description => "On-site checkout will be switched to normal checkout.", + }, + 'Koha::Exceptions::Checkout::PreviouslyCheckedOut' => { + isa => 'Koha::Exceptions::Checkout', + description => "This biblio has been previously checked out by this patron.", + }, + 'Koha::Exceptions::Checkout::Renew' => { + isa => 'Koha::Exceptions::Checkout', + description => "Checkout will be renewed.", + }, + 'Koha::Exceptions::Checkout::ZeroCheckoutsAllowed' => { + isa => 'Koha::Exceptions::Checkout', + description => "Matching issuing rule that does not allow any checkouts.", + }, + +); + +1; diff --git a/Koha/Exceptions/Hold.pm b/Koha/Exceptions/Hold.pm new file mode 100644 index 0000000..acceeb9 --- /dev/null +++ b/Koha/Exceptions/Hold.pm @@ -0,0 +1,47 @@ +package Koha::Exceptions::Hold; + +use Modern::Perl; + +use Exception::Class ( + + 'Koha::Exceptions::Hold' => { + description => 'Something went wrong!', + }, + 'Koha::Exceptions::Hold::ItemLevelHoldNotAllowed' => { + isa => 'Koha::Exceptions::Hold', + description => "Item level hold is not allowed.", + }, + 'Koha::Exceptions::Hold::MaximumHoldsReached' => { + isa => 'Koha::Exceptions::Hold', + description => "Maximum number of holds have been reached.", + fields => ["max_holds_allowed", "current_hold_count"], + }, + 'Koha::Exceptions::Hold::MaximumHoldsForRecordReached' => { + isa => 'Koha::Exceptions::Hold', + description => "Maximum number of holds for a record have been reached.", + fields => ["max_holds_allowed", "current_hold_count"], + }, + 'Koha::Exceptions::Hold::NotAllowedByLibrary' => { + isa => 'Koha::Exceptions::Hold', + description => "This library does not allow holds.", + }, + 'Koha::Exceptions::Hold::NotAllowedFromOtherLibraries' => { + isa => 'Koha::Exceptions::Hold', + description => "Cannot hold from other libraries.", + }, + 'Koha::Exceptions::Hold::NotAllowedInOPAC' => { + isa => 'Koha::Exceptions::Hold', + description => "Holds are disabled in OPAC.", + }, + 'Koha::Exceptions::Hold::OnShelfNotAllowed' => { + isa => 'Koha::Exceptions::Hold', + description => "On-shelf holds are not allowed.", + }, + 'Koha::Exceptions::Hold::ZeroHoldsAllowed' => { + isa => 'Koha::Exceptions::Hold', + description => "Matching hold rule that does not allow any holds.", + }, + +); + +1; diff --git a/Koha/Exceptions/Item.pm b/Koha/Exceptions/Item.pm new file mode 100644 index 0000000..ee2f7ab --- /dev/null +++ b/Koha/Exceptions/Item.pm @@ -0,0 +1,84 @@ +package Koha::Exceptions::Item; + +use Modern::Perl; + +use Exception::Class ( + + 'Koha::Exceptions::Item' => { + description => 'Something went wrong!', + }, + 'Koha::Exceptions::Item::AlreadyHeldForThisPatron' => { + isa => 'Koha::Exceptions::Item', + description => "Item already held for this patron.", + }, + 'Koha::Exceptions::Item::CannotBeTransferred' => { + isa => 'Koha::Exceptions::Item', + description => "Item cannot be transferred from holding library to given library.", + fields => ["from_library", "to_library"], + }, + 'Koha::Exceptions::Item::CheckedOut' => { + isa => 'Koha::Exceptions::Item', + description => "Item has already been checked out.", + fields => ["borrowernumber", "date_due"], + }, + 'Koha::Exceptions::Item::Damaged' => { + isa => 'Koha::Exceptions::Item', + description => "Item is marked as damaged.", + }, + 'Koha::Exceptions::Item::FromAnotherLibrary' => { + isa => 'Koha::Exceptions::Item', + description => "Libraries are independent and item is not from this library.", + fields => ["current_library", "from_library"], + }, + 'Koha::Exceptions::Item::Held' => { + isa => 'Koha::Exceptions::Item', + description => "Item held.", + fields => ["borrowernumber", "hold_queue_length", "status"], + }, + 'Koha::Exceptions::Item::HighHolds' => { + isa => 'Koha::Exceptions::Item', + description => "High demand item. Loan period shortened.", + fields => ["num_holds", "duration", "returndate"], + }, + 'Koha::Exceptions::Item::Lost' => { + isa => 'Koha::Exceptions::Item', + description => "Item is marked as lost.", + fields => ["code", "status"], + }, + 'Koha::Exceptions::Item::NotForLoan' => { + isa => 'Koha::Exceptions::Item', + description => "Item is marked as not for loan.", + fields => ["code", "status"], + }, + 'Koha::Exceptions::Item::NotFound' => { + isa => 'Koha::Exceptions::Item', + description => "Item not found.", + fields => ['itemnumber'], + }, + 'Koha::Exceptions::Item::NotForLoanForcing' => { + isa => 'Koha::Exceptions::Item', + description => "Item is marked as not for loan, but it is possible to override.", + fields => ["notforloan"], + }, + 'Koha::Exceptions::Item::Restricted' => { + isa => 'Koha::Exceptions::Item', + description => "Item is marked as restricted.", + }, + 'Koha::Exceptions::Item::Transfer' => { + isa => 'Koha::Exceptions::Item', + description => "Item is being transferred.", + fields => ["datesent", "from_library", "to_library"], + }, + 'Koha::Exceptions::Item::UnknownBarcode' => { + isa => 'Koha::Exceptions::Item', + description => "Item has unknown barcode, or no barcode at all.", + fields => ["barcode"], + }, + 'Koha::Exceptions::Item::Withdrawn' => { + isa => 'Koha::Exceptions::Item', + description => "Item is marked as withdrawn.", + } + +); + +1; diff --git a/Koha/Exceptions/ItemType.pm b/Koha/Exceptions/ItemType.pm new file mode 100644 index 0000000..4ceb4b3 --- /dev/null +++ b/Koha/Exceptions/ItemType.pm @@ -0,0 +1,18 @@ +package Koha::Exceptions::ItemType; + +use Modern::Perl; + +use Exception::Class ( + + 'Koha::Exceptions::ItemType' => { + description => 'Something went wrong!', + }, + 'Koha::Exceptions::ItemType::NotForLoan' => { + isa => 'Koha::Exceptions::ItemType', + description => "This type of items are not for loan.", + fields => ["itemtype", "status", "code"], + }, + +); + +1; diff --git a/Koha/Exceptions/Patron.pm b/Koha/Exceptions/Patron.pm new file mode 100644 index 0000000..0801c88 --- /dev/null +++ b/Koha/Exceptions/Patron.pm @@ -0,0 +1,66 @@ +package Koha::Exceptions::Patron; + +use Modern::Perl; + +use Exception::Class ( + + 'Koha::Exceptions::Patron' => { + description => 'Something went wrong!', + }, + 'Koha::Exceptions::Patron::AgeRestricted' => { + isa => 'Koha::Exceptions::Patron', + description => "Age restriction applies for patron.", + fields => ["age_restriction"], + }, + 'Koha::Exceptions::Patron::CardExpired' => { + isa => 'Koha::Exceptions::Patron', + description => "Patron's card has expired.", + fields => ["expiration_date"], + }, + 'Koha::Exceptions::Patron::CardLost' => { + isa => 'Koha::Exceptions::Patron', + description => "Patron's card has been marked as lost.", + }, + 'Koha::Exceptions::Patron::Debarred' => { + isa => 'Koha::Exceptions::Patron', + description => "Patron is debarred.", + fields => ["expiration", "comment"], + }, + 'Koha::Exceptions::Patron::DebarredOverdue' => { + isa => 'Koha::Exceptions::Patron', + description => "Patron is debarred because of overdue checkouts.", + fields => ["number_of_overdues"], + }, + 'Koha::Exceptions::Patron::Debt' => { + isa => 'Koha::Exceptions::Patron', + description => "Patron has debts.", + fields => ["max_outstanding", "current_outstanding"], + }, + 'Koha::Exceptions::Patron::DebtGuarantees' => { + isa => 'Koha::Exceptions::Patron', + description => "Patron's guarantees have debts.", + fields => ["max_outstanding", "current_outstanding", "guarantees"], + }, + 'Koha::Exceptions::Patron::FromAnotherLibrary' => { + isa => 'Koha::Exceptions::Patron', + description => "Libraries are independent and this patron is from another library than we are now logged in.", + fields => ["patron_branch", "current_branch"], + }, + 'Koha::Exceptions::Patron::GoneNoAddress' => { + isa => 'Koha::Exceptions::Patron', + description => "Patron gone no address.", + }, + 'Koha::Exceptions::Patron::NotFound' => { + isa => 'Koha::Exceptions::Patron', + description => "Patron not found.", + fields => ['borrowernumber'], + }, + 'Koha::Exceptions::Patron::OtherCharges' => { + isa => 'Koha::Exceptions::Patron', + description => "Patron has other outstanding charges.", + fields => ["balance", "other_charges"], + }, + +); + +1; -- 1.9.1