1 package Evergreen::Application::Search::AddedContent::ContentCafe;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
4 use OpenILS::Application::AppUtils;
5 use OpenSRF::Utils::SettingsClient;
6 my $apputils = "OpenILS::Application::AppUtils";
9 use OpenSRF::EX qw(:try);
15 my $urlbase = "ContentCafe";
18 review => "Review.asmx",
19 annotation => "Annotation.asmx",
20 member => "Member.asmx",
24 my $conf = OpenSRF::Utils::SettingsClient->new;
25 $host = $conf->config_value(
26 "apps", "open-ils.search","app_settings", "added_content", "host");
27 $username = $conf->config_value(
28 "apps", "open-ils.search","app_settings", "added_content", "username");
29 $password = $conf->config_value(
30 "apps", "open-ils.search","app_settings", "added_content", "password");
32 $enabled = 1 if ($host and $username and $password);
37 # Fetches the added content and returns the data as a string.
38 # If not data is retrieved (or timeout occurs), undef is returned
39 sub retrieve_added_content {
40 my( $type, $isbn, $summary ) = @_;
41 return undef unless ( $isbn && $isbn ne "" );
43 my $func = "fnDetailByItemKey";
44 if($summary) { $func = "fnContentByItemKey"; }
46 my $url = "$host/$urlbase/" . $types->{$type} .
47 "/$func?UserId=$username&Password=$password&ItemKey=$isbn";
50 warn "Added Content URL: $url\n";
55 $data = LWP::UserAgent->new->get($url)->content;
62 # warn "received content data:\n$data\n";
66 __PACKAGE__->register_method(
68 api_name => "open-ils.search.added_content.summary.retrieve",
70 Returns an object like so:
73 Inventory : true/false,
74 Annotation : true/false,
79 This object indicates the existance of each type of added content for the given ISBN
84 my( $self, $client, $isbn ) = @_;
90 Annotation => "false",
97 my $data = retrieve_added_content( "member", $isbn, 1 );
98 return {} unless $data;
101 $doc = XML::LibXML->new->parse_string($data);
102 } catch Error with { $doc = undef };
105 return $summary unless $doc;
107 for my $node ( $doc->getDocumentElement->childNodes ) {
108 if( $node->localName ) {
109 $summary->{$node->localName} = $node->textContent;
119 __PACKAGE__->register_method(
121 api_name => "open-ils.search.added_content.review.retrieve.random",
123 Returns a singe random review article object
127 __PACKAGE__->register_method(
129 api_name => "open-ils.search.added_content.review.retrieve.all",
131 Returns an array review article objects
136 my( $self, $client, $isbn ) = @_;
139 return $ret unless $enabled;
140 my $data = retrieve_added_content( "review", $isbn );
141 return $ret unless $data;
145 $doc = XML::LibXML->new->parse_string($data);
146 } catch Error with { $doc = undef };
150 if( $self->api_name =~ /random/ ) { return undef; }
154 my $reviews = $doc->findnodes("//*[local-name()='Review']");
156 for my $rev ( $reviews->get_nodelist() ) {
158 for my $node ($rev->childNodes) {
160 if( $node->localName ) {
161 if( $node->localName eq "ReviewText" ) {
162 $revobj ->{'text'} = $node->textContent;
164 if( $node->localName eq "ReviewLiteral" ) {
165 $revobj->{'info'} = $node->textContent;
171 if( $self->api_name =~ /random/ ) { return $revobj; }
172 push( @$ret, $revobj );
179 __PACKAGE__->register_method(
181 api_name => "open-ils.search.added_content.toc.retrieve",
183 Returns the table of contents for the given ISBN
188 my( $self, $client, $isbn ) = @_;
190 my $data = retrieve_added_content( "toc", $isbn );
191 return undef unless $data;
195 $doc = XML::LibXML->new->parse_string($data);
196 } catch Error with { $doc = undef };
199 my @nodes = $doc->findnodes("//*[local-name()='TOCText']")->get_nodelist();
202 return $nodes[0]->textContent;