Example #1
0
    def get(self, request):
        """
        Top events

         route eventAnalytics/topevents
         return The most frequent events, which are sorted by the number of appearances in a dataset in a descending order.
         description This method internally calls method top_events of EventOperationsClient class.
                        This class is available as dependency in eventanalytics-<version-here>-py3-none-any.whl

         apiEndpoint : POST /api/eventanalytics/v3/findTopEvents of eventanalytics
                       service.
         apiNote Finds the most frequent events, which are sorted by the number of appearances in a dataset in a descending order.
         throws MindsphereError if an error occurs while attempting to invoke the sdk call.

        """
        logger.info("eventAnalytics/topevents invoked.")
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":
            try:
                response = client.top_events(data_generator.get_top_events_data())
                logger.info("Getting response successfully for topevents "+ json.dumps(response))
            except exceptions.MindsphereError as err:
                logger.error("Getting error for topevents "+err)
                return HttpResponse(
                    err,
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(
                json.dumps(response), content_type="application/json", status=status.HTTP_200_OK
            )
    def get(self, request, **kwargs):
        """
        filter asset types which contains

        route filterassettypecontains
        return List all asset types available for tenant with provided filter(asset types whose name contains provided
               filterValue).

        param filterValue - specify the value for fieldType(name) to look for while filtering asset types..
        description This method internally calls method get_asset_types_contains of AssettypeClient
                     class. This class is available as dependency in assetmanagement-<version-here>-py3-none-any.whl.
        apiEndpoint : GET /api/assetmanagement/v3/assettypes of asset management service.

        apiNote List all asset types.
        throws MindsphereError if an error occurs while attempting to invoke the sdk call.
        """
        logger.info("assets/filterassettypecontains invoked.")
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":
            try:
                response = client.get_asset_types_contains(field_type=data_generator.FieldTypeEnum.NAME,
                                                           filter_value=request.GET.get("filterValue", None))
                logger.info(
                    "Getting response successfully for create filterassettypecontains " + json.dumps(response.to_dict))
            except exceptions.MindsphereError as err:
                logger.error("Getting error for create filterassettypecontains " + err)
                return HttpResponse(
                    err,
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(
                json.dumps(response.to_dict), content_type="application/json", status=status.HTTP_200_OK
            )
    def get(self, request, **kwargs):
        """

         route <str:id>/aspects
         return List of all aspects for provided asset id.
         param id : Unique identifier of an asset. (passed in keyword arguments.)
         description This method internally calls method list_asset_aspects of StructureClient class.
                     This class is available as dependency in assetmanagement-<version-here>-py3-none-any.whl

         apiEndpoint : GET /api/assetmanagement/v3/assets/{id}/aspects of asset management service.

         apiNote Get all static and dynamic aspects of a given asset.
         throws Error if an error occurs while attempting to invoke the sdk call.

        """
        logger.info("assets/<str:id>/aspects invoked.")
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":
            try:
                did = kwargs.get("id", "")
                logger.info("AssetId is " + did)
                request_object = data_generator.generate_aspects_of_asset_request(id=did)
                aspects_of_asset = client.list_asset_aspects(request_object)
                logger.info(
                    "Getting response successfully for  list of aspects with id" + json.dumps(aspects_of_asset.to_dict))
            except exceptions.MindsphereError as err:
                logger.error("Getting error for listofaspect with assetId " + err)
                return HttpResponse(
                    err,
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(
                json.dumps(aspects_of_asset.to_dict), content_type="application/json", status=status.HTTP_200_OK
            )
    def get(self, request):
        """
        List all assets.

         route /assets
         return List all assets available for tenant.
         description This method internally calls method list_assets of AssetsClient class.
                        This class is available as dependency in assetmanagement-<version-here>-py3-none-any.whl

         apiEndpoint : GET /api/assetmanagement/v3/assets of asset management service.

         apiNote List all assets available for the authenticated user.
         throws MindsphereError if an error occurs while attempting to invoke the sdk call.

        """
        logger.info("assets/assets invoked.")
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":
            try:
                request_object = data_generator.generate_list_assets_input()
                asset = client.list_assets(request_object)
                logger.info("Getting response successfully for  getallasset" + json.dumps(asset.to_dict()))
            except exceptions.MindsphereError as err:
                logger.error("Getting eeror for getallasset " + err)
                return HttpResponse(
                    err,
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(
                json.dumps(asset.to_dict()), content_type="application/json", status=status.HTTP_200_OK
            )
    def get(self, request, **kwargs):
        """

         route <str:id>/aspects
         return List of all aspects for provided asset id.
         param id : Unique identifier of an asset. (passed in keyword arguments.)
         description This method internally calls method list_asset_aspects of StructureClient class.
                     This class is available as dependency in assetmanagement-<version-here>-py3-none-any.whl

         apiEndpoint : GET /api/assetmanagement/v3/assets/{id}/aspects of asset management service.

         apiNote Get all static and dynamic aspects of a given asset.
         throws Error if an error occurs while attempting to invoke the sdk call.

        """
        logger.info("assets/<str:id>/aspects invoked.")
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":
            try:
                request_object = GetRootAssetRequest(if_none_match=None)
                asset = client.get_root_asset(request_object)
                asset = serialization_filter.sanitize_for_serialization(asset)
                resonse = json.dumps(asset)
                logger.info(resonse)
            except exceptions.MindsphereError as err:
                logger.error(err)
                return HttpResponse(
                    err,
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(
                resonse, content_type="application/json", status=status.HTTP_200_OK
            )
    def get(self, request, **kwargs):
        """
         Create aspect type.

         route assets/aspects
         param tenantName - Name of the tenant for which you want to create aspect type. Passed in request.
         return Created aspect type information object.
         description This method internally calls method save_aspect_type of AspecttypeClient class.
                        This class is available as dependency in assetmanagement-<version-here>-py3-none-any.whl

         apiEndpoint : PUT /api/assetmanagement/v3/aspecttypes/{id} of asset management service.

         apiNote Create or Update an aspect type
         throws MindsphereError if an error occurs while attempting to invoke the sdk call.

        """
        logger.info("assets/aspects invoked.")
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":
            try:
                request_object = data_generator.generate_aspect_input(
                    tenant=request.GET.get("tenantName", None)
                )
                aspect = client.save_aspect_type(request_object)
                logger.info("Getting response successfully for create aspects " + json.dumps(aspect.to_dict))
            except exceptions.MindsphereError as err:
                logger.error("Getting error for create aspects " + err)
                return HttpResponse(
                    err,
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(
                json.dumps(aspect.to_dict), content_type="application/json", status=status.HTTP_200_OK
            )
    def get(self, request, **kwargs):
        """
        filtering asset which of given filter_value type.

         route filterassetsoftype
         return List all assets available for tenant with provided filter.

         param filter_value - specify the value  to look for while filtering assets.
         description This method internally calls method get_assets_starts_with of AssetsClient class.
                     Assets which are of provided type (filter_value)  will be returned.
                     This class is available as dependency in assetmanagement-<version-here>-py3-none-any.whl

         apiEndpoint : GET /api/assetmanagement/v3/assets of asset management service.

         apiNote List all assets available for the authenticated user.
         throws MindsphereError if an error occurs while attempting to invoke the sdk call.
        """
        logger.info("assets/filterassetsoftype invoked.")
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":
            try:
                response = client.get_assets_of_type(request.GET.get("filterValue", None))
                logger.info("Getting response successfully for filterassetsoftype" + json.dumps(response.to_dict))
            except exceptions.MindsphereError as err:
                logger.error("Getting error for filterassetsoftype " + err)
                return HttpResponse(
                    err,
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(
                json.dumps(response.to_dict), content_type="application/json", status=status.HTTP_200_OK
            )
    def get(self, request, **kwargs):
        """
                get time series
                route : timeseriesaggregate/get/<str:entityid>/<str:propertyname>
                requestparam : entityId - An Asset Id for which aggregates are to be retrieved.
                requestparam :  propertySetName - property setname for which aggregates will be be retrieved.
                note :  Non existent/Incorrect entityId and propertySetName will result in MindsphereError.
                param --->  request - HttpRequest object
                returns : Time series aggregates in String format.
                returnType : String
                description : This method - get internally calls method retrieve_aggregates of AggregatesClient class.
                            This class is available as dependency in tsaggregates-<version-here>-py3-none-any.whl.
                            For retrieve_aggregates, two parameters are passed - entityId - An Asset Id for which aggregates
                            are to be retrieved and property setname for which aggregates will be be retrieved.
                            With an absence of any other parameters aggregates will be returned by following rule :
                            The parameters from, to, intervalUnit, intervalValue, and count are used to determine the time
                            range and interval length to return aggregates for. Intelligent auto-completion is applied to allow
                            clients to only provide a subset of the parameters, according to the following rules:
                            In case none of the parameters is provided, intervalUnit is set to DAY, intervalValue is set to 1,
                            to is set to the current time, and from is set to the current time minus 7 days.
                apiEndpoint : GET /api/iottsaggregates/v4/aggregates of aggregate service.
                           service.
                apiNote : Returns a list of aggregates for a given asset and aspect. The time range of the aggregates can be defined by a
                        combination of parameters; such as from, to, intervalUnit, intervalValue and count. Time range can be specified anywhere
                        in past or future for which timeseries data is present. In the case no time series data was available for an aggregation
                        interval, no aggregate will be returned. Pre-computed aggregates are aligned with the tenant's time zone.
                throws MindsphereError : if an error occurs while attempting to invoke the sdk call.

        """
        logger.info(
            "timeseriesaggregate/get/<str:entityid>/<str:propertyname> invoked"
        )
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":
            try:
                entity_id = kwargs.get("entityid", "")
                property_name = kwargs.get("propertyname", "")
                logger.info("Request params are- enitityID:" + entity_id +
                            " propertyName: " + property_name)
                request_object = RetrieveAggregatesRequest()
                request_object.asset_id = entity_id
                request_object.aspect_name = property_name
                aggregateList = client.retrieve_aggregates(request_object)
                aggregate_json = serialization_filter.sanitize_for_serialization(
                    aggregateList)
                aggregate_json = json.dumps(aggregate_json)
                logger.info(
                    "Getting response successfully for timeseriesaggregate" +
                    aggregate_json)
            except exceptions.MindsphereError as err:
                logger.error("Getting error for timeseriesaggregate" + err)
                return HttpResponse(
                    err,
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(aggregate_json,
                                content_type="application/json",
                                status=status.HTTP_200_OK)
Example #9
0
    def get(self, request, **kwargs):
        """
        get time series

         route timeSeries/get/<str:entityid>/<str:propertyname>/<str:from>/<str:to>
         param entityId - unique identifier of the asset (entity)
         param propertyname - Name of the aspect (property set).
         param from - Beginning of the time range to be retrieved (exclusive).
         param to - End of the time range to be retrieved (inclusive).
         return Timeseries data on successful execution.

         description This method internally calls method retrieve_timeseries of
                       TimeSeriesOperationsClient class. This class is available as dependency
                       in timeseries-<version-here>-py3-none-any.whl.
                       entityId, propertySetName, from and to are passed in request object as given by user(path variables)
                       and hence incorrect/non-existent values for entiyId and/or propertyname  will result in MindsphereError.

         apiEndpoint : GET /api/iottimeseries/v3/timeseries/{entityId}/{propertySetName} of timeseries service.
                      service. service.
         apiNote Retrieve time series data for one combination of an asset (entity) and an(a) aspect (property set).
         throws MindsphereError if an error occurs while attempting to invoke the
                                      sdk call.

        """
        logger.info(
            "timeSeries/get/<str:entityid>/<str:propertyname>/<str:from>/<str:to> invoked"
        )
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":
            try:
                entity_id = kwargs.get("entityid", "")
                property_name = kwargs.get("propertyname", "")
                _from = kwargs.get("from", "")
                to = kwargs.get("to", "")
                qryparam = request.query_params
                logger.info("Request params are- enitityID:" + entity_id +
                            " propertyName: " + property_name + " from:" +
                            _from + " to:" + to)
                request_object = RetrieveTimeseriesRequest()
                request_object.entity_id = entity_id
                request_object.property_set_name = property_name
                request_object._from = qryparam['from']
                request_object.to = qryparam['to']
                timseriesList = client.retrieve_timeseries(request_object)
                timeseries_json = serialization_filter.sanitize_for_serialization(
                    timseriesList)
                timeseries_json = json.dumps(timeseries_json)
                logger.info("Getting response successfully for gettimeSeries" +
                            timeseries_json)
            except exceptions.MindsphereError as err:
                logger.error(err.message)
                return HttpResponse(
                    json.dumps(err.message.message),
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(timeseries_json,
                                content_type="application/json",
                                status=status.HTTP_200_OK)
Example #10
0
    def get(self, request, **kwargs):
        """
        delete time series

         route timeSeries/delete/<str:entityid>/<str:propertyname>/<str:from>/<str:to>
         param entityId - unique identifier of the asset (entity), (required)
         param propertyname - Name of the aspect (property set), (required)
         param from - beginning of the timerange to delete (exclusive), (required)
         param to - end of the timerange to delete (inclusive),   (required)

         return "successfully deleted timeseriesdata" on successful execution.

         description This method internally calls method delete_timeseries of
                       TimeSeriesOperationsClient class. This class is available as dependency
                       in timeseries-<version-here>-py3-none-any.whl.
                       entityId, propertyname, from and to  are passed as given by user and
                       hence incorrect/non-existent values of entityId and/or propertyname  will result in MindsphereError.
         apiEndpoint : DELETE /api/iottimeseries/v3/timeseries/{entityId}/{propertySetName} of timeseries service.

         apiNote Delete time series data for one combination of an asset (entity) and an(a) aspect (property set).
                    All property values within the given time range are deleted.
         throws MindsphereError if an error occurs while attempting to invoke the
                sdk call.

        """
        logger.info(
            "timeSeries/delete/<str:entityid>/<str:propertyname>/<str:from>/<str:to> invoked"
        )
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":
            try:
                entity_id = kwargs.get("entityid", "")
                property_name = kwargs.get("propertyname", "")
                _from = kwargs.get("from", "")
                to = kwargs.get("to", "")
                logger.info("Request params are- enitityID:" + entity_id +
                            " propertyName: " + property_name + " from:" +
                            _from + " to:" + to)
                request_object = DeleteUpdatedTimeseriesRequest()
                request_object.entity_id = entity_id
                request_object.property_set_name = property_name
                request_object._from = _from
                request_object.to = to
                client.delete_timeseries(request_object)
                logger.info("successfully deleted timeseriesdata")
            except exceptions.MindsphereError as err:
                logger.info(err.message)
                return HttpResponse(
                    json.dumps(err.message.message),
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse("successfully deleted timeseriesdata",
                                content_type="application/json",
                                status=status.HTTP_200_OK)
Example #11
0
    def put(self, request, **kwargs):
        """
        put time series

         route timeSeries/create/<str:entityid>/<str:propertyname>
         param entityId - unique identifier of the asset (entity)
         param propertyname - Name of the aspect (property set).

         return "successfully uploaded timeseriesdata" on successful execution.

         description This method internally calls method create_or_update_timeseries_data of
                     TimeSeriesOperationsClient class. This class is available as dependency
                     in timeseries-<version-here>-py3-none-any.whl. Creation of timeseries requires `timeseries`
                     data structure to be passed in request body.
         apiEndpoint : PUT /api/iottimeseries/v3/timeseries of timeseries service.
                         service.
         apiNote Create or update time series data for mutiple unique asset-aspect (entity-property set) combinations.
         throws MindsphereError if an error occurs while attempting to invoke the
                sdk call.

        """
        logger.info(
            "timeSeries/create/<str:entityid>/<str:propertyname> invoked")
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "PUT":
            try:
                entity_id = kwargs.get("entityid", "")
                property_name = kwargs.get("propertyname", "")
                logger.info("Request params are- entityID: " + entity_id +
                            "propertyname" + property_name)
                requestObject = CreateOrUpdateTimeseriesDataRequest()
                requestObject.entity_id = entity_id
                requestObject.property_set_name = property_name
                timeSeriesData = json.dumps(request.data)
                timeSeriesDataItems = json.loads(timeSeriesData)
                # timeSeriesDataItem = TimeSeriesDataItem()
                # timeSeriesDataItem.fields = {
                #     "test": 15
                # }
                # timeSeriesDataItem.time = "2020-11-11T02:52:00Z"
                # timeSeriesDataItems = [timeSeriesDataItem]
                requestObject.timeseries = timeSeriesDataItems
                client.create_or_update_timeseries_data(requestObject)
                logger.info("timeseries uploaded Successfully ")
            except exceptions.MindsphereError as err:
                logger.info(err.message)
                return HttpResponse(
                    json.dumps(err.message.message),
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse("successfully uploaded timeseriesdata",
                                content_type="application/text",
                                status=status.HTTP_200_OK)
Example #12
0
    def get(self, request, **kwargs):
        """
         create Diagnostic Activation.

         route mindconnect/diagnosticActivationsCreate/<str:agentid>/<str:status>
         param : agentid ---> Unique identifier of the agent.
         param : status --->  Status of the activation.
         return Created diagnostic activation data.

         description This method internally calls method diagnostic_activations_post of DiagnosticActivationsClient class.
                     This class is available as dependency in mindconnect-<version-here>-py3-none-any.whl.

         apiEndpoint : POST /api/mindconnect/v3/diagnosticActivations of mindconnect service.

         apiNote Creates a new diagnostic activation.
         throws MindsphereError if an error occurs while attempting to invoke the sdk call.

        """
        logger.info(
            "mindconnect/diagnosticActivationsCreate/<str:agentid>/<str:status> invoked"
        )
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":
            try:
                agent_id = kwargs.get("agentid", "")
                status = kwargs.get("status", "")
                logger.info("Request params are- agentid:" + agent_id +
                            " status: " + status)

                diagnosticActivation = DiagnosticActivation(agent_id=agent_id,
                                                            status=status)
                request_object = DiagnosticActivationsPostRequest(
                    diagnostic_activation=diagnosticActivation)

                response = client.diagnostic_activations_post(request_object)
                respose_json = serialization_filter.sanitize_for_serialization(
                    response)
                respose_json = json.dumps(respose_json)
                logger.info(
                    "Getting response successfully for diagnosticActivationsCreate"
                    + respose_json)
            except exceptions.MindsphereError as err:
                logger.error("Getting error for diagnosticActivationsCreate" +
                             err)
                return HttpResponse(
                    err,
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(respose_json,
                                content_type="application/json",
                                status=status.HTTP_200_OK)
Example #13
0
    def get(self, request):
        """
        pattern matching events

         route eventAnalytics/matchEventPattern

         return List of events matching pattern.

         description This method internally calls method match_patterns_over_events of PatternOperationsClient
                        class.
                        This class is available as dependency in eventanalytics-<version-here>-py3-none-any.whl.
                        The request object is formed and passed dynamically.(See data_generator.get_pattern_matching_data())
                        This method takes data as part of request body.
                        Data structure with four parts - maxPatternInterval, patternsList, nonEvents and eventsInput.

                        maxPatternInterval ---> The maximum time length (in milliseconds) of the sliding window where the
                        pattern occurs (Maximum difference allowed between the first event of the pattern and the last one).

                        patternsList ---> The patterns to be found in events. The eventText can contain regular expressions.
                        The acceptable syntax for the regular expressions is the java syntax. minRepetitions and maxRepetitions
                        represent the minimum and maximum number of events of the specified type that are allowed to occur in
                        order for the pattern to be matched on the events.

                        nonEvents ---> A list of events that is not allowed to be part of a pattern. Any pattern which contains
                         a non-event is excluded from the final report.

                        eventsInput ---> Metadata for the events list specifying the property name of the item in the events list
                        that contains the text of the event and the list with the events that will be processed.

         apiEndpoint : POST /api/eventanalytics/v3/matchEventPatterns of eventanalytics
                       service.
         apiNote :   Applies the patterns specified in body on a list of events. Finds all instances of the specified pattern(s)
                   in a collection of events.
         throws MindsphereError if an error occurs while attempting to invoke the sdk call.

        """
        logger.info("eventAnalytics/matchEventPattern invoked.")
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":
            try:
                response = client.match_patterns_over_events(data_generator.get_pattern_matching_data())
                logger.info("Getting response successfully for matchEventPattern " + json.dumps(response.to_dict))
            except exceptions.MindsphereError as err:
                logger.error("Getting error for matchEventPattern " + err)
                return HttpResponse(
                    err,
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(
                json.dumps(response.to_dict), content_type="application/json", status=status.HTTP_200_OK
            )
    def get(self, request, **kwargs):
        """

         route iotbulk/retrievetimeseries/<str:entityid>/<str:propertyname>/<str:from>/<str:to>
         param entityId - Unique identifier of the asset (entity).
         param propertyname - Unique name of the aspect (property set name).
         param from - Beginning of the time range to read (exclusive). ‘from’ time must be less than ‘to’ time.
                      Range between ‘from’ and ‘to’ time must be less than 90 days.
         param to -   End of the time range to retrieve (inclusive).

         return Retrieve time series data for a single asset (entity) and aspect (property set).
                Returns data for the specified time range.

         description :  This method internally calls method retrieve_timeseries of ReadOperationsClient class.
                            This class is available as dependency in iottsbulk-<version-here>-py3-none-any.whl.

          apiEndpoint : GET /api/iottsbulk/v3/timeseries/{entity}/{propertySetName} of iot bulk service.
                      service.
         apiNote Retrieve time series data.
         throws MindsphereError if an error occurs while attempting to invoke the sdk call.


        """
        logger.info("iotbulk/retrievetimeseries/<str:entityid>/<str:propertyname>/<str:from>/<str:to> invoked")
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":
            try:
                entity_id = kwargs.get("entityid", "")
                property_name = kwargs.get("propertyname", "")
                _from = kwargs.get("from", "")
                to = kwargs.get("to", "")
                logger.info(
                    "Request params are- enitityID:" + entity_id + " propertyName: " + property_name + " from:" + _from + " to:" + to)
                retrieveTimeseriesRequest = RetrieveTimeseriesRequest()
                retrieveTimeseriesRequest.entity = entity_id
                retrieveTimeseriesRequest.property_set_name = property_name
                retrieveTimeseriesRequest._from = _from
                retrieveTimeseriesRequest.to = to
                response = client.retrieve_timeseries(retrieveTimeseriesRequest)
                logger.info("Getting response successfully for retrievetimeseries "+response)
            except exceptions.MindsphereError as err:
                logger.error("getting error for retrievetimeseries " + err)
                return HttpResponse(
                    err,
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(
                json.dumps(response.to_dict()), content_type="application/json", status=status.HTTP_200_OK
            )
    def get(self, request):
        """

        route iotbulk/importjobpost

        return Created import job object(JobStatus) information.

        description This method internally calls method create_import_job of BulkImportOperationsClient class.
                    This class is available as dependency in iottsbulk-<version-here>-py3-none-any.whl.

        apiEndpoint : POST /api/iottsbulk/v3/importJobs of iot bulk service.
                       service.
        apiNote Create bulk import job for importing time series data.
        throws MindsphereError if an error occurs while attempting to invoke the sdk call.

        """
        logger.info("iotbulk/importjobpost invoked.")
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":
            try:
                createImportJobRequest = CreateImportJobRequest()
                bulkImportInput = BulkImportInput()
                data = Data()
                data.entity = "5908ae5c5e4f4e18b0be58cd21ee675f"
                data.property_set_name = "test_2020_11_11"

                fileInfo = FileInfo()
                fileInfo.file_path = "test11.json"
                fileInfo._from = "2020-12-16T04:30:00.01Z"
                fileInfo.to = "2020-12-16T04:35:00.30Z"
                fileInfoList = [fileInfo]

                data.timeseries_files = fileInfoList
                dataList = [data]

                bulkImportInput.data = dataList
                createImportJobRequest.bulk_import_input = bulkImportInput
                response = client.create_import_job(createImportJobRequest)
                logger.info("Getting response successfully for importjobpost " + response)
            except exceptions.MindsphereError as err:
                logger.error("getting error for importjobpost " + err)
                return HttpResponse(
                    err,
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(
                json.dumps(response.to_dict()), content_type="application/json", status=status.HTTP_200_OK
            )
Example #16
0
    def put(self, request, **kwargs):
        """
        put time series
        """
        logger.info('timeSeries/put invoked')
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "PUT":
            try:
                # timeseries = UpdatedTimeSeries()
                # timeSeriesItem = TimeSeriesItem()
                # timeSeriesItem.entity_id = "535140e4980e413497d112015ddd47ff"
                # timeSeriesItem.property_set_name = "testaspect2812"
                #
                # timeSeriesDataItem = TimeSeriesDataItem()
                # timeSeriesDataItem.fields = {
                #     "test": 15
                # }
                # timeSeriesDataItem.time = "2020-11-11T02:52:00Z"
                # timeSeriesDataItems = [timeSeriesDataItem]
                # timeSeriesItem.data = timeSeriesDataItems
                # timeSeriesItems = [timeSeriesItem]
                # timeseries.timeseries = tim = timeSeriesItems
                # createOrUpdateTimeseriesRequest = CreateOrUpdateTimeseriesRequest()
                # createOrUpdateTimeseriesRequest.timeseries = timeseries

                requestObj = json.dumps(request.data)
                timeseries = json.loads(requestObj)
                createOrUpdateTimeseriesRequest = CreateOrUpdateTimeseriesRequest(
                )
                createOrUpdateTimeseriesRequest.timeseries = timeseries

                response = client.create_or_update_timeseries(
                    createOrUpdateTimeseriesRequest)
                timeseries_json = serialization_filter.sanitize_for_serialization(
                    response)
                timeseries_json = json.dumps(timeseries_json)
                logger.info("timeseries updated Successfully " +
                            timeseries_json)
            except exceptions.MindsphereError as err:
                logger.error(err.message)
                return HttpResponse(
                    json.dumps(err.message.message),
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(timeseries_json,
                                content_type="application/json",
                                status=status.HTTP_200_OK)
    def get(self, request, **kwargs):
        """

         route files/fileservicecreate/<str:entity_id>
         param entityId - An Asset Id for which file needs to be created/stored.
         note Non existent/Incorrect entityId will result in MindsphereError.

         return "Successfully uploaded the file and file path :" <filepath-here> upon successful execution.

         description This method internally calls method put_file of
                       FileServiceClient class. This class is available as dependency
                       in iotfileservices-<version-here>-py3-none-any.whl.
                       The required fields are :
                       1)file string($binary) the file attached content.
                       2)entityId - unique identifier of the asset (entity)
                       3)filepath - url path of the file along with filename.
         apiEndpoint : PUT /api/iotfile/v3/files/{entityId}/{filepath} of iot file
                         service.
         apiNote Create or update a file for the specified asset (entity) and path,
                   with the provided content.
         throws MindsphereError if an error occurs while attempting to invoke the
                 sdk call.


        """

        logger.info("files/fileservicecreate/<str:entity_id> invoked")
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":
            try:
                entity_id = kwargs.get("entity_id", "")
                logger.info("Request param is- entityID: " + entity_id)
                request_object = data_generator.generate_put_file_input(entity_id)
                client.put_file(request_object)
                logger.info("Successfully uploaded the file and file path :" + request_object.filepath)
            except exceptions.MindsphereError as err:
                logger.error("Getting error for fileservicecreate " + err)
                return HttpResponse(
                    err,
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(
                "Successfully uploaded the file and file path :" + request_object.filepath,
                content_type="application/json",
                status=status.HTTP_200_OK
            )
    def get(self, request, **kwargs):
        """
        Create asset.

         route assets/assets/<str:typeid>
         param typeid - Id of the assettype from which you want to create an
                             Asset. - passed as path variables
         param parentid    - Desired parentId of the asset. - passed in request.
         note Asset creation requires typeid and parentid to be provided in
                request body hence this two values cannot be empty. Values of this
                variables are passed as provided by user hence non existent/Incorrect
                values will result in MindsphereError.

         return Created asset on successful execution.

         description This method internally generates dynamic request
                       body for asset and calls method add_asset
                       AssetsClient.This class is available as part of dependency :
                       assetmanagement-sdk-<version-here>.jar.
                       
         apiEndpoint : POST /api/assetmanagement/v3/assets of assetmanagement service
         throws MindsphereError if an error occurs while attempting to invoke the
               sdk call.

        """
        logger.info("assets/assets/<str:typeid> invoked.")
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":
            try:
                logger.info("Request param is - typeID:" + kwargs.get("typeid", ""))
                root = client.get_root_asset(data_generator.generate_root_asset_input())
                request_object = data_generator.generate_asset_input(
                    type_id=kwargs.get("typeid", ""),
                    parent_id=request.GET.get("parentid", None),
                )
                asset = client.add_asset(request_object)
                logger.info("Getting response successfully " + json.dumps(asset.to_dict))
            except exceptions.MindsphereError as err:
                logger.error("Error occured " + err)
                return HttpResponse(
                    err,
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(
                json.dumps(asset.to_dict), content_type="application/json", status=status.HTTP_200_OK
            )
Example #19
0
    def get(self, request, **kwargs):
        """

         route mindconnect/recoverableRecordIdDownloadLinkGet/<str:id>
         param id - Unique identifier of the recoverable record.

         return Response of download link in String format.

         description This method internally calls method recoverable_records_id_download_link_get of RecordRecoveryClient class.
                     This class is available as dependency in mindconnect-<version-here>-py3-none-any.whl.

         apiEndpoint : GET /api/mindconnect/v3/recoverableRecords/{id}/downloadLink of mindconnect service.
                       service.
         apiNote Get download link of record payload.
         throws MindsphereError if an error occurs while attempting to invoke the sdk call.

        """
        logger.info(
            "mindconnect/recoverableRecordIdDownloadLinkGet/<str:id> invoked")
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":
            try:
                id = kwargs.get("id", "")
                logger.info("Request param is- Id:" + id)
                request_object = RecoverableRecordsIdDownloadLinkGetRequest(
                    id=id)
                response = client.recoverable_records_id_download_link_get(
                    request_object)
                respose_json = serialization_filter.sanitize_for_serialization(
                    response)
                respose_json = json.dumps(respose_json)
                logger.info(
                    "Getting response successfully for recoverableRecordIdDownloadLinkGet "
                    + respose_json)
            except exceptions.MindsphereError as err:
                logger.error(
                    "Getting error for recoverableRecordIdDownloadLinkGet " +
                    err)
                return HttpResponse(
                    err,
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(respose_json,
                                content_type="application/json",
                                status=status.HTTP_200_OK)
Example #20
0
    def get(self, request, **kwargs):
        """

         route mindconnect/diagnosticActivationsGetbyidmessage/<str:id>
         param id - Unique identifier of diagnostic activation resource. (required)

         return Paged diagnostic information messages.

         description This method - diagnosticActivationsIdGetTest internally calls method diagnosticActivationsIdMessagesGet of
                     DiagnosticActivationsClient class. This class is available as dependency in mindconnect-<version-here>-py3-none-any.whl.

         apiEndpoint : GET /api/mindconnect/v3/diagnosticActivations/{id}/messages of mindconnect service.

         apiNote Get a diagnostic messages of specific activation resource.
         throws MindsphereError if an error occurs while attempting to invoke the sdk call.

        """
        logger.info(
            "mindconnect/diagnosticActivationsGetbyidmessage/<str:id> invoked")
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":
            try:
                did = kwargs.get("id", "")
                logger.info("Request param is - Id:" + did)
                request_object = DiagnosticActivationsIdMessagesGetRequest(
                    id=did)
                response = client.diagnostic_activations_id_messages_get(
                    request_object)
                respose_json = serialization_filter.sanitize_for_serialization(
                    response)
                respose_json = json.dumps(respose_json)
                logger.info(
                    "Getting response successfully for diagnosticActivationsGetbyidmessage "
                    + respose_json)
            except exceptions.MindsphereError as err:
                logger.error(
                    "Getting error for diagnosticActivationsGetbyidmessage " +
                    err)
                return HttpResponse(
                    err,
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(respose_json,
                                content_type="application/json",
                                status=status.HTTP_200_OK)
    def put(self, request, **kwargs):
        """
         Create aspect type.

         route assets/aspects
         param tenantName - Name of the tenant for which you want to create aspect type. Passed in request.
         return Created aspect type information object.
         description This method internally calls method save_aspect_type of AspecttypeClient class.
                        This class is available as dependency in assetmanagement-<version-here>-py3-none-any.whl

         apiEndpoint : PUT /api/assetmanagement/v3/aspecttypes/{id} of asset management service.

         apiNote Create or Update an aspect type
         throws MindsphereError if an error occurs while attempting to invoke the sdk call.

        """
        logger.info("put aspectt invoked.")
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "PUT":
            try:
                ifmatch = kwargs.get("ifmatch", "")
                aspect_id = kwargs.get("id", "")
                requestObj = json.dumps(request.data)
                aspect = json.loads(requestObj)
                request_object = SaveAspectTypeRequest(id=aspect_id, aspecttype=aspect, if_match=ifmatch)
                response = client.save_aspect_type(request_object)
                response = serialization_filter.sanitize_for_serialization(response)
                response = json.dumps(response)
                applink = {"ApplinK": getLink()}
                response = json.loads(response)
                response.update(applink)
                print(json.dumps(response))
                logger.info("Getting response successfully " + json.dumps(response))
            except exceptions.MindsphereError as err:
                logger.error(err.message)
                status_code = err.message.status_code
                return HttpResponse(
                    json.dumps(err.message.message),
                    content_type="application/json",
                    status=status_code,
                )
            return HttpResponse(
                json.dumps(response), content_type="application/json", status=status.HTTP_200_OK
            )
Example #22
0
    def get(self, request, **kwargs):
        """

         route mindconnect/datapointMappingCreate

         return Created data point mapping.

         description This method internally calls method data_point_mappings_post of MappingsClient class.
                        This class is available as dependency in mindconnect-<version-here>-py3-none-any.whl.

         apiEndpoint : POST /api/mindconnect/v3/dataPointMappings of mindconnect service.

         apiNote Create single mapping.
         throws MindsphereError if an error occurs while attempting to invoke the sdk call.

        """
        logger.info("mindconnect/datapointMappingCreate invoked.")
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":
            try:
                mapping = Mapping(agent_id="ad22f8a7ebb24b8fb41767afd2c63f08",
                                  data_point_id="SDKDP13",
                                  entity_id="078b1908bc9347678168760934465587",
                                  property_set_name="TyreTemperature",
                                  property_name="FLWheel",
                                  keep_mapping=False)
                request_object = DataPointMappingsPostRequest(mapping=mapping)
                response = client.data_point_mappings_post(request_object)
                respose_json = serialization_filter.sanitize_for_serialization(
                    response)
                respose_json = json.dumps(respose_json)
                logger.info(
                    "Getting response successfully for datapointMappingCreate "
                    + respose_json)
            except exceptions.MindsphereError as err:
                logger.error("Getting error for datapointMappingCreate " + err)
                return HttpResponse(
                    err,
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(respose_json,
                                content_type="application/json",
                                status=status.HTTP_200_OK)
    def get(self, request, **kwargs):
        """

         route assets/assetlocation/<str:id>/<str:ifmatch>
         param assetId : Unique identifier of an asset.

         return 'Location updated successfully' on successful execution.
         description This method internally calls method save_asset_location of LocationsClient class.
                     This class is available as dependency in assetmanagement-<version-here>-py3-none-any.whl.
                     If the given asset has own location, this endpoint will update that location.  If the given asset has4
                     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.

         apiEndpoint : PUT /api/assetmanagement/v3/assets/{id}/location of asset management service.

         apiNote   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.
         throws MindsphereError if an error occurs while attempting to invoke the sdk call.

        """
        logger.info("assets/assetlocation/<str:id>/<str:ifmatch> invoked.")
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":

            try:
                ifmatch = kwargs.get("ifmatch", "")
                did = kwargs.get("id", "")
                logger.info("Request params are - Id: " + did + " and ifmatch:" + ifmatch)
                request_object = data_generator.generate_location_update_input(if_match=ifmatch,
                                                                               id=did)
                client.save_asset_location(request_object)
                logger.info("Location updated successfully")
            except exceptions.MindsphereError as err:
                logger.error("Getting eroor for assetlocation " + err)
                return HttpResponse(
                    err,
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(
                'Location updated successfully', content_type="application/json", status=status.HTTP_200_OK
            )
Example #24
0
    def get(self, request, **kwargs):
        """

         route mindconnect/datapointMappingGet/<str:id>
         param id - Unique identifier of the mapping resource.

         return Data point mapping data for Id in String format.

         description This method - dataPointMappingsIdGetTest internally calls method dataPointMappingsIdGet of MappingsClient
                     class.
                     This class is available as dependency in mindconnect-<version-here>-py3-none-any.whl.

         apiEndpoint : GET /api/mindconnect/v3/dataPointMappings/{id} of mindconnect service.
                       service.
         apiNote Get a mapping by id.
         throws MindsphereError if an error occurs while attempting to invoke the sdk call.

        """
        logger.info("mindconnect/datapointMappingGet/<str:id> invoked")
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":
            try:
                id = kwargs.get("id", "")
                logger.info("Request param is- Id:" + id)
                request_object = DataPointMappingsIdGetRequest(id=id)
                response = client.data_point_mappings_id_get(request_object)
                respose_json = serialization_filter.sanitize_for_serialization(
                    response)
                respose_json = json.dumps(respose_json)
                logger.info(
                    "Getting response successfully for datapointMappingGet by id "
                    + respose_json)
            except exceptions.MindsphereError as err:
                logger.error("Getting error for datapointMappingGet by id" +
                             err)
                return HttpResponse(
                    err,
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(respose_json,
                                content_type="application/json",
                                status=status.HTTP_200_OK)
    def get(self, request, **kwargs):
        """

         route assets/assetfiles/<str:id>
         return Details of uploaded file upon successful execution.
         param id : Unique identifier for an asset.
         param fileid : Unique identifier of file resource
         param ifmatch : Last known version to facilitate optimistic locking.
         note : id, ifmatch and key are passed via keyword arguments.
         param key : Keyword for the file to be assigned to an asset.
         description This method internally calls method save_asset_file_assignment of AssetsClient class.
                        This class is available as dependency in assetmanagement-<version-here>-py3-none-any.whl

         apiEndpoint : PUT /api/assetmanagement/v3/assets/{id}/fileAssignments/{key} of asset management service.
         apiNote Save a file assignment to a given asset.
         throws MindsphereError if an error occurs while attempting to invoke the sdk call.

        """
        logger.info("assets/assetfiles/<str:id> invoked.")
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":
            try:
                logger.info("Request param is Id:" + kwargs.get("id", ""))
                assignment = data_generator.generate_file_assignment(
                    fileid=request.GET.get("fileid", None)
                )
                request_object = data_generator.generate_save_asset_file_assignment_input(kwargs.get("id", ""),
                                                                                          request.GET.get("ifmatch",
                                                                                                          None),
                                                                                          request.GET.get("key", None),
                                                                                          assignment)
                asset = client.save_asset_file_assignment(request_object)
                logger.info("Getting response successfully for  assetfiles with id" + json.dumps(asset.to_dict))
            except exceptions.MindsphereError as err:
                logger.error("Getting error for assetfiles with id" + err)
                return HttpResponse(
                    err,
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(
                json.dumps(asset.to_dict()), content_type="application/json", status=status.HTTP_200_OK
            )
    def get(self, request, **kwargs):
        """
        list multi part file

         route files/fileservicelistmultipartfile/<str:entity_id>/<str:path>
         param entityId - An Asset Id for which multipart file needs to be retrieved.
         note Non existent/Incorrect entityId will result in MindsphereError.
         param filePath - path of the file along with filename.

         return List of files

         description This method internally calls method get_file_list of
                     FileServiceClient class. This class is available as dependency
                     in iotfileservices-<version-here>-py3-none-any.whl.

         apiEndpoint : GET /api/iotfile/v3/fileslist/{entityId}/{filepath} of iot file
                         service.
         apiNote list multi part uploads
         throws MindsphereError if an error occurs while attempting to invoke the
                                      sdk call.

        """
        logger.info("files/fileservicelistmultipartfile/<str:entity_id>/<str:path> invoked")
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":
            try:
                path = kwargs.get("path", "")
                entity_id = kwargs.get("entity_id", "")
                logger.info("Request params are- path:" + path + " entityId:" + entity_id)
                response = data_generator.generate_file_list_input(entity_id, path)
                payload = serialization_filter.sanitize_for_serialization(response)
                payload = json.dumps(payload)
                logger.info("Getting response for fileservicelistmultipartfile "+payload)
            except exceptions.MindsphereError as err:
                logger.error("Getting error for fileservicelistmultipartfile "+err)
                return HttpResponse(
                    err,
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(
                payload, content_type="application/json", status=status.HTTP_200_OK
            )
    def get(self, request, **kwargs):
        """
        Create asset type.


         route assets/assettype/<str:tenant>
         param tenant : Name of tenant for which you wish to create asset type.
         param aspectname : Name of an aspect type which you wish to associate with asset type.
         param  aspectid : Id of an aspect which you wish to associate with asset type.
         note : apsectname ans aspectid passed in request whereas tenant is passed in URL.
         return Created asset type.
         description This method internally calls method save_asset_type of AssettypeClient class.
                        This class is available as dependency in assetmanagement-<version-here>-py3-none-any.whl

         apiEndpoint : PUT /api/assetmanagement/v3/assettypes/{id} of asset management service.

         apiNote Create or Update an asset type.
         throws MindsphereError if an error occurs while attempting to invoke the sdk call.

        """
        logger.info("assets/assettype/<str:tenant> invoked.")
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":
            try:
                logger.info("Request param is- Tenant: " + kwargs.get("tenant", ""))
                request_object = data_generator.generate_asset_type_input(
                    tenant=kwargs.get("tenant", ""),
                    aspect_id=request.GET.get("aspectid", None),
                    aspect_name=request.GET.get("aspectname", None),
                )
                aspect = client.save_asset_type(request_object)
                logger.info("Getting response successfully for create assettype " + json.dumps(aspect.to_dict))
            except exceptions.MindsphereError as err:
                logger.error("Getting error for create assettype " + err)
                return HttpResponse(
                    err,
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(
                json.dumps(aspect.to_dict), content_type="application/json", status=status.HTTP_200_OK
            )
Example #28
0
    def get(self, request):
        """
        filter events
      
         route eventAnalytics/filterEvents
         
         return List of events after filtering.
         
         description This method - filterEvents internally calls method filterEvents of EventOperationsClient class.
                        This class is available as dependency in eventanalytics-<version-here>-py3-none-any.whl. 
                        The request object is formed and passed dynamically.
                        This method takes data as part of request body.
                        `data` is a Data structure with two parts eventsMetadata, events.

                        eventsMetadata Metadata ->  for the events list specifying the property name of the item in the
                        events list that contains the text of the event (eventTextPropertyName) and time window length in
                        miliseconds of the period in which time interval will be split (splitInterval).

                        events List -->  with the events that will be processed.
                       
         apiEndpoint : POST /api/eventanalytics/v3/filterEvents of eventanalytics
                       service.
         apiNote  Simplifies the dataset to the most meaningful data. Filtering the dataset based on the text of the event.
         throws MindsphereError if an error occurs while attempting to invoke the sdk call.

        """
        logger.info("eventAnalytics/filterEvents invoked")
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":
            try:
                response = client.filter_events(data_generator.get_filter_events_data())
                logger.info("Getting response successfully for filterEvents " + json.dumps(response.to_dict))
            except exceptions.MindsphereError as err:
                logger.error("Getting error for filterEvents " + err)
                return HttpResponse(
                    err,
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(
                json.dumps(response.to_dict), content_type="application/json", status=status.HTTP_200_OK
            )
    def get(self, request, **kwargs):
        """
         updating file
         route files/fileserviceupdate/<str:entity_id>/<str:path>
         param entityId - An Asset Id for which file needs to be updated.
         note Non existent/Incorrect entityId will result in MindsphereError.

         return "Successfully updated the file and file path :" + <filepath>,

         description This method internally calls method put_file of
                     FileServiceClient class. This class is available as dependency
                    in iotfileservices-<version-here>-py3-none-any.whl.
         apiEndpoint : PUT /api/iotfile/v3/files/{entityId} of iot file service.
                       service.
         apiNote Write a file.
         throws MindsphereError if an error occurs while attempting to invoke the
                                     sdk call.
        """
        logger.info("files/fileserviceupdate/<str:entity_id>/<str:path> invoked")
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":
            try:
                entity_id = kwargs.get("entity_id", "")
                path = kwargs.get("path", "")
                logger.info("Request param are- entityID: " + entity_id + " and Path: " + path)
                if_match = request.GET.get("if_match", "")
                request_object = data_generator.generate_update_file_input(entity_id, path, if_match)
                client.put_file(request_object)
                logger.info("Successfully updated the file and file path :" + request_object.filepath)
            except exceptions.MindsphereError as err:
                logger.error("Getting error for fileserviceupdate " + err)
                return HttpResponse(
                    err,
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(
                "Successfully updated the file and file path :" + request_object.filepath,
                content_type="application/json",
                status=status.HTTP_200_OK
            )
    def get(self, request, **kwargs):
        """
        delete file

        route files/fileservicedelete/<str:entity_id>/<str:path>
        param entityId - An Asset Id for which file needs to be deleted.
        note Non existent/Incorrect entityId will result in MindsphereError.
        param filepath - path of the file along with filename.
        returns "Successfully deleted the file." upon successful execution.
        description This method internally calls method delete_file of
                    FileServiceClient class. This class is available as dependency
                    in iotfileservices-<version-here>-py3-none-any.whl.
        apiEndpoint : DELETE /api/iotfile/v3/files/{entityId}/{filepath} of iot file
                       service.
        apiNote Delete a file for the specified asset (entity) and path.
        throws MindsphereError if an error occurs while attempting to invoke the
                                      sdk call.

        """
        logger.info("files/fileservicedelete/<str:entity_id>/<str:path> invoked.")
        client = sdk_util.build_sdk_client(self.__class__.__name__, request)
        if request.method == "GET":
            try:
                entity_id = kwargs.get("entity_id", "")
                path = kwargs.get("path", "")
                logger.info("Request params are- path:" + path + " entityId:" + entity_id)
                request_object = data_generator.generate_delete_file_input(entity_id, path)
                client.delete_file(request_object)
                logger.info("Successfully deleted the file.")
            except exceptions.MindsphereError as err:
                logger.error("Error while deleting file "+err)
                return HttpResponse(
                    err,
                    content_type="application/json",
                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                )
            return HttpResponse(
                "Successfully deleted the file.",
                content_type="application/json",
                status=status.HTTP_200_OK
            )