From 213d158c0d0b0d08c9285f96523df64a151a6983 Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley Date: Wed, 21 Mar 2012 13:50:48 -0400 Subject: [PATCH] done? needs more testing but i like it! Signed-off-by: Lebbeous Fogle-Weekley --- Open-ILS/scratch-recur.pl | 63 ------------------ Open-ILS/scratch-recur2.pl | 75 ---------------------- .../perlmods/lib/OpenILS/Application/Fielder.pm | 30 ++++++++- .../perlmods/lib/OpenILS/Application/Flattener.pm | 21 +++++- 4 files changed, 46 insertions(+), 143 deletions(-) delete mode 100644 Open-ILS/scratch-recur.pl delete mode 100644 Open-ILS/scratch-recur2.pl diff --git a/Open-ILS/scratch-recur.pl b/Open-ILS/scratch-recur.pl deleted file mode 100644 index fd37de7160..0000000000 --- a/Open-ILS/scratch-recur.pl +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/perl -w - -use strict; - -use Data::Dumper; - -my $one = { - -and => [ - {foo => "bar"}, - {baz => {">=" => 3}} - ] -}; - -my $two = { - "xact_start" => {">" => "today"}, - "circ_lib" => "BR1" -}; - -my $three = { - -not => [ - {abc => {between => [1,32]}}, - {def => {">=" => 1}}, - {"ghi" => [1,2,3,4], "jkl" => 5} - ] -}; - -sub newkey { - return "XXX" . shift; -} - -sub recursively_mark_column_names { - my ($o, $state) = @_; - - $state ||= {}; - - if (ref $o eq 'HASH') { - foreach my $key (keys %$o) { - if (not $state->{in_expr} and $key =~ /^[a-z]/) { - $state->{in_expr} = 1; - - my $newkey = newkey($key); - print "attempting replacement of $key with $newkey\n"; - - $o->{$newkey} = $o->{$key}; - delete $o->{$key}; - - recursively_mark_column_names($o->{$newkey}, $state); - - $state->{in_expr} = 0; - } else { - recursively_mark_column_names($o->{$key}, $state); - } - } - } elsif (ref $o eq 'ARRAY') { - recursively_mark_column_names($_, $state) foreach @$o; - } # else scalar, nothing to do? -} - -recursively_mark_column_names($one); -recursively_mark_column_names($two); -recursively_mark_column_names($three); - -print Dumper($one, $two, $three), "\n"; diff --git a/Open-ILS/scratch-recur2.pl b/Open-ILS/scratch-recur2.pl deleted file mode 100644 index a751afa7fb..0000000000 --- a/Open-ILS/scratch-recur2.pl +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/perl -w - -use strict; - -use Data::Dumper; - -my $one = { - -and => [ - {foo => "bar"}, - {baz => {">=" => 3}} - ] -}; - -my $two = { - "xact_start" => {">" => "today"}, - "circ_lib" => "BR1" -}; - -my $three = { - -not => [ - {abc => {between => [1,32]}}, - {def => {">=" => 1}}, - {"ghi" => [1,2,3,4], "jkl" => 5} - ] -}; - -sub newkey { - my ($key) = @_; - - return ("+sometable", "XXX$key"); -} - -sub expand_key { - my ($o, $key) = @_; - - my ($table, $column) = newkey($key); - - $o->{$table} ||= {}; - - $o->{$table}{$column} = $o->{$key}; - delete $o->{$key}; - - return $o->{$table}{$column}; -} - -sub recursively_mark_column_names { - my ($o, $state) = @_; - - $state ||= {}; - - if (ref $o eq 'HASH') { - foreach my $key (keys %$o) { - if (not $state->{in_expr} and $key =~ /^[a-z]/) { - $state->{in_expr} = 1; - - print "attempting replacement of $key\n"; - my $deeper = expand_key($o, $key); - - recursively_mark_column_names($deeper, $state); - - $state->{in_expr} = 0; - } else { - recursively_mark_column_names($o->{$key}, $state); - } - } - } elsif (ref $o eq 'ARRAY') { - recursively_mark_column_names($_, $state) foreach @$o; - } # else scalar, nothing to do? -} - -recursively_mark_column_names($one); -recursively_mark_column_names($two); -recursively_mark_column_names($three); - -print Dumper($one, $two, $three), "\n"; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Fielder.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Fielder.pm index bab2f960c5..9659004de5 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Fielder.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Fielder.pm @@ -186,7 +186,9 @@ sub flattened_search { # Stream back flattened results. while (my $resp = $req->recv(timeout => 60)) { $conn->respond( - OpenILS::Application::Flattener::process_result($map, $resp) + OpenILS::Application::Flattener::process_result( + $map, $resp->content + ) ); } @@ -200,7 +202,31 @@ __PACKAGE__->register_method( method => 'flattened_search', api_name => 'open-ils.fielder.flattened_search', stream => 1, - argc => 5 + argc => 5, + signature => { + params => [ + {name => "auth", type => "string", desc => "auth token"}, + {name => "hint", type => "string", + desc => "fieldmapper class hint of core object"}, + {name => "map", type => "object", desc => q{ + path-field mapping structure. See documentation under + docs/TechRef/Flattener in the Evergreen source tree.} }, + {name => "where", type => "object", desc => q{ + simplified query clause (like the 'where' clause of a + json_query, but different). See documentation under + docs/TechRef/Flattener in the Evergreen source tree.} }, + {name => "slo", type => "object", desc => q{ + simplified sort/limit/offset object. See documentation under + docs/TechRef/Flattener in the Evergreen source tree.} } + ], + return => { + desc => q{ + A stream of objects flattened to your specifications. See + documentation under docs/TechRef/Flattener in the Evergreen + source tree.}, + type => "object" + } + } ); 1; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Flattener.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Flattener.pm index b5bce11d77..2cd2c19e10 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Flattener.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Flattener.pm @@ -344,10 +344,25 @@ sub finish_jffolo { } sub process_result { - my ($map, $resp) = @_; + my ($map, $fmobj) = @_; - # XXX TODO - return $resp; + my $flatrow = {}; + + while (my ($key, $mapping) = each %$map) { + next unless $mapping->{display}; + + my @path = @{ $mapping->{path} }; + my $field = pop @path; + + my $obj = $fmobj; + while (my $step = shift @path) { + $obj = $obj->$step; + } + + $flatrow->{$key} = $obj->$field; + } + + return $flatrow; } 1; -- 2.11.0