R/Unit.r

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


#' Unit Class
#'
#' @field uri 
#' @field label 
#' @field comment 
#' @field ontologiesReferences 
#' @field properties 
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
Unit <- R6::R6Class(
  'Unit',
  public = list(
    `uri` = NULL,
    `label` = NULL,
    `comment` = NULL,
    `ontologiesReferences` = NULL,
    `properties` = NULL,
    initialize = function(`uri`, `label`, `comment`, `ontologiesReferences`, `properties`){
      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`
      }
      if (!missing(`properties`)) {
        stopifnot(is.list(`properties`), length(`properties`) != 0)
        lapply(`properties`, function(x) stopifnot(R6::is.R6(x)))
        self$`properties` <- `properties`
      }
    },
    toJSON = function() {
      UnitObject <- list()
      if (!is.null(self$`uri`)) {
        UnitObject[['uri']] <- self$`uri`
      }
      if (!is.null(self$`label`)) {
        UnitObject[['label']] <- self$`label`
      }
      if (!is.null(self$`comment`)) {
        UnitObject[['comment']] <- self$`comment`
      }
      if (!is.null(self$`ontologiesReferences`)) {
        UnitObject[['ontologiesReferences']] <- lapply(self$`ontologiesReferences`, function(x) x$toJSON())
      }
      if (!is.null(self$`properties`)) {
        UnitObject[['properties']] <- lapply(self$`properties`, function(x) x$toJSON())
      }

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