1 use strict; use warnings;
2 package OpenILS::Application::Cat;
3 use OpenILS::Application::AppUtils;
4 use OpenSRF::Application;
5 use OpenILS::Application::Cat::Utils;
6 use base qw/OpenSRF::Application/;
7 use Time::HiRes qw(time);
8 use OpenSRF::EX qw(:try);
10 use OpenILS::Utils::Fieldmapper;
12 my $utils = "OpenILS::Application::Cat::Utils";
16 OpenSRF::Application->method_lookup( "blah" );
18 warn "Child Init Failed: " . shift() . "\n";
23 __PACKAGE__->register_method(
24 method => "biblio_record_tree_retrieve",
25 api_name => "open-ils.cat.biblio.record.tree.retrieve",
27 note => "Returns the tree associated with the nodeset of the given doc id"
30 sub biblio_record_tree_retrieve {
32 my( $self, $client, $recordid ) = @_;
34 warn "In retrieve " . time() . "\n";
35 my $name = "open-ils.storage.biblio.record_marc.retrieve";
36 my $method = $self->method_lookup($name);
39 throw OpenSRF::EX::PANIC ("Could not lookup method $name");
42 my ($marcxml) = $method->run($recordid);
43 warn "After marxml retrieve " . time() . "\n";
46 if(UNIVERSAL::isa($marcxml,"OpenSRF::EX")) {
50 return undef unless $marcxml;
52 my $nodes = OpenILS::Utils::FlatXML->new()->xml_to_nodeset( $marcxml->marc );
53 my $tree = $utils->nodeset2tree( $nodes->nodeset );
54 $tree->owner_doc( $marcxml->id() );
55 warn "Returning Tree " . time() . "\n";
59 __PACKAGE__->register_method(
60 method => "biblio_record_tree_commit",
61 api_name => "open-ils.cat.biblio.record.tree.commit",
62 argc => 2, #(session_id, biblio_tree )
63 note => "Walks the tree and commits any changed nodes " .
64 "adds any new nodes, and deletes any deleted nodes",
67 sub biblio_record_tree_commit {
69 my( $self, $user_session, $client, $tree ) = @_;
70 new Fieldmapper::biblio::record_node ($tree);
72 $self->OpenILS::Application::AppUtils->check_user_session( $user_session ); #throws EX on error
75 my $docid = $tree->owner_doc();
77 # turn the tree into a nodeset
78 my $nodeset = $utils->tree2nodeset($tree);
79 $nodeset = $utils->clean_nodeset( $nodeset );
81 if(!defined($docid)) { # be sure
82 for my $node (@$nodeset) {
83 $docid = $node->owner_doc();
84 last if defined($docid);
88 # turn the nodeset into a doc
89 my $marcxml = OpenILS::Utils::FlatXML->new()->nodeset_to_xml( $nodeset );
91 my $biblio = Fieldmapper::biblio::record_marc->new();
92 $biblio->id( $docid );
93 $biblio->marc( $marcxml->toString() );
95 my $session = $utils->start_db_session();
97 warn "Sending updated doc $docid to db\n";
98 my $req = $session->request( "open-ils.storage.biblio.record_marc.update", $biblio );
100 my $status = $req->recv();
101 if(ref($status) and $status->isa("Error")) {
102 throw $status (" +++++++ Document Update Failed " . $status->stringify() ) ;
105 $utils->commit_db_session( $session );
107 my $method = $self->method_lookup( "open-ils.cat.biblio.record.tree.retrieve" );
110 throw OpenSRF::EX::PANIC
111 ("Unable to find method open-ils.cat.biblio.record.tree.retrieve");
113 my ($ans) = $method->run( $docid );
118 __PACKAGE__->register_method(
119 method => "biblio_mods_slim_retrieve",
120 api_name => "open-ils.cat.biblio.mods.slim.retrieve",
122 note => "Returns the displayable data from the MODS record with a given IDs " .
123 "The first ID provided is considered the 'master' document, which means that " .
124 "it's author, subject, etc. will be used. Subjects are gathered from all docs."
127 sub biblio_mods_slim_retrieve {
128 my( $self, $client, @recordids ) = @_;
130 my $name = "open-ils.storage.biblio.record_marc.retrieve";
131 my $method = $self->method_lookup($name);
134 throw OpenSRF::EX::PANIC ("Could not lookup method $name");
137 my $u = $utils->new();
140 for my $id (@recordids) {
141 my ($marcxml) = $method->run($id);
142 if(!$marcxml) { warn "Nothing from storage"; return undef; }
144 if(UNIVERSAL::isa($marcxml,"OpenSRF::EX")) {
145 throw $marcxml ($marcxml->stringify());;
149 $u->start_mods_batch( $marcxml->marc );
152 $u->push_mods_batch( $marcxml->marc );
156 my $mods = $u->finish_mods_batch();