Skip to content

Commit

Permalink
Merge pull request #210 from R-ArcGIS/attach_meta
Browse files Browse the repository at this point in the history
Make attachment metadata optional
  • Loading branch information
JosiahParry authored Jul 19, 2024
2 parents 7a78682 + 89b7f61 commit 754bd2d
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 32 deletions.
5 changes: 3 additions & 2 deletions R/attachments.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#' @param global_ids mutally exclusive with `definition_expression` and `object_ids`. The global IDs of the features to query attachments of.
#' @param keywords default `NULL`. A character vector of the keywords to filter on.
#' @param attachment_types default `NULL`. A character vector of attachment types to filter on.
#' @param return_metadata default `TRUE`. Returns metadata stored in the `exifInfo` field.
#' @param overwrite default `FALSE`. A
#' @rdname attachments
#' @references [ArcGIS REST API Documentation](https://developers.arcgis.com/rest/services-reference/enterprise/query-attachments-feature-service-layer/)
Expand Down Expand Up @@ -49,6 +50,7 @@ query_layer_attachments <- function(
global_ids = NULL,
attachment_types = NULL,
keywords = NULL,
return_metadata = TRUE,
...,
token = arc_token()
# Ignored arguments for now:
Expand Down Expand Up @@ -93,7 +95,7 @@ query_layer_attachments <- function(
attachmentsDefinitionExpression = attachments_definition_expression,
keywords = keywords,
returnUrl = TRUE,
returnMetadata = TRUE,
returnMetadata = return_metadata,
f = "json"
)

Expand Down Expand Up @@ -125,7 +127,6 @@ unnest_attachment_groups <- function(x) {
}



# Attachment types
possible_attachment_types <- c(
"7z", "aif", "avi", "bmp", "csv", "doc", "docx", "dot", "ecw", "emf", "eps",
Expand Down
58 changes: 28 additions & 30 deletions man/arc_open.Rd

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

3 changes: 3 additions & 0 deletions man/attachments.Rd

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

40 changes: 40 additions & 0 deletions tests/testthat/test-attachments.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
furl <- "https://services1.arcgis.com/hLJbHVT9ZrDIzK0I/arcgis/rest/services/v8_Wide_Area_Search_Form_Feature_Layer___a2fe9c/FeatureServer/0"
layer <- arc_open(furl)

test_that("query_layer_attachments() default args", {
# connect to the layer
expect_no_error()
})


test_that("query_layer_attachments() no metadata", {
att <- query_layer_attachments(layer, return_metadata = FALSE)
expect_true(all(is.na(att$exifInfo)))
})


test_that("query_layer_attachments() filter on layer field", {
att <- query_layer_attachments(layer, "followup_status = 'needs_followup'")
expect_equal(nrow(att), 24L)
})

test_that("query_layer_attachments() filter on attachment field", {
att <-
query_layer_attachments(
layer,
attachments_definition_expression = "att_name like 'image0%'"
)
expect_true(all(grepl("image0*", att$name)))
})


test_that("download_attachments()", {
tmp <- tempdir()
att <-
query_layer_attachments(
layer,
attachments_definition_expression = "att_name like 'image0%'"
)
res <- download_attachments(att, tmp)
expect_true(all(basename(unlist(res)) %in% list.files(tmp)))
})

0 comments on commit 754bd2d

Please sign in to comment.