R/TradeRelationship.r

# Altana Atlas API
#
# Altana Atlas for Regulatory Risk and Trade Compliance
#
# OpenAPI spec version: {{ version or \"v0.0.1\" }}
# Contact: engineering@altanatech.com
# Generated by: https://github.com/swagger-api/swagger-codegen.git

#' TradeRelationship Class
#'
#' @field importer_company_canon_id 
#' @field exporter_company_canon_id 
#' @field importer_canon_id 
#' @field exporter_canon_id 
#' @field importer_company_name 
#' @field exporter_company_name 
#' @field risks 
#' @field hs_traded 
#' @field industries 
#' @field number_records 
#' @field countries_of_origin 
#' @field countries_of_destination 
#' @field importer_restrictions 
#' @field exporter_restrictions 
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
TradeRelationship <- R6::R6Class(
  'TradeRelationship',
  public = list(
    `importer_company_canon_id` = NULL,
    `exporter_company_canon_id` = NULL,
    `importer_canon_id` = NULL,
    `exporter_canon_id` = NULL,
    `importer_company_name` = NULL,
    `exporter_company_name` = NULL,
    `risks` = NULL,
    `hs_traded` = NULL,
    `industries` = NULL,
    `number_records` = NULL,
    `countries_of_origin` = NULL,
    `countries_of_destination` = NULL,
    `importer_restrictions` = NULL,
    `exporter_restrictions` = NULL,
    initialize = function(`importer_company_canon_id`, `exporter_company_canon_id`, `importer_canon_id`, `exporter_canon_id`, `importer_company_name`, `exporter_company_name`, `risks`, `hs_traded`, `industries`, `number_records`, `countries_of_origin`, `countries_of_destination`, `importer_restrictions`, `exporter_restrictions`){
      if (!missing(`importer_company_canon_id`)) {
        stopifnot(is.character(`importer_company_canon_id`), length(`importer_company_canon_id`) == 1)
        self$`importer_company_canon_id` <- `importer_company_canon_id`
      }
      if (!missing(`exporter_company_canon_id`)) {
        stopifnot(is.character(`exporter_company_canon_id`), length(`exporter_company_canon_id`) == 1)
        self$`exporter_company_canon_id` <- `exporter_company_canon_id`
      }
      if (!missing(`importer_canon_id`)) {
        stopifnot(is.character(`importer_canon_id`), length(`importer_canon_id`) == 1)
        self$`importer_canon_id` <- `importer_canon_id`
      }
      if (!missing(`exporter_canon_id`)) {
        stopifnot(is.character(`exporter_canon_id`), length(`exporter_canon_id`) == 1)
        self$`exporter_canon_id` <- `exporter_canon_id`
      }
      if (!missing(`importer_company_name`)) {
        stopifnot(is.character(`importer_company_name`), length(`importer_company_name`) == 1)
        self$`importer_company_name` <- `importer_company_name`
      }
      if (!missing(`exporter_company_name`)) {
        stopifnot(is.character(`exporter_company_name`), length(`exporter_company_name`) == 1)
        self$`exporter_company_name` <- `exporter_company_name`
      }
      if (!missing(`risks`)) {
        stopifnot(is.list(`risks`), length(`risks`) != 0)
        lapply(`risks`, function(x) stopifnot(R6::is.R6(x)))
        self$`risks` <- `risks`
      }
      if (!missing(`hs_traded`)) {
        stopifnot(is.list(`hs_traded`), length(`hs_traded`) != 0)
        lapply(`hs_traded`, function(x) stopifnot(is.character(x)))
        self$`hs_traded` <- `hs_traded`
      }
      if (!missing(`industries`)) {
        stopifnot(is.list(`industries`), length(`industries`) != 0)
        lapply(`industries`, function(x) stopifnot(is.character(x)))
        self$`industries` <- `industries`
      }
      if (!missing(`number_records`)) {
        stopifnot(is.numeric(`number_records`), length(`number_records`) == 1)
        self$`number_records` <- `number_records`
      }
      if (!missing(`countries_of_origin`)) {
        stopifnot(is.list(`countries_of_origin`), length(`countries_of_origin`) != 0)
        lapply(`countries_of_origin`, function(x) stopifnot(is.character(x)))
        self$`countries_of_origin` <- `countries_of_origin`
      }
      if (!missing(`countries_of_destination`)) {
        stopifnot(is.list(`countries_of_destination`), length(`countries_of_destination`) != 0)
        lapply(`countries_of_destination`, function(x) stopifnot(is.character(x)))
        self$`countries_of_destination` <- `countries_of_destination`
      }
      if (!missing(`importer_restrictions`)) {
        stopifnot(is.list(`importer_restrictions`), length(`importer_restrictions`) != 0)
        lapply(`importer_restrictions`, function(x) stopifnot(R6::is.R6(x)))
        self$`importer_restrictions` <- `importer_restrictions`
      }
      if (!missing(`exporter_restrictions`)) {
        stopifnot(is.list(`exporter_restrictions`), length(`exporter_restrictions`) != 0)
        lapply(`exporter_restrictions`, function(x) stopifnot(R6::is.R6(x)))
        self$`exporter_restrictions` <- `exporter_restrictions`
      }
    },
    toJSON = function() {
      TradeRelationshipObject <- list()
      if (!is.null(self$`importer_company_canon_id`)) {
        TradeRelationshipObject[['importer_company_canon_id']] <- self$`importer_company_canon_id`
      }
      if (!is.null(self$`exporter_company_canon_id`)) {
        TradeRelationshipObject[['exporter_company_canon_id']] <- self$`exporter_company_canon_id`
      }
      if (!is.null(self$`importer_canon_id`)) {
        TradeRelationshipObject[['importer_canon_id']] <- self$`importer_canon_id`
      }
      if (!is.null(self$`exporter_canon_id`)) {
        TradeRelationshipObject[['exporter_canon_id']] <- self$`exporter_canon_id`
      }
      if (!is.null(self$`importer_company_name`)) {
        TradeRelationshipObject[['importer_company_name']] <- self$`importer_company_name`
      }
      if (!is.null(self$`exporter_company_name`)) {
        TradeRelationshipObject[['exporter_company_name']] <- self$`exporter_company_name`
      }
      if (!is.null(self$`risks`)) {
        TradeRelationshipObject[['risks']] <- lapply(self$`risks`, function(x) x$toJSON())
      }
      if (!is.null(self$`hs_traded`)) {
        TradeRelationshipObject[['hs_traded']] <- self$`hs_traded`
      }
      if (!is.null(self$`industries`)) {
        TradeRelationshipObject[['industries']] <- self$`industries`
      }
      if (!is.null(self$`number_records`)) {
        TradeRelationshipObject[['number_records']] <- self$`number_records`
      }
      if (!is.null(self$`countries_of_origin`)) {
        TradeRelationshipObject[['countries_of_origin']] <- self$`countries_of_origin`
      }
      if (!is.null(self$`countries_of_destination`)) {
        TradeRelationshipObject[['countries_of_destination']] <- self$`countries_of_destination`
      }
      if (!is.null(self$`importer_restrictions`)) {
        TradeRelationshipObject[['importer_restrictions']] <- lapply(self$`importer_restrictions`, function(x) x$toJSON())
      }
      if (!is.null(self$`exporter_restrictions`)) {
        TradeRelationshipObject[['exporter_restrictions']] <- lapply(self$`exporter_restrictions`, function(x) x$toJSON())
      }

      TradeRelationshipObject
    },
    fromJSON = function(TradeRelationshipJson) {
      TradeRelationshipObject <- jsonlite::fromJSON(TradeRelationshipJson)
      if (!is.null(TradeRelationshipObject$`importer_company_canon_id`)) {
        self$`importer_company_canon_id` <- TradeRelationshipObject$`importer_company_canon_id`
      }
      if (!is.null(TradeRelationshipObject$`exporter_company_canon_id`)) {
        self$`exporter_company_canon_id` <- TradeRelationshipObject$`exporter_company_canon_id`
      }
      if (!is.null(TradeRelationshipObject$`importer_canon_id`)) {
        self$`importer_canon_id` <- TradeRelationshipObject$`importer_canon_id`
      }
      if (!is.null(TradeRelationshipObject$`exporter_canon_id`)) {
        self$`exporter_canon_id` <- TradeRelationshipObject$`exporter_canon_id`
      }
      if (!is.null(TradeRelationshipObject$`importer_company_name`)) {
        self$`importer_company_name` <- TradeRelationshipObject$`importer_company_name`
      }
      if (!is.null(TradeRelationshipObject$`exporter_company_name`)) {
        self$`exporter_company_name` <- TradeRelationshipObject$`exporter_company_name`
      }
      if (!is.null(TradeRelationshipObject$`risks`)) {
        self$`risks` <- lapply(TradeRelationshipObject$`risks`, function(x) {
          risksObject <- Risk$new()
          risksObject$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE))
          risksObject
        })
      }
      if (!is.null(TradeRelationshipObject$`hs_traded`)) {
        self$`hs_traded` <- TradeRelationshipObject$`hs_traded`
      }
      if (!is.null(TradeRelationshipObject$`industries`)) {
        self$`industries` <- TradeRelationshipObject$`industries`
      }
      if (!is.null(TradeRelationshipObject$`number_records`)) {
        self$`number_records` <- TradeRelationshipObject$`number_records`
      }
      if (!is.null(TradeRelationshipObject$`countries_of_origin`)) {
        self$`countries_of_origin` <- TradeRelationshipObject$`countries_of_origin`
      }
      if (!is.null(TradeRelationshipObject$`countries_of_destination`)) {
        self$`countries_of_destination` <- TradeRelationshipObject$`countries_of_destination`
      }
      if (!is.null(TradeRelationshipObject$`importer_restrictions`)) {
        self$`importer_restrictions` <- lapply(TradeRelationshipObject$`importer_restrictions`, function(x) {
          importer_restrictionsObject <- Restriction$new()
          importer_restrictionsObject$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE))
          importer_restrictionsObject
        })
      }
      if (!is.null(TradeRelationshipObject$`exporter_restrictions`)) {
        self$`exporter_restrictions` <- lapply(TradeRelationshipObject$`exporter_restrictions`, function(x) {
          exporter_restrictionsObject <- Restriction$new()
          exporter_restrictionsObject$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE))
          exporter_restrictionsObject
        })
      }
    },
    toJSONString = function() {
       sprintf(
        '{
           "importer_company_canon_id": %s,
           "exporter_company_canon_id": %s,
           "importer_canon_id": %s,
           "exporter_canon_id": %s,
           "importer_company_name": %s,
           "exporter_company_name": %s,
           "risks": [%s],
           "hs_traded": [%s],
           "industries": [%s],
           "number_records": %d,
           "countries_of_origin": [%s],
           "countries_of_destination": [%s],
           "importer_restrictions": [%s],
           "exporter_restrictions": [%s]
        }',
        self$`importer_company_canon_id`,
        self$`exporter_company_canon_id`,
        self$`importer_canon_id`,
        self$`exporter_canon_id`,
        self$`importer_company_name`,
        self$`exporter_company_name`,
        lapply(self$`risks`, function(x) paste(x$toJSON(), sep=",")),
        lapply(self$`hs_traded`, function(x) paste(paste0('"', x, '"'), sep=",")),
        lapply(self$`industries`, function(x) paste(paste0('"', x, '"'), sep=",")),
        self$`number_records`,
        lapply(self$`countries_of_origin`, function(x) paste(paste0('"', x, '"'), sep=",")),
        lapply(self$`countries_of_destination`, function(x) paste(paste0('"', x, '"'), sep=",")),
        lapply(self$`importer_restrictions`, function(x) paste(x$toJSON(), sep=",")),
        lapply(self$`exporter_restrictions`, function(x) paste(x$toJSON(), sep=","))
      )
    },
    fromJSONString = function(TradeRelationshipJson) {
      TradeRelationshipObject <- jsonlite::fromJSON(TradeRelationshipJson)
      self$`importer_company_canon_id` <- TradeRelationshipObject$`importer_company_canon_id`
      self$`exporter_company_canon_id` <- TradeRelationshipObject$`exporter_company_canon_id`
      self$`importer_canon_id` <- TradeRelationshipObject$`importer_canon_id`
      self$`exporter_canon_id` <- TradeRelationshipObject$`exporter_canon_id`
      self$`importer_company_name` <- TradeRelationshipObject$`importer_company_name`
      self$`exporter_company_name` <- TradeRelationshipObject$`exporter_company_name`
      self$`risks` <- lapply(TradeRelationshipObject$`risks`, function(x) Risk$new()$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE)))
      self$`hs_traded` <- TradeRelationshipObject$`hs_traded`
      self$`industries` <- TradeRelationshipObject$`industries`
      self$`number_records` <- TradeRelationshipObject$`number_records`
      self$`countries_of_origin` <- TradeRelationshipObject$`countries_of_origin`
      self$`countries_of_destination` <- TradeRelationshipObject$`countries_of_destination`
      self$`importer_restrictions` <- lapply(TradeRelationshipObject$`importer_restrictions`, function(x) Restriction$new()$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE)))
      self$`exporter_restrictions` <- lapply(TradeRelationshipObject$`exporter_restrictions`, function(x) Restriction$new()$fromJSON(jsonlite::toJSON(x, auto_unbox = TRUE)))
    }
  )
)
altana-tech/atlas-api-r-sdk documentation built on Dec. 19, 2021, 1:36 a.m.