[open-ils-commits] [GIT] Evergreen ILS branch master updated. 3791aec127f76fe78d83fe508f38c6399cf01bbf

Evergreen Git git at git.evergreen-ils.org
Fri Dec 9 16:50:37 EST 2011


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, master has been updated
       via  3791aec127f76fe78d83fe508f38c6399cf01bbf (commit)
      from  def53e4743953d0ad50f24f52145d8db5da85b58 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 3791aec127f76fe78d83fe508f38c6399cf01bbf
Author: Art Rhyno <artrhyno at uwindsor.ca>
Date:   Fri Dec 9 16:36:28 2011 -0500

    Added CUFTS support in ResolverResolver
    
    This is based on the CUFTS implementation for UPEI. This is
    very closely modeled on the SFX implementation.
    
    opensrf.xml.example has been modified to include a <resolver_type>
    element for ResolverResolver; by default, SFX will be used and this
    shouldn't break anything else. If you use CUFTS rather than SFX, you
    can specify 'cufts'.
    
    Signed-off-by: Art Rhyno <artrhyno at uwindsor.ca>
    Signed-off-by: Dan Scott <dscott at laurentian.ca>

diff --git a/Open-ILS/examples/opensrf.xml.example b/Open-ILS/examples/opensrf.xml.example
index 9a3eaa3..2fea59d 100644
--- a/Open-ILS/examples/opensrf.xml.example
+++ b/Open-ILS/examples/opensrf.xml.example
@@ -1086,6 +1086,7 @@ vim:et:ts=4:sw=4:
                 </app_settings>
             </open-ils.reporter-store>
 
+<!-- resolver_type defaults to sfx but can also be cufts -->
 <!--
            <open-ils.resolver>
                <keepalive>3</keepalive>
@@ -1105,7 +1106,8 @@ vim:et:ts=4:sw=4:
                </unix_config>
                <app_settings>
                   <cache_timeout>86400</cache_timeout>
-                  <default_url_base>http://path/to/sfx</default_url_base>
+                  <default_url_base>http://path/to/sfx_or_cufts</default_url_base>
+                  <resolver_type>sfx</resolver_type>
                </app_settings>
             </open-ils.resolver>
 -->
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/ResolverResolver.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/ResolverResolver.pm
index 76a84ed..1351a68 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/ResolverResolver.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/ResolverResolver.pm
@@ -83,6 +83,7 @@ my $prefix = "open-ils.resolver_"; # Prefix for caching values
 my $cache;
 my $cache_timeout;
 my $default_url_base;              # Default resolver location
+my $resolver_type;              # Default resolver type
 
 our ($ua, $parser);
 
@@ -94,6 +95,8 @@ sub initialize {
         "apps", "open-ils.resolver", "app_settings", "cache_timeout" ) || 300;
     $default_url_base = $sclient->config_value(
         "apps", "open-ils.resolver", "app_settings", "default_url_base");
+    $resolver_type = $sclient->config_value(
+        "apps", "open-ils.resolver", "app_settings", "resolver_type");
 }
 
 sub child_init {
@@ -112,6 +115,124 @@ sub resolve_holdings {
     my $id_value = shift;     # the normalized ISSN or ISBN
     my $url_base = shift || $default_url_base; 
 
+    if ($resolver_type eq 'cufts') {
+        return cufts_holdings($self,$conn,$id_type,$id_value,$url_base);
+    } else {
+        return sfx_holdings($self,$conn,$id_type,$id_value,$url_base);
+    }
+}
+
+sub cufts_holdings{
+
+    my $self = $_[0];
+    my $conn = $_[1];
+    my $id_type = $_[2];
+    my $id_value = $_[3];
+    my $url_base = $_[4];
+
+    # We'll use this in our cache key
+    my $method = $self->api_name;
+
+    # We might want to return raw JSON for speedier responses
+    my $format = 'fieldmapper';
+    if ($self->api_name =~ /raw$/) {
+        $format = 'raw';
+    }
+
+    # Nice little CUFTS OpenURL request
+    my $url_args = '?';
+
+    if ($id_type eq 'issn') {
+        $url_args .= "&issn=$id_value";
+    } elsif ($id_type eq 'isbn') {
+        $url_args .= "&isbn=$id_value";
+    }
+    
+    my $ckey = $prefix . $method . $url_base . $id_type . $id_value; 
+
+    # Check the cache to see if we've already looked this up
+    # If we have, shortcut our return value
+    my $result = $cache->get_cache($ckey) || undef;
+    if ($result) {
+        $logger->info("Resolver found a cache hit");    
+        return $result;
+    }
+
+    # Otherwise, let's go and grab the info from the CUFTS server
+    my $req = HTTP::Request->new('GET', "$url_base$url_args");
+
+    # Let's see what we we're trying to request
+    $logger->info("Resolving the following request: $url_base$url_args");
+
+    my $res = $ua->request($req);
+
+    my $xml = $res->content;
+    my $parsed_cufts = $parser->parse_string($xml);
+
+    my (@targets) = $parsed_cufts->findnodes('/CUFTS/resource/service[@name="journal"]');
+
+    my @cufts_result;
+    foreach my $target (@targets) {
+        my %full_txt;
+
+        # Ensure we have a name and especially URL to return
+        $full_txt{'name'} = $target->findvalue('../@name[1]');
+        $full_txt{'url'} = $target->findvalue('./result/url') || next;
+        $full_txt{'coverage'} = $target->findvalue('./result/ft_start_date') . ' - ' . $target->findvalue('./result/ft_end_date');
+        my $embargo = "";
+        my $days_embargo = $target->findvalue('./result/embargo_days') || '';
+        if (length($days_embargo) > 0) {
+            $days_embargo = $days_embargo . " days ";
+        }
+        my $months_embargo = $target->findvalue('./result/embargo_months') || '';
+        if (length($months_embargo) > 0) {
+            $months_embargo = $months_embargo . " months ";
+        }
+        my $years_embargo = $target->findvalue('./result/embargo_years') || '';
+        if (length($years_embargo) > 0) {
+            $years_embargo = $years_embargo . " years ";
+        }
+        if (length($years_embargo . $months_embargo . $days_embargo) > 0) {
+            $embargo = "(most recent " . $years_embargo . $months_embargo . $days_embargo . "unavailable due to publisher restrictions)";
+        }
+        $full_txt{'embargo'} = $embargo;
+
+        if ($format eq 'raw') {
+            push @cufts_result, {
+                public_name => $full_txt{'name'},
+                target_url => $full_txt{'url'},
+                target_coverage => $full_txt{'coverage'},
+                target_embargo => $full_txt{'embargo'},
+            };
+        } else {
+            my $rhr = Fieldmapper::resolver::holdings_record->new;
+            $rhr->public_name($full_txt{'name'});
+            $rhr->target_url($full_txt{'url'});
+            $rhr->target_coverage($full_txt{'coverage'});
+            $rhr->target_embargo($full_txt{'embargo'});
+            push @cufts_result, $rhr;
+        }
+    }
+
+    # Stuff this into the cache
+    $cache->put_cache($ckey, \@cufts_result, $cache_timeout);
+    
+    # Don't return the list unless it contains results
+    if (scalar(@cufts_result)) {
+        return \@cufts_result;
+    }
+
+    return undef;
+}
+
+sub sfx_holdings{
+
+    my $self = $_[0];
+    my $conn = $_[1];
+    my $id_type = $_[2];
+    my $id_value = $_[3];
+    my $url_base = $_[4];
+
     # We'll use this in our cache key
     my $method = $self->api_name;
 

-----------------------------------------------------------------------

Summary of changes:
 Open-ILS/examples/opensrf.xml.example              |    4 +-
 .../lib/OpenILS/Application/ResolverResolver.pm    |  121 ++++++++++++++++++++
 2 files changed, 124 insertions(+), 1 deletions(-)


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list