Org unit retrieval cleanup
authorBill Erickson <berick@esilibrary.com>
Mon, 12 Mar 2012 19:05:50 +0000 (15:05 -0400)
committerBill Erickson <berick@esilibrary.com>
Wed, 27 Jun 2012 17:23:55 +0000 (13:23 -0400)
Clean up and consolidate the various org unit retrieval method (in Perl)
to reduce code/confusion and make it easier to integrate changes to the
org unit tree in the future.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>

Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/ScriptBuilder.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Collections.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Search/CNBrowse.pm

index 77277e4..966a991 100644 (file)
@@ -2789,46 +2789,6 @@ 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"
index 792f53b..2529d6b 100644 (file)
@@ -189,89 +189,8 @@ 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, $add_types ) = @_;
+       my( $self, $orglist ) = @_;
 
        return $orglist unless ref $orglist; 
     return $$orglist[0] if @$orglist == 1;
@@ -283,11 +202,6 @@ 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;
@@ -1220,22 +1134,6 @@ 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;
@@ -1456,11 +1354,12 @@ 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 = $cache->get_cache("orgtree.$locale");
+       my $tree = $ORG_TREE{$locale} || $cache->get_cache("orgtree.$locale");
        return $tree if $tree;
 
        my $ses = OpenILS::Utils::CStoreEditor->new;
@@ -1476,6 +1375,7 @@ sub get_org_tree {
                ]
        )->[0];
 
+    $ORG_TREE{$locale} = $tree;
        $cache->put_cache("orgtree.$locale", $tree);
        return $tree;
 }
index b9b79be..1c397e1 100644 (file)
@@ -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->fetch_org_tree->id,
+        $org_id || $U->get_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->fetch_org_tree->id,
+        $org_id || $U->get_org_tree->id,
         'sms.disable_authentication_requirement.callnumbers'
     );
 
index 7589cab..f042665 100644 (file)
@@ -275,16 +275,7 @@ sub insert_org_methods {
        my ( $editor, $runner ) = @_;
 
        if(!$ORG_TREE) {
-               $ORG_TREE = $editor->search_actor_org_unit(
-                       [
-                               {"parent_ou" => undef },
-                               {
-                                       flesh                           => -1,
-                                       flesh_fields    => { aou =>  ['children'] },
-                                       order_by                        => { aou => 'name'}
-                               }
-                       ]
-               )->[0];
+               $ORG_TREE = $U->get_org_tree;
                flatten_org_tree($ORG_TREE);
        }
 
index e5da73c..97c07f7 100644 (file)
@@ -727,7 +727,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->fetch_org_tree(), $org->id);
+       $org = $U->find_org($U->get_org_tree(), $org->id);
 
        my @data;
        for my $uid (@$user_list) {
index 82ad1af..0933acc 100644 (file)
@@ -1928,7 +1928,7 @@ sub format_biblio_record_entry {
 
     if ($for_print) {
         $bib_id = $arg1;
-        $context_org = $arg2 || $U->fetch_org_tree->id;
+        $context_org = $arg2 || $U->get_org_tree->id;
         $e = new_editor(xact => 1);
     } elsif ($for_email) {
         $auth = $arg1;
index eade47a..4e4d9c8 100644 (file)
@@ -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_slim_org_tree;
+       my $tree = $U->get_org_tree;
        my $name = _find_shortname($orgid, $tree);
 
        $logger->debug("cn browse found or name $name");