Beispiel #1
0
    def is_record_response(self, response_json, class_detail, pack):
        try:
            from zcrmsdk.src.com.zoho.crm.api.initializer import Initializer
        except Exception:
            from ..initializer import Initializer

        response_json = dict(response_json)
        record_instance = JSONConverter.__get_instance_from_name(pack)
        module_api_name = self.common_api_handler.get_module_api_name()

        module_detail = {}
        class_name = Constants.RECORD_NAMESPACE.rpartition('.')[-1]

        if module_api_name is not None:
            self.common_api_handler.set_module_api_name(None)
            full_detail = Utility.search_json_details(module_api_name)

            if full_detail is not None:
                module_detail = full_detail[Constants.MODULEDETAILS]
                class_name = str(full_detail[
                    Constants.MODULEPACKAGENAME]).rpartition('.')[-1]
                record_instance = JSONConverter.__get_instance_from_name(
                    full_detail[Constants.MODULEPACKAGENAME])

            else:
                module_detail = self.__get_module_detail_from_user_spec_json(
                    module_api_name)

        for key, value in class_detail.items():
            module_detail[key] = value

        record_detail = Initializer.json_details[Constants.RECORD_NAMESPACE]

        class_list = record_instance.__class__.mro()

        for each_class in class_list:
            if Constants.RECORD_TYPE in str(each_class):
                class_name = Constants.RECORD_CLASS_NAME
                break

        key_values = {}

        for key_name in response_json.keys():
            member_name = self.build_name(key_name)
            key_detail = {}

            if len(module_detail) > 0 and (key_name in module_detail
                                           or member_name in module_detail):
                key_detail = module_detail[
                    key_name] if key_name in module_detail.keys(
                    ) else module_detail[member_name]

            elif member_name in record_detail:
                key_detail = record_detail[member_name]

            key_data = response_json[key_name]
            key_value = None

            if len(key_detail) > 0:
                key_name = key_detail[Constants.NAME]
                key_value = self.get_data(key_data, key_detail)

            else:
                key_value = self.redirector_for_json_to_object(key_data)

            key_values[key_name] = key_value

        setattr(
            record_instance,
            self.construct_private_member(class_name, Constants.KEY_VALUES),
            key_values)

        return record_instance
Beispiel #2
0
    def is_record_request(self, record_instance, class_detail, instance_number,
                          member_detail):
        try:
            from zcrmsdk.src.com.zoho.crm.api.initializer import Initializer
        except Exception:
            from ..initializer import Initializer

        lookup = False
        skip_mandatory = False
        class_member_name = None
        if member_detail is not None:
            lookup = member_detail[
                Constants.
                LOOKUP] if Constants.LOOKUP in member_detail else False
            skip_mandatory = member_detail[
                Constants.
                SKIP_MANDATORY] if Constants.SKIP_MANDATORY in member_detail else False
            class_member_name = member_detail[Constants.NAME]

        request_json, module_detail = {}, {}
        module_api_name = self.common_api_handler.get_module_api_name()
        class_name = record_instance.__class__.__name__

        if module_api_name is not None:
            self.common_api_handler.set_module_api_name(None)
            full_detail = Utility.search_json_details(module_api_name)

            if full_detail is not None:
                module_detail = full_detail[Constants.MODULEDETAILS]

            else:
                module_detail = self.__get_module_detail_from_user_spec_json(
                    module_api_name)
        else:
            module_detail = class_detail
            class_detail = Initializer.json_details[Constants.RECORD_NAMESPACE]

        class_list = record_instance.__class__.mro()

        for each_class in class_list:
            if Constants.RECORD_TYPE in str(each_class):
                class_name = Constants.RECORD_CLASS_NAME
                break

        key_values = getattr(
            record_instance,
            self.construct_private_member(class_name, Constants.KEY_VALUES))
        key_modified = getattr(
            record_instance,
            self.construct_private_member(class_name, Constants.KEY_MODIFIED))

        required_keys, primary_keys = {}, {}

        if not skip_mandatory:
            for key_name, key_detail in module_detail.items():
                name = key_detail[Constants.NAME]
                if Constants.REQUIRED in key_detail and key_detail[
                        Constants.REQUIRED]:
                    required_keys[name] = True

                if Constants.PRIMARY in key_detail and key_detail[
                        Constants.PRIMARY]:
                    primary_keys[name] = True

            for key_name, key_detail in class_detail.items():
                name = key_detail[Constants.NAME]
                if Constants.REQUIRED in key_detail and key_detail[
                        Constants.REQUIRED]:
                    required_keys[name] = True

                if Constants.PRIMARY in key_detail and key_detail[
                        Constants.PRIMARY]:
                    primary_keys[name] = True

        for key_name in key_modified.keys():
            if key_modified.get(key_name) != 1:
                continue

            key_detail = {}
            key_value = key_values.get(
                key_name) if key_name in key_values else None
            json_value = None
            member_name = self.build_name(key_name)

            if len(module_detail) > 0 and (member_name in module_detail
                                           or key_name in module_detail):
                key_detail = module_detail[
                    key_name] if key_name in module_detail else module_detail[
                        member_name]

            elif member_name in class_detail:
                key_detail = class_detail[member_name]

            if len(key_detail) > 0:
                if Constants.READ_ONLY in key_detail or (Constants.NAME
                                                         not in key_detail):
                    continue

                if self.value_checker(class_name, key_name, key_detail,
                                      key_value, self.unique_dict,
                                      instance_number):
                    json_value = self.set_data(key_detail, key_value)

            else:
                json_value = self.redirector_for_object_to_json(key_value)

            if key_value is not None:
                required_keys.pop(key_name, None)
                primary_keys.pop(key_name, None)

            request_json[key_name] = json_value

        if skip_mandatory or self.check_exception(
                class_member_name, record_instance, instance_number, lookup,
                required_keys, primary_keys, {}) is True:
            return request_json