def concat(options1: ConfigParams, options2: ConfigParams,
               *keys: str) -> ConfigParams:
        """
        Concatinates two options by combining duplicated properties into comma-separated list

        :param options1:    first options to merge
        :param options2:    second options to merge
        :param keys:        when define it limits only to specific keys
        """

        options = ConfigParams.from_value(options1)
        for key in options2.get_keys():
            value1 = options1.get_as_string(key) or ''
            value2 = options2.get_as_string(key) or ''

            if value1 != '' and value2 != '':
                if keys is None or len(keys) == 0 or key in keys:
                    options.set_as_object(key, value1 + ',' + value2)

            elif value1 != '':
                options.set_as_object(key, value1)
            elif value2 != '':
                options.set_as_object(key, value2)

        return options
コード例 #2
0
    def from_value(value):
        """
        Creates a new ContainerConfig object filled with key-value pairs from specified object.
        The value is converted into ConfigParams object which is used to create the object.

        :param value: an object with key-value pairs used to initialize a new ContainerConfig.

        :return: a new ContainerConfig object.
        """
        config = ConfigParams.from_value(value)
        return ContainerConfig.from_config(config)
コード例 #3
0
    def from_value(value: Any) -> 'ContainerConfig':
        """
        Creates a new :class:`ContainerConfig <pip_services3_container.config.ContainerConfig.ContainerConfig>` object filled with key-value pairs from specified object.
        The value is converted into :class:`ConfigParams <pip_services3_commons.config.ConfigParams.ConfigParams>` object which is used to create the object.

        :param value: an object with key-value pairs used to initialize a new :class:`ContainerConfig <pip_services3_container.config.ContainerConfig.ContainerConfig>`.

        :return: a new :class:`ContainerConfig <pip_services3_container.config.ContainerConfig.ContainerConfig>` object.
        """
        config = ConfigParams.from_value(value)
        return ContainerConfig.from_config(config)
コード例 #4
0
    def test_config_from_object(self):
        value = AnyValueMap.from_tuples(
            "field1", ConfigParams.from_string("field11=123;field12=ABC"),
            "field2",
            AnyValueArray.from_values(
                123, "ABC",
                ConfigParams.from_string("field21=543;field22=XYZ")), "field3",
            True)

        config = ConfigParams.from_value(value)
        assert 7 == len(config)
        assert 123 == config.get_as_integer("field1.field11")
        assert "ABC" == config.get_as_string("field1.field12")
        assert 123 == config.get_as_integer("field2.0")
        assert "ABC" == config.get_as_string("field2.1")
        assert 543 == config.get_as_integer("field2.2.field21")
        assert "XYZ" == config.get_as_string("field2.2.field22")
        assert True == config.get_as_boolean("field3")
    def rename(options: ConfigParams, from_name: str,
               to_name: str) -> Optional[ConfigParams]:
        """
        Renames property if the target name is not used.

        :param options: configuration options
        :param from_name: original property name.
        :param to_name: property name to rename to.
        :return: updated configuration options
        """
        from_value = options.get_as_object(from_name)
        if from_value is None:
            return options

        to_value = options.get_as_object(to_name)
        if to_value is not None:
            return options

        options = ConfigParams.from_value(options)
        options.set_as_object(to_name, from_value)
        options.remove(from_name)
        return options