}
}
+# This method will delete cache key
+sub delete_cache {
+ my $session_id = shift;
+ my $cache_key = shift;
+ my $new_cache = {};
+
+ try {
+ $logger->info("EbookAPI: delete_cache cache for key:$cache_key and session_id: $session_id ");
+ my $cached_session = retrieve_session($session_id);
+ if ($cached_session) {
+ $logger->debug("EbookAPI: delete_cache: Retrieving Cached Session for session_id: ".$session_id);
+ # re-authorize cached session, if applicable
+ my $cache_obj = new_handler($session_id, $cached_session);
+
+ $logger->debug("EbookAPI: delete_cache cache before removing key: " . Dumper($cache_obj));
+ delete $cache_obj->{$cache_key};
+ $cache->delete_cache($session_id);
+ $cache->put_cache($session_id, $cache_obj, $cache_timeout);
+ $logger->debug("EbookAPI: delete_cache cache after removing key: " . Dumper($cache_obj));
+ }
+ } catch Error with {
+ $logger->error("EbookAPI: error removing cache for key: ".$cache_key);
+ };
+}
+
sub retrieve_session {
my $session_id = shift;
unless ($session_id) {
return;
}
my $module = ref($ses);
- $logger->info("EbookAPI: starting new $module handler from cached session $session_id...");
+ $logger->debug("EbookAPI: starting new $module handler from cached session $session_id...");
$module->use;
my $handler = $module->new($ses);
return $handler;
my $session_id = shift;
my $vendor = shift;
my $result = 0;
- $logger->info("EbookAPI: logout_session: Clearing Session ($vendor) for session_id: $session_id");
+ $logger->debug("EbookAPI: logout_session: Clearing Session ($vendor) for session_id: $session_id");
try { # fail silently if there's no pre-existing cache to delete
$cache->delete_cache($session_id);
$result = 1;
} catch Error with {
- $logger->info("EbookAPI: logout_session: No existing session found ($vendor) for session_id: $session_id");
+ $logger->error("EbookAPI: logout_session: No existing session found ($vendor) for session_id: $session_id");
};
- $logger->info("EbookAPI: logout_session: Cache is cleared ($vendor) for session_id: $session_id");
+ $logger->debug("EbookAPI: logout_session: Cache is cleared ($vendor) for session_id: $session_id");
my $cached_session = retrieve_session($session_id);
retrun $result;
my $vendor = shift;
my $ou = shift;
- $logger->info("EbookAPI: check_session: Checking Session ($vendor) for session_id (if any): $session_id");
+ $logger->debug("EbookAPI: check_session: Checking Session ($vendor) for session_id (if any): $session_id");
return start_session($self, $conn, $vendor, $ou) unless $session_id;
# Check if the session requested belongs to the same vendor
my $cached_session = retrieve_session($session_id);
if ($cached_session) {
- $logger->info("EbookAPI: check_session: Retrieving Cached Session ($vendor) for session_id: ".$session_id);
+ $logger->debug("EbookAPI: check_session: Retrieving Cached Session ($vendor) for session_id: ".$session_id);
# re-authorize cached session, if applicable
my $handler = new_handler($session_id, $cached_session);
$handler->do_client_auth();
# TODO handle API versions?
if ($vendor_handlers{$vendor}) {
$module = $vendor_handlers{$vendor};
- $logger->info("EbookAPI: _start_session: Module '$module' ");
+ $logger->debug("EbookAPI: _start_session: Module '$module' ");
} else {
$logger->error("EbookAPI: No handler module found for $vendor!");
return;
# our "session" is actually just our handler object, serialized and cached
$cache->put_cache($handler->{session_id}, $handler, $cache_timeout);
- $logger->info("EbookAPI: _start_session: New session created for '$vendor' : " .$handler->{session_id});
+ $logger->debug("EbookAPI: _start_session: New session created for '$vendor' : " .$handler->{session_id});
return $handler->{session_id};
}
$res = $handler->$action($title_id, $user_token);
}
+ if ($action eq 'checkout' || $action eq 'checkin') {
+ delete_cache($session_id,'checkouts');
+ } elsif ($action eq 'place_hold' || $action eq 'cancel_hold') {
+ delete_cache($session_id,'holds');
+ }
+
if (defined ($res)) {
return $res;
} else {
my ($self, $conn, $auth, $session_id, $barcode) = @_;
my $patron_id = 0;
- $logger->info("EbookAPI: getting patron id for patron $barcode");
+ $logger->info("EbookAPI: getting patron id for patron $barcode ");
# verify that user is authenticated in EG
my $editor = new_editor(authtoken => $auth);
$logger->info("EbookAPI: User Authenticated. Now, registering the patron with RBDigital");
my $handler = new_handler($session_id);
- return $handler->register_patron($editor->requestor->usrname, $password);
+ #Get user library card number/barcode from DB
+ my $user_barcode = "";
+ if ($editor->requestor->card) {
+ my $user_library_card = $editor->retrieve_actor_card($editor->requestor->card);
+
+ if ($user_library_card && $user_library_card->barcode) {
+ $user_barcode = $user_library_card->barcode;
+ }
+ }
+
+ return $handler->register_patron($editor->requestor->usrname, $password, $user_barcode);
}
__PACKAGE__->register_method(
if ($action eq 'add') {
$logger->debug("EbookAPI: Calling add_to_wishlist($patron_id, $isbn)");
+ delete_cache($session_id,$cache_key);
return $handler->add_to_wishlist($patron_id, $isbn);
} elsif ($action eq 'delete') {
+ delete_cache($session_id,$cache_key);
return $handler->delete_from_wishlist($patron_id, $isbn);
} elsif ($action eq 'get') {
# Locate wishlist from cache first
# "email": "jsmith@yahoo.com",
# "postalCode": "30904",
# "isActive": false,
-# "libraryId": {libraryId}
+# "libraryId": {libraryId},
+# "libraryCard": {libraryCard}
# }
sub register_patron {
- my ($self, $username, $password) = @_;
+ my ($self, $username, $password, $user_barcode) = @_;
my $base_uri = $self->{base_uri};
my $library_id = $self->{library_id};
my $session_id = $self->{session_id};
return 0;
}
+
$logger->info("EbookAPI: Building a request for patron registration");
my $request_content = {
firstName => $user_req->first_given_name,
email => $user_req->email,
postalCode => $postal_code,
isActive => $is_active,
- libraryId => $library_id
+ libraryId => $library_id,
+ libraryCard => $user_barcode
};
my $req = {
# Load vendor tabs for authenticated patrons only
if (defined($self->editor->requestor)) {
- $logger->info("EbookAPI: load_rbdigital_common: Token: ". $self->ctx->{authtoken});
my $session_id = "";
-
+ # Get cached session based on authtoken that contains the ebook session id
my $cached_session = $cache->get_cache($self->ctx->{authtoken}) || undef;
- $logger->info("EbookAPI: load_rbdigital_common: Cached session result: ".Dumper($cached_session));
+ $logger->debug("EbookAPI: load_rbdigital_common: Cached session retrieved: ".Dumper($cached_session));
if ($cached_session) {
$session_id = $cached_session;
- $logger->info("EbookAPI: load_rbdigital_common: Retrieved cached session_id: $session_id");
+ $logger->debug("EbookAPI: load_rbdigital_common: Retrieved cached session_id: $session_id");
} else {
$session_id = _get_ebook_session_id($session_id, $self->editor->requestor->home_ou);
- $logger->info("EbookAPI: load_rbdigital_common: Retrieved new session: $session_id");
+ $logger->debug("EbookAPI: load_rbdigital_common: Retrieved new session: $session_id");
# Save session id into cache
$cache->put_cache($self->ctx->{authtoken}, $session_id, $cache_timeout);
}
+ # Assign session id to global variable so it can be saved to cookie as well.
$ebook_rbdigital_session_id = $session_id;
- $logger->info("EbookAPI: load_rbdigital_common: after checking session id: $session_id");
$self->ctx->{rbdigital_session_id} = $session_id;
$self->ctx->{vendors} = [];
$self->ctx->{wishlist} = [];
# Call method to know if the user's home library is tied to RBdigital portal
my $is_patron_authorized_to_register_with_rbdigital = _is_authorized($self->editor->authtoken, $session_id);
$self->ctx->{is_patron_authorized_to_register_with_rbdigital} = $is_patron_authorized_to_register_with_rbdigital;
- $logger->info('EbookAPI: is_patron_authorized_to_register_with_rbdigital: '.$is_patron_authorized_to_register_with_rbdigital);
+ $logger->debug('EbookAPI: is_patron_authorized_to_register_with_rbdigital: '.$is_patron_authorized_to_register_with_rbdigital);
# Call sub to get all the vendors to be displayed on the UI
$self->ctx->{vendors} = _get_authorized_vendors($self->editor->authtoken, $session_id);