1 package OpenILS::WWW::EGCatLoader;
2 use strict; use warnings;
3 use Apache2::Const -compile => qw(OK DECLINED FORBIDDEN HTTP_INTERNAL_SERVER_ERROR REDIRECT HTTP_BAD_REQUEST);
4 use OpenSRF::Utils::JSON;
5 use OpenSRF::Utils::Logger qw/$logger/;
6 use OpenILS::Utils::CStoreEditor qw/:funcs/;
7 use OpenILS::Utils::Fieldmapper;
8 use OpenILS::Application::AppUtils;
9 my $U = 'OpenILS::Application::AppUtils';
13 # library : aou object
19 $ctx->{page} = 'library';
21 $self->timelog("load_library() began");
23 my $lib_id = $ctx->{page_args}->[0];
24 $lib_id = $self->_resolve_org_id_or_shortname($lib_id);
26 return Apache2::Const::HTTP_BAD_REQUEST unless $lib_id;
28 my $aou = $ctx->{get_aou}->($lib_id);
29 my $sname = $aou->parent_ou;
31 $ctx->{library} = $aou;
32 if ($aou->parent_ou) {
33 $ctx->{parent} = $ctx->{get_aou}->($aou->parent_ou);
36 $self->timelog("got basic lib info");
38 # Get mailing address from the cache
39 $library_cache ||= OpenSRF::Utils::Cache->new('global');
40 my $address_cache_key = "TPAC_aou_address_cache_$lib_id";
41 my $address = OpenSRF::Utils::JSON->JSON2perl($library_cache->get_cache($address_cache_key));
44 $ctx->{mailing_address} = $address;
45 } elsif (!$address && $aou->mailing_address) {
46 # We didn't get cached hours, so hit the database
47 my $session = OpenSRF::AppSession->create("open-ils.actor");
48 $ctx->{mailing_address} =
49 $session->request('open-ils.actor.org_unit.address.retrieve',
50 $aou->mailing_address)->gather(1);
51 $library_cache->put_cache($address_cache_key, OpenSRF::Utils::JSON->perl2JSON($ctx->{mailing_address}), 360);
54 # Get current hours of operation
55 my $hours_cache_key = "TPAC_aouhoo_cache_$lib_id";
56 my $hours = OpenSRF::Utils::JSON->JSON2perl($library_cache->get_cache($hours_cache_key));
58 # If we don't have cached hours, try the database
60 $hours = $self->editor->retrieve_actor_org_unit_hours_of_operation($lib_id);
61 # If we got hours from the database, cache them
63 $library_cache->put_cache($hours_cache_key, OpenSRF::Utils::JSON->perl2JSON($hours), 360);
67 # After all that, if we have hours, pass them to the context object
69 $ctx->{hours} = $hours;
72 return Apache2::Const::OK;