zoom: allow local torus record.
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 22 Jun 2011 10:01:25 +0000 (12:01 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 22 Jun 2011 10:02:27 +0000 (12:02 +0200)
One or more Torus records may be specified in local zoom configuration.
The torus element may include a records element which holds zero or
record elements.

etc/config-zoom.xml
src/filter_zoom.cpp
xml/schema/filter_zoom.rnc
xml/schema/filter_zoom.rng
xml/schema/filter_zoom.xsd

index 8335b30..daea9da 100644 (file)
@@ -1,8 +1,5 @@
 <?xml version="1.0"?>
 <metaproxy xmlns="http://indexdata.com/metaproxy" version="1.0">
-  <!-- Z39.50 proxy which relays to target specified in Init otherinfo 
-  (VAL_RPOXY). If no target is given, it relays to target
-  z3950.indexdata.dk -->
   <start route="start"/>
   <filters>
     <filter id="frontend" type="frontend_net">
@@ -11,9 +8,32 @@
     </filter>
     <filter id="backend" type="zoom">
       <torus
-            url="http://newmk2.indexdata.com/torus2/searchable.ebsco/records/?query=udb%3D%db"
+         url="http://newmk2.indexdata.com/torus2/searchable.ebsco/records/?query=udb%3D%db"
             xsldir="."
-      />
+           >   
+       <records>
+         <record>
+           <piggyback>1</piggyback>
+           <queryEncoding>UTF-8</queryEncoding>
+           <udb>z-local</udb>
+           <cclmap_term>1=1016 s=al</cclmap_term>
+           <cclmap_ti>1=4 s=pw t=l,r</cclmap_ti>
+           <requestSyntax>usmarc</requestSyntax>
+           <transform>tmarc.xsl</transform>
+           <zurl>localhost:9999/db01</zurl>
+         </record>
+         <record>
+           <piggyback>1</piggyback>
+           <queryEncoding>UTF-8</queryEncoding>
+           <udb>sru-local</udb>
+           <cclmap_term>s=al</cclmap_term>
+           <cclmap_ti>1=title s=pw t=l,r</cclmap_ti>
+           <sru>get</sru>
+           <transform>tmarc.xsl</transform>
+           <zurl>localhost:9999/db01</zurl>
+         </record>
+       </records>
+      </torus>
       <fieldmap cql="cql.anywhere"/>
       <fieldmap cql="cql.serverChoice"/>
       <fieldmap cql="dc.creator" ccl="au"/>
index f7de862..5863285 100644 (file)
@@ -52,7 +52,7 @@ namespace metaproxy_1 {
             std::string cfAuth;
             std::string cfProxy;
             std::string cfSubDb;
-            std::string database;
+            std::string udb;
             std::string target;
             std::string query_encoding;
             std::string sru;
@@ -122,9 +122,10 @@ namespace metaproxy_1 {
             void process(metaproxy_1::Package & package);
             void configure(const xmlNode * ptr, bool test_only);
         private:
+            void configure_local_records(const xmlNode * ptr, bool test_only);
             FrontendPtr get_frontend(mp::Package &package);
             void release_frontend(mp::Package &package);
-            SearchablePtr parse_torus(const xmlNode *ptr);
+            SearchablePtr parse_torus_record(const xmlNode *ptr);
             struct cql_node *convert_cql_fields(struct cql_node *cn, ODR odr);
             std::map<mp::Session, FrontendPtr> m_clients;            
             boost::mutex m_mutex;
@@ -133,6 +134,7 @@ namespace metaproxy_1 {
             std::map<std::string,std::string> fieldmap;
             std::string xsldir;
             CCL_bibset bibset;
+            std::map<std::string,SearchablePtr> s_map;
         };
     }
 }
@@ -322,112 +324,140 @@ yf::Zoom::Impl::~Impl()
     ccl_qual_rm(&bibset);
 }
 
-yf::Zoom::SearchablePtr yf::Zoom::Impl::parse_torus(const xmlNode *ptr1)
+yf::Zoom::SearchablePtr yf::Zoom::Impl::parse_torus_record(const xmlNode *ptr)
 {
-    SearchablePtr notfound;
-    if (!ptr1)
-        return notfound;
-    for (ptr1 = ptr1->children; ptr1; ptr1 = ptr1->next)
+    Zoom::SearchablePtr s(new Searchable(bibset));
+    
+    for (ptr = ptr->children; ptr; ptr = ptr->next)
     {
-        if (ptr1->type != XML_ELEMENT_NODE)
+        if (ptr->type != XML_ELEMENT_NODE)
             continue;
-        if (!strcmp((const char *) ptr1->name, "record"))
+        if (!strcmp((const char *) ptr->name, "layer"))
+            ptr = ptr->children;
+        else if (!strcmp((const char *) ptr->name,
+                         "authentication"))
+        {
+            s->authentication = mp::xml::get_text(ptr);
+        }
+        else if (!strcmp((const char *) ptr->name,
+                         "cfAuth"))
+        {
+            s->cfAuth = mp::xml::get_text(ptr);
+        } 
+        else if (!strcmp((const char *) ptr->name,
+                         "cfProxy"))
+        {
+            s->cfProxy = mp::xml::get_text(ptr);
+        }  
+        else if (!strcmp((const char *) ptr->name,
+                         "cfSubDb"))
+        {
+            s->cfSubDb = mp::xml::get_text(ptr);
+        }  
+        else if (!strcmp((const char *) ptr->name, "udb"))
+        {
+            s->udb = mp::xml::get_text(ptr);
+        }
+        else if (!strcmp((const char *) ptr->name, "zurl"))
+        {
+            s->target = mp::xml::get_text(ptr);
+        }
+        else if (!strcmp((const char *) ptr->name, "sru"))
         {
-            const xmlNode *ptr2 = ptr1;
-            for (ptr2 = ptr2->children; ptr2; ptr2 = ptr2->next)
+            s->sru = mp::xml::get_text(ptr);
+        }
+        else if (!strcmp((const char *) ptr->name,
+                         "queryEncoding"))
+        {
+            s->query_encoding = mp::xml::get_text(ptr);
+        }
+        else if (!strcmp((const char *) ptr->name,
+                         "piggyback"))
+        {
+            s->piggyback = mp::xml::get_bool(ptr, true);
+        }
+        else if (!strcmp((const char *) ptr->name,
+                         "requestSyntax"))
+        {
+            s->request_syntax = mp::xml::get_text(ptr);
+        }
+        else if (!strcmp((const char *) ptr->name,
+                         "elementSet"))
+        {
+            s->element_set = mp::xml::get_text(ptr);
+        }
+        else if (!strcmp((const char *) ptr->name,
+                         "recordEncoding"))
+        {
+            s->record_encoding = mp::xml::get_text(ptr);
+        }
+        else if (!strcmp((const char *) ptr->name,
+                         "transform"))
+        {
+            s->transform_xsl_fname = mp::xml::get_text(ptr);
+        }
+        else if (!strcmp((const char *) ptr->name,
+                         "useTurboMarc"))
+        {
+            ; // useTurboMarc is ignored
+        }
+        else if (!strncmp((const char *) ptr->name,
+                          "cclmap_", 7))
+        {
+            std::string value = mp::xml::get_text(ptr);
+            ccl_qual_fitem(s->ccl_bibset, value.c_str(),
+                           (const char *) ptr->name + 7);
+        }
+    }
+    return s;
+}
+
+void yf::Zoom::Impl::configure_local_records(const xmlNode *ptr, bool test_only)
+{
+    while (ptr && ptr->type != XML_ELEMENT_NODE)
+        ptr = ptr->next;
+    
+    if (ptr)
+    {
+        if (!strcmp((const char *) ptr->name, "records"))
+        {
+            for (ptr = ptr->children; ptr; ptr = ptr->next)
             {
-                if (ptr2->type != XML_ELEMENT_NODE)
+                if (ptr->type != XML_ELEMENT_NODE)
                     continue;
-                if (!strcmp((const char *) ptr2->name, "layer"))
+                if (!strcmp((const char *) ptr->name, "record"))
                 {
-                    Zoom::SearchablePtr s(new Searchable(bibset));
-
-                    const xmlNode *ptr3 = ptr2;
-                    for (ptr3 = ptr3->children; ptr3; ptr3 = ptr3->next)
+                    SearchablePtr s = parse_torus_record(ptr);
+                    if (s)
                     {
-                        if (ptr3->type != XML_ELEMENT_NODE)
-                            continue;
-                        if (!strcmp((const char *) ptr3->name,
-                                    "authentication"))
+                        std::string udb = s->udb;
+                        if (udb.length())
+                            s_map[s->udb] = s;
+                        else
                         {
-                            s->authentication = mp::xml::get_text(ptr3);
-                        }
-                        else if (!strcmp((const char *) ptr3->name,
-                                    "cfAuth"))
-                        {
-                            s->cfAuth = mp::xml::get_text(ptr3);
-                        } 
-                        else if (!strcmp((const char *) ptr3->name,
-                                    "cfProxy"))
-                        {
-                            s->cfProxy = mp::xml::get_text(ptr3);
-                        }  
-                        else if (!strcmp((const char *) ptr3->name,
-                                    "cfSubDb"))
-                        {
-                            s->cfSubDb = mp::xml::get_text(ptr3);
-                        }  
-                        else if (!strcmp((const char *) ptr3->name, "id"))
-                        {
-                            s->database = mp::xml::get_text(ptr3);
-                        }
-                        else if (!strcmp((const char *) ptr3->name, "zurl"))
-                        {
-                            s->target = mp::xml::get_text(ptr3);
-                        }
-                        else if (!strcmp((const char *) ptr3->name, "sru"))
-                        {
-                            s->sru = mp::xml::get_text(ptr3);
-                        }
-                        else if (!strcmp((const char *) ptr3->name,
-                                         "queryEncoding"))
-                        {
-                            s->query_encoding = mp::xml::get_text(ptr3);
-                        }
-                        else if (!strcmp((const char *) ptr3->name,
-                                         "piggyback"))
-                        {
-                            s->piggyback = mp::xml::get_bool(ptr3, true);
-                        }
-                        else if (!strcmp((const char *) ptr3->name,
-                                         "requestSyntax"))
-                        {
-                            s->request_syntax = mp::xml::get_text(ptr3);
-                        }
-                        else if (!strcmp((const char *) ptr3->name,
-                                         "elementSet"))
-                        {
-                            s->element_set = mp::xml::get_text(ptr3);
-                        }
-                        else if (!strcmp((const char *) ptr3->name,
-                                         "recordEncoding"))
-                        {
-                            s->record_encoding = mp::xml::get_text(ptr3);
-                        }
-                        else if (!strcmp((const char *) ptr3->name,
-                                         "transform"))
-                        {
-                            s->transform_xsl_fname = mp::xml::get_text(ptr3);
-                        }
-                        else if (!strcmp((const char *) ptr3->name,
-                                         "useTurboMarc"))
-                        {
-                            ; // useTurboMarc is ignored
-                        }
-                        else if (!strncmp((const char *) ptr3->name,
-                                          "cclmap_", 7))
-                        {
-                            std::string value = mp::xml::get_text(ptr3);
-                            ccl_qual_fitem(s->ccl_bibset, value.c_str(),
-                                           (const char *) ptr3->name + 7);
+                            throw mp::filter::FilterException
+                                ("No udb for local torus record");
                         }
                     }
-                    return s;
+                }
+                else
+                {
+                    throw mp::filter::FilterException
+                        ("Bad element " 
+                         + std::string((const char *) ptr->name)
+                         + " in zoom filter inside element "
+                         "<torus><records>");
                 }
             }
         }
+        else
+        {
+            throw mp::filter::FilterException
+                ("Bad element " 
+                 + std::string((const char *) ptr->name)
+                 + " in zoom filter inside element <torus>");
+        }
     }
-    return notfound;
 }
 
 void yf::Zoom::Impl::configure(const xmlNode *ptr, bool test_only)
@@ -450,6 +480,7 @@ void yf::Zoom::Impl::configure(const xmlNode *ptr, bool test_only)
                         "Bad attribute " + std::string((const char *)
                                                        attr->name));
             }
+            configure_local_records(ptr->children, test_only);
         }
         else if (!strcmp((const char *) ptr->name, "cclmap"))
         {
@@ -504,16 +535,39 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases(
     else
         torus_db = database;
  
-    xmlDoc *doc = mp::get_searchable(m_p->torus_url, torus_db);
-    if (!doc)
+    SearchablePtr sptr;
+
+    std::map<std::string,SearchablePtr>::iterator it;
+    it = m_p->s_map.find(torus_db);
+    if (it != m_p->s_map.end())
+        sptr = it->second;
+    else
     {
-        *error = YAZ_BIB1_DATABASE_DOES_NOT_EXIST;
-        *addinfo = database.c_str();
-        BackendPtr b;
-        return b;
+        xmlDoc *doc = mp::get_searchable(m_p->torus_url, torus_db);
+        if (!doc)
+        {
+            *error = YAZ_BIB1_DATABASE_DOES_NOT_EXIST;
+            *addinfo = database.c_str();
+            BackendPtr b;
+            return b;
+        }
+        const xmlNode *ptr = xmlDocGetRootElement(doc);
+        if (ptr)
+        {   // presumably ptr is a records element node
+            // parse first record in document
+            for (ptr = ptr->children; ptr; ptr = ptr->next)
+            {
+                if (ptr->type == XML_ELEMENT_NODE
+                    && !strcmp((const char *) ptr->name, "record"))
+                {
+                    sptr = m_p->parse_torus_record(ptr);
+                    break;
+                }
+            }
+        }
+        xmlFreeDoc(doc);
     }
-    SearchablePtr sptr = m_p->parse_torus(xmlDocGetRootElement(doc));
-    xmlFreeDoc(doc);
+
     if (!sptr)
     {
         *error = YAZ_BIB1_DATABASE_DOES_NOT_EXIST;
@@ -708,7 +762,6 @@ Z_Records *yf::Zoom::Frontend::get_records(Odr_int start,
 
                 strcpy(rec_type_str, b->sptr->use_turbomarc ?
                        "txml" : "xml");
-                
                 // prevent buffer overflow ...
                 if (b->sptr->record_encoding.length() > 0 &&
                     b->sptr->record_encoding.length() < 
index 8882a62..15bc99a 100644 (file)
@@ -8,7 +8,27 @@ filter_zoom =
   attribute name { xsd:NCName }?,
   element mp:torus {
     attribute url { xsd:string },
-    attribute xsldir { xsd:string }?
+    attribute xsldir { xsd:string }?,
+    element mp:records {
+      element mp:record {
+        element mp:authentication { xsd:string }?,
+        element mp:piggyback { xsd:string }?,
+        element mp:queryEncoding { xsd:string }?,
+        element mp:udb { xsd:string },
+        element mp:cclmap_au { xsd:string }?,
+       element mp:cclmap_date { xsd:string }?,
+       element mp:cclmap_isbn { xsd:string }?,
+        element mp:cclmap_su { xsd:string }?,
+        element mp:cclmap_term { xsd:string }?,
+        element mp:cclmap_ti { xsd:string }?,
+        element mp:elementSet { xsd:string }?,
+        element mp:recordEncoding { xsd:string }?,
+        element mp:requestSyntax { xsd:string }?,
+        element mp:sru { xsd:string }?,
+        element mp:transform { xsd:string }?,
+        element mp:zurl { xsd:string }
+      }*
+    }?
   }?,
   element mp:fieldmap {
     attribute cql { xsd:string },
index a174e3d..0e97481 100644 (file)
             <data type="string"/>
           </attribute>
         </optional>
+        <optional>
+          <element name="mp:records">
+            <zeroOrMore>
+              <element name="mp:record">
+                <optional>
+                  <element name="mp:authentication">
+                    <data type="string"/>
+                  </element>
+                </optional>
+                <optional>
+                  <element name="mp:piggyback">
+                    <data type="string"/>
+                  </element>
+                </optional>
+                <optional>
+                  <element name="mp:queryEncoding">
+                    <data type="string"/>
+                  </element>
+                </optional>
+                <element name="mp:udb">
+                  <data type="string"/>
+                </element>
+                <optional>
+                  <element name="mp:cclmap_au">
+                    <data type="string"/>
+                  </element>
+                </optional>
+                <optional>
+                  <element name="mp:cclmap_date">
+                    <data type="string"/>
+                  </element>
+                </optional>
+                <optional>
+                  <element name="mp:cclmap_isbn">
+                    <data type="string"/>
+                  </element>
+                </optional>
+                <optional>
+                  <element name="mp:cclmap_su">
+                    <data type="string"/>
+                  </element>
+                </optional>
+                <optional>
+                  <element name="mp:cclmap_term">
+                    <data type="string"/>
+                  </element>
+                </optional>
+                <optional>
+                  <element name="mp:cclmap_ti">
+                    <data type="string"/>
+                  </element>
+                </optional>
+                <optional>
+                  <element name="mp:recordEncoding">
+                    <data type="string"/>
+                  </element>
+                </optional>
+                <optional>
+                  <element name="mp:requestSyntax">
+                    <data type="string"/>
+                  </element>
+                </optional>
+                <optional>
+                  <element name="mp:sru">
+                    <data type="string"/>
+                  </element>
+                </optional>
+                <optional>
+                  <element name="mp:transform">
+                    <data type="string"/>
+                  </element>
+                </optional>
+                <element name="mp:zurl">
+                  <data type="string"/>
+                </element>
+              </element>
+            </zeroOrMore>
+          </element>
+        </optional>
       </element>
     </optional>
     <zeroOrMore>
index ef571b2..a68a571 100644 (file)
   </xs:group>
   <xs:element name="torus">
     <xs:complexType>
+      <xs:sequence>
+        <xs:element minOccurs="0" ref="mp:records"/>
+      </xs:sequence>
       <xs:attribute name="url" use="required" type="xs:string"/>
       <xs:attribute name="xsldir" type="xs:string"/>
     </xs:complexType>
   </xs:element>
+  <xs:element name="records">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element minOccurs="0" maxOccurs="unbounded" ref="mp:record"/>
+      </xs:sequence>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="record">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element minOccurs="0" ref="mp:authentication"/>
+        <xs:element minOccurs="0" ref="mp:piggyback"/>
+        <xs:element minOccurs="0" ref="mp:queryEncoding"/>
+        <xs:element ref="mp:udb"/>
+        <xs:element minOccurs="0" ref="mp:cclmap_au"/>
+        <xs:element minOccurs="0" ref="mp:cclmap_date"/>
+        <xs:element minOccurs="0" ref="mp:cclmap_isbn"/>
+        <xs:element minOccurs="0" ref="mp:cclmap_su"/>
+        <xs:element minOccurs="0" ref="mp:cclmap_term"/>
+        <xs:element minOccurs="0" ref="mp:cclmap_ti"/>
+        <xs:element minOccurs="0" ref="mp:recordEncoding"/>
+        <xs:element minOccurs="0" ref="mp:requestSyntax"/>
+        <xs:element minOccurs="0" ref="mp:sru"/>
+        <xs:element minOccurs="0" ref="mp:transform"/>
+        <xs:element ref="mp:zurl"/>
+      </xs:sequence>
+    </xs:complexType>
+  </xs:element>
+  <xs:element name="authentication" type="xs:string"/>
+  <xs:element name="piggyback" type="xs:string"/>
+  <xs:element name="queryEncoding" type="xs:string"/>
+  <xs:element name="udb" type="xs:string"/>
+  <xs:element name="cclmap_au" type="xs:string"/>
+  <xs:element name="cclmap_date" type="xs:string"/>
+  <xs:element name="cclmap_isbn" type="xs:string"/>
+  <xs:element name="cclmap_su" type="xs:string"/>
+  <xs:element name="cclmap_term" type="xs:string"/>
+  <xs:element name="cclmap_ti" type="xs:string"/>
+  <xs:element name="recordEncoding" type="xs:string"/>
+  <xs:element name="requestSyntax" type="xs:string"/>
+  <xs:element name="sru" type="xs:string"/>
+  <xs:element name="transform" type="xs:string"/>
+  <xs:element name="zurl" type="xs:string"/>
   <xs:element name="fieldmap">
     <xs:complexType>
       <xs:attribute name="cql" use="required" type="xs:string"/>