<commit_before># -*- coding: utf-8 -*-

# Copyright 2015 Telefonica Investigación y Desarrollo, S.A.U
#
# This file is part of FIWARE project.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# See the License for the specific language governing permissions and
# limitations under the License.
#
# For those usages not covered by the Apache version 2.0 License please
# contact with <EMAIL>


from utils.rest_client_utils import RestClient, API_ROOT_URL_ARG_NAME, response_body_to_dict, \
    HEADER_CONTENT_TYPE, HEADER_REPRESENTATION_XML
from utils.logger_utils import get_logger

logger = get_logger(__name__)


#URI ELEMENT
SDC_BASE_URI = "{" + API_ROOT_URL_ARG_NAME + "}"
PRODUCTANDRELEASE_RESOURCE_ROOT_URI = SDC_BASE_URI + "/catalog/productandrelease"
PRODUCTANDRELEASE_RESOURCE_DETAIL_URI = PRODUCTANDRELEASE_RESOURCE_ROOT_URI + "/{environment_name}"

#BODY ELEMENT
PRODUCTANDRELEASE_BODY_ROOT= "productAndReleaseDtoes"

class ProductAndReleaseResourceClient(RestClient):

    def __init__(self, protocol, host, port, tenant_id, resource=None, headers=None):
        """
        Class constructor. Inits default attributes.
        :param protocol: Connection protocol (HTTP | HTTPS)
        :param host: Host
        :param port: Port
        :param tenant_id: TenantID
        :param resource: Base URI resource
        :param headers: HTTP Headers
        :return: None
        """
        if headers is None:
            self.headers = {HEADER_CONTENT_TYPE: HEADER_REPRESENTATION_XML}
        self.headers = headers
        self.tenant_id = tenant_id
        super(ProductAndReleaseResourceClient, self).__init__(protocol, host, port, resource=resource)

    def get_productandrelease(self):
        """
        Get All ProductAndReleases
        :return: All product and Releses from SDC Catalog
        """
        logger.info("Get all ProductAndReleases")
        response = self.get(PRODUCTANDRELEASE_RESOURCE_ROOT_URI, headers=self.headers)
        sr_response = response_body_to_dict(response, self.headers[HEADER_CONTENT_TYPE],
                                          xml_root_element_name=PRODUCTANDRELEASE_BODY_ROOT)
        return sr_response<commit_msg>ADD: get_allproductrelease returns a duple<commit_after># -*- coding: utf-8 -*-

# Copyright 2015 Telefonica Investigación y Desarrollo, S.A.U
#
# This file is part of FIWARE project.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# See the License for the specific language governing permissions and
# limitations under the License.
#
# For those usages not covered by the Apache version 2.0 License please
# contact with <EMAIL>


from utils.rest_client_utils import RestClient, API_ROOT_URL_ARG_NAME, response_body_to_dict, \
    HEADER_CONTENT_TYPE, HEADER_REPRESENTATION_XML
from utils.logger_utils import get_logger

logger = get_logger(__name__)


#URI ELEMENT
SDC_BASE_URI = "{" + API_ROOT_URL_ARG_NAME + "}"
PRODUCTANDRELEASE_RESOURCE_ROOT_URI = SDC_BASE_URI + "/catalog/productandrelease"
PRODUCTANDRELEASE_RESOURCE_DETAIL_URI = PRODUCTANDRELEASE_RESOURCE_ROOT_URI + "/{environment_name}"

#BODY ELEMENT
PRODUCTANDRELEASE_BODY_ROOT= "productAndReleaseDtoes"

class ProductAndReleaseResourceClient(RestClient):

    def __init__(self, protocol, host, port, tenant_id, resource=None, headers=None):
        """
        Class constructor. Inits default attributes.
        :param protocol: Connection protocol (HTTP | HTTPS)
        :param host: Host
        :param port: Port
        :param tenant_id: TenantID
        :param resource: Base URI resource
        :param headers: HTTP Headers
        :return: None
        """
        if headers is None:
            self.headers = {HEADER_CONTENT_TYPE: HEADER_REPRESENTATION_XML}
        self.headers = headers
        self.tenant_id = tenant_id
        super(ProductAndReleaseResourceClient, self).__init__(protocol, host, port, resource=resource)

    def get_allproductandrelease(self):
        """
        Get All ProductAndReleases
        :return: A duple: All product and Releses from SDC Catalog as a dict, the 'Request' response
        """
        logger.info("Get all ProductAndReleases")
        response = self.get(PRODUCTANDRELEASE_RESOURCE_ROOT_URI, headers=self.headers)
        sr_response = response_body_to_dict(response, self.headers[HEADER_CONTENT_TYPE],
                                          xml_root_element_name=PRODUCTANDRELEASE_BODY_ROOT)
        return sr_response, response
{'fraction_non_alphanumeric': 0.07452703993884961, 'fraction_numerical': 0.004204089432447927, 'mean_word_length': 3.6899641577060933, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2369032', 'n_tokens_mistral': 1517, 'n_tokens_neox': 1474, 'n_words': 452}