Skip to content

Commit

Permalink
added brapi_post_search_people() and updated brapi_get_search_people_…
Browse files Browse the repository at this point in the history
…searchResultsDbId()
  • Loading branch information
mverouden committed May 1, 2021
1 parent 80bb5de commit a2684d5
Show file tree
Hide file tree
Showing 47 changed files with 398 additions and 46 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export(brapi_post_people)
export(brapi_post_programs)
export(brapi_post_search_lists)
export(brapi_post_search_locations)
export(brapi_post_search_people)
export(brapi_post_seasons)
export(brapi_post_studies)
export(brapi_post_trials)
Expand Down
27 changes: 21 additions & 6 deletions R/brapi_get_search_people_searchResultsDbId.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#'
#' @details Returns the result of the advanced searching for the people resource.
#'
#' See [Search Services for additional implementation details](https://github.com/plantbreeding/API/blob/master/Specification/GeneralInfo/Search_Services.md).
#'
#' @return data.frame
#'
#' @author Maikel Verouden
Expand All @@ -29,6 +27,10 @@
#' @examples
#' \dontrun{
#' con <- brapi_db()$testserver
#' con[["token"]] <- "YYYY"
#'
#' TO BE ADDED: AN EXAMPLE WITH A SAVED OR ASYNCHRONOUS SEARCH
#' Still to be completed:
#' brapi_get_search_people_searchResultsDbId(con = con,
#' searchResultsDbId = "")
#' }
Expand All @@ -54,10 +56,23 @@ brapi_get_search_people_searchResultsDbId <- function(con = NULL,
try({
## Make the call and receive the response
resp <- brapirv2:::brapi_GET(url = callurl, usedArgs = usedArgs)
## Extract the content from the response object in human readable form
cont <- httr::content(x = resp, as = "text", encoding = "UTF-8")
## Convert the content object into a data.frame
out <- brapirv2:::brapi_result2df(cont, usedArgs)
## Check call status
while (httr::status_code(resp) == 202) {
Sys.sleep(5)
resp <- brapirv2:::brapi_GET(url = callurl, usedArgs = usedArgs)
status <- jsonlite::fromJSON(httr::content(x = resp,
as = "text",
encoding = "UTF-8"))[["metadata"]][["status"]]
if (length(status) != 0) {
brapirv2:::brapi_message(msg = paste0(status[["message"]], "\n"))
}
}
if (httr::status_code(resp) == 200) {
## Extract the content from the response object in human readable form
cont <- httr::content(x = resp, as = "text", encoding = "UTF-8")
## Convert the content object into a data.frame
out <- brapirv2:::brapi_result2df(cont, usedArgs)
}
})
## Set class of output
class(out) <- c(class(out), "brapi_get_search_people_searchResultsDbId")
Expand Down
19 changes: 10 additions & 9 deletions R/brapi_post_search_lists.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
#' the search range, when the entity was last modified. Coded in the ISO 8601
#' standard extended format, where date, time and time zone information needs
#' to be provided (check for example https://www.w3.org/TR/NOTE-datetime).
#' @param externalReferenceIDs vector of type character; required: FALSE; List
#' of external reference identifiers. Could be a simple strings or a URIs.
#' (use with `externalReferenceSources` parameter); default: &quot;&quot;,
#' when using multiple values supply as c(&quot;value1&quot;,
#' @param externalReferenceIDs vector of type character; required: FALSE;
#' External reference identifier(s) to search for. Could be a simple strings
#' or a URIs (use with `externalReferenceSources` parameter).; default:
#' &quot;&quot;, when using multiple values supply as c(&quot;value1&quot;,
#' &quot;value2&quot;).
#' @param externalReferenceSources vector of type character; required: FALSE;
#' List of identifiers for the source system or database of an external
#' reference (use with `externalReferenceIDs` parameter);
#' default: &quot;&quot;, when using multiple values supply as
#' c(&quot;value1&quot;, &quot;value2&quot;).
#' Source system or database identifier(s) of an external reference(s) to
#' search for (use with `externalReferenceIDs` parameter); default:
#' &quot;&quot;, when using multiple values supply as c(&quot;value1&quot;,
#' &quot;value2&quot;).
#' @param listDbIds vector of type character; required: FALSE; Unique
#' identifiers of generic lists to searh for; default: &quot;&quot;, when
#' using multiple values supply as c(&quot;value1&quot;, &quot;value2&quot;).
Expand Down Expand Up @@ -59,7 +59,8 @@
#'
#' @details Advanced searching for the list resource. Function will return
#' either the search results (Status 200 for an immediate response) or a
#' searchResultsDbId (Status 202 for both a saved and an asynchronous search).
#' `searchResultsDbId` (Status 202 for both a saved and an asynchronous
#' search).
#'
#' @return data.frame
#'
Expand Down
21 changes: 12 additions & 9 deletions R/brapi_post_search_locations.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@
#' @param countryNames vector of type character; required: FALSE; Full country
#' name(s) to search for; default: &quot;&quot;, when using multiple values
#' supply as c(&quot;value1&quot;, &quot;value2&quot;).
#' @param externalReferenceIDs vector of type character; required: FALSE; List
#' of external reference identifiers. Could be a simple strings or a URIs.
#' (use with `externalReferenceSources` parameter); default: &quot;&quot;,
#' when using multiple values supply as c(&quot;value1&quot;,
#' @param externalReferenceIDs vector of type character; required: FALSE;
#' External reference identifier(s) to search for. Could be a simple strings
#' or a URIs (use with `externalReferenceSources` parameter).; default:
#' &quot;&quot;, when using multiple values supply as c(&quot;value1&quot;,
#' &quot;value2&quot;).
#' @param externalReferenceSources vector of type character; required: FALSE;
#' List of identifiers for the source system or database of an external
#' reference (use with `externalReferenceIDs` parameter);
#' default: &quot;&quot;, when using multiple values supply as
#' c(&quot;value1&quot;, &quot;value2&quot;).
#' Source system or database identifier(s) of an external reference(s) to
#' search for (use with `externalReferenceIDs` parameter); default:
#' &quot;&quot;, when using multiple values supply as c(&quot;value1&quot;,
#' &quot;value2&quot;).
#' @param instituteAddresses vector of type character; required: FALSE; The institute
#' street address(es) to search for; default: &quot;&quot;, when using
#' multiple values supply as c(&quot;value1&quot;, &quot;value2&quot;).
Expand All @@ -77,7 +77,10 @@
#' @param pageSize integer; required: FALSE; The size of the pages to be
#' returned. Default is `1000`.
#'
#' @details Advanced searching for the locations resource.
#' @details Advanced searching for the locations resource. Function will return
#' either the search results (Status 200 for an immediate response) or a
#' `searchResultsDbId` (Status 202 for both a saved and an asynchronous
#' search).
#'
#' @return data.frame
#'
Expand Down
124 changes: 124 additions & 0 deletions R/brapi_post_search_people.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#' @title
#' post /search/people
#'
#' @description
#' Submit a search request for People
#'
#' @param con list; required: TRUE; BrAPI connection object
#' @param emailAddresses vector of type character; required: FALSE; email
#' address(es) for person(s) to search for; default: &quot;&quot;, when
#' using multiple values supply as c(&quot;value1&quot;,
#' &quot;value2&quot;).
#' @param externalReferenceIDs vector of type character; required: FALSE;
#' External reference identifier(s) to search for. Could be a simple strings
#' or a URIs (use with `externalReferenceSources` parameter).; default:
#' &quot;&quot;, when using multiple values supply as c(&quot;value1&quot;,
#' &quot;value2&quot;).
#' @param externalReferenceSources vector of type character; required: FALSE;
#' Source system or database identifier(s) of an external reference(s) to
#' search for (use with `externalReferenceIDs` parameter); default:
#' &quot;&quot;, when using multiple values supply as c(&quot;value1&quot;,
#' &quot;value2&quot;).
#' @param firstNames vector of type character; required: FALSE; Person(s) first
#' name(s) to search for; default: &quot;&quot;, when using multiple values
#' supply as c(&quot;value1&quot;, &quot;value2&quot;).
#' @param middleNames vector of type character; required: FALSE; Person(s)
#' middle name(s) to search for; default: &quot;&quot;, when using multiple
#' values supply as c(&quot;value1&quot;, &quot;value2&quot;).
#' @param lastNames vector of type character; required: FALSE; Person(s) last
#' name(s) to search for; default: &quot;&quot;, when using multiple values
#' supply as c(&quot;value1&quot;, &quot;value2&quot;).
#' @param mailingAddresses vector of type character; required: FALSE; physical
#' address(es) of a person(s) to search for; default: &quot;&quot;, when
#' using multiple values supply as c(&quot;value1&quot;, &quot;value2&quot;).
#' @param personDbIds vector of type character; required: FALSE; Unique
#' Identifier(s) for person(s) to search for; default: &quot;&quot;, when
#' using multiple values supply as c(&quot;value1&quot;, &quot;value2&quot;).
#' @param phoneNumbers vector of type character; required: FALSE; phone
#' number(s) of person(s) to search for; default: &quot;&quot;, when using
#' multiple values supply as c(&quot;value1&quot;, &quot;value2&quot;).
#' @param userIDs vector of type character; required: FALSE; A systems user
#' identifier(s) associated with person(s) to search for. Different from
#' personDbId because you could have a person who is not a user of the
#' system.; default: &quot;&quot;, when using multiple values supply as
#' c(&quot;value1&quot;, &quot;value2&quot;).
#' @param page integer; required: FALSE; Which result page is requested. The
#' page indexing starts at 0 (the first page is `page = 0`). Default is `0`.
#' @param pageSize integer; required: FALSE; The size of the pages to be
#' returned. Default is `1000`.
#'
#' @details Advanced searching for the people resource. Function will return
#' either the search results (Status 200 for an immediate response) or a
#' `searchResultsDbId` (Status 202 for both a saved and an asynchronous
#' search).
#'
#' @return data.frame
#'
#' @author Maikel Verouden
#'
#' @references \href{https://app.swaggerhub.com/apis/PlantBreedingAPI/BrAPI-Core/2.0#/People/post_search_people }{BrAPI SwaggerHub}
#'
#' @family brapi-core
#' @family People
#'
#' @examples
#' \dontrun{
#' con <- brapi_db()$testserver
#' con[["token"]] <- "YYYY"
#'
#' TO BE ADDED STILL
#' }
#'
#' @export
brapi_post_search_people <- function(con = NULL,
emailAddresses = '',
externalReferenceIDs = '',
externalReferenceSources = '',
firstNames = '',
middleNames = '',
lastNames = '',
mailingAddresses = '',
personDbIds = '',
phoneNumbers = '',
userIDs = '',
page = 0,
pageSize = 1000) {
## Create a list of used arguments
usedArgs <- brapirv2:::brapi_usedArgs(origValues = FALSE)
## Check if BrAPI server can be reached given the connection details
brapi_checkCon(con = usedArgs[["con"]], verbose = FALSE)
## Check validity of used and required arguments
brapirv2:::brapi_checkArgs(usedArgs, reqArgs = "")
## Obtain the call url
callurl <- brapirv2:::brapi_POST_callURL(usedArgs = usedArgs,
callPath = "/search/people",
reqArgs = "",
packageName = "BrAPI-Core",
callVersion = 2.0)
## Build the Body
callbody <- brapirv2:::brapi_POST_callBody(usedArgs = usedArgs,
reqArgs = "")

try({
## Make the call and receive the response
resp <- brapirv2:::brapi_POST(url = callurl, body = callbody, usedArgs = usedArgs)
## Message about call status
if (httr::status_code(resp) == 200) {
message(paste0("Immediate Response.", "\n"))
} else if (httr::status_code(resp) == 202) {
message(paste0("Saved or Asynchronous Response has provided a searchResultsDbId.", "\n"))
message(paste0("Use the GET /search/people/{searchResultsDbId} call to retrieve the paginated output.", "\n"))
} else {
stop(paste0("The POST /search/people call resulted in Server status, ", httr::http_status(resp)[["message"]]))
}
## Extract the content from the response object in human readable form
cont <- httr::content(x = resp, as = "text", encoding = "UTF-8")
## Convert the content object into a data.frame
out <- brapirv2:::brapi_result2df(cont, usedArgs)
})
## Set class of output
class(out) <- c(class(out), "brapi_post_search_people")
## Show pagination information from metadata
brapirv2:::brapi_serverinfo_metadata(cont)
return(out)
}
2 changes: 1 addition & 1 deletion R/brapi_put_people_personDbId.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#'
#' @param con list; required: TRUE; BrAPI connection object
#' @param personDbId character; required: TRUE; The unique ID of a person
##' @param additionalInfo list; required: FALSE; Additional arbitrary information.
#' @param additionalInfo list; required: FALSE; Additional arbitrary information.
#' If provided use the following construct list(additionalProp1 = "string",
#' additionalProp2 = "string", additionalProp3 = "string").
#'
Expand Down
1 change: 1 addition & 0 deletions man/brapi_get_commoncropnames.Rd

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

1 change: 1 addition & 0 deletions man/brapi_get_lists.Rd

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

1 change: 1 addition & 0 deletions man/brapi_get_lists_listDbId.Rd

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

1 change: 1 addition & 0 deletions man/brapi_get_locations.Rd

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

1 change: 1 addition & 0 deletions man/brapi_get_locations_locationDbId.Rd

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

2 changes: 2 additions & 0 deletions man/brapi_get_people.Rd

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

2 changes: 2 additions & 0 deletions man/brapi_get_people_personDbId.Rd

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

1 change: 1 addition & 0 deletions man/brapi_get_programs.Rd

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

1 change: 1 addition & 0 deletions man/brapi_get_programs_programDbId.Rd

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

1 change: 1 addition & 0 deletions man/brapi_get_search_lists_searchResultsDbId.Rd

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

1 change: 1 addition & 0 deletions man/brapi_get_search_locations_searchResultsDbId.Rd

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

8 changes: 6 additions & 2 deletions man/brapi_get_search_people_searchResultsDbId.Rd

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

Loading

0 comments on commit a2684d5

Please sign in to comment.