Revert "Org unit retrieval cleanup" user/csharp/retain_galileo_auth
authorChris Sharp <csharp@georgialibraries.org>
Mon, 6 May 2013 19:41:51 +0000 (15:41 -0400)
committerChris Sharp <csharp@georgialibraries.org>
Mon, 6 May 2013 19:41:51 +0000 (15:41 -0400)
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

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 d818454..a7be74f 100644 (file)
@@ -2797,6 +2797,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"
index f98645b..070a232 100644 (file)
@@ -203,8 +203,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;
@@ -216,6 +297,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;
@@ -1148,6 +1234,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;
@@ -1368,12 +1470,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;
@@ -1389,7 +1490,6 @@ sub get_org_tree {
                ]
        )->[0];
 
-    $ORG_TREE{$locale} = $tree;
        $cache->put_cache("orgtree.$locale", $tree);
        return $tree;
 }
index fbf140a..b518a24 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->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'
     );
 
index f042665..7589cab 100644 (file)
@@ -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);
        }
 
index 8d61327..8c7c99b 100644 (file)
@@ -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) {
index 6d149ca..f22a349 100644 (file)
@@ -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;
index 4e4d9c8..eade47a 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_org_tree;
+       my $tree = $U->get_slim_org_tree;
        my $name = _find_shortname($orgid, $tree);
 
        $logger->debug("cn browse found or name $name");