Skip to content
requests.py 61.4 KiB
Newer Older
                case _:
                    raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are "
                                    f"'{expected_parameters}', but received: {kwargs}")

        return response

    @staticmethod
    def delete_entity_by_id_returning_response(kwargs) -> str:
        if 'id' in kwargs:
            return f"Delete Entity Request with id set to '{kwargs['id']}'"

lopezaguilar's avatar
lopezaguilar committed
    @staticmethod
    def delete_subscription(kwargs) -> str:
        if 'id' in kwargs:
            return f"Delete Subscription with id set to '{kwargs['id']}'"

    @staticmethod
    def query_subscriptions(kwargs) -> str:
        expected_parameters = ['context', 'limit', 'offset', 'accept']

        result = [x for x in kwargs if x not in expected_parameters]
        response = 'Query Subscription Request with data:'
        for key, value in kwargs.items():
            match key:
                case 'context':
                    response = f"{response} and\n    Query Parameter: context set to '{value}'"
                case 'limit':
                    response = f"{response} and\n    Query Parameter: limit set to '{value}'"
                case 'offset':
                    response = f"{response} and\n    Query Parameter: offset set to '{value}'"
                case 'accept':
                    response = f"{response} and\n    Query Parameter: accept set to '{value}'"
                # If an exact match is not confirmed, this last case will be used if provided
                case _:
                    raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are "
                                    f"'{expected_parameters}', but received: {kwargs}")

        return response

lopezaguilar's avatar
lopezaguilar committed
    @staticmethod
    def retrieve_context_source_registration_subscription(kwargs) -> str:
        expected_parameters = ['subscription_id', 'context', 'accept']

        result = [x for x in kwargs if x not in expected_parameters]
        response = 'Retrieve Context Source Registration Subscription with data:'
        for key, value in kwargs.items():
            match key:
                case 'subscription_id':
                    response = f"{response} and\n    Query Parameter: subscription id set to '{value}'"
                case 'context':
                    response = f"{response} and\n    Query Parameter: context set to '{value}'"
                case 'accept':
                    response = f"{response} and\n    Query Parameter: accept set to '{value}'"
                # If an exact match is not confirmed, this last case will be used if provided
                case _:
                    raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are "
                                    f"'{expected_parameters}', but received: {kwargs}")

        return response

    @staticmethod
    def delete_context_source_registration_with_return(kwargs) -> str:
        if 'id' in kwargs:
            return f"Delete Context Source Registration with id set to '{kwargs['id']}'"

    @staticmethod
    def update_context_source_registration_subscription(kwargs) -> str:
        if 'subscription_id' in kwargs and 'subscription_update_fragment' in kwargs:
            return (f"Update Context Source Registration Subscription "
                    f"with subscription id set to '{kwargs['subscription_id']}' and "
                    f"subscription update fragment set to '{kwargs['subscription_update_fragment']}'")
        else:
            raise Exception(f"ERROR, expected 'subscription_id' and 'subscription_update_fragment' but received: {kwargs}")

    @staticmethod
    def update_context_source_registration_subscription_from_file(kwargs) -> str:
        if 'subscription_id' in kwargs and 'subscription_update_fragment' in kwargs:
            return (f"Update Context Source Registration Subscription from file "
                    f"with subscription id set to '{kwargs['subscription_id']}' and "
                    f"subscription update fragment set to '{kwargs['subscription_update_fragment']}'")
        else:
            raise Exception(f"ERROR, expected 'subscription_id' and 'subscription_update_fragment' but received: {kwargs}")

    @staticmethod
    def retrieve_context_source_registration(kwargs) -> str:
        expected_parameters = ['context_source_registration_id', 'context', 'accept']

        result = [x for x in kwargs if x not in expected_parameters]
        response = 'Retrieve Context Source Registration with data:'
        for key, value in kwargs.items():
            match key:
                case 'context_source_registration_id':
                    response = f"{response} and\n    Query Parameter: context source registration id set to '{value}'"
                case 'context':
                    response = f"{response} and\n    Query Parameter: context set to '{value}'"
                case 'accept':
                    response = f"{response} and\n    Query Parameter: accept set to '{value}'"
                # If an exact match is not confirmed, this last case will be used if provided
                case _:
                    raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are "
                                    f"'{expected_parameters}', but received: {kwargs}")

        return response

    @staticmethod
    def query_context_source_registrations(kwargs) -> str:
        expected_parameters = ['context', 'id', 'type', 'attrs',
                               'q', 'csf', 'georel', 'geometry',
                               'coordinates', 'geoproperty', 'timeproperty', 'timerel',
                               'timeAt', 'limit', 'page', 'accept']

        result = [x for x in kwargs if x not in expected_parameters]
        response = "Retrieve Temporal Representation of Entity"
        for key, value in kwargs.items():
            match key:
                case 'context':
                    response = f"{response} and\n    Query Parameter: context set to '{value}'"
                case 'id':
                    response = f"{response} and\n    Query Parameter: id set to '{value}'"
                case 'type':
                    response = f"{response} and\n    Query Parameter: type set to '{value}'"
                case 'attrs':
                    response = f"{response} and\n    Query Parameter: attrs set to '{value}'"
                case 'q':
                    response = f"{response} and\n    Query Parameter: q set to '{value}'"
                case 'csf':
                    response = f"{response} and\n    Query Parameter: csf set to '{value}'"
                case 'georel':
                    response = f"{response} and\n    Query Parameter: georel set to '{value}'"
                case 'geometry':
                    response = f"{response} and\n    Query Parameter: geometry set to '{value}'"
                case 'coordinates':
                    response = f"{response} and\n    Query Parameter: coordinates set to '{value}'"
                case 'geoproperty':
                    response = f"{response} and\n    Query Parameter: geoproperty set to '{value}'"
                case 'timeproperty':
                    response = f"{response} and\n    Query Parameter: timeproperty set to '{value}'"
                case 'timerel':
                    response = f"{response} and\n    Query Parameter: timerel set to '{value}'"
                case 'timeAt':
                    response = f"{response} and\n    Query Parameter: timeAt set to '{value}'"
                case 'limit':
                    response = f"{response} and\n    Query Parameter: limit set to '{value}'"
                case 'page':
                    response = f"{response} and\n    Query Parameter: page set to '{value}'"
                case 'accept':
                    response = f"{response} and\n    Query Parameter: accept set to '{value}'"
                # If an exact match is not confirmed, this last case will be used if provided
                case _:
                    raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are "
                                    f"'{expected_parameters}', but received: {kwargs}")

        return response

    @staticmethod
    def update_context_source_registration_with_return(kwargs) -> str:
        if 'id' in kwargs and 'filename' in kwargs and 'content' in kwargs:
            return (f"Update Context Source Registration with id set to '{kwargs['id']}' "
                    f"and registration update fragment set to '{kwargs['filename']}' "
                    f"and content-type set to '{kwargs['content']}'")

lopezaguilar's avatar
lopezaguilar committed
    @staticmethod
    def delete_temporal_representation_of_entity_with_returning_response(kwargs) -> str:
        if 'id' in kwargs:
            return f"Delete Temporal Representation Of Entity With Returning Response with id set to '{kwargs['id']}'"

lopezaguilar's avatar
lopezaguilar committed
    @staticmethod
    def retrieve_context_source_registration_subscription_2(kwargs) -> str:
        if 'id' in kwargs:
            return f"Retrieve Context Source Registration Subscription with id set to '{kwargs['id']}'"
        else:
            raise Exception(f"ERROR, expected 'id' but received: '{kwargs}'")

    @staticmethod
    def delete_context_source_registration_subscription(kwargs) -> str:
        if 'id' in kwargs:
            return f"Delete Context Source Registration Subscription with id set to '{kwargs['id']}'"
        else:
            raise Exception(f"ERROR, expected 'id' but received: '{kwargs}'")

    @staticmethod
    def create_context_source_registration_subscription(kwargs) -> str:
        if 'filename' in kwargs:
lopezaguilar's avatar
lopezaguilar committed
            return (f"Create Context Source Registration Subscription with filename set to '{kwargs['filename']}', "
                    f"accept set to '${{EMPTY}}', and content-type set to 'application/ld+json'")
lopezaguilar's avatar
lopezaguilar committed
        else:
            raise Exception(f"ERROR, expected 'filename' but received: '{kwargs}'")

lopezaguilar's avatar
lopezaguilar committed
    @staticmethod
    def append_attribute_to_temporal_entity(kwargs) -> str:
        expected_parameters = ['id', 'fragment_filename', 'content_type']

        result = [x for x in kwargs if x not in expected_parameters]
        response = 'Append Attribute to Temporal Entity'
        for key, value in kwargs.items():
            match key:
                case 'id':
                    response = f"{response} and\n    Query Parameter: id set to '{value}'"
                case 'fragment_filename':
                    response = f"{response} and\n    Query Parameter: fragment_filename set to '{value}'"
                case 'content_type':
                    response = f"{response} and\n    Query Parameter: content_type set to '{value}'"
                # If an exact match is not confirmed, this last case will be used if provided
                case _:
                    raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are "
                                    f"'{expected_parameters}', but received: {kwargs}")

        return response

lopezaguilar's avatar
lopezaguilar committed
    @staticmethod
    def append_entity_attributes(kwargs) -> str:
        expected_parameters = ['id', 'fragment_filename', 'content_type']

        result = [x for x in kwargs if x not in expected_parameters]
        response = 'Append Entity Attributes'
        for key, value in kwargs.items():
            match key:
                case 'id':
                    response = f"{response} and\n    Query Parameter: id set to '{value}'"
                case 'fragment_filename':
                    response = f"{response} and\n    Query Parameter: fragment_filename set to '{value}'"
                case 'content_type':
                    response = f"{response} and\n    Query Parameter: content_type set to '{value}'"
                # If an exact match is not confirmed, this last case will be used if provided
                case _:
                    raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are "
                                    f"'{expected_parameters}', but received: {kwargs}")

        return response

    @staticmethod
    def update_entity_attributes(kwargs) -> str:
        expected_parameters = ['id', 'fragment_filename', 'content_type']

        result = [x for x in kwargs if x not in expected_parameters]
        response = 'Update Entity Attributes'
        for key, value in kwargs.items():
            match key:
                case 'id':
                    response = f"{response} and\n    Query Parameter: id set to '{value}'"
                case 'fragment_filename':
                    response = f"{response} and\n    Query Parameter: fragment_filename set to '{value}'"
                case 'content_type':
                    response = f"{response} and\n    Query Parameter: content_type set to '{value}'"
                # If an exact match is not confirmed, this last case will be used if provided
                case _:
                    raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are "
                                    f"'{expected_parameters}', but received: {kwargs}")

        return response

    def get_value(self, params, param_position, param_key):
        data = [x for x in params if f'{param_key}=' in x]
        if len(data) == 1:
            # The name of the attribute is passed to the function in the form attribute=value
            data = data[0]
            data = data.split('=')
            if data[0] != param_key:
        elif len(data) == 0:
            # There is no attribute=something therefore we have to apply the position
            try:
                data = params[param_position]

                # Workaround
                if 'accept' in data and param_key != 'accept':
                    data = ''
            except IndexError:
                return ''
        return self.get_value_simple(data=data)

    def get_value_simple(self, data):
            value = self.variables[data]
            return value
        except KeyError:
            try:
                value = self.apiutils_variables[data]
                return value
            except KeyError:
                try:
                    value = self.config_file.get_variable(variable=data)
                    return value
                except KeyError:
lopezaguilar's avatar
lopezaguilar committed
                    try:
                        aux = self.template_params_value[self.name]
                        value = aux[data]
                        return value
                    except KeyError:
                        return data