R/TraitDTO.r

# sunagriAPI
#
# An instance of OpenSILEX WebService
#
# OpenAPI spec version: 3.3.0
# 
# Generated by: https://github.com/swagger-api/swagger-codegen.git


#' TraitDTO Class
#'
#' @field uri 
#' @field label 
#' @field comment 
#' @field ontologiesReferences 
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
TraitDTO <- R6::R6Class(
  'TraitDTO',
  public = list(
    `uri` = NULL,
    `label` = NULL,
    `comment` = NULL,
    `ontologiesReferences` = NULL,
    initialize = function(`uri`, `label`, `comment`, `ontologiesReferences`){
      if (!missing(`uri`)) {
        stopifnot(is.character(`uri`), length(`uri`) == 1)
        self$`uri` <- `uri`
      }
      if (!missing(`label`)) {
        stopifnot(is.character(`label`), length(`label`) == 1)
        self$`label` <- `label`
      }
      if (!missing(`comment`)) {
        stopifnot(is.character(`comment`), length(`comment`) == 1)
        self$`comment` <- `comment`
      }
      if (!missing(`ontologiesReferences`)) {
        stopifnot(is.list(`ontologiesReferences`), length(`ontologiesReferences`) != 0)
        lapply(`ontologiesReferences`, function(x) stopifnot(R6::is.R6(x)))
        self$`ontologiesReferences` <- `ontologiesReferences`
      }
    },
    toJSON = function() {
      TraitDTOObject <- list()
      if (!is.null(self$`uri`)) {
        TraitDTOObject[['uri']] <- self$`uri`
      }
      if (!is.null(self$`label`)) {
        TraitDTOObject[['label']] <- self$`label`
      }
      if (!is.null(self$`comment`)) {
        TraitDTOObject[['comment']] <- self$`comment`
      }
      if (!is.null(self$`ontologiesReferences`)) {
        TraitDTOObject[['ontologiesReferences']] <- lapply(self$`ontologiesReferences`, function(x) x$toJSON())
      }

      TraitDTOObject
    },
    fromJSON = function(TraitDTOJson) {
      TraitDTOObject <- jsonlite::fromJSON(TraitDTOJson)
      if (!is.null(TraitDTOObject$`uri`)) {
        self$`uri` <- TraitDTOObject$`uri`
      }
      if (!is.null(TraitDTOObject$`label`)) {
        self$`label` <- TraitDTOObject$`label`
      }
      if (!is.null(TraitDTOObject$`comment`)) {
        self$`comment` <- TraitDTOObject$`comment`
      }
      if (!is.null(TraitDTOObject$`ontologiesReferences`)) {
        self$`ontologiesReferences` <- lapply(TraitDTOObject$`ontologiesReferences`, function(x) {
          ontologiesReferencesObject <- OntologyReference$new()
          ontologiesReferencesObject$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE, null = "null"))
          ontologiesReferencesObject
        })
      }
    },
    fromJSONObject = function(TraitDTOObject) {
      if (!is.null(TraitDTOObject$`uri`)) {
        self$`uri` <- TraitDTOObject$`uri`
      }
      if (!is.null(TraitDTOObject$`label`)) {
        self$`label` <- TraitDTOObject$`label`
      }
      if (!is.null(TraitDTOObject$`comment`)) {
        self$`comment` <- TraitDTOObject$`comment`
      }
      if (!is.null(TraitDTOObject$`ontologiesReferences`)) {
        self$`ontologiesReferences` <- lapply(TraitDTOObject$`ontologiesReferences`, function(x) {
          ontologiesReferencesObject <- OntologyReference$new()
          ontologiesReferencesObject$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE, null = "null"))
          ontologiesReferencesObject
        })
      }
    },
    toJSONString = function() {
      ontologiesReferencesList = paste(lapply(self$`ontologiesReferences`, function(x) x$toJSONString()),collapse = ",")
       sprintf(
        '{
           "uri": %s,
           "label": %s,
           "comment": %s,
           "ontologiesReferences": [%s]
        }',
        jsonlite::toJSON(self$`uri`,auto_unbox=TRUE, null = "null"),
        jsonlite::toJSON(self$`label`,auto_unbox=TRUE, null = "null"),
        jsonlite::toJSON(self$`comment`,auto_unbox=TRUE, null = "null"),
        ontologiesReferencesList
      )
    },
    fromJSONString = function(TraitDTOJson) {
      TraitDTOObject <- jsonlite::fromJSON(TraitDTOJson)
      self$`uri` <- TraitDTOObject$`uri`
      self$`label` <- TraitDTOObject$`label`
      self$`comment` <- TraitDTOObject$`comment`
      self$`ontologiesReferences` <- lapply(TraitDTOObject$`ontologiesReferences`, function(x) OntologyReference$new()$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE)))
    }
  )
)
OpenSILEX/phis-ws-client-r-tool documentation built on Sept. 10, 2020, 8:42 a.m.