Beispiel #1
0
    def _get_subscriptions_from_nws(self, *args, **kwargs):
        """
        Search for all subscriptions by a parameter
        """
        url = "/notification/v1/subscription" #?subscriber_id=%s" % (subscriber_id)

        number_of_args = len(kwargs)
        if number_of_args > 0:
            url += '?'
            for k,v in kwargs.iteritems():
                if k is not None and v is not None:
                    url += k + '=' + v
                    if number_of_args > 1:
                        url += '&'
                    number_of_args -= 1

        dao = NWS_DAO()
        response = dao.getURL(url, {"Accept": "application/json"})

        if response.status != 200:
            raise DataFailureException(url, response.status, response.data)

        subscriptions = SubscriptionList()
        Serializer().deserialize(subscriptions, response.data)

        return subscriptions.view_models
Beispiel #2
0
    def get_person_by_uwregid(self, uwregid):
        url = "/notification/v1/person/%s" % (uwregid)

        dao = NWS_DAO()
        response = dao.getURL(url, {"Accept": "application/json"})

        if response.status != 200:
            raise DataFailureException(url, response.status, response.data)

        person = Person()
        Serializer().deserialize(person, response.data)
        return person
Beispiel #3
0
    def get_person_by_surrogate_id(self, surrogate_id):
        #Validate input
        self._validate_subscriber_id(surrogate_id)

        url = "/notification/v1/person/%s" % (surrogate_id)

        dao = NWS_DAO()
        response = dao.getURL(url, {"Accept": "application/json"})

        if response.status != 200:
            raise DataFailureException(url, response.status, response.data)

        person = Person()
        Serializer().deserialize(person, response.data)
        return person
Beispiel #4
0
    def get_channels(self, first_result = 1, max_results = 10):
        """
        Search for all channels
        """
        url = "/notification/v1/channel?first_result=%s&max_results=%s" % (first_result, max_results)

        dao = NWS_DAO()
        response = dao.getURL(url, {"Accept": "application/json"})

        if response.status != 200:
            raise DataFailureException(url, response.status, response.data)

        channel_list = ChannelList()
        Serializer().deserialize(channel_list, response.data)

        return channel_list.view_models
Beispiel #5
0
    def get_channels_by_sln_year_quarter(self, channel_type, sln, year, quarter):
        """
        Search for all channels by sln, year and quarter
        """
        url = "/notification/v1/channel?type=%s&tag_sln=%s&tag_year=%s&tag_quarter=%s" % (channel_type, sln, year, quarter)

        dao = NWS_DAO()
        response = dao.getURL(url, {"Accept": "application/json"})

        if response.status != 200:
            raise DataFailureException(url, response.status, response.data)

        channel_list = ChannelList()
        Serializer().deserialize(channel_list, response.data)

        return channel_list.view_models
Beispiel #6
0
    def get_channel_by_surrogate_id(self, channel_type, surrogate_id):
        """
        Get a channel by surrogate id
        """
        key = "%s|%s" % (channel_type, surrogate_id)
        url = "/notification/v1/channel/%s" % (quote(key))

        dao = NWS_DAO()
        response = dao.getURL(url, {"Accept": "application/json"})

        if response.status != 200:
            raise DataFailureException(url, response.status, response.data)

        channel = Channel()
        Serializer().deserialize(channel, response.data)

        return channel
Beispiel #7
0
    def get_channel_by_channel_id(self, channel_id):
        """
        Get a channel by channel id
        """
        #Validate the channel_id
        self._validate_uuid(channel_id)

        url = "/notification/v1/channel/%s" % (channel_id)

        dao = NWS_DAO()
        response = dao.getURL(url, {"Accept": "application/json"})

        if response.status != 200:
            raise DataFailureException(url, response.status, response.data)

        channel = Channel()
        Serializer().deserialize(channel, response.data)

        return channel
Beispiel #8
0
    def get_endpoint_by_endpoint_id(self, endpoint_id):
        """
        Get an endpoint by endpoint id
        """
        #Validate the channel_id
        self._validate_uuid(endpoint_id)

        url = "/notification/v1/endpoint/%s" % (endpoint_id)

        dao = NWS_DAO()
        response = dao.getURL(url, {"Accept": "application/json"})

        if response.status != 200:
            raise DataFailureException(url, response.status, response.data)

        endpoint = Endpoint()
        Serializer().deserialize(endpoint, response.data)

        return endpoint
Beispiel #9
0
    def get_endpoints_by_subscriber_id(self, subscriber_id):
        """
        Search for all endpoints by a given subscriber
        """
        #Validate input
        self._validate_subscriber_id(subscriber_id)

        url = "/notification/v1/endpoint?subscriber_id=%s" % (subscriber_id)

        dao = NWS_DAO()
        response = dao.getURL(url, {"Accept": "application/json"})

        if response.status != 200:
            raise DataFailureException(url, response.status, response.data)

        endpoint_list = EndpointList()
        Serializer().deserialize(endpoint_list, response.data)

        return endpoint_list.view_models
Beispiel #10
0
    def term_has_active_channel(self, channel_type, term):
        """
        Checks to see if there exists a channel for the given sws.Term object's
        year and quarter.
        """
        #Sets now to midnight of current day to allow for caching
        now = datetime.combine(datetime.utcnow().date(), time.min).isoformat()

        dao = NWS_DAO()
        url = "/notification/v1/channel?tag_year=%s&tag_quarter=%s&max_results=1&expires_after=%s" % (term.year, term.quarter, now)
        response = dao.getURL(url, {"Accept": "application/json"})
        if response.status != 200:
            return False

        data = json.loads(response.data)
        if "TotalCount" in data:
            if data["TotalCount"] > 0:
                return True

        return False
Beispiel #11
0
    def get_endpoint_by_address(self, endpoint_address):
        """
        Get an endpoint by address
        """

        url = "/notification/v1/endpoint?endpoint_address=%s" % endpoint_address

        dao = NWS_DAO()
        response = dao.getURL(url, {"Accept": "application/json"})

        if response.status != 200:

            raise DataFailureException(url, response.status, response.data)

        endpoint_list = EndpointList()
        Serializer().deserialize(endpoint_list, response.data)

        endpoint_vms = endpoint_list.view_models
        if len(endpoint_vms) == 0:
            raise DataFailureException(url, 404, {"Message": "No endpoint found"})

        endpoint = endpoint_vms[0]
        return endpoint
Beispiel #12
0
    def get_endpoint_by_subscriber_id_and_protocol(self, subscriber_id, protocol):
        """
        Get an endpoint by subscriber_id and protocol
        """
        self._validate_subscriber_id(subscriber_id)

        url = "/notification/v1/endpoint?subscriber_id=%s&protocol=%s" % (subscriber_id, protocol)

        dao = NWS_DAO()
        response = dao.getURL(url, {"Accept": "application/json"})

        if response.status != 200:
            raise DataFailureException(url, response.status, response.data)

        endpoint_list = EndpointList()
        Serializer().deserialize(endpoint_list, response.data)

        endpoint_vms = endpoint_list.view_models
        if len(endpoint_vms) == 0:
            raise DataFailureException(url, 404, {"Message": "No SMS endpoint found"})

        endpoint = endpoint_vms[0]
        return endpoint