R/validate_api.R

# mzTab-M reference implementation and validation API.
#
# This is the mzTab-M reference implementation and validation API service.
#
# The version of the OpenAPI document: 2.0.0
# Contact: nils.hoffmann@cebitec.uni-bielefeld.de
# Generated by: https://openapi-generator.tech

#' @docType class
#' @title Validate operations
#' @description rmzTabM.Validate
#' @format An \code{R6Class} generator object
#' @field apiClient Handles the client-server communication.
#'
#' @section Methods:
#' \describe{
#' \strong{ ValidateMzTabFile } \emph{  }
#' Validates an mzTab file in XML or JSON representation and reports syntactic, structural, and semantic errors.
#'
#' \itemize{
#' \item \emph{ @param } mztabfile \link{MzTab}
#' \item \emph{ @param } level Enum < [info, warn, error] >
#' \item \emph{ @param } max.errors integer
#' \item \emph{ @param } semantic.validation character
#' \item \emph{ @returnType } list( \link{ValidationMessage} ) \cr
#'
#'
#' \item status code : 200 | Validation Okay
#'
#' \item return type : array[ValidationMessage]
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 415 | Unsupported content type
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 422 | Invalid input
#'
#' \item return type : array[ValidationMessage]
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' \item status code : 0 | Unexpected error
#'
#' \item return type : Error
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' }
#'
#'
#' @examples
#' \dontrun{
#' ####################  ValidateMzTabFile  ####################
#'
#' library(rmzTabM)
#' # MzTab | mzTab file that should be validated.
#' var.mztabfile <- MzTab$new()
#' # character | The level of errors that should be reported, one of ERROR, WARN, INFO.
#' var.level <- 'info' 
#' # integer | The maximum number of errors to return.
#' var.max.errors <- 100 
#' # character | Whether a semantic validation against the default rule set should be performed.
#' var.semantic.validation <- FALSE 
#'
#' api.instance <- ValidateApi$new()
#'
#' result <- api.instance$ValidateMzTabFile(var.mztabfile, 
#'   level=var.level, max.errors=var.max.errors, 
#'   semantic.validation=var.semantic.validation
#' )
#'
#'
#' }
#' @importFrom R6 R6Class
#' @importFrom caTools base64encode
#' @export
ValidateApi <- R6::R6Class(
  'ValidateApi',
  public = list(
    apiClient = NULL,
    #' @description Create a new ValidateApi object.
    #' @param apiClient An initialized \link{ApiClient}.
    initialize = function(apiClient) {
      if (!missing(apiClient)) {
        self$apiClient <- apiClient
      }
      else {
        self$apiClient <- ApiClient$new()
      }
    },
    #' @description Validate an MzTab object.
    #' @param mztabfile The \link{MzTab} object to validate.
    #' @param level The validation level.
    #' @param max.errors The maximum number of errors.
    #' @param semantic.validation Whether semantic validation should also be performed.
    #' @param ... local optional variable arguments
    ValidateMzTabFile = function(mztabfile,
                                 level = 'info',
                                 max.errors = 100,
                                 semantic.validation = FALSE,
                                 ...) {
      apiResponse <-
        self$ValidateMzTabFileWithHttpInfo(mztabfile, level, max.errors, semantic.validation, ...)
      resp <- apiResponse$response
      if (httr::status_code(resp) >= 200 &&
          httr::status_code(resp) <= 299) {
        apiResponse
      } else if (httr::status_code(resp) >= 300 &&
                 httr::status_code(resp) <= 399) {
        apiResponse
      } else if (httr::status_code(resp) >= 400 &&
                 httr::status_code(resp) <= 499) {
        apiResponse
      } else if (httr::status_code(resp) >= 500 &&
                 httr::status_code(resp) <= 599) {
        apiResponse
      }
    },
    #' @description Validate an MzTab file but include HTTP response info.
    #' @param mztabfile The \link{MzTab} object to validate.
    #' @param level The validation level.
    #' @param max.errors The maximum number of errors.
    #' @param semantic.validation Whether semantic validation should also be performed.
    #' @param ... local optional variable arguments
    ValidateMzTabFileWithHttpInfo = function(mztabfile,
                                             level = 'info',
                                             max.errors = 100,
                                             semantic.validation = FALSE,
                                             ...) {
      args <- list(...)
      queryParams <- list()
      headerParams <- c()
      
      if (missing(`mztabfile`)) {
        stop("Missing required parameter `mztabfile`.")
      }
      
      queryParams['level'] <- level
      
      queryParams['maxErrors'] <- max.errors
      
      queryParams['semanticValidation'] <- semantic.validation
      
      if (!missing(`mztabfile`)) {
        body <- `mztabfile`$toJSONString()
      } else {
        body <- NULL
      }
      
      urlPath <- "/validate"
      
      resp <-
        self$apiClient$CallApi(
          url = paste0(self$apiClient$basePath, urlPath),
          method = "POST",
          queryParams = queryParams,
          headerParams = headerParams,
          body = body,
          ...
        )
      
      if (httr::status_code(resp) >= 200 &&
          httr::status_code(resp) <= 299) {
        deserializedRespObj <- tryCatch(
          self$apiClient$deserialize(
            resp,
            "array[ValidationMessage]",
            loadNamespace("rmzTabM")
          ),
          error = function(e) {
            stop("Failed to deserialize response")
          }
        )
        ApiResponse$new(deserializedRespObj, resp)
      } else if (httr::status_code(resp) >= 300 &&
                 httr::status_code(resp) <= 399) {
        ApiResponse$new(paste(
          "Server returned " ,
          httr::status_code(resp) ,
          " response status code."
        ),
        resp)
      } else if (httr::status_code(resp) >= 400 &&
                 httr::status_code(resp) <= 499) {
        ApiResponse$new("API client error", resp)
      } else if (httr::status_code(resp) >= 500 &&
                 httr::status_code(resp) <= 599) {
        ApiResponse$new("API server error", resp)
      }
    }
  )
)
lifs-tools/rmzTab-m documentation built on Jan. 26, 2023, 4:45 p.m.