Skip to content

Commit 08da027

Browse files
committed
support #410 move business logic to function 'fetch_layer_styles_from_dbi'
1 parent ed99caa commit 08da027

6 files changed

+67
-37
lines changed

DESCRIPTION

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: geoflow
2-
Version: 0.9999.20250204
3-
Date: 2025-02-04
2+
Version: 0.9999.20250205
3+
Date: 2025-02-05
44
Title: Orchestrate Geospatial (Meta)Data Management Workflows and Manage FAIR Services
55
Description: An engine to facilitate the orchestration and execution of metadata-driven data management workflows, in compliance with FAIR
66
(Findable, Accessible, Interoperable and Reusable) data management principles. By means of a pivot metadata model, relying on the DublinCore standard (<https://dublincore.org/>),

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export(executeWorkflowJob)
1313
export(extract_cell_components)
1414
export(extract_kvp)
1515
export(extract_kvps)
16+
export(fetch_layer_styles_from_dbi)
1617
export(filter_sf_by_cqlfilter)
1718
export(geoflowLogger)
1819
export(geoflow_action)

R/geoflow_utils.R

+34
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,40 @@ create_geoflow_data_from_dbi <- function(dbi, schema, table){
753753
return(entity_data)
754754
}
755755

756+
#'@name fetch_layer_styles_from_dbi
757+
#'@aliases fetch_layer_styles_from_dbi
758+
#'@title fetch_layer_styles_from_dbi
759+
#'
760+
#'@usage fetch_layer_styles_from_dbi(entity, dbi, schema, table)
761+
#'
762+
#'@param entity a \link{geoflow_entity} to be used and enriched
763+
#'@param dbi a dbi connection
764+
#'@param schema schema
765+
#'@param table table
766+
#'@return the entity, enriched with layer styles
767+
#'
768+
#'@author Emmanuel Blondel, \email{emmanuel.blondel1@@gmail.com}
769+
#'@export
770+
fetch_layer_styles_from_dbi <- function(entity, dbi, schema, table){
771+
if(DBI::dbExistsTable(dbi, "layer_styles")){
772+
#assume this is a special table
773+
styles_sql = sprintf("select * from layer_styles where f_table_schema='%s' and f_table_name='%s'",
774+
schema, table)
775+
styles = DBI::dbGetQuery(dbi, statement = styles_sql)
776+
if(nrow(styles)>0){
777+
styles[order(styles$useasdefault,decreasing = T),] #make sure we list the default one first
778+
#add style names in geoflow_data
779+
for(i in 1:nrow(styles)){
780+
style = styles[i,]
781+
entity$data$addStyle(style$stylename)
782+
}
783+
#add style defs as entity resource to delegate copy after entity dir is created
784+
entity$addResource("layer_styles", styles)
785+
}
786+
}
787+
return(entity)
788+
}
789+
756790
#'@name describeOGCRelation
757791
#'@aliases describeOGCRelation
758792
#'@title describeOGCRelation

inst/metadata/entity/entity_handler_dbi_df.R

+2-18
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,8 @@ handle_entities_dbi_df = function(handler, source, config){
2020
entity_data = create_geoflow_data_from_dbi(dbi, schema, expected_table_id)
2121
entity$setData(entity_data)
2222

23-
#associated styles
24-
if(DBI::dbExistsTable(dbi, "layer_styles")){
25-
#assume this is a special table
26-
styles_sql = sprintf("select * from layer_styles where f_table_schema='%s' and f_table_name='%s'",
27-
schema, expected_table_id)
28-
styles = DBI::dbGetQuery(dbi, statement = styles_sql)
29-
if(nrow(styles)>0){
30-
styles[order(styles$useasdefault,decreasing = T),] #make sure we list the default one first
31-
#add style names in geoflow_data
32-
for(i in 1:nrow(styles)){
33-
style = styles[i,]
34-
entity$data$addStyle(style$stylename)
35-
}
36-
#add style defs as entity resource to delegate copy after entity dir is created
37-
entity$addResource("layer_styles", styles)
38-
}
39-
}
40-
23+
#feth layer_styles (if any) from DBI
24+
entity = fetch_layer_styles_from_dbi(entity, dbi, schema, expected_table_id)
4125
}else{
4226
warnMsg = sprintf("No DB table named '%s' available, skipping data enrichment from DB!", expected_table_id)
4327
config$logger.warn(warnMsg)

inst/metadata/entity/entity_handler_dbi_geometry_columns.R

+2-17
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,8 @@ handle_entities_dbi_geometry_columns <- function(handler, source, config, handle
5454
entity_data = create_geoflow_data_from_dbi(dbi, db_table$f_table_schema, db_table$f_table_name)
5555
entity$setData(entity_data)
5656

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

7560
return(entity)
7661
})

man/fetch_layer_styles_from_dbi.Rd

+26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)