From: Lebbeous Fogle-Weekley Date: Thu, 23 Feb 2012 20:39:14 +0000 (-0500) Subject: first method from pencil notes working X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=3dae08b27ddce6f98344939aa0045e8b1027b1ab;p=evergreen%2Fequinox.git first method from pencil notes working Signed-off-by: Lebbeous Fogle-Weekley --- diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index c19811078b..4071e9f61f 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -4354,11 +4354,11 @@ SELECT usr, - - - - - + + + + + diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm index d214274ca6..b3777c2a44 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm @@ -1458,7 +1458,15 @@ sub get_org_descendants { } sub get_org_ancestors { - my($self, $org_id) = @_; + my($self, $org_id, $use_cache) = @_; + + my ($cache, $orgs); + + if ($use_cache) { + $cache = OpenSRF::Utils::Cache->new("global", 0); + $orgs = $cache->get_cache("org.ancestors.$org_id"); + return $orgs if $orgs; + } my $org_list = OpenILS::Utils::CStoreEditor->new->json_query({ select => { @@ -1473,9 +1481,10 @@ sub get_org_ancestors { where => {id => $org_id} }); - my @orgs; - push(@orgs, $_->{id}) for @$org_list; - return \@orgs; + $orgs = [ map { $_->{id} } @$org_list ]; + + $cache->put_cache("org.ancestors.$org_id", $orgs) if $use_cache; + return $orgs; } sub get_org_full_path { diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm index 8b99746df5..3c422c0b33 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm @@ -503,6 +503,8 @@ sub pub_fleshed_serial_issuance_retrieve_batch { } sub received_siss_by_bib { + # XXX this is somewhat wrong in implementation and should not be used in + # new places - senator my $self = shift; my $client = shift; my $bib = shift; @@ -614,6 +616,8 @@ q/A hash of optional arguments. Valid keys and their meanings: sub scoped_bib_holdings_summary { + # XXX this is somewhat wrong in implementation and should not be used in + # new places - senator my $self = shift; my $client = shift; my $bibid = shift; @@ -643,7 +647,7 @@ __PACKAGE__->register_method( api_level => 1, argc => 1, signature => { - desc => 'Receives a Bib ID and other optional params and returns set of holdings statements', + desc => '** DEPRECATED and only used by JSPAC. Somewhat wrong in implementation. *** Receives a Bib ID and other optional params and returns set of holdings statements', params => [ { name => 'bibid', desc => 'id of the bre to which the issuances belong', @@ -662,23 +666,64 @@ q/A hash of optional arguments. Valid keys and their meanings: } ); -# XXX give a less confusing name, as this addresses what -# scoped_bib_holdings_summary() does, only more correctly. Maybe use api_level -# to offer the old and the new functionality side by side, if not replacing -# the old function altogether +# This is a helper for scoped_holding_summary_tree_for_bib() a little further down -sub scoped_holdings_tree_for_bib { - my ($self, $client, $bib, $opts) = @_; +sub _place_org_node { + my ($node, $tree, $org_tree) = @_; - # XXX trying to implement the first method defined in my notes (the pencil page) - - # TODO $opts->{org_unit} ||= top_of_org_tree; - $opts->{depth} ||= 0; - $opts->{limit} ||= 10; - $opts->{offset} ||= 0; + my @ancestry = reverse @{ $U->get_org_ancestors($node->{org_unit}, 1) }; + shift @ancestry; # discard current org_unit - my $e = new_editor; + foreach (@ancestry) { # in leaf-to-root order + my $graft_point = _find_ou_in_holdings_tree($tree, $_); + + if ($graft_point) { + push @{$graft_point->{children}}, $node; + return; + } else { + $node = { + org_unit => $_, + holding_summaries => [], + children => [$node] + } + } + } + + # If we reach this point, we got all the way to the top of the org tree + # without finding corresponding nodes in $tree (holdings tree), so the + # latter must be empty, and we need to make $tree just point to $node. + + %$tree = %$node; +} + +# This is a helper for scoped_holding_summary_tree_for_bib() a little further down + +sub _find_ou_in_holdings_tree { + my ($tree, $id) = @_; + + return $tree if $tree->{org_unit} eq $id; + if (ref $tree->{children}) { + foreach (@{$tree->{children}}) { + my $maybe = _find_ou_in_holdings_tree($_, $id); + return $maybe if $maybe; + } + } + + return; +} + +# XXX deprecate/replace scoped_bib_holdings_summary + +sub scoped_holding_summary_tree_for_bib { + my ($self, $client, $bib, $org_unit, $depth, $limit, $offset) = @_; + + $depth ||= 0; + $limit ||= 10; + $offset ||= 0; + + my $org_tree = $U->get_org_tree; # caches + my $e = new_editor; my $rows = $e->json_query({ select => { sasum => [qw/summary_type id generated_coverage/], @@ -693,21 +738,90 @@ sub scoped_holdings_tree_for_bib { }, where => { "+sdist" => { - holding_lib => $U->get_org_descendants( - int($opts->{org_unit}), int($opts->{depth}) - ) + holding_lib => + $U->get_org_descendants(int($org_unit), int($depth)) }, "+ssub" => {record_entry => int($bib)} }, - limit => int($opts->{limit}), - offset => int($opts->{offset}) + limit => int($limit), + offset => int($offset) }) or return $e->die_event; - $e->disconnect; + my $result = {}; + + foreach my $row (@$rows) { + my $org_node_needs_placed = 0; + my $org_node = + _find_ou_in_holdings_tree($result, $row->{holding_lib}); + + if (not $org_node) { + $org_node_needs_placed = 1; + $org_node = { + org_unit => $row->{holding_lib}, + holding_summaries => [], + children => [] + }; + } + + push @{$org_node->{holding_summaries}}, { + id => $row->{id}, + summary_type => $row->{summary_type}, + generated_coverage => + OpenSRF::Utils::JSON->JSON2perl($row->{generated_coverage}) + }; + + if ($org_node_needs_placed) { + _place_org_node($org_node, $result, $org_tree); + } + } + + return $result; +} + +__PACKAGE__->register_method( + method => "scoped_holding_summary_tree_for_bib", + api_name => "open-ils.serial.holding_summary_tree.by_bib", + api_level => 1, + argc => 1, + signature => { + desc => q/Return a set of holding summaries organized into a tree + of nodes that look like: + {org_unit:, holding_summaries:[], children:[]} + /, + params => [ + { name => "bibid", + desc => "ID of the bre to which holdings belong", + type => "number" + }, + { name => "org_unit", type => "number" }, + { name => "depth", type => "number" }, + { name => "limit", type => "number" }, + { name => "offset", type => "number" } + ] + } +); + +sub grouped_holdings_for_summary { + my ($self, $client, $summary_type, $summary_id, $limit, $offset) = @_; } +__PACKAGE__->register_method( + method => "grouped_holdings_for_summary", + api_name => "open-ils.serial.holdings.grouped_by_summary", + api_level => 1, + argc => 1, + signature => { + desc => q/Return a tree of holdings associated with a given summary + grouped by all but the last of either chron or enum units./, + params => [ + # XXX ? + ] + } +); + + ########################################################################## # unit methods #