From 92d4819df711e3d3a91d59d7515c505a8beb75bf Mon Sep 17 00:00:00 2001 From: Chris Sharp Date: Mon, 6 May 2013 15:41:51 -0400 Subject: [PATCH] Revert "Org unit retrieval cleanup" This reverts commit 68a4e3b1c8133c9c98503f5d2128e054bf1d2114. GALILEO uses open-ils.actor.org_tree.slim_hash.retrieve, which was removed in this commit without considering that effect. This revert attempts to restore that functionality. Conflicts: Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm --- .../src/perlmods/lib/OpenILS/Application/Actor.pm | 40 ++++++++ .../perlmods/lib/OpenILS/Application/AppUtils.pm | 108 ++++++++++++++++++++- .../src/perlmods/lib/OpenILS/Application/Cat.pm | 4 +- .../lib/OpenILS/Application/Circ/ScriptBuilder.pm | 11 ++- .../lib/OpenILS/Application/Collections.pm | 2 +- .../lib/OpenILS/Application/Search/Biblio.pm | 2 +- .../lib/OpenILS/Application/Search/CNBrowse.pm | 2 +- 7 files changed, 159 insertions(+), 10 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm index 5f6073fa4b..b65b9a9fcd 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm @@ -2790,6 +2790,46 @@ sub safe_token_home_lib { } + +__PACKAGE__->register_method( + method => 'slim_tree', + api_name => "open-ils.actor.org_tree.slim_hash.retrieve", +); +sub slim_tree { + my $tree = new_editor()->search_actor_org_unit( + [ + {"parent_ou" => undef }, + { + flesh => -1, + flesh_fields => { aou => ['children'] }, + order_by => { aou => 'name'}, + select => { aou => ["id","shortname", "name"]}, + } + ] + )->[0]; + + return trim_tree($tree); +} + + +sub trim_tree { + my $tree = shift; + return undef unless $tree; + my $htree = { + code => $tree->shortname, + name => $tree->name, + }; + if( $tree->children and @{$tree->children} ) { + $htree->{children} = []; + for my $c (@{$tree->children}) { + push( @{$htree->{children}}, trim_tree($c) ); + } + } + + return $htree; +} + + __PACKAGE__->register_method( method => "update_penalties", api_name => "open-ils.actor.user.penalties.update" diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm index b54694afec..499b6c6571 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm @@ -189,8 +189,89 @@ sub simple_scalar_request { return $val; } + + + + +my $tree = undef; +my $orglist = undef; +my $org_typelist = undef; +my $org_typelist_hash = {}; + +sub __get_org_tree { + + # can we throw this version away?? + + my $self = shift; + if($tree) { return $tree; } + + # see if it's in the cache + $tree = $cache_client->new()->get_cache('_orgtree'); + if($tree) { return $tree; } + + if(!$orglist) { + warn "Retrieving Org Tree\n"; + $orglist = $self->simple_scalar_request( + "open-ils.cstore", + "open-ils.cstore.direct.actor.org_unit.search.atomic", + { id => { '!=' => undef } } + ); + } + + if( ! $org_typelist ) { + warn "Retrieving org types\n"; + $org_typelist = $self->simple_scalar_request( + "open-ils.cstore", + "open-ils.cstore.direct.actor.org_unit_type.search.atomic", + { id => { '!=' => undef } } + ); + $self->build_org_type($org_typelist); + } + + $tree = $self->build_org_tree($orglist,1); + $cache_client->new()->put_cache('_orgtree', $tree); + return $tree; + +} + +my $slimtree = undef; +sub get_slim_org_tree { + + my $self = shift; + if($slimtree) { return $slimtree; } + + # see if it's in the cache + $slimtree = $cache_client->new()->get_cache('slimorgtree'); + if($slimtree) { return $slimtree; } + + if(!$orglist) { + warn "Retrieving Org Tree\n"; + $orglist = $self->simple_scalar_request( + "open-ils.cstore", + "open-ils.cstore.direct.actor.org_unit.search.atomic", + { id => { '!=' => undef } } + ); + } + + $slimtree = $self->build_org_tree($orglist); + $cache_client->new->put_cache('slimorgtree', $slimtree); + return $slimtree; + +} + + +sub build_org_type { + my($self, $org_typelist) = @_; + for my $type (@$org_typelist) { + $org_typelist_hash->{$type->id()} = $type; + } +} + + + sub build_org_tree { - my( $self, $orglist ) = @_; + + my( $self, $orglist, $add_types ) = @_; return $orglist unless ref $orglist; return $$orglist[0] if @$orglist == 1; @@ -202,6 +283,11 @@ sub build_org_tree { for my $org (@list) { next unless ($org); + + if(!ref($org->ou_type()) and $add_types) { + $org->ou_type( $org_typelist_hash->{$org->ou_type()}); + } + next if (!defined($org->parent_ou) || $org->parent_ou eq ""); my ($parent) = grep { $_->id == $org->parent_ou } @list; @@ -1134,6 +1220,22 @@ sub fetch_bill { return($bill, $evt); } +my $ORG_TREE; +sub fetch_org_tree { + my $self = shift; + return $ORG_TREE if $ORG_TREE; + return $ORG_TREE = OpenILS::Utils::CStoreEditor->new->search_actor_org_unit( + [ + {"parent_ou" => undef }, + { + flesh => -1, + flesh_fields => { aou => ['children'] }, + order_by => { aou => 'name'} + } + ] + )->[0]; +} + sub walk_org_tree { my( $self, $node, $callback ) = @_; return unless $node; @@ -1354,12 +1456,11 @@ sub get_org_types { return $org_types = OpenILS::Utils::CStoreEditor->new->retrieve_all_actor_org_unit_type(); } -my %ORG_TREE; sub get_org_tree { my $self = shift; my $locale = shift || ''; my $cache = OpenSRF::Utils::Cache->new("global", 0); - my $tree = $ORG_TREE{$locale} || $cache->get_cache("orgtree.$locale"); + my $tree = $cache->get_cache("orgtree.$locale"); return $tree if $tree; my $ses = OpenILS::Utils::CStoreEditor->new; @@ -1375,7 +1476,6 @@ sub get_org_tree { ] )->[0]; - $ORG_TREE{$locale} = $tree; $cache->put_cache("orgtree.$locale", $tree); return $tree; } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm index 1c397e1e1b..b9b79bee32 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm @@ -1286,7 +1286,7 @@ sub acn_sms_msg { my($self, $conn, $auth, $org_id, $carrier, $number, $target_ids) = @_; my $sms_enable = $U->ou_ancestor_setting_value( - $org_id || $U->get_org_tree->id, + $org_id || $U->fetch_org_tree->id, 'sms.enable' ); # We could maybe make a Validator for this on the templates @@ -1295,7 +1295,7 @@ sub acn_sms_msg { } my $disable_auth = $U->ou_ancestor_setting_value( - $org_id || $U->get_org_tree->id, + $org_id || $U->fetch_org_tree->id, 'sms.disable_authentication_requirement.callnumbers' ); diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/ScriptBuilder.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/ScriptBuilder.pm index f042665ed9..7589cab9ef 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/ScriptBuilder.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/ScriptBuilder.pm @@ -275,7 +275,16 @@ sub insert_org_methods { my ( $editor, $runner ) = @_; if(!$ORG_TREE) { - $ORG_TREE = $U->get_org_tree; + $ORG_TREE = $editor->search_actor_org_unit( + [ + {"parent_ou" => undef }, + { + flesh => -1, + flesh_fields => { aou => ['children'] }, + order_by => { aou => 'name'} + } + ] + )->[0]; flatten_org_tree($ORG_TREE); } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm index 8d61327174..8c7c99b712 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm @@ -741,7 +741,7 @@ sub transaction_details { or return $e->event; $org = $org->[0]; # get a reference to the org inside of the tree - $org = $U->find_org($U->get_org_tree(), $org->id); + $org = $U->find_org($U->fetch_org_tree(), $org->id); my @data; for my $uid (@$user_list) { diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm index 6d149cabbb..f22a3492b8 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm @@ -1973,7 +1973,7 @@ sub format_biblio_record_entry { if ($for_print) { $bib_id = $arg1; - $context_org = $arg2 || $U->get_org_tree->id; + $context_org = $arg2 || $U->fetch_org_tree->id; $e = new_editor(xact => 1); } elsif ($for_email) { $auth = $arg1; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/CNBrowse.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/CNBrowse.pm index 4e4d9c865d..eade47a727 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/CNBrowse.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/CNBrowse.pm @@ -80,7 +80,7 @@ sub cn_browse { my( $self, $conn, $cn, $orgid, $size, $offset, $copy_statuses, $copy_locations ) = @_; my $ses = OpenSRF::AppSession->create('open-ils.supercat'); - my $tree = $U->get_org_tree; + my $tree = $U->get_slim_org_tree; my $name = _find_shortname($orgid, $tree); $logger->debug("cn browse found or name $name"); -- 2.11.0