Exemplo n.º 1
0
    def POST(self, map_name, l_name, format):
        data = get_data(name="style", mandatory=["resource"],
                        authorized=["name", "title", "abstract", "resource"])

        url = urlparse.urlparse(data["resource"]["href"])
        if url.path.startswith(web.ctx.homepath):
            path = url.path[len(web.ctx.homepath):]
        else:
            raise webapp.BadRequest(message="Resource href (%s) is not handled by MRA." % url.path)

        try:
            _, map_name, _, s_name = path.rsplit("/", 3)
        except ValueError:
            raise webapp.NotFound(message="ressource '%s' was not found." % path)

        s_name = s_name.rsplit(".", 1)[0]

        # Get the new style.
        mf = get_mapfile(map_name)

        try:
            style = open(tools.get_style_path(s_name)).read()
        except IOError, OSError:
            with webapp.mightNotFound("style", mapfile=map_name):
                style = mf.get_style_sld(s_name)
Exemplo n.º 2
0
    def POST(self, map_name, format):
        data = get_data(name="layer",
                        mandatory=["name", "resource"],
                        authorized=["name", "title", "abstract", "resource", "enabled"])

        l_name = data.pop("name")
        l_enabled = data.pop("enabled", True)

        # This means we can have one mapfile for each workspace
        # and if eveything uses urls it should work *almost* as is.
        url = urlparse.urlparse(data["resource"]["href"])
        if url.path.startswith(web.ctx.homepath):
            path = url.path[len(web.ctx.homepath):]
        else:
            raise webapp.BadRequest(message="Resource href is not handled by MRA.")

        try:
            _, map_name, _, ws_name, st_type, st_name, r_type, r_name = path.rsplit("/", 7)
        except ValueError:
            raise webapp.NotFound(message="ressource '%s' was not found." % path)

        r_name = r_name.rsplit(".", 1)[0]

        mf, ws = get_mapfile_workspace(map_name, ws_name)
        with webapp.mightNotFound(r_type, workspace=ws_name):
            try:
                model = ws.get_model(r_name, r_type[:-1], st_name)
            except ValueError:
                webapp.NotFound("Invalid layer model '%s'" % r_type[:-1])

        with webapp.mightConflict("layer", mapfile=map_name):
            mf.create_layer(ws, model, l_name, l_enabled)
        mf.save()

        webapp.Created("%s/maps/%s/layers/%s%s" % (web.ctx.home, map_name, l_name, (".%s" % format) if format else ""))
Exemplo n.º 3
0
    def POST(self, format):
        data = get_data(name="mapfile", mandatory=["name"], authorized=["name", "title", "abstract"])

        map_name = data.pop("name")
        path = tools.mk_mapfile_path(map_name)

        with webapp.mightConflict(message="Mapfile '{exception}' already exists."):
            mapfile.create_mapfile(path, map_name, data)

        webapp.Created("%s/maps/%s%s" % (web.ctx.home, map_name, (".%s" % format) if format else ""))
Exemplo n.º 4
0
    def PUT(self, map_name, format):
        mf = get_mapfile(map_name)
        path = tools.mk_mapfile_path(map_name)

        data = get_data(name="mapfile", mandatory=["name"], authorized=["name", "title", "abstract"])
        if map_name != data.pop("name"):
            raise webapp.Forbidden("Can't change the name of a mapfile.")

        mf.update(data)
        mf.save()
Exemplo n.º 5
0
    def PUT(self, map_name, ws_name, cs_name, format):
        mf, ws = get_mapfile_workspace(map_name, ws_name)

        data = get_data(name="coverageStore", mandatory=["name"], authorized=["name", "title", "abstract", "connectionParameters"])
        if cs_name != data.pop("name"):
            raise webapp.Forbidden("Can't change the name of a coverage store.")

        with webapp.mightNotFound("coverageStore", workspace=ws_name):
            ws.update_coveragestore(cs_name, data)
        ws.save()
Exemplo n.º 6
0
    def POST(self, format):
        """Create a new workspace."""

        data = get_data(name="workspace", mandatory=["name"], authorized=["name"])
        ws_name = data.pop("name")

        with webapp.mightConflict():
            mra.create_workspace(ws_name).save()

        webapp.Created("%s/workspaces/%s.%s" % (web.ctx.home, ws_name, format))
Exemplo n.º 7
0
    def POST(self, map_name, ws_name, cs_name, format):
        mf, ws = get_mapfile_workspace(map_name, ws_name)

        data = get_data(name="coverage", mandatory=["name"], authorized=["name", "title", "abstract"])

        with webapp.mightConflict("coverage", coveragestore=cs_name):
            ws.create_coveragemodel(data["name"], cs_name, data)
        ws.save()

        webapp.Created("%s/maps/%s/workspaces/%s/coveragestores/%s/coverages/%s%s" % (
                web.ctx.home, map_name, ws.name, cs_name, data["name"], (".%s" % format) if format else ""))
Exemplo n.º 8
0
    def POST(self, map_name, ws_name, ds_name, format):
        mf, ws = get_mapfile_workspace(map_name, ws_name)

        data = get_data(name="featureType", mandatory=["name"], authorized=["name", "title", "abstract"])
        with webapp.mightConflict("featureType", datastore=ds_name):
            with webapp.mightNotFound("featureType", datastore=ds_name):
                ws.create_featuretypemodel(data["name"], ds_name, data)
        ws.save()

        webapp.Created("%s/maps/%s/workspaces/%s/datastores/%s/featuretypes/%s%s" % (
                web.ctx.home, map_name, ws.name, ds_name, data["name"], (".%s" % format) if format else ""))
Exemplo n.º 9
0
    def POST(self, map_name, ws_name, format):
        mf, ws = get_mapfile_workspace(map_name, ws_name)

        data = get_data(name="coverageStore", mandatory=["name"], authorized=["name", "title", "abstract", "connectionParameters"])
        cs_name = data.pop("name")

        with webapp.mightConflict("coverageStore", workspace=ws_name):
            ws.create_coveragestore(cs_name, data)
        ws.save()

        webapp.Created("%s/maps/%s/workspaces/%s/coveragestores/%s%s" % (
                web.ctx.home, map_name, ws_name, cs_name, (".%s" % format) if format else ""))
Exemplo n.º 10
0
    def PUT(self, map_name, ws_name, ds_name, ft_name, format):
        mf, ws = get_mapfile_workspace(map_name, ws_name)

        data = get_data(name="featureType", mandatory=["name"], authorized=["name", "title", "abstract"])
        if ft_name != data["name"]:
            raise webapp.Forbidden("Can't change the name of a feature type.")

        metadata = dict((k, v) for k, v in data.iteritems() if k in ["title", "abstract"])

        with webapp.mightNotFound("featureType", datastore=ds_name):
            ws.update_featuretypemodel(ft_name, ds_name, metadata)
        ws.save()
Exemplo n.º 11
0
    def PUT(self, l_name, format):
        """Modify layer <l>."""

        mf = mra.get_available()

        data = get_data(name="layer", mandatory=[],
                        authorized=["name", "title", "abstract", "resource", "enabled", "defaultStyle"])
        if l_name != data.get("name", l_name):
            raise webapp.Forbidden("Can't change the name of a layer.")

        l_enabled = data.pop("enabled", True)

        mf = mra.get_available()
        with webapp.mightNotFound():
            layer = mf.get_layer(l_name)

        # update resource if changed
        href = data.get("resource", {}).get("href")
        if href:
            try:
                ws_name, st_type, st_name, r_type, r_name = mra.href_parse(href, 5)
            except ValueError:
                raise webapp.NotFound(message="resource \"%s\" was not found." % href)

            st_type, r_type = st_type[:-1], r_type[:-1] # Remove trailing s.

            ws = get_workspace(ws_name)
            with webapp.mightNotFound(r_type, workspace=ws_name):
                try:
                    model = ws.get_layermodel(r_type, st_name, r_name)
                except ValueError:
                    raise KeyError(r_type)

            if layer.get_mra_metadata("type") != r_type:
                raise webapp.BadRequest("Can't change a \"%s\" layer into a \"%s\"."
                                    % (layer.get_mra_metadata("type"), r_type))

            model.configure_layer(layer, l_enabled)

        # If we have a defaultStyle apply it.
        s_name = data.get("defaultStyle", {}).get("name")
        if s_name:
            with webapp.mightNotFound():
                style = mra.get_style(s_name)
            layer.add_style_sld(mf, s_name, style)
            
            # Remove the automatic default style.
            for s_name in layer.iter_styles():
                if s_name == tools.get_dflt_sld_name(layer.ms.type):
                    layer.remove_style(s_name)

        mf.save()
Exemplo n.º 12
0
    def PUT(self, map_name, ws_name, cs_name, c_name, format):
        mf, ws = get_mapfile_workspace(map_name, ws_name)

        data = get_data(name="coverage", mandatory=["name"], authorized=["name", "title", "abstract"])
        if c_name != data["name"]:
            raise webapp.Forbidden("Can't change the name of a coverage.")


        metadata = dict((k, v) for k, v in data.iteritems() if k in ["title", "abstract"])

        with webapp.mightNotFound("coverage", coveragestore=cs_name):
            ws.update_coveragemodel(c_name, cs_name, metadata)
        ws.save()
Exemplo n.º 13
0
    def PUT(self, ows, format):
        """To enable or disable OGC service..."""

        mf = mra.get_available()
        data = get_data(name=ows, mandatory=["enabled"], authorized=["enabled"])
        is_enabled = data.pop("enabled")
        # TODO: That would be cool to be able to control each operation...
        values = {True: "*", "True": "*", "true": "*", 
                  False: "", "False": "", "false": ""}
        if is_enabled not in values:
            raise KeyError("\"%s\" is not valid" % is_enabled)
        mf.set_metadata("%s_enable_request" % ows, values[is_enabled])
        mf.save()
Exemplo n.º 14
0
    def PUT(self, ws_name, cs_name, format):
        """Modify coverage store <ds>."""
        
        ws = get_workspace(ws_name)
        data = get_data(name="coverageStore", 
                        mandatory=["name"], 
                        authorized=["name", "title", "abstract", "connectionParameters"])
        if cs_name != data.pop("name"):
            raise webapp.Forbidden("Can't change the name of a coverage store.")

        with webapp.mightNotFound("coverageStore", workspace=ws_name):
            ws.update_coveragestore(cs_name, data)
        ws.save()
Exemplo n.º 15
0
    def PUT(self, ws_name, ds_name, format):
        """Modify data store <ds>."""

        ws = get_workspace(ws_name)

        data = get_data(name="dataStore", mandatory=["name"], authorized=["name", "title", "abstract", "connectionParameters"])

        if ds_name != data.pop("name"):
            raise webapp.Forbidden("Can't change the name of a data store.")

        with webapp.mightNotFound("dataStore", workspace=ws_name):
            ws.update_datastore(ds_name, data)
        ws.save()
Exemplo n.º 16
0
    def PUT(self, l_name, format):
        """Modify layer <l>."""

        mf = mra.get_available()

        data = get_data(name="layer", mandatory=[],
                        authorized=["name", "resource", "defaultStyle"])
        if l_name != data.get("name", l_name):
            raise webapp.Forbidden("Can't change the name of a layer.")

        l_enabled = True # TODO: => data.pop("enabled", True)

        mf = mra.get_available()
        with webapp.mightNotFound():
            layer = mf.get_layer(l_name)

        # update resource if changed
        href = data.get("resource", {}).get("href")
        if href:
            try:
                ws_name, st_type, st_name, r_type, r_name = mra.href_parse(href, 5)
            except ValueError:
                raise webapp.NotFound(message="resource \"%s\" was not found." % href)

            st_type, r_type = st_type[:-1], r_type[:-1] # Remove trailing s.

            ws = get_workspace(ws_name)
            with webapp.mightNotFound(r_type, workspace=ws_name):
                try:
                    model = ws.get_layermodel(r_type, st_name, r_name)
                except ValueError:
                    raise KeyError(r_type)

            if layer.get_mra_metadata("type") != r_type:
                raise webapp.BadRequest("Can't change a \"%s\" layer into a \"%s\"."
                                    % (layer.get_mra_metadata("type"), r_type))
        model.configure_layer(layer, l_enabled)

        # If we have a defaultStyle apply it.
        s_name = data.get("defaultStyle", {}).get("name")
        if s_name:
            with webapp.mightNotFound():
                style = mra.get_style(s_name)
            layer.add_style_sld(mf, s_name, style)
            
            # Remove the automatic default style.
            for s_name in layer.iter_styles():
                if s_name == tools.get_dflt_sld_name(layer.ms.type):
                    layer.remove_style(s_name)

        mf.save()
Exemplo n.º 17
0
    def PUT(self, ws_name, cs_name, c_name, format):
        """Modify coverage <c>."""
        
        ws = get_workspace(ws_name)

        data = get_data(name="coverage", mandatory=["name"], authorized=["name", "title", "abstract"])
        if c_name != data["name"]:
            raise webapp.Forbidden("Can't change the name of a coverage.")

        metadata = dict((k, v) for k, v in data.iteritems() if k in ["title", "abstract"])

        with webapp.mightNotFound("coverage", coveragestore=cs_name):
            ws.update_coveragemodel(c_name, cs_name, metadata)
        ws.save()
Exemplo n.º 18
0
    def PUT(self, ws_name, ds_name, ft_name, format):
        """Modify feature type <ft>."""

        ws = get_workspace(ws_name)

        data = get_data(name="featureType", mandatory=["name"], authorized=["name", "title", "abstract"])
        if ft_name != data["name"]:
            raise webapp.Forbidden("Can't change the name of a feature type.")

        metadata = dict((k, v) for k, v in data.iteritems() if k in ["title", "abstract"])

        with webapp.mightNotFound("featureType", datastore=ds_name):
            ws.update_featuretypemodel(ds_name, ft_name, metadata)
        ws.save()
Exemplo n.º 19
0
    def POST(self, map_name, format):
        mf = get_mapfile(map_name)

        data = get_data(name="layerGroup", mandatory=["name"], authorized=["name", "title", "abstract", "layers"])
        lg_name = data.pop("name")
        layers = [mf.get_layer(l_name) for l_name in data.pop("layers", [])]

        with webapp.mightConflict("layerGroup", mapfile=map_name):
            lg = mf.create_layergroup(lg_name, data)
        lg.add(*layers)

        mf.save()

        webapp.Created("%s/maps/%s/layergroups/%s%s" % (web.ctx.home, map_name, lg.name, (".%s" % format) if format else ""))
Exemplo n.º 20
0
    def POST(self, ws_name, format):
        """Create a new data store."""

        ws = get_workspace(ws_name)

        data = get_data(name="dataStore", mandatory=["name"], 
                        authorized=["name", "title", "abstract", "connectionParameters"])
        ds_name = data.pop("name")

        with webapp.mightConflict("dataStore", workspace=ws_name):
            ws.create_datastore(ds_name, data)

        ws.save()

        webapp.Created("%s/workspaces/%s/datastores/%s.%s" % (
                web.ctx.home, ws_name, ds_name, format))
Exemplo n.º 21
0
    def POST(self, format):
        """Create a new layer group."""

        mf = mra.get_available()

        data = get_data(name="layerGroup", mandatory=["name"], authorized=["name", "title", "abstract", "layers"])
        lg_name = data.pop("name")
        with webapp.mightNotFound():
            layers = [mf.get_layer(l_name) for l_name in data.pop("layers", [])]

        with webapp.mightConflict():
            lg = mf.create_layergroup(lg_name, data)
        lg.add(*layers)

        mf.save()

        webapp.Created("%s/layergroups/%s.%s" % (web.ctx.home, lg.name, format))
Exemplo n.º 22
0
    def POST(self, format):
        """Create a new layer."""

        data = get_data(name="layer",
                        mandatory=["name", "resource"],
                        authorized=["name", "title", "abstract", "resource", "enabled", "defaultStyle"])

        l_name = data.pop("name")
        l_enabled = data.pop("enabled", True)

        href = data["resource"]["href"]
        try:
            ws_name, st_type, st_name, r_type, r_name = mra.href_parse(href, 5)
        except ValueError:
            raise webapp.NotFound(message="resource \"%s\" was not found." % href)

        st_type, r_type = st_type[:-1], r_type[:-1] # Remove trailing s.

        ws = get_workspace(ws_name)
        with webapp.mightNotFound(r_type, workspace=ws_name):
            try:
                model = ws.get_layermodel(r_type, st_name, r_name)
            except ValueError:
                raise KeyError(r_type)

        mf = mra.get_available()
        with webapp.mightConflict():
            mf.create_layer(model, l_name, l_enabled)

        # If we have a defaultStyle apply it.
        s_name = data.get("defaultStyle", {}).get("name")
        if s_name:
            with webapp.mightNotFound():
                style = mra.get_style(s_name)
                layer = mf.get_layer(l_name)
            layer.add_style_sld(mf, s_name, style)

            # Remove the automatic default style.
            for s_name in layer.iter_styles():
                if s_name == tools.get_dflt_sld_name(layer.ms.type):
                    layer.remove_style(s_name)

        mf.save()

        webapp.Created("%s/layers/%s.%s" % (web.ctx.home, l_name, format))
Exemplo n.º 23
0
    def PUT(self, map_name, lg_name, format):
        mf = get_mapfile(map_name)

        with webapp.mightNotFound("layerGroup", mapfile=map_name):
            lg = mf.get_layergroup(lg_name)

        data = get_data(name="layerGroup", mandatory=["name"], authorized=["name", "title", "abstract", "layers"])
        if lg_name != data.pop("name"):
            raise webapp.Forbidden("Can't change the name of a layergroup.")

        layers = data.pop("layers", [])
        if not isinstance(layers, list) or any(not isinstance(x, basestring) for x in layers):
            raise webapp.BadRequest("layers must be a list of layer names.")

        lg.clear()
        lg.add(*layers)

        mf.save()
Exemplo n.º 24
0
    def POST(self, ws_name, cs_name, format):
        """Create a new coverage."""

        ws = get_workspace(ws_name)
        data = get_data(name="coverage", mandatory=["name"], authorized=["name", "title", "abstract"])
        with webapp.mightConflict("coverage", coveragestore=cs_name):
            with webapp.mightNotFound("coverage", coveragestore=cs_name):
                ws.create_coveragemodel(data["name"], cs_name, data)
        ws.save()

        # Then creates the associated layer by default:
        model = ws.get_coveragemodel(cs_name, data["name"])
        mf = mra.get_available()
        with webapp.mightConflict():
            mf.create_layer(model, data["name"], True)
        mf.save()

        webapp.Created("%s/workspaces/%s/coveragestores/%s/coverages/%s.%s" % (
                web.ctx.home, ws.name, cs_name, data["name"], format))
Exemplo n.º 25
0
    def POST(self, ws_name, format):
        """Create new coverage store.""" 

        ws = get_workspace(ws_name)
        data = get_data(name="coverageStore", mandatory=["name"], authorized=["name", "title", "abstract", "connectionParameters"])
        cs_name = data.pop("name")

        with webapp.mightConflict("coverageStore", workspace=ws_name):
            ws.create_coveragestore(cs_name, data)
        ws.save()

        # Then creates the associated layer by default:
        # model = ws.get_coveragetypemodel(cs_name, data["name"])
        # mf = mra.get_available()
        # with webapp.mightConflict():
        #     mf.create_layer(model, data["name"], True)
        # mf.save()

        webapp.Created("%s/workspaces/%s/coveragestores/%s.%s" % (
                web.ctx.home, ws_name, cs_name, format))
Exemplo n.º 26
0
    def PUT(self, lg_name, format):
        """Modify layergroup <lg>."""

        mf = mra.get_available()

        with webapp.mightNotFound():
            lg = mf.get_layergroup(lg_name)

        data = get_data(name="layerGroup", mandatory=["name"], authorized=["name", "title", "abstract", "layers"])
        if lg_name != data.pop("name"):
            raise webapp.Forbidden("Can't change the name of a layergroup.")

        layers = data.pop("layers", [])
        if not isinstance(layers, list) or any(not isinstance(x, basestring) for x in layers):
            raise webapp.BadRequest("layers must be a list of layer names.")

        lg.clear()
        lg.add(*layers)

        mf.save()
Exemplo n.º 27
0
    def PUT(self, map_name, l_name, format):
        mf = get_mapfile(map_name)

        data = get_data(name="layer", mandatory=["name", "resource"],
                        authorized=["name", "title", "abstract", "resource", "enabled"])
        if l_name != data.pop("name"):
            raise webapp.Forbidden("Can't change the name of a layer.")

        l_enabled = data.pop("enabled", True)

        # This means we can have one mapfile for each workspace
        # and if eveything uses urls it should work *almost* as is.
        r_href = data["resource"]["href"]
        try:
            _, map_name, _, ws_name, st_type, st_name, r_type, r_name = r_href.rsplit("/", 7)
        except ValueError:
            raise webapp.NotFound(message="ressource '%s' was not found." % r_href)

        r_name = r_name.rsplit(".", 1)[0]

        ws = mf.get_workspace(ws_name)
        with webapp.mightNotFound(r_type, workspace=ws_name):
            try:
                model = ws.get_model(r_name, r_type[:-1], st_name)
            except ValueError:
                raise webapp.NotFound("Invalid layer model '%s'" % st_type)

        with webapp.mightNotFound("layer", mapfile=map_name):
            layer = mf.get_layer(l_name)

            if layer.get_mra_metadata("type") != r_type:
                raise webapp.BadRequest("Can't change a '%s' layer into a '%s'." % (
                        layer.get_mra_metadata("type"), r_type))

            model.configure_layer(ws, layer, l_enabled)
        mf.save()
Exemplo n.º 28
0
    def POST(self, ws_name, ds_name, format):
        """Create a new feature type. It create the associated layer by defaut.
        This layer is added in the mapfile: <layer.map>

        """
        ws = get_workspace(ws_name)
        data = get_data(name="featureType", mandatory=["name"],
                        authorized=["name", "title", "abstract"])

        # Creates first the feature type:
        with webapp.mightConflict("featureType", datastore=ds_name):
            with webapp.mightNotFound("featureType", datastore=ds_name):
                ws.create_featuretypemodel(ds_name, data["name"], data)
        ws.save()

        # Then creates the associated layer by default:
        model = ws.get_featuretypemodel(ds_name, data["name"])
        mf = mra.get_available()
        with webapp.mightConflict():
            mf.create_layer(model, data["name"], True)
        mf.save()

        webapp.Created("%s/workspaces/%s/datastores/%s/featuretypes/%s.%s" % (
                web.ctx.home, ws.name, ds_name, data["name"], format))