mstrio > datasources > datasource_map¶
- class mstrio.datasources.datasource_map.DatasourceMap(connection, id=None, project=None, default_connection_map=False, ds_connection=None, datasource=None, user=None, login=None, locale=None)¶
Bases:
EntityBase
,DeleteMixin
Object representation of Strategy One Connection Mapping
The connection mapping provides mapping between a user or a user group and a datasource login for the given datasource and datasource connection.
- Parameters:
connection (Connection) –
id (str | None) –
project (Project | str | None) –
default_connection_map (bool) –
ds_connection (DatasourceConnection | None) –
datasource (DatasourceInstance | None) –
login (DatasourceLogin | None) –
locale (Language | None) –
- connection¶
A Strategy One connection object
- id¶
ID of connection mapping.
- project¶
The project the mapping is assigned to.
- default_connection_map¶
Whether the mapping is the default for the project.
- ds_connection¶
The mapped Datasource Connection
- datasource¶
The mapped Datasource Instance
- user¶
The mapped User or UserGroup
- login¶
The mapped Datasource Login
- locale¶
The mapping’s locale. When empty, it’s equivalent to ‘default’ in Workstation and means that default locale for the environment will be used.
- alter(user=None, ds_connection=None, datasource=None, login=None, locale=None)¶
Replace the connection mapping with a newly created one with field values copied unless new ones are specified.
- Parameters:
connection – A Strategy One connection object
user (User | UserGroup | str | None) – The User or UserGroup to be mapped
ds_connection (DatasourceConnection | str | None) – The Datasource Connection to be mapped
datasource (DatasourceInstance | str | None) – The Datasource Instance to be mapped
login (DatasourceLogin | str | None) – The Datasource Login to be mapped
locale (Language | str | None) – The locale to be mapped
- Returns:
DatasourceMap object
- classmethod bulk_from_dict(source_list, connection=None, to_snake_case=True, with_missing_value=False)¶
Creates multiple objects from a list of dictionaries. For each dictionary provided the keys in camel case are changed to object’s attribute names (by default in snake case) and dict values are composed to their proper data types such as Enums, list of Enums etc. as specified in the object’s _FROM_DICT_MAP.
- Parameters:
cls (T) – Class (type) of the objects that should be created.
source_list (List[Dict[str, Any]]) – A list of dictionaries from which the objects will be constructed.
connection (Connection, optional) – A MSTR Connection object. Defaults to None.
to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case. Defaults to True.
with_missing_value (bool) – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.
- Returns:
A list of objects of type T.
- Return type:
T
- classmethod create(connection, project, user, ds_connection, datasource, login, locale=None, locale_id=None, locale_name=None)¶
Create a new connection mapping on the server. If more than one locale related parameters are provided, locale has priority, then locale_id.
- Parameters:
connection (Connection) – A Strategy One connection object
project (Project | str) – The project the mapping is to be assigned to
user (User | UserGroup | str) – The User or UserGroup to be mapped
ds_connection (DatasourceConnection | str) – The Datasource Connection to be mapped
datasource (DatasourceInstance | str) – The Datasource Instance to be mapped
login (DatasourceLogin | str) – The Datasource Login to be mapped
locale (Language | str | None) – The locale to be mapped.
locale_id (str | None) – The id of locale to be mapped.
locale_name (str | None) – The name of locale to be mapped.
- Returns:
DatasourceMap object
- Return type:
- delete(force=False)¶
Delete object.
- Parameters:
force (bool) – If True, then no additional prompt will be shown before deleting object.
self (Entity) –
- Returns:
True on success. False otherwise.
- Return type:
bool
- fetch(attr=None)¶
Fetch the latest object’s state from the I-Server.
Note
This method can overwrite local changes made to the object.
- Parameters:
attr (Optional[str]) – Attribute name to be fetched. If not specified
dictionary. (it will use all getters specified in _API_GETTERS) –
None. (Defaults to) –
- Raises:
ValueError – If attr cannot be fetched.
- Return type:
None
- classmethod from_dict(source, connection, to_snake_case=True)¶
- Overrides Dictable.from_dict() to instantiate an object from
a dictionary without calling any additional getters.
- Parameters:
cls (T) – Class (type) of an object that should be created.
source (dict[str, Any]) – a dictionary from which an object will be constructed.
connection (Connection) – A Strategy One Connection object.
to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case, default True.
with_missing_value – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.
- Returns:
An object of type T.
- Return type:
T
- list_properties(excluded_properties=None)¶
Fetches all attributes from the server and converts all properties of the object to a dictionary.
- Parameters:
excluded_properties (list[str], optional) – A list of object properties that should be excluded from the dict. Defaults to None.
- Returns:
- A dictionary which keys are object’s attribute names, and
which values are object’s attribute values.
- Return type:
dict
- print()¶
Pretty Print all properties of the object.
- Return type:
None
- classmethod to_csv(objects, name, path=None, properties=None)¶
Exports MSTR objects to a csv file.
Optionally, saves only the object properties specified in the properties parameter.
- Parameters:
objects (T | list[T]) – List of objects of the same type that
exported. (will be) –
name (str) – The name of the csv file ending with ‘.csv’
path (Optional[str], optional) – A path to the directory where the file will be saved. Defaults to None.
properties (Optional[list[str]], optional) – A list of object’s attribute names that should be included in the exported file. Defaults to None.
- Raises:
TypeError – If objects is not of type T or list of type T
objects. –
- Return type:
None
- to_dataframe()¶
Converts all properties of the object to a dataframe.
- Returns:
A DataFrame object containing object properties.
- Return type:
DataFrame
- to_dict(camel_case=True)¶
Converts an object to a dictionary excluding object’s private properties. When converting the object to a dictionary, the object’s attributes become the dictionary’s keys and are in camel case by default Attribute values stored as objects are automatically converted to non-/ primitive data structures.
- Parameters:
camel_case (bool, optional) – Set to True if attribute names should be converted from snake case to camel case. Defaults to True.
- Returns:
- A dictionary representation of object’s attributes and values.
By default, the dictionary keys are in camel case.
- Return type:
dict
- update_properties()¶
Save compatible local changes of the object attributes to the I-Server. Changes are retrieved from the self._altered_properties dictionary. After the process of update has finished, self._altered_properties is cleared. For this method to work properly, you must override the _alter_properties() method in a subclass.
- Raises:
requests.HTTPError – If I-Server raises exception
- Return type:
None
- mstrio.datasources.datasource_map.list_datasource_mappings(connection, project=None, to_dictionary=False, limit=None, user=None, ds_connection=None, datasource=None, login=None, locale=None, default_connection_map=False)¶
Get list of connection mappings: objects or dicts. Optionally filter by specifying filters. When returned as dictionaries, connection mappings that have default locale
will have ‘locale’ property with empty name and id.
- Parameters:
connection (Connection) – Strategy One connection object returned by connection.Connection()
default_connection_map (bool) – True if requesting default connection mappings. Default False
project (Project | str | None) – The project (or its id) which mappings are to be fetched. Optional unless requesting the default mappings.
to_dictionary (bool) – If True returns dict, by default (False) returns DatasourceMap objects.
limit (int | None) – limit the number of elements returned. If None (default), all objects are returned.
locale (Language | str | None) – filter list by locale
login (DatasourceLogin | str | None) – filter list by datasource login
datasource (DatasourceInstance | str | None) – filter list by datasource instance
ds_connection (DatasourceConnection | str | None) – filter list by datasource connection
user (User | UserGroup | str | None) – filter list by user or user group
- Returns:
list[‘DatasourceMap’] by default list[dict] if to_dictionary is True
- Return type:
list[DatasourceMap] | list[dict]
Examples
>>> list_datasource_mappings(connection)