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 ) = @_;
40 my $func = "fnDetailByItemKey";
41 if($summary) { $func = "fnContentByItemKey"; }
43 my $url = "$host/$urlbase/" . $types->{$type} .
44 "/$func?UserId=$username&Password=$password&ItemKey=$isbn";
47 warn "Added Content URL: $url\n";
52 $data = LWP::UserAgent->new->get($url)->content;
59 warn "received content data:\n$data\n";
63 __PACKAGE__->register_method(
65 api_name => "open-ils.search.added_content.summary.retrieve",
67 Returns an object like so:
70 Inventory : true/false,
71 Annotation : true/false,
76 This object indicates the existance of each type of added content for the given ISBN
81 my( $self, $client, $isbn ) = @_;
82 my $data = retrieve_added_content( "member", $isbn, 1 );
83 my $doc = XML::LibXML->new->parse_string($data);
85 return $summary unless $doc;
87 for my $node ( $doc->getDocumentElement->childNodes ) {
88 if( $node->localName ) {
89 $summary->{$node->localName} = $node->textContent;
99 __PACKAGE__->register_method(
101 api_name => "open-ils.search.added_content.review.retrieve.random",
103 Returns a singe random review article object
107 __PACKAGE__->register_method(
109 api_name => "open-ils.search.added_content.review.retrieve.all",
111 Returns an array review article objects
116 my( $self, $client, $isbn ) = @_;
118 my $data = retrieve_added_content( "review", $isbn );
119 my $doc = XML::LibXML->new->parse_string($data);
123 if( $self->api_name =~ /random/ ) { return undef; }
127 my $reviews = $doc->findnodes("//*[local-name()='Review']");
129 for my $rev ( $reviews->get_nodelist() ) {
131 for my $node ($rev->childNodes) {
133 if( $node->localName ) {
134 if( $node->localName eq "ReviewText" ) {
135 $revobj ->{'text'} = $node->textContent;
137 if( $node->localName eq "ReviewLiteral" ) {
138 $revobj->{'info'} = $node->textContent;
144 if( $self->api_name =~ /random/ ) { return $revobj; }
145 push( @$ret, $revobj );
152 __PACKAGE__->register_method(
154 api_name => "open-ils.search.added_content.toc.retrieve",
156 Returns the table of contents for the given ISBN
161 my( $self, $client, $isbn ) = @_;
163 my $data = retrieve_added_content( "toc", $isbn );
164 my $doc = XML::LibXML->new->parse_string($data);
167 my @nodes = $doc->findnodes("//*[local-name()='TOCText']")->get_nodelist();
170 return $nodes[0]->textContent;