def test_merge_modes(self):
     from c2cgeoportal_geoportal.lib.wmstparsing import TimeInformation
     ti = TimeInformation()
     self.assertFalse(ti.has_time())
     self.assertTrue(ti.to_dict() is None)
     ti.merge_mode("single")
     self.assertEqual(ti.mode, "single")
     ti.merge_mode("single")
     self.assertEqual(ti.mode, "single")
Пример #2
0
    def _group(
        self,
        path,
        group,
        layers,
        depth=1,
        min_levels=1,
        mixed=True,
        time_=None,
        dim=None,
        wms_layers=None,
        layers_name=None,
        **kwargs,
    ):
        if wms_layers is None:
            wms_layers = []
        if layers_name is None:
            layers_name = []
        children = []
        errors = set()

        if re.search("[/?#]", group.name):  # pragma: no cover
            errors.add("The group has an unsupported name '{}'.".format(
                group.name))

        # escape loop
        if depth > 30:
            errors.add("Too many recursions with group '{}'".format(
                group.name))
            return None, errors

        ogc_servers = None
        org_depth = depth
        if depth == 1:
            ogc_servers = list(self._get_ogc_servers(group, 1))
            # check if mixed content
            mixed = len(ogc_servers) != 1 or ogc_servers[0] is False
            if not mixed:
                time_ = TimeInformation()
            dim = DimensionInformation()

        for tree_item in group.children:
            if isinstance(tree_item, main.LayerGroup):
                group_theme, gp_errors = self._group(
                    "{}/{}".format(path, tree_item.name),
                    tree_item,
                    layers,
                    depth=depth + 1,
                    min_levels=min_levels,
                    mixed=mixed,
                    time_=time_,
                    dim=dim,
                    wms_layers=wms_layers,
                    layers_name=layers_name,
                    **kwargs,
                )
                errors |= gp_errors
                if group_theme is not None:
                    children.append(group_theme)
            elif self._layer_included(tree_item):
                if tree_item.name in layers:
                    layers_name.append(tree_item.name)
                    if isinstance(tree_item, main.LayerWMS):
                        wms_layers.extend(tree_item.layer.split(","))

                    layer_theme, l_errors = self._layer(tree_item,
                                                        mixed=mixed,
                                                        time_=time_,
                                                        dim=dim,
                                                        **kwargs)
                    errors |= l_errors
                    if layer_theme is not None:
                        if depth < min_levels:
                            errors.add(
                                "The Layer '{}' is under indented ({:d}/{:d})."
                                .format(path + "/" + tree_item.name, depth,
                                        min_levels))
                        else:
                            children.append(layer_theme)

        if children:
            group_theme = {
                "id": group.id,
                "name": group.name,
                "children": children,
                "metadata": self._get_metadatas(group, errors),
                "mixed": False,
            }
            if not mixed:
                for name, nb in list(Counter(layers_name).items()):
                    if nb > 1:
                        errors.add(
                            "The GeoMapFish layer name '{}', cannot be two times "
                            "in the same block (first level group).".format(
                                name))

            group_theme["mixed"] = mixed
            if org_depth == 1:
                if not mixed:
                    group_theme["ogcServer"] = cast(List, ogc_servers)[0]
                    if time_.has_time() and time_.layer is None:
                        group_theme["time"] = time_.to_dict()

                    group_theme["dimensions"] = dim.get_dimensions()

            return group_theme, errors
        return None, errors