From 0ee132793d24722488f8aa8ee49be76dc9a7b13a Mon Sep 17 00:00:00 2001 From: miker Date: Mon, 14 Apr 2008 13:16:42 +0000 Subject: [PATCH] adding open-ils.fielder app git-svn-id: svn://svn.open-ils.org/ILS/trunk@9335 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/examples/fm_IDL.xml | 2 +- Open-ILS/examples/opensrf.xml.example | 19 +++ .../perlmods/OpenILS/Application/Fielder.pm | 109 ++++++++++++++++++ 3 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 Open-ILS/src/perlmods/OpenILS/Application/Fielder.pm diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 5a4ca53090..dba433b47f 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -1778,7 +1778,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - + diff --git a/Open-ILS/examples/opensrf.xml.example b/Open-ILS/examples/opensrf.xml.example index d75bcba670..f3d8d30196 100644 --- a/Open-ILS/examples/opensrf.xml.example +++ b/Open-ILS/examples/opensrf.xml.example @@ -695,6 +695,24 @@ vim:et:ts=4:sw=4: + + 3 + 1 + perl + OpenILS::Application::Fielder + 17 + + open-ils.fielder_unix.sock + open-ils.fielder_unix.pid + 1000 + open-ils.fielder_unix.log + 5 + 15 + 3 + 5 + + + @@ -729,6 +747,7 @@ vim:et:ts=4:sw=4: open-ils.reporter open-ils.reporter-store open-ils.permacrud + open-ils.fielder diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Fielder.pm b/Open-ILS/src/perlmods/OpenILS/Application/Fielder.pm new file mode 100644 index 0000000000..c555d702f5 --- /dev/null +++ b/Open-ILS/src/perlmods/OpenILS/Application/Fielder.pm @@ -0,0 +1,109 @@ +# vim:et:ts=4:sw=4: + +package OpenILS::Application::Fielder; +use OpenILS::Application; +use base qw/OpenILS::Application/; + +use Unicode::Normalize; +use OpenSRF::EX qw/:try/; + +use OpenSRF::AppSession; +use OpenSRF::Utils::SettingsClient; +use OpenSRF::Utils::Logger qw/:level/; + +use OpenILS::Utils::Fieldmapper; +use OpenSRF::Utils::JSON; + +use OpenILS::Utils::CStoreEditor qw/:funcs/; + +use XML::LibXML; +use XML::LibXML::XPathContext; +use XML::LibXSLT; + +our %namespace_map = ( + oils_persist=> {ns => 'http://open-ils.org/spec/opensrf/IDL/persistence/v1'}, + oils_obj => {ns => 'http://open-ils.org/spec/opensrf/IDL/objects/v1'}, + idl => {ns => 'http://opensrf.org/spec/IDL/base/v1'}, + reporter => {ns => 'http://open-ils.org/spec/opensrf/IDL/reporter/v1'}, + perm => {ns => 'http://open-ils.org/spec/opensrf/IDL/permacrud/v1'}, +); + + +my $log = 'OpenSRF::Utils::Logger'; + +my $parser = XML::LibXML->new(); +my $xslt = XML::LibXSLT->new(); + +my $xpc = XML::LibXML::XPathContext->new(); +$xpc->registerNs($_, $namespace_map{$_}{ns}) for ( keys %namespace_map ); + +my $idl; + +sub initialize { + + my $conf = OpenSRF::Utils::SettingsClient->new; + my $idl_file = $conf->config_value( 'IDL' ); + + $idl = $parser->parse_file( $idl_file ); + + $log->debug( 'IDL XML file loaded' ); + + generate_methods(); + +} +sub child_init {} + +sub CRUD_action_object_permcheck { + my $self = shift; + my $client = shift; + my $obj = shift; + + my $query = $obj->{query}; + my $fields = $obj->{fields}; + + return undef unless $fields; + return undef unless $query; + + $fields = [$fields] if (!ref($fields)); + + my $e = new_editor(); + + my $obj_class = $self->{class_hint}; + + my $req = $e-json_query({ + select => { $obj_class => $fields }, + from => $obj_class, + where => $query + }); + + while (my $res = $req->recv) { + $client->respond($res->content); + } + + return undef; + +} + +sub generate_methods { + try { + for my $class_node ( $xpc->findnodes( '//idl:class[@oils_persist:field_safe="true"]', $idl->documentElement ) ) { + my $hint = $class_node->getAttribute('id'); + $log->debug("Fielder class_node $hint"); + + __PACKAGE__->register_method( + method => 'CRUD_action_object_permcheck', + api_name => 'open-ils.fielder.' . $hint, + class_hint => $hint, + stream => 1, + argc => 1 + ); + } + } catch Error with { + my $e = shift; + $log->error("error generating Fielder methods: $e"); + }; +} + + +1; + -- 2.43.2