# coding: utf-8

"""
    RDF4J API

    No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)  # noqa: E501

    OpenAPI spec version: 2.0
    
    Generated by: https://github.com/swagger-api/swagger-codegen.git
"""


from __future__ import absolute_import

import re  # noqa: F401

# python 2 and python 3 compatibility library
import six

from graphdb.rdf4j.api_client import ApiClient


class TransactionsApi(object):
    """NOTE: This class is auto generated by the swagger code generator program.

    Do not edit the class manually.
    Ref: https://github.com/swagger-api/swagger-codegen
    """

    def __init__(self, api_client=None):
        if api_client is None:
            api_client = ApiClient()
        self.api_client = api_client

    def execute_transaction_action(self, repository_id, transaction_id, action, **kwargs):  # noqa: E501
        """Execute a transaction action  # noqa: E501

        Execute a transaction action.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.execute_transaction_action(repository_id, transaction_id, action, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str repository_id: The repository ID (required)
        :param str transaction_id: The transaction ID (required)
        :param str action: Type of possible actions in a transaction (required)
        :param str subj: Restricts the operation to statements with the specified N-Triples encoded resource as subject.
        :param str pred: Restricts the operation to statements with the specified N-Triples encoded resource as predicate.
        :param str obj: Restricts the operation to statements with the specified N-Triples encoded resource as object.
        :param str context: Restricts the operation to statements with the specified N-Triples encoded resource as context.
        :param str query_ln: Specifies the query language that is used for the query. Acceptable values are strings denoting the query languages supported by the server, i.e. 'serql' for SeRQL queries and 'sparql' for SPARQL queries. If not specified, the server assumes the query is a SPARQL query.
        :param bool infer: Specifies whether inferred statements should be included in the query evaluation. Inferred statements are included by default. Specifying any value other than 'true' (ignoring case) restricts the query evluation to explicit statements only.
        :param str update: Specifies the Update operation to be executed. The value is expected to be a syntactically valid SPARQL 1.1 Update string.
        :param str base_uri: Specifies a base IRI to be used when parsing the SPARQL update operation.
        :param str using_graph_uri: One or more named graph IRIs to be used as the default graph(s) for retrieving statements.
        :param str using_named_graph_uri: One or more named graph IRIs to be used as named graphs for retrieving statements.
        :param str remove_graph_uri: One or more named graph IRIs to be used as the default graph(s) for removing statements.
        :param str insert_graph_uri: One or more named graph IRIs to be used as the default graph(s) for inserting statements.
        :param str rdf_dataquery: A parsable RDF document or a query to evaluate; rdf-data is used for the ADD and DELETE actions, query - for the QUERY action.
        :return: int
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.execute_transaction_action_with_http_info(repository_id, transaction_id, action, **kwargs)  # noqa: E501
        else:
            (data) = self.execute_transaction_action_with_http_info(repository_id, transaction_id, action, **kwargs)  # noqa: E501
            return data

    def execute_transaction_action_with_http_info(self, repository_id, transaction_id, action, **kwargs):  # noqa: E501
        """Execute a transaction action  # noqa: E501

        Execute a transaction action.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.execute_transaction_action_with_http_info(repository_id, transaction_id, action, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str repository_id: The repository ID (required)
        :param str transaction_id: The transaction ID (required)
        :param str action: Type of possible actions in a transaction (required)
        :param str subj: Restricts the operation to statements with the specified N-Triples encoded resource as subject.
        :param str pred: Restricts the operation to statements with the specified N-Triples encoded resource as predicate.
        :param str obj: Restricts the operation to statements with the specified N-Triples encoded resource as object.
        :param str context: Restricts the operation to statements with the specified N-Triples encoded resource as context.
        :param str query_ln: Specifies the query language that is used for the query. Acceptable values are strings denoting the query languages supported by the server, i.e. 'serql' for SeRQL queries and 'sparql' for SPARQL queries. If not specified, the server assumes the query is a SPARQL query.
        :param bool infer: Specifies whether inferred statements should be included in the query evaluation. Inferred statements are included by default. Specifying any value other than 'true' (ignoring case) restricts the query evluation to explicit statements only.
        :param str update: Specifies the Update operation to be executed. The value is expected to be a syntactically valid SPARQL 1.1 Update string.
        :param str base_uri: Specifies a base IRI to be used when parsing the SPARQL update operation.
        :param str using_graph_uri: One or more named graph IRIs to be used as the default graph(s) for retrieving statements.
        :param str using_named_graph_uri: One or more named graph IRIs to be used as named graphs for retrieving statements.
        :param str remove_graph_uri: One or more named graph IRIs to be used as the default graph(s) for removing statements.
        :param str insert_graph_uri: One or more named graph IRIs to be used as the default graph(s) for inserting statements.
        :param str rdf_dataquery: A parsable RDF document or a query to evaluate; rdf-data is used for the ADD and DELETE actions, query - for the QUERY action.
        :return: int
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['repository_id', 'transaction_id', 'action', 'subj', 'pred', 'obj', 'context', 'query_ln', 'infer', 'update', 'base_uri', 'using_graph_uri', 'using_named_graph_uri', 'remove_graph_uri', 'insert_graph_uri', 'rdf_dataquery']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method execute_transaction_action" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'repository_id' is set
        if self.api_client.client_side_validation and ('repository_id' not in params or
                                                       params['repository_id'] is None):  # noqa: E501
            raise ValueError("Missing the required parameter `repository_id` when calling `execute_transaction_action`")  # noqa: E501
        # verify the required parameter 'transaction_id' is set
        if self.api_client.client_side_validation and ('transaction_id' not in params or
                                                       params['transaction_id'] is None):  # noqa: E501
            raise ValueError("Missing the required parameter `transaction_id` when calling `execute_transaction_action`")  # noqa: E501
        # verify the required parameter 'action' is set
        if self.api_client.client_side_validation and ('action' not in params or
                                                       params['action'] is None):  # noqa: E501
            raise ValueError("Missing the required parameter `action` when calling `execute_transaction_action`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'repository_id' in params:
            path_params['repositoryID'] = params['repository_id']  # noqa: E501
        if 'transaction_id' in params:
            path_params['transactionID'] = params['transaction_id']  # noqa: E501

        query_params = []
        if 'action' in params:
            query_params.append(('action', params['action']))  # noqa: E501
        if 'subj' in params:
            query_params.append(('subj', params['subj']))  # noqa: E501
        if 'pred' in params:
            query_params.append(('pred', params['pred']))  # noqa: E501
        if 'obj' in params:
            query_params.append(('obj', params['obj']))  # noqa: E501
        if 'context' in params:
            query_params.append(('context', params['context']))  # noqa: E501
        if 'query_ln' in params:
            query_params.append(('queryLn', params['query_ln']))  # noqa: E501
        if 'infer' in params:
            query_params.append(('infer', params['infer']))  # noqa: E501
        if 'update' in params:
            query_params.append(('update', params['update']))  # noqa: E501
        if 'base_uri' in params:
            query_params.append(('baseURI', params['base_uri']))  # noqa: E501
        if 'using_graph_uri' in params:
            query_params.append(('using-graph-uri', params['using_graph_uri']))  # noqa: E501
        if 'using_named_graph_uri' in params:
            query_params.append(('using-named-graph-uri', params['using_named_graph_uri']))  # noqa: E501
        if 'remove_graph_uri' in params:
            query_params.append(('remove-graph-uri', params['remove_graph_uri']))  # noqa: E501
        if 'insert_graph_uri' in params:
            query_params.append(('insert-graph-uri', params['insert_graph_uri']))  # noqa: E501

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        if 'rdf_dataquery' in params:
            body_params = params['rdf_dataquery']
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/rdf+xml', 'application/sparql-results+json', 'application/sparql-results+xml', 'application/x-binary-rdf-results-table'])  # noqa: E501

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.select_header_content_type(  # noqa: E501
            ['application/rdf+xml', 'text/plain', 'text/turtle', 'text/rdf+n3', 'text/x-nquads', 'application/ld+json', 'application/rdf+json', 'application/trix', 'application/x-trig', 'application/x-binary-rdf', 'application/sparql-query'])  # noqa: E501

        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/repositories/{repositoryID}/transactions/{transactionID}', 'PUT',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='int',  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)

    def rollback_transaction(self, repository_id, transaction_id, **kwargs):  # noqa: E501
        """Abort a transaction  # noqa: E501

        An active transaction can be aborted by means of a HTTP DELETE request on the transaction resource. This will execute a transaction rollback on the repository and will close the transacion. After executing a DELETE, further operations on the same transaction will result in an error.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.rollback_transaction(repository_id, transaction_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str repository_id: The repository ID (required)
        :param str transaction_id: The transaction ID (required)
        :return: int
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.rollback_transaction_with_http_info(repository_id, transaction_id, **kwargs)  # noqa: E501
        else:
            (data) = self.rollback_transaction_with_http_info(repository_id, transaction_id, **kwargs)  # noqa: E501
            return data

    def rollback_transaction_with_http_info(self, repository_id, transaction_id, **kwargs):  # noqa: E501
        """Abort a transaction  # noqa: E501

        An active transaction can be aborted by means of a HTTP DELETE request on the transaction resource. This will execute a transaction rollback on the repository and will close the transacion. After executing a DELETE, further operations on the same transaction will result in an error.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.rollback_transaction_with_http_info(repository_id, transaction_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str repository_id: The repository ID (required)
        :param str transaction_id: The transaction ID (required)
        :return: int
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['repository_id', 'transaction_id']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method rollback_transaction" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'repository_id' is set
        if self.api_client.client_side_validation and ('repository_id' not in params or
                                                       params['repository_id'] is None):  # noqa: E501
            raise ValueError("Missing the required parameter `repository_id` when calling `rollback_transaction`")  # noqa: E501
        # verify the required parameter 'transaction_id' is set
        if self.api_client.client_side_validation and ('transaction_id' not in params or
                                                       params['transaction_id'] is None):  # noqa: E501
            raise ValueError("Missing the required parameter `transaction_id` when calling `rollback_transaction`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'repository_id' in params:
            path_params['repositoryID'] = params['repository_id']  # noqa: E501
        if 'transaction_id' in params:
            path_params['transactionID'] = params['transaction_id']  # noqa: E501

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/repositories/{repositoryID}/transactions/{transactionID}', 'DELETE',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='int',  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)

    def start_new_transaction(self, repository_id, **kwargs):  # noqa: E501
        """Start a new transaction  # noqa: E501

        Start a new transaction.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.start_new_transaction(repository_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str repository_id: The repository ID (required)
        :return: int
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.start_new_transaction_with_http_info(repository_id, **kwargs)  # noqa: E501
        else:
            (data) = self.start_new_transaction_with_http_info(repository_id, **kwargs)  # noqa: E501
            return data

    def start_new_transaction_with_http_info(self, repository_id, **kwargs):  # noqa: E501
        """Start a new transaction  # noqa: E501

        Start a new transaction.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.start_new_transaction_with_http_info(repository_id, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str repository_id: The repository ID (required)
        :return: int
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['repository_id']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method start_new_transaction" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'repository_id' is set
        if self.api_client.client_side_validation and ('repository_id' not in params or
                                                       params['repository_id'] is None):  # noqa: E501
            raise ValueError("Missing the required parameter `repository_id` when calling `start_new_transaction`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'repository_id' in params:
            path_params['repositoryID'] = params['repository_id']  # noqa: E501

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/repositories/{repositoryID}/transactions', 'POST',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='int',  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)
