-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
191 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
function(action, entity, config){ | ||
|
||
if(!requireNamespace("geonode4R", quietly = TRUE)){ | ||
stop("The 'geonode4R-publish-ogc-services' action requires the 'geonode4R' package") | ||
} | ||
|
||
#shortcut for geonode config | ||
GEONODE_CONFIG <- config$software$output$geonode_config | ||
GEONODE <- config$software$output$geonode | ||
if(is.null(GEONODE)){ | ||
errMsg <- "This action requires a GeoNode software to be declared in the configuration" | ||
config$logger.error(errMsg) | ||
stop(errMsg) | ||
} | ||
|
||
data_objects <- list() | ||
if(is.null(entity$data$dir)){ | ||
data_objects <- list(entity$data) | ||
}else{ | ||
data_objects <- entity$data$getData() | ||
} | ||
|
||
if(length(data_objects)>0) for(data_object in data_objects){ | ||
|
||
#datasource | ||
datasource <- data_object$uploadSource[[1]] | ||
datasource_name <- NULL | ||
datasource_file <- NULL | ||
if(!is.null(datasource)){ | ||
datasource_name <- unlist(strsplit(datasource, "\\."))[1] | ||
datasource_file <- attr(datasource, "uri") | ||
attributes(datasource) <- NULL | ||
}else{ | ||
if(data_object$upload){ | ||
errMsg <- sprintf("Upload source is missing!") | ||
stop(errMsg) | ||
} | ||
} | ||
|
||
#layername/sourcename | ||
layername <- if(!is.null(data_object$layername)) data_object$layername else entity$identifiers$id | ||
|
||
#upload | ||
#------------------------------------------------------------------------------------------------- | ||
if(data_object$upload){ | ||
|
||
config$logger.info("Upload mode is set to true") | ||
if(startsWith(data_object$uploadType,"db") || data_object$uploadType == "other"){ | ||
warnMsg <- "Skipping upload: Upload mode is only valid for types 'shp', 'spatialite' or 'h2'" | ||
config$logger.warn(warnMsg) | ||
}else{ | ||
uploaded <- FALSE | ||
config$logger.info("Upload from local file(s)") | ||
filepath <- file.path(getwd(), "data", datasource) | ||
config$logger.info(sprintf("File to upload to GeoNode: %s", filepath)) | ||
if(file.exists(filepath)){ | ||
config$logger.info(sprintf("Upload file '%s' [%s] to GeoNode...", filepath, data_object$uploadType)) | ||
files = list.files(path = "data", pattern = datasource_name, full.names = TRUE) | ||
files = files[!endsWith(files, ".zip")] | ||
created = GEONODE$upload(files) | ||
uploaded = created$success | ||
}else{ | ||
errMsg <- sprintf("Upload from local file(s): no zipped file found for source '%s' (%s)", filepath, datasource) | ||
config$logger.error(errMsg) | ||
stop(errMsg) | ||
} | ||
|
||
if(uploaded){ | ||
infoMsg <- sprintf("Successful GeoNode upload for file '%s' (%s)", datasource_file, data_object$uploadType) | ||
config$logger.info(infoMsg) | ||
}else{ | ||
errMsg <- "Error during GeoNode file upload. Aborting 'geonode4R' action!" | ||
config$logger.error(errMsg) | ||
stop(errMsg) | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
inst/extdata/workflows/config_metadata_gsheets_sdi_geonode_shp.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"profile": { | ||
"id": "my-geonode-shp-workflow", | ||
"name": "My GeoNode shp workflow", | ||
"project": "Test geoflow project to publish shapefile in GeoNode", | ||
"organization": "My organization", | ||
"logos": [], | ||
"mode": "entity", | ||
"options": { | ||
"line_separator": "_\n" | ||
} | ||
}, | ||
"metadata": { | ||
"entities": [ | ||
{ | ||
"handler": "gsheet", | ||
"source": "https://docs.google.com/spreadsheets/d/1H4tNcAzZRadVKf2BZ1C_m7DTAe22nkkXr55HCOjmLn0/edit?usp=sharing" | ||
} | ||
], | ||
"contacts" : [ | ||
{ | ||
"handler": "gsheet", | ||
"source": "https://docs.google.com/spreadsheets/d/1BqlXwA2fKiRuozNAQhBb_PbQVSPTCfl8_Q9rfM8E2ws/edit?usp=sharing" | ||
} | ||
] | ||
}, | ||
"software": [ | ||
{ | ||
"id": "my-geonode", | ||
"type": "output", | ||
"software_type": "geonode", | ||
"parameters": { | ||
"url": "{{GEONODE_URL}}", | ||
"user": "{{GEONODE_USER}}", | ||
"pwd": "{{GEONODE_PASSWORD}}", | ||
"logger": "DEBUG" | ||
} | ||
} | ||
], | ||
"actions": [ | ||
{ | ||
"id": "geonode4R-publish-ogc-services", | ||
"run": true | ||
} | ||
] | ||
} |
50 changes: 50 additions & 0 deletions
50
tests/testthat/test_config_metadata_gsheets_sdi_geonode_shp.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# test_config_metadata_gsheets_geonode_shp.R | ||
# Author: Emmanuel Blondel <[email protected]> | ||
# | ||
# Description: Integration tests for config_metadata_gsheets_geonode_shp.json workflow | ||
#======================= | ||
require(geoflow, quietly = TRUE) | ||
require(testthat) | ||
|
||
cfg_file = system.file("extdata/workflows/config_metadata_gsheets_sdi_geonode_shp.json", package = "geoflow") | ||
|
||
#init | ||
test_that("init",{ | ||
CFG <- geoflow::initWorkflow(cfg_file) | ||
expect_is(CFG$metadata$content, "list") | ||
expect_equal(length(CFG$metadata$content), 2L) | ||
expect_equal(names(CFG$metadata$content), c("contacts", "entities")) | ||
expect_equal(length(CFG$metadata$content$contacts), 3L) | ||
expect_equal(length(CFG$getContacts()), 3L) | ||
expect_equal(length(CFG$metadata$content$entities), 1L) | ||
expect_equal(length(CFG$getEntities()), 1L) | ||
expect_equal(length(CFG$actions), 1L) | ||
expect_equal(length(CFG$software), 2L) | ||
expect_equal(names(CFG$software), c("input", "output")) | ||
expect_equal(length(CFG$software$input), 0L) | ||
expect_equal(length(CFG$software$output), 2L) | ||
}) | ||
|
||
#debug | ||
test_that("debug",{ | ||
DEBUG <- geoflow::debugWorkflow(cfg_file, entityIndex = 1, dir = ".") | ||
expect_equal(names(DEBUG), c("config", "entity")) | ||
expect_is(DEBUG$config, "list") | ||
expect_is(DEBUG$entity, "geoflow_entity") | ||
}) | ||
|
||
#execute | ||
test_that("execute",{ | ||
EXEC <- geoflow::executeWorkflow(cfg_file, dir = ".") | ||
expect_true(dir.exists(EXEC)) | ||
expect_true(file.exists(file.path(EXEC, "job.json"))) | ||
expect_true(file.exists(file.path(EXEC, "job-logs.txt"))) | ||
expect_true(file.exists(file.path(EXEC, "config_copyof_contacts_1.csv"))) | ||
expect_true(file.exists(file.path(EXEC, "config_copyof_entities_1.csv"))) | ||
expect_true(dir.exists(file.path(EXEC, "entities"))) | ||
entity_dirs <- list.dirs(path = file.path(EXEC, "entities"), full.names = F,recursive = F) | ||
expect_true(all(entity_dirs %in% c("my-geoflow-shapefile-record1"))) | ||
config <- geoflow::initWorkflow(cfg_file) | ||
GEONODE <- config$software$output$geonode | ||
#TODO | ||
}) |
4 changes: 2 additions & 2 deletions
4
tests/testthat/test_config_metadata_gsheets_sdi_geoserver_shp.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# test_config_metadata_gsheets_geoserver_geotiff.R | ||
# test_config_metadata_gsheets_geoserver_shp.R | ||
# Author: Emmanuel Blondel <[email protected]> | ||
# | ||
# Description: Integration tests for config_metadata_gsheets_geoserver_geotiff.json workflow | ||
# Description: Integration tests for config_metadata_gsheets_geoserver_shp.json workflow | ||
#======================= | ||
require(geoflow, quietly = TRUE) | ||
require(testthat) | ||
|