Exemple #1
0
    def terminate(self, terminate: Terminate):
        try:
            self._logger.info(
                "Terminate: Request for Referenceid: {} and programcode {}".
                format(terminate.referenceid, terminate.programcode),
                extra={
                    "programcode": terminate.programcode,
                    "referenceid": terminate.referenceid,
                    "action": "Terminate",
                },
            )

            client = retrieve_zeepclient(
                self._config.base_url,
                super()._localstore,
                self._config.wsdl,
                self._config.root_cert,
            )
            payload = {"reference-id": terminate.referenceid}

            response = client.service.terminate(**payload)
            if (isnotnull_whitespaceorempty(response)
                    and isnotnull_whitespaceorempty(response["result-code"])
                    and response["result-msg"] is not None):
                terminate.response_referenceid = response["reference-id"]
                terminate.status = internalstatus_conversion(
                    response["result-code"], response["result-msg"])
                terminate.responsemessage = response["result-msg"]
                self._logger.info(
                    "Terminate: Response for referenceid:{} status:{} message:{} programcode:{}"
                    .format(
                        terminate.referenceid,
                        response["result-code"],
                        terminate.responsemessage,
                        terminate.programcode,
                    ),
                    extra={
                        "programcode": terminate.programcode,
                        "referenceid": terminate.referenceid,
                        "action": "Terminate",
                    },
                )

                if terminate.status.casefold(
                ) == InternalStatusType.SUCCESS.casefold():
                    return True
        except Exception as e:
            self._logger.error(
                "Terminate: Gateway error: SiriusXm: Error Occured: {}".format(
                    e),
                exc_info=True,
                stack_info=True,
                extra={
                    "programcode": terminate.programcode,
                    "referenceid": terminate.referenceid,
                    "action": "Terminate",
                },
            )
            terminate.responsemessage = e

        return False
Exemple #2
0
def serviceerror_conversion(responsemessage: str):
    if (isnotnull_whitespaceorempty(responsemessage) and
        ("No reference id found").casefold() in responsemessage.casefold()):
        return InternalStatusType.NOTFOUND

    return InternalStatusType.INTERNALSERVERERROR
Exemple #3
0
    def assign_agent(self, agentassignment: AgentAssignment):
        try:
            self._logger.info(
                "AgentAssignment: Request for Referenceid: {} programcode {} ."
                .format(agentassignment.referenceid,
                        agentassignment.programcode),
                extra={
                    "programcode": agentassignment.programcode,
                    "referenceid": agentassignment.referenceid,
                    "action": "AgentAssignment",
                },
            )
            client = retrieve_zeepclient(
                self._config.base_url,
                super()._localstore,
                self._config.wsdl,
                self._config.root_cert,
            )
            agent_assignment = {
                "reference-id": agentassignment.referenceid,
                "is-assigned": agentassignment.isassigned,
            }

            response = client.service.agentAssigned(**agent_assignment)
            if (isnotnull_whitespaceorempty(response)
                    and isnotnull_whitespaceorempty(response["result-code"])
                    and response["result-msg"] is not None):
                agentassignment.response_referenceid = response["reference-id"]
                agentassignment.responsestatus = internalstatus_conversion(
                    response["result-code"], response["result-msg"])
                agentassignment.responsemessage = response["result-msg"]

                self._logger.info(
                    "AgentAssignment:Response for referenceid:{} status:{} message:{} programcode:{}"
                    .format(
                        agentassignment.referenceid,
                        response["result-code"],
                        agentassignment.responsemessage,
                        agentassignment.programcode,
                    ),
                    extra={
                        "programcode": agentassignment.programcode,
                        "referenceid": agentassignment.referenceid,
                        "action": "AgentAssignment",
                    },
                )

                if (agentassignment.responsestatus.casefold() ==
                        InternalStatusType.SUCCESS.casefold()):
                    return True
        except Exception as e:
            self._logger.error(
                "AgentAssignment: Gateway error: SiriusXm: Error Occured: {}".
                format(e),
                exc_info=True,
                stack_info=True,
                extra={
                    "programcode": agentassignment.programcode,
                    "referenceid": agentassignment.referenceid,
                    "action": "AgentAssignment",
                },
            )
            agentassignment.responsemessage = e

        return False
Exemple #4
0
def test_is_not_nullorempty_on_different_value_returns_as_expected(
        input, expected):
    assert isnotnull_whitespaceorempty(input) == expected
Exemple #5
0
def get_vehicledata_for_config_enabled_client_only(
    self, id: str, programcode: ProgramCode, ctsversion: CtsVersion
):
    try:
        self._logger.info(
            "GetVehicleData: Read Vehicle data from DynamoDB for id: {} programcode: {}".format(
                id, programcode
            ),
            extra={
                "programcode": programcode,
                "id": id,
                "action": "GetVehicleData",
                "cts-version": ctsversion,
            },
        )
        dynamodb_check_timelimit = (
            self._config.dynamodb_check_timelimit
            if isnotnull_whitespaceorempty(self._config.dynamodb_check_timelimit)
            else 0
        )
        if (
            self._config.dynamodb_check_enable
            and dynamodb_check_timelimit > 0
            and isnotnull_whitespaceorempty(id)
        ):
            # Query for Items Matching current timestamp within given time limit and Partition/Sort Key in descending order
            for dataresponse in self._Table.query(
                hash_key=programcode + "-" + id,
                range_key_condition=self._Table.event_datetime.between(
                    convert_utc_timestamp_to_epoch(
                        datetime.utcnow() - timedelta(minutes=dynamodb_check_timelimit)
                    ),
                    get_utc_epoch(),
                ),
                scan_index_forward=False,
                limit=1,
            ):
                if dataresponse:
                    self._logger.info(
                        "GetVehicleData: Successfully retrieved vehicle data from DynamoDB for id: {} programcode: {}".format(
                            id, programcode
                        ),
                        extra={
                            "programcode": programcode,
                            "id": id,
                            "action": "GetVehicleData",
                            "cts-version": ctsversion,
                        },
                    )
                    return dataresponse
                else:
                    return None
            return None
        return None
    except Exception as e:
        self._logger.error(
            "GetVehicleData: Error retrieving data from DynamoDB for id:{} e:{}".format(
                id, e
            ),
            exc_info=True,
            stack_info=True,
            extra={
                "id": id,
                "programcode": programcode,
                "cts-version": ctsversion,
                "action": "GetVehicleData",
            },
        )
        return None
Exemple #6
0
def map_vehicledata_response(msisdn, programcode, response_status, response):
    return VehicleData(
        msisdn=msisdn,
        status=response_status,
        programcode=programcode,
        calldate=response["CallDate"] if ("CallDate") in response
        and isnotnull_whitespaceorempty(response["CallDate"]) else "NONE",
        calltime=response["CallTime"] if ("CallTime") in response
        and isnotnull_whitespaceorempty(response["CallTime"]) else "NONE",
        event_datetime=get_utc_epoch(),
        timestamp=get_timestamp_from_calldate(
            response["CallDate"],
            response["CallTime"],
        ) if (isnotnull_whitespaceorempty(response["CallDate"] if (
            "CallDate") in response else None)
              and isnotnull_whitespaceorempty(response["CallTime"] if (
                  "CallTime") in response else None)) else datetime.now(),
        customerfirstname=response["CustomerFirstName"] if
        ("CustomerFirstName") in response and isnotnull_whitespaceorempty(
            response["CustomerFirstName"]) else "NONE",
        customerlastname=response["CustomerLastName"] if
        ("CustomerLastName") in response and isnotnull_whitespaceorempty(
            response["CustomerLastName"]) else "NONE",
        modelyear=response["VehicleYear"] if ("VehicleYear") in response
        and isnotnull_whitespaceorempty(response["VehicleYear"]) else "NONE",
        brand=response["Make"] if ("Make") in response
        and isnotnull_whitespaceorempty(response["Make"]) else "NONE",
        modelname=response["Model"] if ("Model") in response
        and isnotnull_whitespaceorempty(response["Model"]) else "NONE",
        modelcode=response["Make"] if ("Make") in response
        and isnotnull_whitespaceorempty(response["Make"]) else "NONE",
        vin=response["VIN"] if ("VIN") in response
        and isnotnull_whitespaceorempty(response["VIN"]) else "NONE",
        modelcolor=response["ExteriorColor"] if ("ExteriorColor") in response
        and isnotnull_whitespaceorempty(response["ExteriorColor"]) else "NONE",
        phonenumber=response["FromLocationPhoneNo"] if
        ("FromLocationPhoneNo") in response and isnotnull_whitespaceorempty(
            response["FromLocationPhoneNo"]) else "NONE",
        srnumber=response["SRNumber"] if ("SRNumber") in response
        and isnotnull_whitespaceorempty(response["SRNumber"]) else "NONE",
        locationaddress=response["FromLocationAddress"] if
        ("FromLocationAddress") in response and isnotnull_whitespaceorempty(
            response["FromLocationAddress"]) else "NONE",
        locationcity=response["FromLocationCity"] if
        ("FromLocationCity") in response and isnotnull_whitespaceorempty(
            response["FromLocationCity"]) else "NONE",
        locationstate=response["FromLocationState"] if
        ("FromLocationState") in response and isnotnull_whitespaceorempty(
            response["FromLocationState"]) else "NONE",
        locationpostalcode=response["FromLocationZip"] if
        ("FromLocationZip") in response and isnotnull_whitespaceorempty(
            response["FromLocationZip"]) else "NONE",
        countrycode=response["FromLocationCountry"] if
        ("FromLocationCountry") in response and isnotnull_whitespaceorempty(
            response["FromLocationCountry"]) else "NONE",
        locationconfidence=response["Location_confidence"] if
        ("Location_confidence") in response and isnotnull_whitespaceorempty(
            response["Location_confidence"]) else "NONE",
        locationtrueness=response["Location_trueness"] if
        ("Location_trueness") in response and isnotnull_whitespaceorempty(
            response["Location_trueness"]) else "NONE",
        cruisingrange=response["Cruising_range"] if
        ("Cruising_range") in response and isnotnull_whitespaceorempty(
            response["Cruising_range"]) else "NONE",
        ismoving=response["Is_moving"] if ("Is_moving") in response
        and isnotnull_whitespaceorempty(response["Is_moving"]) else False,
        latitude=response["FromLocationLatitude"] if
        ("FromLocationLatitude") in response and isnotnull_whitespaceorempty(
            response["FromLocationLatitude"]) else 0,
        longitude=response["FromLocationLongitude"] if
        ("FromLocationLongitude") in response and isnotnull_whitespaceorempty(
            response["FromLocationLongitude"]) else 0,
        altitude=response["Altitude"] if ("Altitude") in response
        and isnotnull_whitespaceorempty(response["Altitude"]) else "NONE",
        headingdirection=response["Direction_heading"] if
        ("Direction_heading") in response and isnotnull_whitespaceorempty(
            response["Direction_heading"]) else "NONE",
        language=response["Hmi_language"] if ("Hmi_language") in response
        and isnotnull_whitespaceorempty(response["Hmi_language"]) else "NONE",
        responsemessage="Successfully retrieved",
    )
Exemple #7
0
    def get_vehicledata(self, msisdn: str, programcode: ProgramCode):
        try:
            self._logger.info(
                "GetVehicleData: Payload received for msisdn: {} programcode: {}"
                .format(msisdn, programcode),
                extra={
                    "msisdn": msisdn,
                    "programcode": programcode,
                    "cts-version": CtsVersion.ONE_DOT_ZERO,
                    "action": "GetVehicleData",
                },
            )

            dataresponse = None
            # check and get data from database based of db check flag
            if self._config.dynamodb_check_enable:
                dataresponse = get_data_from_database(self, msisdn,
                                                      programcode,
                                                      CtsVersion.ONE_DOT_ZERO)

            if dataresponse is not None:
                return dataresponse
            else:
                client = retrieve_zeepclient(
                    self._config.base_url,
                    super()._localstore,
                    self._config.wsdl,
                    self._config.root_cert,
                )

                vehicle_locationrequest = {
                    "Header": {
                        "SourceName": "",
                        # Optional
                        "TargetName": "",
                        "TransactionId": "",
                        "Timestamp": datetime.now(),
                    },
                    # Optional
                    "CTIInteractionID": "",
                    "MDN": msisdn,
                }
                with client.settings(raw_response=True):
                    fullresponse = client.service.RequestVehicleLocation(
                        **vehicle_locationrequest)

                    operation = client.service._binding._operations[
                        "RequestVehicleLocation"]

                    response = client.service._binding.process_reply(
                        client, operation, fullresponse)
                    headerresponse = get_additionaldata_from_header(
                        self, fullresponse, msisdn, programcode)

                response_status = InternalStatusType.INTERNALSERVERERROR
                if (isnotnull_whitespaceorempty(response)
                        and ("Response") in response
                        and ("ResponseStatus") in response["Response"]
                        and response["Response"]["ResponseStatus"] is not None
                        and ("ResponseDescription") in response["Response"]
                        and response["Response"]["ResponseDescription"]
                        is not None):
                    response_status = internalstatus_conversion(
                        response["Response"]["ResponseStatus"],
                        response["Response"]["ResponseDescription"],
                    )

                    if response_status == InternalStatusType.SUCCESS:
                        self._logger.info(
                            "GetVehicleData: Successfully received response from external SOAP call for msisdn:{} status:{} programcode:{} response_payload:{}"
                            .format(msisdn, Status.SUCCESS, programcode,
                                    response),
                            extra={
                                "msisdn": msisdn,
                                "programcode": programcode,
                                "cts-version": CtsVersion.ONE_DOT_ZERO,
                                "action": "GetVehicleData",
                            },
                        )

                        # Map vehicle data success response using external call response
                        vehicledata = map_vehicledata_response(
                            msisdn, programcode, response_status, response)

                        # Save the data in dynamodb for audit and return the model on success
                        self.save_vehicledata(msisdn, programcode, vehicledata,
                                              headerresponse)

                        return vehicledata

            self._logger.error(
                "GetVehicleData: Error occurred in external SOAP call for msisdn: {} programcode: {} status: {} error_response_payload: {}"
                .format(msisdn, programcode, response_status, response),
                exc_info=True,
                stack_info=True,
                extra={
                    "msisdn": msisdn,
                    "programcode": programcode,
                    "cts-version": CtsVersion.ONE_DOT_ZERO,
                    "action": "GetVehicleData",
                },
            )

            return VehicleData(
                msisdn=msisdn,
                status=response_status,
                responsemessage="{status}{description}".format(
                    status=response["Response"]["ResponseStatus"],
                    description=", {} ".format(
                        response["Response"]["ResponseDescription"]),
                ),
            )

        except Exception as e:
            self._logger.error(
                "GetVehicleData: Gateway error: External Verizon : Error Occured: {} for msisdn: {} programcode: {}"
                .format(e, msisdn, programcode),
                exc_info=True,
                stack_info=True,
                extra={
                    "msisdn": msisdn,
                    "programcode": programcode,
                    "cts-version": CtsVersion.ONE_DOT_ZERO,
                    "action": "GetVehicleData",
                },
            )

            return VehicleData(
                status=InternalStatusType.INTERNALSERVERERROR,
                responsemessage=e.args[0] if e.args.__len__() > 0 else None,
            )