LP#1347774 move evergreen.get_locale_name to API
authorBill Erickson <berick@esilibrary.com>
Fri, 1 Aug 2014 19:26:29 +0000 (15:26 -0400)
committerBill Erickson <berick@esilibrary.com>
Fri, 1 Aug 2014 19:27:16 +0000 (15:27 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Search.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm

index 9ebb6da..1e1db25 100644 (file)
@@ -7,6 +7,7 @@ use OpenSRF::Utils::Logger qw(:logger);
 
 use OpenILS::Utils::Fieldmapper;
 use OpenILS::Utils::ModsParser;
+use OpenILS::Utils::CStoreEditor qw/:funcs/;
 use OpenSRF::Utils::SettingsClient;
 use OpenSRF::Utils::Cache;
 
@@ -119,5 +120,36 @@ sub spellcheck {
 }
 
 
+__PACKAGE__->register_method(
+    method    => "get_locale_name",
+    api_name  => "open-ils.search.locale_name",
+    signature => {
+        desc  => q/
+            Given a locale code (e.g. en_us) returns the name and 
+            description of the locale./,
+        param => [
+            {
+                name => 'locale',
+                desc => 'Locale code',
+                type => 'string'
+            },
+        ],
+        return => {
+            desc => q/
+                Hash of "name" and "description".  
+                Undef if the locale is not found/,
+            type => 'hash'
+        }
+    }
+);
+
+sub get_locale_name {
+    my ($self, $client, $locale) = @_;
+    my $data = new_editor->json_query(
+        {from => ['evergreen.get_locale_name', $locale]})->[0];
+    # evergreen.get_locale_name returns a hash regardless
+    return ($data and $data->{name}) ? $data : undef;
+}
+
 
 1;
index 1514ad1..d8feb90 100644 (file)
@@ -10,6 +10,7 @@ use Apache2::Log;
 use OpenSRF::EX qw(:try);
 use OpenSRF::AppSession;
 use OpenILS::Utils::CStoreEditor (':funcs', personality => 'open-ils.prcud');
+use OpenILS::Application::AppUtils;
 use List::MoreUtils qw/uniq/;
 
 use constant OILS_HTTP_COOKIE_SKIN => 'eg_skin';
@@ -292,15 +293,11 @@ sub load_locale_handlers {
         my $tag = $locale_tags[$idx];
         next if grep { $_ eq $tag } keys %registered_locales;
 
-        my $res = $editor->json_query({
-            "from" => [
-                "evergreen.get_locale_name",
-                $tag
-            ]
-        });
+        my $locale = OpenILS::Application::AppUtils->simplereq(
+            'open-ils.search', 
+            'open-ils.search.locale_name', $tag) or next;
 
-        my $locale_name = $res->[0]->{"name"} if exists $res->[0]->{"name"};
-        next unless $locale_name;
+        my $locale_name = $locale->{name};
 
         my $parent_tag = '';
         my $sub_idx = $idx;