From: Sebastian Hammer Date: Mon, 30 Jul 2007 23:16:33 +0000 (+0000) Subject: Enabled passing settings values to normalization stylesheet. X-Git-Tag: PAZPAR2.1.0.2~27 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=a9527ef447794713570f93f8cddef6e352536f6b;p=pazpar2-moved-to-github.git Enabled passing settings values to normalization stylesheet. --- diff --git a/src/config.c b/src/config.c index 9eeb6bc..256fa4e 100644 --- a/src/config.c +++ b/src/config.c @@ -1,4 +1,4 @@ -/* $Id: config.c,v 1.39 2007-07-30 11:52:08 quinn Exp $ +/* $Id: config.c,v 1.40 2007-07-30 23:16:33 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.39 2007-07-30 11:52:08 quinn Exp $ */ +/* $Id: config.c,v 1.40 2007-07-30 23:16:33 quinn Exp $ */ #include @@ -338,7 +338,7 @@ static struct conf_service *parse_service(xmlNode *node) else if (!strcmp((const char *) xml_setting, "postproc")) setting = Metadata_setting_postproc; else if (!strcmp((const char *) xml_setting, "parameter")) - setting = Metadata_setting_no; + setting = Metadata_setting_parameter; else { yaz_log(YLOG_FATAL, diff --git a/src/logic.c b/src/logic.c index 5b0517b..e9fa969 100644 --- a/src/logic.c +++ b/src/logic.c @@ -1,4 +1,4 @@ -/* $Id: logic.c,v 1.57 2007-07-30 11:52:08 quinn Exp $ +/* $Id: logic.c,v 1.58 2007-07-30 23:16:33 quinn Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -262,6 +262,44 @@ xmlDoc *record_to_xml(struct session_database *sdb, Z_External *rec) return rdoc; } +#define MAX_XSLT_ARGS 16 + +// Add static values from session database settings if applicable +static void insert_settings_parameters(struct session_database *sdb, + struct session *se, char **parms) +{ + struct conf_service *service = global_parameters.server->service; + int i; + int nparms = 0; + int offset = 0; + + for (i = 0; i < service->num_metadata; i++) + { + struct conf_metadata *md = &service->metadata[i]; + int setting; + + if (md->setting == Metadata_setting_parameter && + (setting = settings_offset(md->name)) > 0) + { + char *val = session_setting_oneval(sdb, setting); + if (val && nparms < MAX_XSLT_ARGS) + { + char *buf; + int len = strlen(val); + buf = nmem_malloc(se->nmem, len + 3); + buf[0] = '\''; + strcpy(buf + 1, val); + buf[len+1] = '\''; + buf[len+2] = '\0'; + parms[offset++] = md->name; + parms[offset++] = buf; + nparms++; + } + } + } + parms[offset] = 0; +} + // Add static values from session database settings if applicable static void insert_settings_values(struct session_database *sdb, xmlDoc *doc) { @@ -288,7 +326,8 @@ static void insert_settings_values(struct session_database *sdb, xmlDoc *doc) } } -xmlDoc *normalize_record(struct session_database *sdb, Z_External *rec) +xmlDoc *normalize_record(struct session_database *sdb, struct session *se, + Z_External *rec) { struct database_retrievalmap *m; xmlDoc *rdoc = record_to_xml(sdb, rec); @@ -300,7 +339,11 @@ xmlDoc *normalize_record(struct session_database *sdb, Z_External *rec) { xmlNodePtr root = 0; - new = xsltApplyStylesheet(m->stylesheet, rdoc, 0); + char *parms[MAX_XSLT_ARGS*2+1]; + + insert_settings_parameters(sdb, se, parms); + + new = xsltApplyStylesheet(m->stylesheet, rdoc, (const char **) parms); root= xmlDocGetRootElement(new); if (!new || !root || !(root->children)) { @@ -1037,7 +1080,8 @@ static struct record_metadata *record_metadata_init( struct record *ingest_record(struct client *cl, Z_External *rec, int record_no) { - xmlDoc *xdoc = normalize_record(client_get_database(cl), rec); + xmlDoc *xdoc = normalize_record(client_get_database(cl), + client_get_session(cl), rec); xmlNode *root, *n; struct record *record; struct record_cluster *cluster; diff --git a/src/pazpar2.h b/src/pazpar2.h index 760d034..91f3aab 100644 --- a/src/pazpar2.h +++ b/src/pazpar2.h @@ -1,4 +1,4 @@ -/* $Id: pazpar2.h,v 1.45 2007-07-16 17:01:46 adam Exp $ +/* $Id: pazpar2.h,v 1.46 2007-07-30 23:16:33 quinn Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -192,7 +192,8 @@ void pazpar2_event_loop(void); int host_getaddrinfo(struct host *host); -xmlDoc *normalize_record(struct session_database *sdb, Z_External *rec); +xmlDoc *normalize_record(struct session_database *sdb, struct session *se, + Z_External *rec); xmlDoc *record_to_xml(struct session_database *sdb, Z_External *rec); struct record *ingest_record(struct client *cl, Z_External *rec, diff --git a/src/settings.c b/src/settings.c index b70a4cc..5a0dd2a 100644 --- a/src/settings.c +++ b/src/settings.c @@ -1,4 +1,4 @@ -/* $Id: settings.c,v 1.25 2007-07-03 11:21:48 adam Exp $ +/* $Id: settings.c,v 1.26 2007-07-30 23:16:33 quinn Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -366,6 +366,30 @@ static void initialize_hard_settings(struct setting_dictionary *dict) dict->num = dict->size; } +// Read any settings names introduced in service definition (config) and add to dictionary +// This is done now to avoid errors if user settings are declared in session overrides +static void initialize_soft_settings() +{ + struct conf_service *service = config->servers->service; + int i; + + for (i = 0; i < service->num_metadata; i++) + { + struct setting set; + struct conf_metadata *md = &service->metadata[i]; + + if (md->setting == Metadata_setting_no) + continue; + + set.precedence = 0; + set.target = ""; + set.name = md->name; + set.value = ""; + set.next = 0; + prepare_dictionary(&set); + } +} + // If we ever decide we need to be able to specify multiple settings directories, // the two calls to read_settings must be split -- so the dictionary is prepared // for the contents of every directory before the databases are updated. @@ -386,6 +410,7 @@ void init_settings(void) memset(new, 0, sizeof(*new)); initialize_hard_settings(new); dictionary = new; + initialize_soft_settings(); } /* diff --git a/src/test_config.c b/src/test_config.c index f351a28..5cd7456 100644 --- a/src/test_config.c +++ b/src/test_config.c @@ -1,4 +1,4 @@ -/* $Id: test_config.c,v 1.3 2007-04-25 07:00:33 marc Exp $ +/* $Id: test_config.c,v 1.4 2007-07-30 23:16:33 quinn Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -47,47 +47,56 @@ void test_conf_service(int argc, char **argv) YAZ_CHECK(!conf_service_add_metadata(0, service, 0, "dead_nmem", Metadata_type_generic, Metadata_merge_unique, + Metadata_setting_no, 1, 1, 1, 0)); YAZ_CHECK(!conf_service_add_metadata(nmem, 0, 0, "service_needed", Metadata_type_generic, Metadata_merge_unique, + Metadata_setting_no, 1, 1, 1, 0)); YAZ_CHECK(!conf_service_add_metadata(nmem, service, -1, "out_of_bounds", Metadata_type_generic, Metadata_merge_unique, + Metadata_setting_no, 1, 1, 1, 0)); YAZ_CHECK(!conf_service_add_metadata(nmem, service, 4, "out_of_bounds", Metadata_type_generic, Metadata_merge_unique, + Metadata_setting_no, 1, 1, 1, 0)); YAZ_CHECK(!conf_service_add_metadata(nmem, service, 0, 0, //missing name Metadata_type_generic, Metadata_merge_unique, + Metadata_setting_no, 1, 1, 1, 0)); // expected metadata sucesses YAZ_CHECK(conf_service_add_metadata(nmem, service, 0, "title", Metadata_type_generic, Metadata_merge_unique, + Metadata_setting_no, 1, 1, 1, 0)); YAZ_CHECK(conf_service_add_metadata(nmem, service, 1, "author", Metadata_type_generic, Metadata_merge_longest, + Metadata_setting_no, 1, 1, 1, 0)); YAZ_CHECK(conf_service_add_metadata(nmem, service, 2, "isbn", Metadata_type_number, Metadata_merge_no, + Metadata_setting_no, 1, 1, 1, 0)); YAZ_CHECK(conf_service_add_metadata(nmem, service, 3, "year", Metadata_type_year, Metadata_merge_range, + Metadata_setting_no, 1, 1, 1, 0)); diff --git a/src/test_record.c b/src/test_record.c index ca4f02b..99502b4 100644 --- a/src/test_record.c +++ b/src/test_record.c @@ -1,4 +1,4 @@ -/* $Id: test_record.c,v 1.7 2007-06-13 21:30:08 adam Exp $ +/* $Id: test_record.c,v 1.8 2007-07-30 23:16:33 quinn Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -59,19 +59,19 @@ void test_record(int argc, char **argv) YAZ_CHECK(conf_service_add_metadata(nmem, service, 0, "title", Metadata_type_generic, Metadata_merge_unique, - 1, 1, 1, 0)); + Metadata_setting_no, 1, 1, 1, 0)); YAZ_CHECK(conf_service_add_metadata(nmem, service, 1, "author", Metadata_type_generic, Metadata_merge_longest, - 1, 1, 1, 0)); + Metadata_setting_no,1, 1, 1, 0)); YAZ_CHECK(conf_service_add_metadata(nmem, service, 2, "isbn", Metadata_type_number, Metadata_merge_no, - 1, 1, 1, 0)); + Metadata_setting_no, 1, 1, 1, 0)); YAZ_CHECK(conf_service_add_metadata(nmem, service, 3, "year", Metadata_type_year, Metadata_merge_range, - 1, 1, 1, 0)); + Metadata_setting_no, 1, 1, 1, 0)); YAZ_CHECK(conf_service_add_sortkey(nmem, service, 0, "relevance", Metadata_sortkey_relevance));