docstr: Import chart(s) with associated datasets and databases.
  ---
  post:
    summary: Import chart(s) with associated datasets and databases
    requestBody:
      required: true
      content:
        multipart/form-data:
          schema:
            type: object
            properties:
              formData:
                description: upload file (ZIP)
                type: string
                format: binary
              passwords:
                description: >-
                  JSON map of passwords for each featured database in the
                  ZIP file. If the ZIP includes a database config in the path
                  `databases/MyDatabase.yaml`, the password should be provided
                  in the following format:
                  `{"databases/MyDatabase.yaml": "my_password"}`.
                type: string
              overwrite:
                description: overwrite existing charts?
                type: boolean
              ssh_tunnel_passwords:
                description: >-
                  JSON map of passwords for each ssh_tunnel associated to a
                  featured database in the ZIP file. If the ZIP includes a
                  ssh_tunnel config in the path `databases/MyDatabase.yaml`,
                  the password should be provided in the following format:
                  `{"databases/MyDatabase.yaml": "my_password"}`.
                type: string
              ssh_tunnel_private_keys:
                description: >-
                  JSON map of private_keys for each ssh_tunnel associated to a
                  featured database in the ZIP file. If the ZIP includes a
                  ssh_tunnel config in the path `databases/MyDatabase.yaml`,
                  the private_key should be provided in the following format:
                  `{"databases/MyDatabase.yaml": "my_private_key"}`.
                type: string
              ssh_tunnel_private_key_passwords:
                description: >-
                  JSON map of private_key_passwords for each ssh_tunnel associated
                  to a featured database in the ZIP file. If the ZIP includes a
                  ssh_tunnel config in the path `databases/MyDatabase.yaml`,
                  the private_key should be provided in the following format:
                  `{"databases/MyDatabase.yaml": "my_private_key_password"}`.
                type: string
    responses:
      200:
        description: Chart import result
        content:
          application/json:
            schema:
              type: object
              properties:
                message:
                  type: string
      400:
        $ref: '#/components/responses/400'
      401:
        $ref: '#/components/responses/401'
      422:
        $ref: '#/components/responses/422'
      500:
        $ref: '#/components/responses/500'
docstr_tok: ["Import","chart","(","s",")","with","associated","datasets","and","databases",".","--","-","post",":","summary",":","Import","chart","(","s",")","with","associated","datasets","and","databases","requestBody",":","required",":","true","content",":","multipart\/form-data",":","schema",":","type",":","object","properties",":","formData",":","description",":","upload","file","(","ZIP",")","type",":","string","format",":","binary","passwords",":","description",":",">","-","JSON","map","of","passwords","for","each","featured","database","in","the","ZIP","file",".","If","the","ZIP","includes","a","database","config","in","the","path","`","databases\/MyDatabase.yaml","`",",","the","password","should","be","provided","in","the","following","format",":","`","{","``","databases\/MyDatabase.yaml","''",":","``","my_password","''","}","`",".","type",":","string","overwrite",":","description",":","overwrite","existing","charts","?","type",":","boolean","ssh_tunnel_passwords",":","description",":",">","-","JSON","map","of","passwords","for","each","ssh_tunnel","associated","to","a","featured","database","in","the","ZIP","file",".","If","the","ZIP","includes","a","ssh_tunnel","config","in","the","path","`","databases\/MyDatabase.yaml","`",",","the","password","should","be","provided","in","the","following","format",":","`","{","``","databases\/MyDatabase.yaml","''",":","``","my_password","''","}","`",".","type",":","string","ssh_tunnel_private_keys",":","description",":",">","-","JSON","map","of","private_keys","for","each","ssh_tunnel","associated","to","a","featured","database","in","the","ZIP","file",".","If","the","ZIP","includes","a","ssh_tunnel","config","in","the","path","`","databases\/MyDatabase.yaml","`",",","the","private_key","should","be","provided","in","the","following","format",":","`","{","``","databases\/MyDatabase.yaml","''",":","``","my_private_key","''","}","`",".","type",":","string","ssh_tunnel_private_key_passwords",":","description",":",">","-","JSON","map","of","private_key_passwords","for","each","ssh_tunnel","associated","to","a","featured","database","in","the","ZIP","file",".","If","the","ZIP","includes","a","ssh_tunnel","config","in","the","path","`","databases\/MyDatabase.yaml","`",",","the","private_key","should","be","provided","in","the","following","format",":","`","{","``","databases\/MyDatabase.yaml","''",":","``","my_private_key_password","''","}","`",".","type",":","string","responses",":","200",":","description",":","Chart","import","result","content",":","application\/json",":","schema",":","type",":","object","properties",":","message",":","type",":","string","400",":","$","ref",":","'","#","\/components\/responses\/400'","401",":","$","ref",":","'","#","\/components\/responses\/401'","422",":","$","ref",":","'","#","\/components\/responses\/422'","500",":","$","ref",":","'","#","\/components\/responses\/500","'"]
code: def import_(self) -> Response:
      """Import chart(s) with associated datasets and databases.
      ---
      post:
        summary: Import chart(s) with associated datasets and databases
        requestBody:
          required: true
          content:
            multipart/form-data:
              schema:
                type: object
                properties:
                  formData:
                    description: upload file (ZIP)
                    type: string
                    format: binary
                  passwords:
                    description: >-
                      JSON map of passwords for each featured database in the
                      ZIP file. If the ZIP includes a database config in the path
                      `databases/MyDatabase.yaml`, the password should be provided
                      in the following format:
                      `{"databases/MyDatabase.yaml": "my_password"}`.
                    type: string
                  overwrite:
                    description: overwrite existing charts?
                    type: boolean
                  ssh_tunnel_passwords:
                    description: >-
                      JSON map of passwords for each ssh_tunnel associated to a
                      featured database in the ZIP file. If the ZIP includes a
                      ssh_tunnel config in the path `databases/MyDatabase.yaml`,
                      the password should be provided in the following format:
                      `{"databases/MyDatabase.yaml": "my_password"}`.
                    type: string
                  ssh_tunnel_private_keys:
                    description: >-
                      JSON map of private_keys for each ssh_tunnel associated to a
                      featured database in the ZIP file. If the ZIP includes a
                      ssh_tunnel config in the path `databases/MyDatabase.yaml`,
                      the private_key should be provided in the following format:
                      `{"databases/MyDatabase.yaml": "my_private_key"}`.
                    type: string
                  ssh_tunnel_private_key_passwords:
                    description: >-
                      JSON map of private_key_passwords for each ssh_tunnel associated
                      to a featured database in the ZIP file. If the ZIP includes a
                      ssh_tunnel config in the path `databases/MyDatabase.yaml`,
                      the private_key should be provided in the following format:
                      `{"databases/MyDatabase.yaml": "my_private_key_password"}`.
                    type: string
        responses:
          200:
            description: Chart import result
            content:
              application/json:
                schema:
                  type: object
                  properties:
                    message:
                      type: string
          400:
            $ref: '#/components/responses/400'
          401:
            $ref: '#/components/responses/401'
          422:
            $ref: '#/components/responses/422'
          500:
            $ref: '#/components/responses/500'
      """
      upload = request.files.get("formData")
      if not upload:
          return self.response_400()
      if not is_zipfile(upload):
          raise IncorrectFormatError("Not a ZIP file")
      with ZipFile(upload) as bundle:
          contents = get_contents_from_bundle(bundle)
  
      if not contents:
          raise NoValidFilesFoundError()
  
      passwords = (
          json.loads(request.form["passwords"])
          if "passwords" in request.form
          else None
      )
      overwrite = request.form.get("overwrite") == "true"
      ssh_tunnel_passwords = (
          json.loads(request.form["ssh_tunnel_passwords"])
          if "ssh_tunnel_passwords" in request.form
          else None
      )
      ssh_tunnel_private_keys = (
          json.loads(request.form["ssh_tunnel_private_keys"])
          if "ssh_tunnel_private_keys" in request.form
          else None
      )
      ssh_tunnel_priv_key_passwords = (
          json.loads(request.form["ssh_tunnel_private_key_passwords"])
          if "ssh_tunnel_private_key_passwords" in request.form
          else None
      )
  
      command = ImportChartsCommand(
          contents,
          passwords=passwords,
          overwrite=overwrite,
          ssh_tunnel_passwords=ssh_tunnel_passwords,
          ssh_tunnel_private_keys=ssh_tunnel_private_keys,
          ssh_tunnel_priv_key_passwords=ssh_tunnel_priv_key_passwords,
      )
      command.run()
      return self.response(200, message="OK")
  
imports: import json
  import logging
  from datetime import datetime
  from io import BytesIO
  from typing import Any, cast, Optional
  from zipfile import is_zipfile, ZipFile
  from flask import redirect, request, Response, send_file, url_for
  from flask_appbuilder.api import expose, protect, rison, safe
  from flask_appbuilder.hooks import before_request
  from flask_appbuilder.models.sqla.interface import SQLAInterface
  from flask_babel import ngettext
  from marshmallow import ValidationError
  from werkzeug.wrappers import Response
  from werkzeug.wsgi import FileWrapper
  from superset import app, is_feature_enabled, thumbnail_cache
  from superset.charts.filters import ChartAllTextFilter, ChartCertifiedFilter, ChartCreatedByMeFilter, ChartFavoriteFilter, ChartFilter, ChartHasCreatedByFilter, ChartOwnedCreatedFavoredByMeFilter, ChartTagFilter
  from superset.charts.schemas import CHART_SCHEMAS, ChartCacheWarmUpRequestSchema, ChartPostSchema, ChartPutSchema, get_delete_ids_schema, get_export_ids_schema, get_fav_star_ids_schema, openapi_spec_methods_override, screenshot_query_schema, thumbnail_query_schema
  from superset.commands.chart.create import CreateChartCommand
  from superset.commands.chart.delete import DeleteChartCommand
  from superset.commands.chart.exceptions import ChartCreateFailedError, ChartDeleteFailedError, ChartForbiddenError, ChartInvalidError, ChartNotFoundError, ChartUpdateFailedError, DashboardsForbiddenError
  from superset.commands.chart.export import ExportChartsCommand
  from superset.commands.chart.importers.dispatcher import ImportChartsCommand
  from superset.commands.chart.update import UpdateChartCommand
  from superset.commands.chart.warm_up_cache import ChartWarmUpCacheCommand
  from superset.commands.exceptions import CommandException
  from superset.commands.importers.exceptions import IncorrectFormatError, NoValidFilesFoundError
  from superset.commands.importers.v1.utils import get_contents_from_bundle
  from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod
  from superset.daos.chart import ChartDAO
  from superset.extensions import event_logger
  from superset.models.slice import Slice
  from superset.tasks.thumbnails import cache_chart_thumbnail
  from superset.tasks.utils import get_current_user
  from superset.utils.screenshots import ChartScreenshot, DEFAULT_CHART_WINDOW_SIZE
  from superset.utils.urls import get_url_path
  from superset.views.base_api import BaseSupersetModelRestApi, RelatedFieldFilter, requires_form_data, requires_json, statsd_metrics
  from superset.views.filters import BaseFilterRelatedUsers, FilterRelatedOwners
label_desc: Use image node_id 14 for calling the ChartRestApi obj's underlying member method code with example usage: obj.import_() and returns: self, self