Source code for assetmanagement.clients.locations_client

# coding: utf-8

"""
    Asset Management API

    Service for configuring, reading and managing assets, asset ~ and aspect types.  # 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 LocationsClient: __base_path__ = '/api/assetmanagement/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 delete_asset_location(self, request_object): """Delete location assigned to given asset. * Only those locations can be deleted here which assigned to the given asset. * If the location inherited from an ancestor asset, you have to delete the location with the assigned assetId (using ‘location’ url in AssetResource object with DELETE method). * The response contains the updated AssetResource with the inherited Location details. :param DeleteAssetLocationRequest request_object: It contains the below parameters --> |br| ( If-Match* - Last known version to facilitate optimistic locking ), |br| ( id* - Unique identifier ) :return: AssetResourceWithHierarchyPath """ logger.info('LocationsClient.delete_asset_location() invoked.') if request_object is None: raise exceptions.MindsphereClientError('`request_object` is not passed when calling `delete_asset_location`') if request_object.if_match is None: raise exceptions.MindsphereClientError('The required parameter `If-Match` is missing from `request_object`, when calling `delete_asset_location`') if request_object.id is None: raise exceptions.MindsphereClientError('The required parameter `id` is missing from `request_object`, when calling `delete_asset_location`') end_point_url = '/assets/{id}/location' 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/hal+json, application/vnd.error+json', 'Content-Type': 'application/json', 'If-Match': request_object.if_match, 'Authorization': 'Bearer ' + str(token)} query_params = {} form_params, local_var_files, body_params = {}, {}, None logger.info('LocationsClient.delete_asset_location() --> 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, 'AssetResourceWithHierarchyPath', self.__model_package__)
[docs] def save_asset_location(self, request_object): """Create or Update location assigned to given asset * If the given asset has own location, this endpoint will update that location. * If the given asset has no location, this endpoint will create a new location and update the given asset. * If the given asset has inherited location, this endpoint will create a new location and update the given asset. If you wanted to update the inherited location you have to use the 'location' url in AssetResource object (with PUT method). :param SaveAssetLocationRequest request_object: It contains the below parameters --> |br| ( If-Match* - Last known version to facilitate optimistic locking ), |br| ( id* - Unique identifier ), |br| ( location* - location ) :return: None """ logger.info('LocationsClient.save_asset_location() invoked.') if request_object is None: raise exceptions.MindsphereClientError('`request_object` is not passed when calling `save_asset_location`') if request_object.if_match is None: raise exceptions.MindsphereClientError('The required parameter `If-Match` is missing from `request_object`, when calling `save_asset_location`') if request_object.id is None: raise exceptions.MindsphereClientError('The required parameter `id` is missing from `request_object`, when calling `save_asset_location`') if request_object.location is None: raise exceptions.MindsphereClientError('The required parameter `location` is missing from `request_object`, when calling `save_asset_location`') end_point_url = '/assets/{id}/location' 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/hal+json, application/vnd.error+json', 'Content-Type': 'application/json', 'If-Match': request_object.if_match, 'Authorization': 'Bearer ' + str(token)} query_params = {} form_params, local_var_files, body_params = {}, {}, request_object.location logger.info('LocationsClient.save_asset_location() --> Proceeding for API Invoker.') return mindsphere_core.invoke_service(self.rest_client_config, api_url, headers, 'PUT', query_params, form_params, body_params, local_var_files, None, self.__model_package__)