'Inserts or overrides slc in the database.
remote_id and import_time fields in params_dict are set to track the
slice origin and ensure correct overrides for multiple imports.
Slice.perm is used to find the datasources and connect them.'

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

    session = db.session
    make_transient(slc_to_import)
    slc_to_import.dashboards = []
    slc_to_import.alter_params(remote_id=slc_to_import.id, import_time=import_time)
    slc_to_override = None
    for slc in session.query(Slice).all():
        if ((u'remote_id' in slc.params_dict) and (slc.params_dict[u'remote_id'] == slc_to_import.id)):
            slc_to_override = slc
    slc_to_import = slc_to_import.copy()
    params = slc_to_import.params_dict
    slc_to_import.datasource_id = ConnectorRegistry.get_datasource_by_name(session, slc_to_import.datasource_type, params[u'datasource_name'], params[u'schema'], params[u'database_name']).id
    if slc_to_override:
        slc_to_override.override(slc_to_import)
        session.flush()
        return slc_to_override.id
    session.add(slc_to_import)
    logging.info(u'Final    slice:    {}'.format(slc_to_import.to_json()))
    session.flush()
    return slc_to_import.id
