|
| 1 | +#' @title Release a resource |
| 2 | +#' @description |
| 3 | +#' This function is used internally to release a resource. It do not returns |
| 4 | +#' anything, but throws a warning if there is no public field to update. |
| 5 | +releaseResource <- function(api, type, id) |
| 6 | +{ |
| 7 | + resource <- mangalGet(api, type, id) |
| 8 | + if(is.null(resource$public)) |
| 9 | + { |
| 10 | + warning(str_c("The resource ", type, '/', id, " has no public field")) |
| 11 | + } else { |
| 12 | + resource$public <- TRUE |
| 13 | + mangalPatch(api, type, resource) |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +#' @title Release a dataset |
| 18 | +#' @description |
| 19 | +#' Releases a dataset, and all objects of lower level (networks and |
| 20 | +#' interactions). |
| 21 | +#' |
| 22 | +#' @param api a \code{\link{mangalapi}} object |
| 23 | +#' @param id the id of the dataset to release |
| 24 | +#' @param force whether to force release even if the dataset is already public |
| 25 | +#' |
| 26 | +#' @export |
| 27 | +releaseDataset <- function(api, id, force=FALSE) |
| 28 | +{ |
| 29 | + dataset <- getDataset(api, id) |
| 30 | + if(dataset$public & (! force)) stop("This dataset is already public") |
| 31 | + # We go through 1) the list of networks, 2) the list of interactions |
| 32 | + for(net_id in dataset$networks) |
| 33 | + { |
| 34 | + net <- getNetwork(api, net_id) |
| 35 | + releaseResource(api, 'network', net_id) |
| 36 | + for(int_id in net$interactions) |
| 37 | + { |
| 38 | + releaseResource(api, 'interaction', int_id) |
| 39 | + } |
| 40 | + } |
| 41 | + releaseResource(api, 'dataset', id) |
| 42 | +} |
| 43 | + |
0 commit comments