Skip to content

Commit

Permalink
support #410 move business logic to function 'fetch_layer_styles_from…
Browse files Browse the repository at this point in the history
…_dbi'
  • Loading branch information
eblondel committed Feb 5, 2025
1 parent ed99caa commit 08da027
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 37 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: geoflow
Version: 0.9999.20250204
Date: 2025-02-04
Version: 0.9999.20250205
Date: 2025-02-05
Title: Orchestrate Geospatial (Meta)Data Management Workflows and Manage FAIR Services
Description: An engine to facilitate the orchestration and execution of metadata-driven data management workflows, in compliance with FAIR
(Findable, Accessible, Interoperable and Reusable) data management principles. By means of a pivot metadata model, relying on the DublinCore standard (<https://dublincore.org/>),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export(executeWorkflowJob)
export(extract_cell_components)
export(extract_kvp)
export(extract_kvps)
export(fetch_layer_styles_from_dbi)
export(filter_sf_by_cqlfilter)
export(geoflowLogger)
export(geoflow_action)
Expand Down
34 changes: 34 additions & 0 deletions R/geoflow_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,40 @@ create_geoflow_data_from_dbi <- function(dbi, schema, table){
return(entity_data)
}

#'@name fetch_layer_styles_from_dbi
#'@aliases fetch_layer_styles_from_dbi
#'@title fetch_layer_styles_from_dbi
#'
#'@usage fetch_layer_styles_from_dbi(entity, dbi, schema, table)
#'
#'@param entity a \link{geoflow_entity} to be used and enriched
#'@param dbi a dbi connection
#'@param schema schema
#'@param table table
#'@return the entity, enriched with layer styles
#'
#'@author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com}
#'@export
fetch_layer_styles_from_dbi <- function(entity, dbi, schema, table){
if(DBI::dbExistsTable(dbi, "layer_styles")){
#assume this is a special table
styles_sql = sprintf("select * from layer_styles where f_table_schema='%s' and f_table_name='%s'",
schema, table)
styles = DBI::dbGetQuery(dbi, statement = styles_sql)
if(nrow(styles)>0){
styles[order(styles$useasdefault,decreasing = T),] #make sure we list the default one first
#add style names in geoflow_data
for(i in 1:nrow(styles)){
style = styles[i,]
entity$data$addStyle(style$stylename)
}
#add style defs as entity resource to delegate copy after entity dir is created
entity$addResource("layer_styles", styles)
}
}
return(entity)
}

#'@name describeOGCRelation
#'@aliases describeOGCRelation
#'@title describeOGCRelation
Expand Down
20 changes: 2 additions & 18 deletions inst/metadata/entity/entity_handler_dbi_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,8 @@ handle_entities_dbi_df = function(handler, source, config){
entity_data = create_geoflow_data_from_dbi(dbi, schema, expected_table_id)
entity$setData(entity_data)

#associated styles
if(DBI::dbExistsTable(dbi, "layer_styles")){
#assume this is a special table
styles_sql = sprintf("select * from layer_styles where f_table_schema='%s' and f_table_name='%s'",
schema, expected_table_id)
styles = DBI::dbGetQuery(dbi, statement = styles_sql)
if(nrow(styles)>0){
styles[order(styles$useasdefault,decreasing = T),] #make sure we list the default one first
#add style names in geoflow_data
for(i in 1:nrow(styles)){
style = styles[i,]
entity$data$addStyle(style$stylename)
}
#add style defs as entity resource to delegate copy after entity dir is created
entity$addResource("layer_styles", styles)
}
}

#feth layer_styles (if any) from DBI
entity = fetch_layer_styles_from_dbi(entity, dbi, schema, expected_table_id)
}else{
warnMsg = sprintf("No DB table named '%s' available, skipping data enrichment from DB!", expected_table_id)
config$logger.warn(warnMsg)
Expand Down
19 changes: 2 additions & 17 deletions inst/metadata/entity/entity_handler_dbi_geometry_columns.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,8 @@ handle_entities_dbi_geometry_columns <- function(handler, source, config, handle
entity_data = create_geoflow_data_from_dbi(dbi, db_table$f_table_schema, db_table$f_table_name)
entity$setData(entity_data)

#associated styles
if(DBI::dbExistsTable(dbi, "layer_styles")){
#assume this is a special table
styles_sql = sprintf("select * from layer_styles where f_table_schema='%s' and f_table_name='%s'",
db_table$f_table_schema, db_table$f_table_name)
styles = DBI::dbGetQuery(dbi, statement = styles_sql)
if(nrow(styles)>0){
styles[order(styles$useasdefault,decreasing = T),] #make sure we list the default one first
#add style names in geoflow_data
for(i in 1:nrow(styles)){
style = styles[i,]
entity$data$addStyle(style$stylename)
}
#add style defs as entity resource to delegate copy after entity dir is created
entity$addResource("layer_styles", styles)
}
}
#feth layer_styles (if any) from DBI
entity = fetch_layer_styles_from_dbi(entity, dbi, db_table$f_table_schema, db_table$f_table_name)

return(entity)
})
Expand Down
26 changes: 26 additions & 0 deletions man/fetch_layer_styles_from_dbi.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 08da027

Please sign in to comment.