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");
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;
99 my $doc = XML::LibXML->new->parse_string($data);
101 return $summary unless $doc;
103 for my $node ( $doc->getDocumentElement->childNodes ) {
104 if( $node->localName ) {
105 $summary->{$node->localName} = $node->textContent;
115 __PACKAGE__->register_method(
117 api_name => "open-ils.search.added_content.review.retrieve.random",
119 Returns a singe random review article object
123 __PACKAGE__->register_method(
125 api_name => "open-ils.search.added_content.review.retrieve.all",
127 Returns an array review article objects
132 my( $self, $client, $isbn ) = @_;
135 return $ret unless $enabled;
136 my $data = retrieve_added_content( "review", $isbn );
137 return $ret unless $data;
138 my $doc = XML::LibXML->new->parse_string($data);
142 if( $self->api_name =~ /random/ ) { return undef; }
146 my $reviews = $doc->findnodes("//*[local-name()='Review']");
148 for my $rev ( $reviews->get_nodelist() ) {
150 for my $node ($rev->childNodes) {
152 if( $node->localName ) {
153 if( $node->localName eq "ReviewText" ) {
154 $revobj ->{'text'} = $node->textContent;
156 if( $node->localName eq "ReviewLiteral" ) {
157 $revobj->{'info'} = $node->textContent;
163 if( $self->api_name =~ /random/ ) { return $revobj; }
164 push( @$ret, $revobj );
171 __PACKAGE__->register_method(
173 api_name => "open-ils.search.added_content.toc.retrieve",
175 Returns the table of contents for the given ISBN
180 my( $self, $client, $isbn ) = @_;
182 my $data = retrieve_added_content( "toc", $isbn );
183 return undef unless $data;
184 my $doc = XML::LibXML->new->parse_string($data);
186 my @nodes = $doc->findnodes("//*[local-name()='TOCText']")->get_nodelist();
189 return $nodes[0]->textContent;