Skip to content

Commit

Permalink
support #410
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Feb 4, 2025
1 parent 9b25370 commit ed99caa
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 6 deletions.
3 changes: 3 additions & 0 deletions R/executeWorkflowJob.R
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ executeWorkflowJob <- function(config, jobdir = NULL, queue = NULL, monitor = NU
}
}

#copyStylesToJobDir
entity$copyStylesToJobDir(config)

#extra identifiers to use in entity identification/actions
entity$enrichWithIdentifiers(config)
#data relations (eg. geosapi & OGC data protocol online resources)
Expand Down
17 changes: 17 additions & 0 deletions R/geoflow_entity.R
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,23 @@ geoflow_entity <- R6Class("geoflow_entity",

},

#'@description This function checks for the availability of layer styles (set as entity resource)
#'that would have been added with DBI handlers from a special DB 'layer_styles' table
#'@param config geoflow config object
copyStylesToJobDir = function(config){
setwd("./data")
if(!is.null(self$resources$layer_styles)){
styles = self$resources$layer_styles
for(i in 1:nrow(styles)){
style = styles[i,]
sld_filename = paste0(style$stylename, ".sld")
config$logger.info(sprintf("Write SLD style '%s'", sld_filename))
XML::saveXML(XML::xmlParse(style$stylesld), sld_filename)
}
}
setwd("..")
},

#'@description Function that will scan zip data files and resolve data objects sourceType and uploadType
#'@param config geoflow config object
#'@param jobdir relative path of the job directory
Expand Down
16 changes: 11 additions & 5 deletions inst/actions/geosapi_publish_ogc_services.R
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,18 @@ function(action, entity, config){
style <- data_object$styles[i]
#check if any style SLD file is available in source
style_sldfile <- paste0(style,".sld")
if(!style %in% gs_styles){
config$logger.warn(sprintf("No style '%s' in Geoserver", style))
if(style_sldfile %in% data_object$source){
config$logger.info(sprintf("Creating GeoServer style '%s' from SLD style file '%s' available as source", style, style_sldfile))
created <- GS$createStyle(file = file.path(getwd(), "data", style_sldfile), name = style, ws = workspace)
style_sldfilepath = file.path(getwd(), "data", style_sldfile)
if(file.exists(style_sldfilepath)){
if(!style %in% gs_styles){
config$logger.warn(sprintf("No style '%s' in Geoserver", style))
config$logger.info(sprintf("Creating GeoServer style '%s' from SLD style file '%s' available as data", style, style_sldfile))
created <- GS$createStyle(file = style_sldfilepath, name = style, ws = workspace)
if(created) reload_styles = TRUE
}else{
config$logger.warn(sprintf("Existing style '%s' in Geoserver", style))
config$logger.info(sprintf("Updating GeoServer style '%s' from SLD style file '%s' available as data", style, style_sldfile))
updated <- GS$updateStyle(file = style_sldfilepath, name = style, ws = workspace)
if(updated) reload_styles = TRUE
}
}
}
Expand Down
22 changes: 21 additions & 1 deletion inst/metadata/entity/entity_handler_dbi_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,28 @@ handle_entities_dbi_df = function(handler, source, config){
table_entry_query = DBI::dbGetQuery(dbi, table_entry_sql)
#check if a table is available in DB
if(nrow(table_entry_query)>0){
entity_data = create_geoflow_data_from_dbi(dbi, table_entry_query$table_schema[1], expected_table_id)
schema = table_entry_query$table_schema[1]
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)
}
}

}else{
warnMsg = sprintf("No DB table named '%s' available, skipping data enrichment from DB!", expected_table_id)
config$logger.warn(warnMsg)
Expand Down
18 changes: 18 additions & 0 deletions inst/metadata/entity/entity_handler_dbi_geometry_columns.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ handle_entities_dbi_geometry_columns <- function(handler, source, config, handle
#data
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)
}
}

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

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

0 comments on commit ed99caa

Please sign in to comment.