+++ /dev/null
-#!/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";
+++ /dev/null
-#!/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";
# 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
+ )
);
}
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;
}
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;