Added support for settings-derived data elements in post-normalization record
authorSebastian Hammer <quinn@indexdata.com>
Mon, 30 Jul 2007 11:52:08 +0000 (11:52 +0000)
committerSebastian Hammer <quinn@indexdata.com>
Mon, 30 Jul 2007 11:52:08 +0000 (11:52 +0000)
src/config.c
src/config.h
src/logic.c
test/test_http.cfg
test/test_http.xml
test/test_http_6.res

index 247df8a..9eeb6bc 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: config.c,v 1.38 2007-07-25 11:00:26 adam Exp $
+/* $Id: config.c,v 1.39 2007-07-30 11:52:08 quinn Exp $
    Copyright (c) 2006-2007, Index Data.
 
 This file is part of Pazpar2.
@@ -19,7 +19,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 02111-1307, USA.
  */
 
-/* $Id: config.c,v 1.38 2007-07-25 11:00:26 adam Exp $ */
+/* $Id: config.c,v 1.39 2007-07-30 11:52:08 quinn Exp $ */
 
 #include <string.h>
 
@@ -52,6 +52,7 @@ struct conf_metadata * conf_metadata_assign(NMEM nmem,
                                             const char *name,
                                             enum conf_metadata_type type,
                                             enum conf_metadata_merge merge,
+                                            enum conf_setting_type setting,
                                             int brief,
                                             int termlist,
                                             int rank,
@@ -74,6 +75,7 @@ struct conf_metadata * conf_metadata_assign(NMEM nmem,
     else
         metadata->merge = merge;    
 
+    metadata->setting = setting;
     metadata->brief = brief;   
     metadata->termlist = termlist;
     metadata->rank = rank;    
@@ -128,6 +130,7 @@ struct conf_metadata* conf_service_add_metadata(NMEM nmem,
                                                 const char *name,
                                                 enum conf_metadata_type type,
                                                 enum conf_metadata_merge merge,
+                                                enum conf_setting_type setting,
                                                 int brief,
                                                 int termlist,
                                                 int rank,
@@ -141,7 +144,7 @@ struct conf_metadata* conf_service_add_metadata(NMEM nmem,
 
     //md = &((service->metadata)[field_id]);
     md = service->metadata + field_id;
-    md = conf_metadata_assign(nmem, md, name, type, merge, 
+    md = conf_metadata_assign(nmem, md, name, type, merge, setting,
                              brief, termlist, rank, sortkey_offset);
     return md;
 }
@@ -242,14 +245,16 @@ static struct conf_service *parse_service(xmlNode *node)
             xmlChar *xml_type = xmlGetProp(n, (xmlChar *) "type");
             xmlChar *xml_termlist = xmlGetProp(n, (xmlChar *) "termlist");
             xmlChar *xml_rank = xmlGetProp(n, (xmlChar *) "rank");
+            xmlChar *xml_setting = xmlGetProp(n, (xmlChar *) "setting");
 
             enum conf_metadata_type type = Metadata_type_generic;
             enum conf_metadata_merge merge = Metadata_merge_no;
+            enum conf_setting_type setting = Metadata_setting_no;
+            enum conf_sortkey_type sk_type = Metadata_sortkey_relevance;
             int brief = 0;
             int termlist = 0;
             int rank = 0;
             int sortkey_offset = 0;
-            enum conf_sortkey_type sk_type = Metadata_sortkey_relevance;
             
             // now do the parsing logic
             if (!xml_name)
@@ -326,6 +331,22 @@ static struct conf_service *parse_service(xmlNode *node)
             else
                 merge = Metadata_merge_no;
 
+            if (xml_setting)
+            {
+                if (!strcmp((const char *) xml_setting, "no"))
+                    setting = Metadata_setting_no;
+                else if (!strcmp((const char *) xml_setting, "postproc"))
+                    setting = Metadata_setting_postproc;
+                else if (!strcmp((const char *) xml_setting, "parameter"))
+                    setting = Metadata_setting_no;
+                else
+                {
+                    yaz_log(YLOG_FATAL,
+                        "Unknown value for medadata/setting: %s", xml_setting);
+                    return 0;
+                }
+            }
+
             // add a sortkey if so specified
             if (xml_sortkey && strcmp((const char *) xml_sortkey, "no"))
             {
@@ -359,7 +380,7 @@ static struct conf_service *parse_service(xmlNode *node)
             // metadata known, assign values
             conf_service_add_metadata(nmem, service, md_node,
                                       (const char *) xml_name,
-                                      type, merge,
+                                      type, merge, setting,
                                       brief, termlist, rank, sortkey_offset);
 
             xmlFree(xml_name);
index 65a19c3..1f51ee4 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: config.h,v 1.25 2007-06-08 13:58:46 adam Exp $
+/* $Id: config.h,v 1.26 2007-07-30 11:52:08 quinn Exp $
    Copyright (c) 2006-2007, Index Data.
 
 This file is part of Pazpar2.
@@ -54,7 +54,12 @@ enum conf_sortkey_type {
     Metadata_sortkey_string         // Flat string
 };
 
-
+// This controls the ability to insert 'static' values from settings into retrieval recs
+enum conf_setting_type {
+    Metadata_setting_no,
+    Metadata_setting_postproc,      // Insert setting value into normalized record
+    Metadata_setting_parameter      // Expose value to normalization stylesheets
+};
 
 // Describes known metadata elements and how they are to be manipulated
 // An array of these structure provides a 'map' against which
@@ -72,6 +77,7 @@ struct conf_metadata
                         // into service/record_cluster->sortkey array
     enum conf_metadata_type type;
     enum conf_metadata_merge merge;
+    enum conf_setting_type setting; // Value is to be taken from session/db settings?
 };
 
 
@@ -81,6 +87,7 @@ struct conf_metadata * conf_metadata_assign(NMEM nmem,
                                             const char *name,
                                             enum conf_metadata_type type,
                                             enum conf_metadata_merge merge,
+                                            enum conf_setting_type setting,
                                             int brief,
                                             int termlist,
                                             int rank,
@@ -118,12 +125,14 @@ struct conf_service
 struct conf_service * conf_service_create(NMEM nmem, 
                                           int num_metadata, int num_sortkeys);
 
+
 struct conf_metadata* conf_service_add_metadata(NMEM nmem, 
                                                 struct conf_service *service,
                                                 int field_id,
                                                 const char *name,
                                                 enum conf_metadata_type type,
                                                 enum conf_metadata_merge merge,
+                                                enum conf_setting_type setting,
                                                 int brief,
                                                 int termlist,
                                                 int rank,
index 42e193a..5b0517b 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: logic.c,v 1.56 2007-07-25 11:41:32 adam Exp $
+/* $Id: logic.c,v 1.57 2007-07-30 11:52:08 quinn Exp $
    Copyright (c) 2006-2007, Index Data.
 
 This file is part of Pazpar2.
@@ -262,13 +262,40 @@ xmlDoc *record_to_xml(struct session_database *sdb, Z_External *rec)
     return rdoc;
 }
 
+// Add static values from session database settings if applicable
+static void insert_settings_values(struct session_database *sdb, xmlDoc *doc)
+{
+    struct conf_service *service = global_parameters.server->service;
+    int i;
+
+    for (i = 0; i < service->num_metadata; i++)
+    {
+        struct conf_metadata *md = &service->metadata[i];
+        int offset;
+
+        if (md->setting == Metadata_setting_postproc &&
+                (offset = settings_offset(md->name)) > 0)
+        {
+            char *val = session_setting_oneval(sdb, offset);
+            if (val)
+            {
+                xmlNode *r = xmlDocGetRootElement(doc);
+                xmlNode *n = xmlNewTextChild(r, 0, (xmlChar *) "metadata",
+                        (xmlChar *) val);
+                xmlSetProp(n, (xmlChar *) "type", (xmlChar *) md->name);
+            }
+        }
+    }
+}
+
 xmlDoc *normalize_record(struct session_database *sdb, Z_External *rec)
 {
     struct database_retrievalmap *m;
     xmlDoc *rdoc = record_to_xml(sdb, rec);
     if (rdoc)
     {
-        for (m = sdb->map; m; m = m->next){
+        for (m = sdb->map; m; m = m->next)
+        {
             xmlDoc *new = 0;
             
             {
@@ -288,6 +315,9 @@ xmlDoc *normalize_record(struct session_database *sdb, Z_External *rec)
             xmlFreeDoc(rdoc);
             rdoc = new;
         }
+
+        insert_settings_values(sdb, rdoc);
+
         if (global_parameters.dump_records)
         {
             FILE *lf = yaz_log_file();
index d3041f4..15ba9e2 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <pazpar2 xmlns="http://www.indexdata.com/pazpar2/1.0">
-<!-- $Id: test_http.cfg,v 1.3 2007-07-18 13:39:11 adam Exp $ -->
+<!-- $Id: test_http.cfg,v 1.4 2007-07-30 11:52:08 quinn Exp $ -->
 <!-- Used by test_http.sh -->
 <server>
   <listen port="9763"/>
@@ -18,6 +18,8 @@
     <metadata name="id"/>
     <metadata name="lccn" merge="unique"/>
     <metadata name="description" brief="yes" merge="longest" rank="3"/>
+
+    <metadata name="test-usersetting" brief="yes" setting="postproc"/>
   </service>
 </server>
 
index cefa3eb..4a86ab2 100644 (file)
@@ -1,7 +1,7 @@
 <settings target="z3950.indexdata.com/marc">
 
   <!-- Used by test test_http.sh -->
-  <!-- $Id: test_http.xml,v 1.3 2007-07-18 13:39:11 adam Exp $ -->
+  <!-- $Id: test_http.xml,v 1.4 2007-07-30 11:52:08 quinn Exp $ -->
 
   <set name="pz:name" value="Local Test"/>
 
@@ -25,4 +25,8 @@
   <set name="pz:nativesyntax" value="iso2709"/>
   <set name="pz:xslt" value="auto"/>
 
+  <!-- Example of application-specific setting -->
+  <!-- Available in output record and/or normalization stylesheet -->
+  <set name="test-usersetting" value="XXXXXXXXXX"/>
+
 </settings>
index d1aae07..e002fa8 100644 (file)
@@ -8,10 +8,12 @@
 <md-title>How to program a computer</md-title>
 <md-author>Jack Collins</md-author>
 <md-id>11224467</md-id>
-<md-lccn>11224467</md-lccn></location>
+<md-lccn>11224467</md-lccn>
+<md-test-usersetting>XXXXXXXXXX</md-test-usersetting></location>
 <location id="z3950.indexdata.com/marc" name="Local Test">
 <md-title>How to program a computer</md-title>
 <md-author>Jack Collins</md-author>
 <md-id>11224466</md-id>
-<md-lccn>11224466</md-lccn></location>
+<md-lccn>11224466</md-lccn>
+<md-test-usersetting>XXXXXXXXXX</md-test-usersetting></location>
 </record>