1 use strict; use warnings;
2 package OpenILS::Application::Cat;
3 use OpenSRF::Application;
4 use OpenILS::Application::Cat::Utils;
5 use base qw/OpenSRF::Application/;
6 use Time::HiRes qw(time);
7 use OpenSRF::EX qw(:try);
9 use OpenILS::Utils::Fieldmapper;
11 my $utils = "OpenILS::Application::Cat::Utils";
15 OpenSRF::Application->method_lookup( "blah" );
17 warn "Child Init Failed: " . shift() . "\n";
22 __PACKAGE__->register_method(
23 method => "biblio_record_tree_retrieve",
24 api_name => "open-ils.cat.biblio.record.tree.retrieve",
26 note => "Returns the tree associated with the nodeset of the given doc id"
29 sub biblio_record_tree_retrieve {
30 my( $self, $client, $recordid ) = @_;
32 warn "In retrieve " . time() . "\n";
33 my $name = "open-ils.storage.biblio.record_marc.retrieve";
34 my $method = $self->method_lookup($name);
37 throw OpenSRF::EX::PANIC ("Could not lookup method $name");
40 my ($marcxml) = $method->run($recordid);
41 warn "After marxml retrieve " . time() . "\n";
44 if(UNIVERSAL::isa($marcxml,"OpenSRF::EX")) {
48 return undef unless $marcxml;
50 # warn $marcxml->marc;
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";
60 __PACKAGE__->register_method(
61 method => "biblio_record_tree_commit",
62 api_name => "open-ils.cat.biblio.record.tree.commit",
64 note => "Walks the tree and commits any changed nodes " .
65 "adds any new nodes, and deletes any deleted nodes",
69 sub biblio_record_tree_commit {
71 my( $self, $client, $tree ) = @_;
72 new Fieldmapper::biblio::record_node ($tree);
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 );
84 if(!defined($docid)) { # be sure
85 for my $node (@$nodeset) {
86 $docid = $node->owner_doc();
87 last if defined($docid);
91 # turn the nodeset into a doc
92 my $marcxml = OpenILS::Utils::FlatXML->new()->nodeset_to_xml( $nodeset );
94 my $biblio = Fieldmapper::biblio::record_marc->new();
95 $biblio->id( $docid );
96 $biblio->marc( $marcxml->toString() );
99 warn "Biblio Object\n";
102 my $session = $utils->start_db_session();
104 warn "Sending updated doc $docid to db\n";
105 my $req = $session->request(
106 "open-ils.storage.biblio.record_marc.update", $biblio );
108 my $status = $req->recv();
109 if(ref($status) and $status->isa("Error")) {
110 warn " +++++++ Document Update Failed";
111 warn $status->stringify() . "\n";
112 throw $status (" +++++++ Document Update Failed " . $status->stringify() ) ;
114 $utils->commit_db_session( $session );
115 warn "Update Successful\n";
118 # commit the altered nodeset nodes to the db
119 #my $hash = $utils->commit_nodeset( $nodeset );
120 # retrieve the altered tree back from the db and return it
123 my $method = $self->method_lookup( "open-ils.cat.biblio.record.tree.retrieve" );
125 throw OpenSRF::EX::PANIC
126 ("Unable to find method open-ils.cat.biblio.record.tree.retrieve");
128 my ($ans) = $method->run( $docid );
129 warn "=================================================================\n";
130 warn "=================================================================\n";
136 __PACKAGE__->register_method(
137 method => "biblio_mods_slim_retrieve",
138 api_name => "open-ils.cat.biblio.mods.slim.retrieve",
140 note => "Returns the displayable data from the MODS record with a given ID",
143 sub biblio_mods_slim_retrieve {
144 my( $self, $client, $recordid ) = @_;
146 #my $name = "open-ils.storage.biblio.record_entry.nodeset.retrieve";
147 my $name = "open-ils.storage.biblio.record_marc.retrieve";
148 my $method = $self->method_lookup($name);
151 throw OpenSRF::EX::PANIC ("Could not lookup method $name");
154 # grab the marc record
155 my ($marcxml) = $method->run($recordid);
156 if(!$marcxml) { warn "Nothing from storage"; return undef; }
158 if(UNIVERSAL::isa($marcxml,"OpenSRF::EX")) {
159 throw $marcxml ($marcxml->stringify());;
162 my $u = $utils->new();
163 $u->start_mods_batch( $marcxml->marc );
165 my $mods = $u->finish_mods_batch();
166 return $u->mods_perl_to_mods_slim( $mods );