Source code for mindconnect.clients.mappings_client

# coding: utf-8

"""
    MindConnect API

     MindConnect API provides following data ingestion functionalities:  # Data Point Mappings  Creating and managing mappings between an agent's data points and an entity's dynamic property to be able to upload TimeSeries data.   Each agent has data points with unique ids. The mapping is between to this id to an entity's dynamic property set's property.  - A data point can be mapped to many property of many property set of many entities.  - A property cannot be mapped from more than one data point.   - A propertyset can have mappings from many agents' many data points to its properties.  - The unit of the datapoint has to be same with the unit of the property.  - The type of the datapoint has to be same with the type of the property.   Whenever data source configuration of an agent is updated via Agent Management API; all mappings with __keepMapping__ attribute set gets their validity attribute updated and all mappings with __keepMapping__ attribute unset are deleted.   # Exchange  Exchanging time series, events, files and data source configuration data. Combination of different data types can be uploaded via exchange endpoint within  multipart body. Maximum size of exchange body is 10MBs.  # Diagnostic Activations  Management of Diagnostic Activations and querying Diagnostic Messages of time series, event, file and data source configuration requests.  - Maximum 5 agents per tenant can be activated for data ingestion tracking.  - For non-agents, the required permission allows to manage diagnostic activation resources of agents in the same tenant as in the token.  - For agents, only the diagnostic activation related to the agent can be managed. Agents are forbidden to view/change the resources of other agents in the same tenant.  - Agents are allowed to update activation for itself only. Users with sufficient scopes are allowed   # noqa: E501
"""


from __future__ import absolute_import

from mindsphere_core.mindsphere_core import logger
from mindsphere_core import mindsphere_core, exceptions, token_service
from mindsphere_core.token_service import init_credentials


[docs]class MappingsClient: __base_path__ = "/api/mindconnect/v3" __model_package__ = __name__.split(".")[0] def __init__(self, rest_client_config=None, mindsphere_credentials=None): self.rest_client_config = rest_client_config self.mindsphere_credentials = init_credentials(mindsphere_credentials)
[docs] def data_point_mappings_get(self, request_object): """Get mappings. Retrieves a list of mappings. :param DataPointMappingsGetRequest request_object: It contains the below parameters --> |br| ( filter - Filter as JSON object. ), |br| ( size - The maximum number of elements in a page. ), |br| ( page - The (0-based) index of page. ), |br| ( sort - The order of returned elements. Multiple fields could be used separated by commas (e.g. ''field1,field2''). Descending order could be requested by appending '',desc'' at the end of parameter.(e.g. ''field1,field2,desc'')' ) :return: PagedMapping """ logger.info("MappingsClient.data_point_mappings_get() invoked.") end_point_url = "/dataPointMappings" end_point_url = end_point_url.format() token = token_service.fetch_token( self.rest_client_config, self.mindsphere_credentials ) api_url = mindsphere_core.build_url( self.__base_path__, end_point_url, self.rest_client_config ) headers = { "Accept": "application/json", "Content-Type": "application/json", "Authorization": "Bearer " + str(token), } query_params = { "filter": request_object.filter, "size": request_object.size, "page": request_object.page, "sort": request_object.sort, } form_params, local_var_files, body_params = {}, {}, None logger.info( "MappingsClient.data_point_mappings_get() --> Proceeding for API Invoker." ) return mindsphere_core.invoke_service( self.rest_client_config, api_url, headers, "GET", query_params, form_params, body_params, local_var_files, "PagedMapping", self.__model_package__, )
[docs] def data_point_mappings_id_delete(self, request_object): """Delete a mapping Deletes a mapping. :param DataPointMappingsIdDeleteRequest request_object: It contains the below parameters --> |br| ( id* - Unique identifier of the mapping resource. ) :return: None """ logger.info("MappingsClient.data_point_mappings_id_delete() invoked.") if request_object is None: raise exceptions.MindsphereClientError( "`request_object` is not passed when calling `data_point_mappings_id_delete`" ) if request_object.id is None: raise exceptions.MindsphereClientError( "The required parameter `id` is missing from `request_object`, when calling `data_point_mappings_id_delete`" ) end_point_url = "/dataPointMappings/{id}" end_point_url = end_point_url.format(id=request_object.id) token = token_service.fetch_token( self.rest_client_config, self.mindsphere_credentials ) api_url = mindsphere_core.build_url( self.__base_path__, end_point_url, self.rest_client_config ) headers = { "Accept": "application/json", "Content-Type": "application/json", "Authorization": "Bearer " + str(token), } query_params = {} form_params, local_var_files, body_params = {}, {}, None logger.info( "MappingsClient.data_point_mappings_id_delete() --> Proceeding for API Invoker." ) return mindsphere_core.invoke_service( self.rest_client_config, api_url, headers, "DELETE", query_params, form_params, body_params, local_var_files, None, self.__model_package__, )
[docs] def data_point_mappings_id_get(self, request_object): """Get a mapping by id Gets a mapping by given id. :param DataPointMappingsIdGetRequest request_object: It contains the below parameters --> |br| ( id* - Unique identifier of the mapping resource. ) :return: Mapping """ logger.info("MappingsClient.data_point_mappings_id_get() invoked.") if request_object is None: raise exceptions.MindsphereClientError( "`request_object` is not passed when calling `data_point_mappings_id_get`" ) if request_object.id is None: raise exceptions.MindsphereClientError( "The required parameter `id` is missing from `request_object`, when calling `data_point_mappings_id_get`" ) end_point_url = "/dataPointMappings/{id}" end_point_url = end_point_url.format(id=request_object.id) token = token_service.fetch_token( self.rest_client_config, self.mindsphere_credentials ) api_url = mindsphere_core.build_url( self.__base_path__, end_point_url, self.rest_client_config ) headers = { "Accept": "application/json", "Content-Type": "application/json", "Authorization": "Bearer " + str(token), } query_params = {} form_params, local_var_files, body_params = {}, {}, None logger.info( "MappingsClient.data_point_mappings_id_get() --> Proceeding for API Invoker." ) return mindsphere_core.invoke_service( self.rest_client_config, api_url, headers, "GET", query_params, form_params, body_params, local_var_files, "Mapping", self.__model_package__, )
[docs] def data_point_mappings_post(self, request_object): """Create single mapping Creates a single mapping. :param DataPointMappingsPostRequest request_object: It contains the below parameters --> |br| ( mapping* - Object describing new mapping resource. ) :return: Mapping """ logger.info("MappingsClient.data_point_mappings_post() invoked.") if request_object is None: raise exceptions.MindsphereClientError( "`request_object` is not passed when calling `data_point_mappings_post`" ) if request_object.mapping is None: raise exceptions.MindsphereClientError( "The required parameter `mapping` is missing from `request_object`, when calling `data_point_mappings_post`" ) end_point_url = "/dataPointMappings" end_point_url = end_point_url.format() token = token_service.fetch_token( self.rest_client_config, self.mindsphere_credentials ) api_url = mindsphere_core.build_url( self.__base_path__, end_point_url, self.rest_client_config ) headers = { "Accept": "application/json", "Content-Type": "application/json", "Authorization": "Bearer " + str(token), } query_params = {} form_params, local_var_files, body_params = {}, {}, request_object.mapping logger.info( "MappingsClient.data_point_mappings_post() --> Proceeding for API Invoker." ) return mindsphere_core.invoke_service( self.rest_client_config, api_url, headers, "POST", query_params, form_params, body_params, local_var_files, "Mapping", self.__model_package__, )