Skip to content

Commit 4df71c3

Browse files
TAlonglongjmckenna
authored andcommitted
Cached(ie default) time dimension used instead of requested time dimension for getfeatureinfo (#311)
1 parent ea2d0a0 commit 4df71c3

File tree

4 files changed

+82
-2
lines changed

4 files changed

+82
-2
lines changed

include/mapcache.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,6 +1749,12 @@ struct mapcache_dimension {
17491749
apr_array_header_t* (*get_all_ogc_formatted_entries)(mapcache_context *ctx, mapcache_dimension *dimension,
17501750
mapcache_tileset *tileset, mapcache_extent *extent, mapcache_grid *grid);
17511751

1752+
/**
1753+
* \brief return all value to override default value
1754+
*/
1755+
apr_array_header_t* (*get_default_value)(mapcache_context *ctx, mapcache_dimension *dimension,
1756+
mapcache_tileset *tileset, mapcache_extent *extent, mapcache_grid *grid);
1757+
17521758
/**
17531759
* \brief parse the value given in the configuration
17541760
*/

lib/connection_pool.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ mapcache_pooled_connection* mapcache_connection_pool_get_connection(mapcache_con
140140
pc->private->next = pcc->head;
141141
pc->private->pcc = pcc;
142142

143+
pcc->max_list_size = ctx->config->cp_hmax;
143144
if(count == pcc->max_list_size) {
144145
/* max number of connections atained, we must destroy the last one that was used */
145146
mapcache_pooled_connection *opc;

lib/dimension_pg.c

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ struct mapcache_dimension_postgresql {
4040
char *dbconnection;
4141
char *get_values_for_entry_query;
4242
char *get_all_values_query;
43+
char *get_default_value_query;
4344
apr_hash_t *get_values_indexes;
4445
apr_hash_t *get_all_indexes;
46+
apr_hash_t *get_default_value_indexes;
4547
};
4648

4749
struct postgresql_dimension_conn {
@@ -74,9 +76,10 @@ static int qparam(mapcache_context *ctx, char *qstring, const char *param, int i
7476
static void parse_queries(mapcache_context *ctx, mapcache_dimension_postgresql *dim) {
7577
const char *keys[9] = {":tileset",":dim",":gridsrs",":minx",":maxx",":miny",":maxy",":start_timestamp",":end_timestamp"};
7678
int i;
77-
int gaidx=1,gvidx=1;
79+
int gaidx=1,gvidx=1,gdidx=1;
7880
dim->get_all_indexes = apr_hash_make(ctx->pool);
7981
dim->get_values_indexes = apr_hash_make(ctx->pool);
82+
dim->get_default_value_indexes = apr_hash_make(ctx->pool);
8083
for(i=0;i<9;i++) {
8184
if(qparam(ctx,dim->get_all_values_query,keys[i],gaidx)) {
8285
apr_hash_set(dim->get_all_indexes,keys[i],APR_HASH_KEY_STRING,INT2VOIDP(gaidx));
@@ -86,6 +89,12 @@ static void parse_queries(mapcache_context *ctx, mapcache_dimension_postgresql *
8689
apr_hash_set(dim->get_values_indexes,keys[i],APR_HASH_KEY_STRING,INT2VOIDP(gvidx));
8790
gvidx++;
8891
}
92+
if (dim->get_default_value_query){
93+
if(qparam(ctx,dim->get_default_value_query,keys[i],gdidx)) {
94+
apr_hash_set(dim->get_default_value_indexes,keys[i],APR_HASH_KEY_STRING,INT2VOIDP(gdidx));
95+
gdidx++;
96+
}
97+
}
8998
}
9099
}
91100

@@ -220,6 +229,14 @@ void mapcache_postgresql_dimension_connection_constructor(mapcache_context *ctx,
220229
*conn_ = NULL;
221230
return;
222231
}
232+
if (dim->get_default_value_query){
233+
prepare_query(ctx,conn->pgconn, "get_default_value", dim->get_default_value_query, dim->get_default_value_indexes);
234+
if(GC_HAS_ERROR(ctx)) {
235+
PQfinish(conn->pgconn);
236+
*conn_ = NULL;
237+
return;
238+
}
239+
}
223240
}
224241

225242
void mapcache_postgresql_dimension_connection_destructor(void *conn_)
@@ -330,6 +347,47 @@ static apr_array_header_t* _mapcache_dimension_postgresql_get_all_entries(mapcac
330347

331348
}
332349

350+
static apr_array_header_t* _mapcache_dimension_postgresql_get_default_entries(mapcache_context *ctx, mapcache_dimension *dim,
351+
mapcache_tileset *tileset, mapcache_extent *extent, mapcache_grid *grid) {
352+
mapcache_dimension_postgresql *sdim = (mapcache_dimension_postgresql*)dim;
353+
PGresult *res;
354+
apr_array_header_t *time_ids = NULL;
355+
mapcache_pooled_connection *pc;
356+
struct postgresql_dimension_conn *conn;
357+
int nParams, *paramLengths,*paramFormats,i;
358+
char **paramValues;
359+
360+
if (sdim->get_default_value_query == NULL){
361+
return NULL;
362+
}
363+
pc = _postgresql_dimension_get_conn(ctx,tileset,sdim);
364+
if (GC_HAS_ERROR(ctx)) {
365+
return NULL;
366+
}
367+
conn = pc->connection;
368+
_mapcache_dimension_postgresql_bind_parameters(ctx,sdim->get_all_indexes,NULL,tileset,extent,grid,0,0,&nParams,&paramValues,&paramLengths,&paramFormats);
369+
if(GC_HAS_ERROR(ctx)) {
370+
_postgresql_dimension_release_conn(ctx, pc);
371+
return NULL;
372+
}
373+
res = PQexecPrepared(conn->pgconn,"get_default_value",nParams,(const char *const*)paramValues,paramLengths,paramFormats,0);
374+
if (PQresultStatus(res) != PGRES_TUPLES_OK) {
375+
//ctx->set_error(ctx, 500, "postgresql query: %s", PQerrorMessage(conn->pgconn));
376+
PQclear(res);
377+
_postgresql_dimension_release_conn(ctx, pc);
378+
return NULL;
379+
}
380+
381+
time_ids = apr_array_make(ctx->pool,0,sizeof(char*));
382+
for(i=0;i<PQntuples(res);i++) {
383+
APR_ARRAY_PUSH(time_ids, char *) = apr_pstrdup(ctx->pool, PQgetvalue(res,i,0));
384+
}
385+
PQclear(res);
386+
_postgresql_dimension_release_conn(ctx, pc);
387+
return time_ids;
388+
389+
}
390+
333391
static void _mapcache_dimension_postgresql_parse_xml(mapcache_context *ctx, mapcache_dimension *dim,
334392
ezxml_t node)
335393
{
@@ -359,6 +417,14 @@ static void _mapcache_dimension_postgresql_parse_xml(mapcache_context *ctx, mapc
359417
ctx->set_error(ctx,400,"postgresql dimension \"%s\" has no <list_query> node", dim->name);
360418
return;
361419
}
420+
child = ezxml_child(node,"default_query");
421+
if(child) {
422+
dimension->get_default_value_query = apr_pstrdup(ctx->pool, child->txt);
423+
} else {
424+
dimension->get_default_value_query = NULL;
425+
// ctx->set_error(ctx,400,"postgresql dimension \"%s\" has no <default_query> node", dim->name);
426+
// return;
427+
}
362428
parse_queries(ctx,dimension);
363429
//printf("q1: %s\n",dimension->get_all_values_query);
364430
//printf("q2: %s\n",dimension->get_values_for_entry_query);
@@ -377,6 +443,7 @@ mapcache_dimension* mapcache_dimension_postgresql_create(mapcache_context *ctx,
377443
dimension->dimension.configuration_parse_xml = _mapcache_dimension_postgresql_parse_xml;
378444
dimension->dimension.get_all_entries = _mapcache_dimension_postgresql_get_all_entries;
379445
dimension->dimension.get_all_ogc_formatted_entries = _mapcache_dimension_postgresql_get_all_entries;
446+
dimension->dimension.get_default_value = _mapcache_dimension_postgresql_get_default_entries;
380447
return (mapcache_dimension*)dimension;
381448
#else
382449
ctx->set_error(ctx,400,"postgresql dimension support requires POSTGRESQL support to be built in");

lib/service_wms.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ void _create_capabilities_wms(mapcache_context *ctx, mapcache_request_get_capabi
314314
if(tileset->dimensions) {
315315
for(i=0; i<tileset->dimensions->nelts; i++) {
316316
apr_array_header_t *values;
317+
apr_array_header_t *default_value;
317318
int value_idx;
318319
char *dimval = NULL;
319320
mapcache_dimension *dimension = APR_ARRAY_IDX(tileset->dimensions,i,mapcache_dimension*);
@@ -337,6 +338,11 @@ void _create_capabilities_wms(mapcache_context *ctx, mapcache_request_get_capabi
337338
if(dimval) {
338339
ezxml_set_txt(dimxml,dimval);
339340
}
341+
default_value = dimension->get_default_value(ctx,dimension,tileset,NULL,NULL);
342+
if (default_value){
343+
dimension->default_value = APR_ARRAY_IDX(default_value,0,char *);
344+
ezxml_set_attr(dimxml,"default",dimension->default_value);
345+
}
340346
}
341347
}
342348

@@ -886,7 +892,7 @@ void _mapcache_service_wms_parse_request(mapcache_context *ctx, mapcache_service
886892
mapcache_dimension *dimension = APR_ARRAY_IDX(tileset->dimensions,i,mapcache_dimension*);
887893
const char *value;
888894
if((value = (char*)apr_table_get(params,dimension->name)) != NULL) {
889-
mapcache_map_set_cached_dimension(ctx,&fi->map,dimension->name,value);
895+
mapcache_map_set_requested_dimension(ctx,&fi->map,dimension->name,value);
890896
GC_CHECK_ERROR(ctx);
891897
}
892898
}

0 commit comments

Comments
 (0)