'Imports the dashboard from the object to the database.
Once dashboard is imported, json_metadata field is extended and stores
remote_id and import_time. It helps to decide if the dashboard has to
be overridden or just copies over. Slices that belong to this
dashboard will be wired to existing tables. This function can be used
to import/export dashboards between multiple superset instances.
Audit metadata isn\'t copies over.'

@classmethod
def import_obj(cls, dashboard_to_import, import_time=None):

    def alter_positions(dashboard, old_to_new_slc_id_dict):
        u'    Updates    slice_ids    in    the    position    json.\n\n                                                Sample    position    json:\n                                                [{\n                                                                "col":    5,\n                                                                "row":    10,\n                                                                "size_x":    4,\n                                                                "size_y":    2,\n                                                                "slice_id":    "3610"\n                                                }]\n                                                '
        position_array = dashboard.position_array
        for position in position_array:
            if (u'slice_id' not in position):
                continue
            old_slice_id = int(position[u'slice_id'])
            if (old_slice_id in old_to_new_slc_id_dict):
                position[u'slice_id'] = u'{}'.format(old_to_new_slc_id_dict[old_slice_id])
        dashboard.position_json = json.dumps(position_array)
    logging.info(u'Started    import    of    the    dashboard:    {}'.format(dashboard_to_import.to_json()))
    session = db.session
    logging.info(u'Dashboard    has    {}    slices'.format(len(dashboard_to_import.slices)))
    slices = copy(dashboard_to_import.slices)
    old_to_new_slc_id_dict = {}
    new_filter_immune_slices = []
    new_timed_refresh_immune_slices = []
    new_expanded_slices = {}
    i_params_dict = dashboard_to_import.params_dict
    for slc in slices:
        logging.info(u'Importing    slice    {}    from    the    dashboard:    {}'.format(slc.to_json(), dashboard_to_import.dashboard_title))
        new_slc_id = Slice.import_obj(slc, import_time=import_time)
        old_to_new_slc_id_dict[slc.id] = new_slc_id
        new_slc_id_str = u'{}'.format(new_slc_id)
        old_slc_id_str = u'{}'.format(slc.id)
        if ((u'filter_immune_slices' in i_params_dict) and (old_slc_id_str in i_params_dict[u'filter_immune_slices'])):
            new_filter_immune_slices.append(new_slc_id_str)
        if ((u'timed_refresh_immune_slices' in i_params_dict) and (old_slc_id_str in i_params_dict[u'timed_refresh_immune_slices'])):
            new_timed_refresh_immune_slices.append(new_slc_id_str)
        if ((u'expanded_slices' in i_params_dict) and (old_slc_id_str in i_params_dict[u'expanded_slices'])):
            new_expanded_slices[new_slc_id_str] = i_params_dict[u'expanded_slices'][old_slc_id_str]
    existing_dashboard = None
    for dash in session.query(Dashboard).all():
        if ((u'remote_id' in dash.params_dict) and (dash.params_dict[u'remote_id'] == dashboard_to_import.id)):
            existing_dashboard = dash
    dashboard_to_import.id = None
    alter_positions(dashboard_to_import, old_to_new_slc_id_dict)
    dashboard_to_import.alter_params(import_time=import_time)
    if new_expanded_slices:
        dashboard_to_import.alter_params(expanded_slices=new_expanded_slices)
    if new_filter_immune_slices:
        dashboard_to_import.alter_params(filter_immune_slices=new_filter_immune_slices)
    if new_timed_refresh_immune_slices:
        dashboard_to_import.alter_params(timed_refresh_immune_slices=new_timed_refresh_immune_slices)
    new_slices = session.query(Slice).filter(Slice.id.in_(old_to_new_slc_id_dict.values())).all()
    if existing_dashboard:
        existing_dashboard.override(dashboard_to_import)
        existing_dashboard.slices = new_slices
        session.flush()
        return existing_dashboard.id
    else:
        copied_dash = dashboard_to_import.copy()
        copied_dash.slices = new_slices
        session.add(copied_dash)
        session.flush()
        return copied_dash.id
