1 package OpenILS::Application::Search::AddedContent;
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");
35 # Fetches the added content and returns the data as a string.
36 # If not data is retrieved (or timeout occurs), undef is returned
37 sub retrieve_added_content {
38 my( $type, $isbn, $summary ) = @_;
39 return undef unless ( $isbn && $isbn ne "" );
41 my $func = "fnDetailByItemKey";
42 if($summary) { $func = "fnContentByItemKey"; }
44 my $url = "$host/$urlbase/" . $types->{$type} .
45 "/$func?UserId=$username&Password=$password&ItemKey=$isbn";
48 warn "Added Content URL: $url\n";
53 $data = LWP::UserAgent->new->get($url)->content;
60 warn "received content data:\n$data\n";
64 __PACKAGE__->register_method(
66 api_name => "open-ils.search.added_content.summary.retrieve",
68 Returns an object like so:
71 Inventory : true/false,
72 Annotation : true/false,
77 This object indicates the existance of each type of added content for the given ISBN
82 my( $self, $client, $isbn ) = @_;
83 my $data = retrieve_added_content( "member", $isbn, 1 );
84 return {} unless $data;
85 my $doc = XML::LibXML->new->parse_string($data);
87 return $summary unless $doc;
89 for my $node ( $doc->getDocumentElement->childNodes ) {
90 if( $node->localName ) {
91 $summary->{$node->localName} = $node->textContent;
101 __PACKAGE__->register_method(
103 api_name => "open-ils.search.added_content.review.retrieve.random",
105 Returns a singe random review article object
109 __PACKAGE__->register_method(
111 api_name => "open-ils.search.added_content.review.retrieve.all",
113 Returns an array review article objects
118 my( $self, $client, $isbn ) = @_;
120 my $data = retrieve_added_content( "review", $isbn );
121 return undef unless $data;
122 my $doc = XML::LibXML->new->parse_string($data);
126 if( $self->api_name =~ /random/ ) { return undef; }
130 my $reviews = $doc->findnodes("//*[local-name()='Review']");
132 for my $rev ( $reviews->get_nodelist() ) {
134 for my $node ($rev->childNodes) {
136 if( $node->localName ) {
137 if( $node->localName eq "ReviewText" ) {
138 $revobj ->{'text'} = $node->textContent;
140 if( $node->localName eq "ReviewLiteral" ) {
141 $revobj->{'info'} = $node->textContent;
147 if( $self->api_name =~ /random/ ) { return $revobj; }
148 push( @$ret, $revobj );
155 __PACKAGE__->register_method(
157 api_name => "open-ils.search.added_content.toc.retrieve",
159 Returns the table of contents for the given ISBN
164 my( $self, $client, $isbn ) = @_;
166 my $data = retrieve_added_content( "toc", $isbn );
167 return undef unless $data;
168 my $doc = XML::LibXML->new->parse_string($data);
170 my @nodes = $doc->findnodes("//*[local-name()='TOCText']")->get_nodelist();
173 return $nodes[0]->textContent;