3 package OpenILS::Application::Fielder;
4 use OpenILS::Application;
5 use base qw/OpenILS::Application/;
7 use Unicode::Normalize;
8 use OpenSRF::EX qw/:try/;
10 use OpenSRF::AppSession;
11 use OpenSRF::Utils::SettingsClient;
12 use OpenSRF::Utils::Logger qw/:level/;
14 use OpenILS::Utils::Fieldmapper;
15 use OpenSRF::Utils::JSON;
17 use OpenILS::Utils::CStoreEditor qw/:funcs/;
20 use XML::LibXML::XPathContext;
23 our %namespace_map = (
24 oils_persist=> {ns => 'http://open-ils.org/spec/opensrf/IDL/persistence/v1'},
25 oils_obj => {ns => 'http://open-ils.org/spec/opensrf/IDL/objects/v1'},
26 idl => {ns => 'http://opensrf.org/spec/IDL/base/v1'},
27 reporter => {ns => 'http://open-ils.org/spec/opensrf/IDL/reporter/v1'},
28 perm => {ns => 'http://open-ils.org/spec/opensrf/IDL/permacrud/v1'},
32 my $log = 'OpenSRF::Utils::Logger';
34 my $parser = XML::LibXML->new();
35 my $xslt = XML::LibXSLT->new();
37 my $xpc = XML::LibXML::XPathContext->new();
38 $xpc->registerNs($_, $namespace_map{$_}{ns}) for ( keys %namespace_map );
44 my $conf = OpenSRF::Utils::SettingsClient->new;
45 my $idl_file = $conf->config_value( 'IDL' );
47 $idl = $parser->parse_file( $idl_file );
49 $log->debug( 'IDL XML file loaded' );
61 my $query = $obj->{query};
62 my $fields = $obj->{fields};
64 $log->debug( 'Field list: '. OpenSRF::Utils::JSON->perl2JSON( $fields ) );
65 $log->debug( 'Query: '. OpenSRF::Utils::JSON->perl2JSON( $query ) );
67 return undef unless $fields;
68 return undef unless $query;
70 $fields = [$fields] if (!ref($fields));
72 my $obj_class = $self->{class_hint};
74 $log->debug( 'Query Class: '. $obj_class );
76 my $req = new_editor()->json_query({
77 select => { $obj_class => $fields },
82 while (my $res = $req->recv) {
83 $client->respond($res->content);
90 sub generate_methods {
92 for my $class_node ( $xpc->findnodes( '//idl:class[@oils_persist:field_safe="true"]', $idl->documentElement ) ) {
93 my $hint = $class_node->getAttribute('id');
94 $log->debug("Fielder class_node $hint");
96 __PACKAGE__->register_method(
97 method => 'fielder_fetch',
98 api_name => 'open-ils.fielder.' . $hint,
106 $log->error("error generating Fielder methods: $e");