done? needs more testing but i like it!
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Wed, 21 Mar 2012 17:50:48 +0000 (13:50 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Wed, 21 Mar 2012 18:03:58 +0000 (14:03 -0400)
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/scratch-recur.pl [deleted file]
Open-ILS/scratch-recur2.pl [deleted file]
Open-ILS/src/perlmods/lib/OpenILS/Application/Fielder.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Flattener.pm

diff --git a/Open-ILS/scratch-recur.pl b/Open-ILS/scratch-recur.pl
deleted file mode 100644 (file)
index fd37de7..0000000
+++ /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 (file)
index a751afa..0000000
+++ /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";
index bab2f96..9659004 100644 (file)
@@ -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;
index b5bce11..2cd2c19 100644 (file)
@@ -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;