示例#1
0
def ows(request):
    """ Main entry point for OWS requests against EOxServer. It uses the
    :class:`ServiceComponent
    <eoxserver.services.ows.component.ServiceComponent>` to dynamically
    determine the handler component for this request.

    If an exception occurs during the handling of the request, an exception
    handler component is determined and dispatched.

    Any response of the service handler and exception handler is transformed
    to a django :class:`HttpResponse <django.http.HttpResponse>` to adhere the
    required interface.
    """

    component = ServiceComponent(env)

    try:
        handler = component.query_service_handler(request)
        result = handler.handle(request)
        default_status = 200
    except HTTPMethodNotAllowedError, e:
        handler = component.query_exception_handler(request)
        result = handler.handle_exception(request, e)
        content, content_type = handler.handle_exception(request, e)[:2]
        result = HttpResponse(content=content,
                              content_type=content_type,
                              status=405)
        result["Allow"] = ", ".join(e.allowed_methods)
def _encode_operations_metadata(conf):
    component = ServiceComponent(env)
    versions = ("1.0.0",)
    get_handlers = component.query_service_handlers(
        service="WPS", versions=versions, method="GET"
    )
    post_handlers = component.query_service_handlers(
        service="WPS", versions=versions, method="POST"
    )
    all_handlers = sorted(
        set(get_handlers + post_handlers), key=lambda h: h.request
    )
    url = conf.http_service_url
    return OWS("OperationsMetadata", *[
        OWS("Operation",
            OWS("DCP",
                OWS("HTTP",
                    # TODO: only select available
                    OWS("Get", **{ns_xlink("href"): url}),
                    OWS("Post", **{ns_xlink("href"): url}),
                )
            ), name=handler.request
        )
        for handler in all_handlers
    ])
示例#3
0
    def encode_service_identification(self, conf):
        # get a list of versions in descending order from all active
        # GetCapabilities handlers.
        component = ServiceComponent(env)
        handlers = component.query_service_handlers(
            service="WCS", request="GetCapabilities"
        )
        versions = sorted(
            set(chain(*[handler.versions for handler in handlers])),
            reverse=True
        )

        elem = OWS("ServiceIdentification",
            OWS("Title", conf.title),
            OWS("Abstract", conf.abstract),
            OWS("Keywords", *[
                OWS("Keyword", keyword) for keyword in conf.keywords
            ]),
            OWS("ServiceType", "OGC WCS", codeSpace="OGC")
        )

        elem.extend(
            OWS("ServiceTypeVersion", version) for version in versions
        )

        elem.extend(
            OWS("Profile", "http://www.opengis.net/%s" % profile)
            for profile in PROFILES
        )

        elem.extend((
            OWS("Fees", conf.fees),
            OWS("AccessConstraints", conf.access_constraints)
        ))
        return elem
示例#4
0
    def encode_service_identification(self, conf):
        # get a list of versions in descending order from all active
        # GetCapabilities handlers.
        component = ServiceComponent(env)
        handlers = component.query_service_handlers(service="WCS",
                                                    request="GetCapabilities")
        versions = sorted(set(
            chain(*[handler.versions for handler in handlers])),
                          reverse=True)

        elem = OWS(
            "ServiceIdentification", OWS("Title", conf.title),
            OWS("Abstract", conf.abstract),
            OWS("Keywords",
                *[OWS("Keyword", keyword) for keyword in conf.keywords]),
            OWS("ServiceType", "OGC WCS", codeSpace="OGC"))

        elem.extend(OWS("ServiceTypeVersion", version) for version in versions)

        elem.extend(
            OWS("Profile", "http://www.opengis.net/%s" % profile)
            for profile in PROFILES)

        elem.extend((OWS("Fees", conf.fees),
                     OWS("AccessConstraints", conf.access_constraints)))
        return elem
示例#5
0
def ows(request):
    """ Main entry point for OWS requests against EOxServer. It uses the
    :class:`ServiceComponent
    <eoxserver.services.ows.component.ServiceComponent>` to dynamically
    determine the handler component for this request.

    If an exception occurs during the handling of the request, an exception
    handler component is determined and dispatched.

    Any response of the service handler and exception handler is transformed
    to a django :class:`HttpResponse <django.http.HttpResponse>` to adhere the
    required interface.
    """

    component = ServiceComponent(env)

    try:
        handler = component.query_service_handler(request)
        result = handler.handle(request)
        default_status = 200
    except HTTPMethodNotAllowedError, e:
        handler = component.query_exception_handler(request)
        result = handler.handle_exception(request, e)
        content, content_type = handler.handle_exception(request, e)[:2]
        result = HttpResponse(
            content=content, content_type=content_type, status=405
        )
        result["Allow"] = ", ".join(e.allowed_methods)
示例#6
0
def _encode_operations_metadata(conf):
    """ Encode OperationsMetadata XML element. """
    component = ServiceComponent(env)
    versions = ("1.0.0", )
    get_handlers = component.query_service_handlers(service="WPS",
                                                    versions=versions,
                                                    method="GET")
    post_handlers = component.query_service_handlers(service="WPS",
                                                     versions=versions,
                                                     method="POST")
    all_handlers = sorted(set(get_handlers + post_handlers),
                          key=lambda h: h.request)
    url = conf.http_service_url
    return OWS(
        "OperationsMetadata", *[
            OWS("Operation",
                OWS(
                    "DCP",
                    OWS(
                        "HTTP",
                        OWS("Get", **{ns_xlink("href"): url}),
                        OWS("Post", **{ns_xlink("href"): url}),
                    )),
                name=handler.request) for handler in all_handlers
        ])
示例#7
0
def ows(request):
    """ Main entry point for OWS requests against EOxServer. It uses the
    :class:`ServiceComponent
    <eoxserver.services.ows.component.ServiceComponent>` to dynamically
    determine the handler component for this request.

    If an exception occurs during the handling of the request, an exception
    handler component is determined and dispatched.

    Any response of the service handler and exception handler is transformed
    to a django :class:`HttpResponse <django.http.HttpResponse>` to adhere the
    required interface.
    """

    component = ServiceComponent(env)

    try:
        handler = component.query_service_handler(request)
        result = handler.handle(request)
        default_status = 200
    except Exception, e:
        logger.debug(traceback.format_exc())
        handler = component.query_exception_handler(request)
        result = handler.handle_exception(request, e)
        default_status = 400
示例#8
0
    def encode_operations_metadata(self, request):
        component = ServiceComponent(env)
        versions = ("2.0.0", "2.0.1")
        get_handlers = component.query_service_handlers(
            service="WCS", versions=versions, method="GET"
        )
        post_handlers = component.query_service_handlers(
            service="WCS", versions=versions, method="POST"
        )
        all_handlers = sorted(
            set(get_handlers + post_handlers),
            key=lambda h: (getattr(h, "index", 10000), h.request)
        )

        http_service_url = get_http_service_url(request)

        operations = []
        for handler in all_handlers:
            methods = []
            if handler in get_handlers:
                methods.append(
                    self.encode_reference("Get", http_service_url)
                )
            if handler in post_handlers:
                post = self.encode_reference("Post", http_service_url)
                post.append(
                    OWS("Constraint",
                        OWS("AllowedValues",
                            OWS("Value", "XML")
                        ), name="PostEncoding"
                    )
                )
                methods.append(post)

            operations.append(
                OWS("Operation",
                    OWS("DCP",
                        OWS("HTTP", *methods)
                    ),
                    # apply default values as constraints
                    *[
                        OWS("Constraint",
                            OWS("NoValues"),
                            OWS("DefaultValue", str(default)),
                            name=name
                        ) for name, default
                        in getattr(handler, "constraints", {}).items()
                    ],
                    name=handler.request
                )
            )

        return OWS("OperationsMetadata", *operations)
示例#9
0
    def encode_operations_metadata(self, request):
        component = ServiceComponent(env)
        versions = ("2.0.0", "2.0.1")
        get_handlers = component.query_service_handlers(service="WCS",
                                                        versions=versions,
                                                        method="GET")
        post_handlers = component.query_service_handlers(service="WCS",
                                                         versions=versions,
                                                         method="POST")
        all_handlers = sorted(set(get_handlers + post_handlers),
                              key=lambda h:
                              (getattr(h, "index", 10000), h.request))

        http_service_url = get_http_service_url(request)

        operations = []
        for handler in all_handlers:
            methods = []
            if handler in get_handlers:
                methods.append(self.encode_reference("Get", http_service_url))
            if handler in post_handlers:
                post = self.encode_reference("Post", http_service_url)
                post.append(
                    OWS("Constraint",
                        OWS("AllowedValues", OWS("Value", "XML")),
                        name="PostEncoding"))
                methods.append(post)

            operations.append(
                OWS(
                    "Operation",
                    OWS("DCP", OWS("HTTP", *methods)),
                    # apply default values as constraints
                    *[
                        OWS("Constraint",
                            OWS("NoValues"),
                            OWS("DefaultValue", str(default)),
                            name=name) for name, default in getattr(
                                handler, "constraints", {}).items()
                    ],
                    name=handler.request))

        return OWS("OperationsMetadata", *operations)
示例#10
0
    def encode_capabilities(self, sections, coverages_qs=None, dataset_series_qs=None):
        conf = CapabilitiesConfigReader(get_eoxserver_config())

        all_sections = "all" in sections
        caps = []
        if all_sections or "serviceidentification" in sections:
            caps.append(
                OWS("ServiceIdentification",
                    OWS("Title", conf.title),
                    OWS("Abstract", conf.abstract),
                    OWS("Keywords", *[
                        OWS("Keyword", keyword) for keyword in conf.keywords
                    ]),
                    OWS("ServiceType", "OGC WCS", codeSpace="OGC"),
                    OWS("ServiceTypeVersion", "2.0.1"),
                    OWS("Profile", "http://www.opengis.net/spec/WCS_application-profile_earth-observation/1.0/conf/eowcs"),
                    OWS("Profile", "http://www.opengis.net/spec/WCS_application-profile_earth-observation/1.0/conf/eowcs_get-kvp"),
                    OWS("Profile", "http://www.opengis.net/spec/WCS_service-extension_crs/1.0/conf/crs"),
                    OWS("Profile", "http://www.opengis.net/spec/WCS/2.0/conf/core"),
                    OWS("Profile", "http://www.opengis.net/spec/WCS_protocol-binding_get-kvp/1.0/conf/get-kvp"),
                    OWS("Profile", "http://www.opengis.net/spec/WCS_protocol-binding_post-xml/1.0/conf/post-xml"),
                    OWS("Profile", "http://www.opengis.net/spec/GMLCOV/1.0/conf/gml-coverage"),
                    OWS("Profile", "http://www.opengis.net/spec/GMLCOV/1.0/conf/multipart"),
                    OWS("Profile", "http://www.opengis.net/spec/GMLCOV/1.0/conf/special-format"),
                    OWS("Profile", "http://www.opengis.net/spec/GMLCOV_geotiff-coverages/1.0/conf/geotiff-coverage"),
                    OWS("Profile", "http://www.opengis.net/spec/WCS_geotiff-coverages/1.0/conf/geotiff-coverage"),
                    OWS("Profile", "http://www.opengis.net/spec/WCS_service-model_crs-predefined/1.0/conf/crs-predefined"),
                    OWS("Profile", "http://www.opengis.net/spec/WCS_service-model_scaling+interpolation/1.0/conf/scaling+interpolation"),
                    OWS("Profile", "http://www.opengis.net/spec/WCS_service-model_band-subsetting/1.0/conf/band-subsetting"),
                    OWS("Fees", conf.fees),
                    OWS("AccessConstraints", conf.access_constraints)
                )
            )

        if all_sections or "serviceprovider" in sections:
            caps.append(
                OWS("ServiceProvider",
                    OWS("ProviderName", conf.provider_name),
                    self.encode_reference("ProviderSite", conf.provider_site),
                    OWS("ServiceContact",
                        OWS("IndividualName", conf.individual_name),
                        OWS("PositionName", conf.position_name),
                        OWS("ContactInfo",
                            OWS("Phone",
                                OWS("Voice", conf.phone_voice),
                                OWS("Facsimile", conf.phone_facsimile)
                            ),
                            OWS("Address",
                                OWS("DeliveryPoint", conf.delivery_point),
                                OWS("City", conf.city),
                                OWS("AdministrativeArea", conf.administrative_area),
                                OWS("PostalCode", conf.postal_code),
                                OWS("Country", conf.country),
                                OWS("ElectronicMailAddress", conf.electronic_mail_address)
                            ),
                            self.encode_reference(
                                "OnlineResource", conf.onlineresource
                            ),
                            OWS("HoursOfService", conf.hours_of_service),
                            OWS("ContactInstructions", conf.contact_instructions)
                        ),
                        OWS("Role", conf.role)
                    )
                )
            )


        if all_sections or "operationsmetadata" in sections:
            component = ServiceComponent(env)
            versions = ("2.0.0", "2.0.1")
            get_handlers = component.query_service_handlers(
                service="WCS", versions=versions, method="GET"
            )
            post_handlers = component.query_service_handlers(
                service="WCS", versions=versions, method="POST"
            )
            all_handlers = sorted(
                set(get_handlers + post_handlers), key=lambda h: h.request
            )

            operations = []
            for handler in all_handlers:
                methods = []
                if handler in get_handlers:
                    methods.append(
                        self.encode_reference("Get", conf.http_service_url)
                    )
                if handler in post_handlers:
                    post = self.encode_reference("Post", conf.http_service_url)
                    post.append(
                        OWS("Constraint", 
                            OWS("AllowedValues", 
                                OWS("Value", "XML")
                            ), name="PostEncoding"
                        )
                    )
                    methods.append(post)

                operations.append(
                    OWS("Operation",
                        OWS("DCP",
                            OWS("HTTP", *methods)
                        ), 
                        # apply default values as constraints
                        *[
                            OWS("Constraint",
                                OWS("NoValues"),
                                OWS("DefaultValue", str(default)),
                                name=name
                            ) for name, default 
                            in getattr(handler, "constraints", {}).items()
                        ],
                        name=handler.request
                    )
                )
            caps.append(OWS("OperationsMetadata", *operations))


        if all_sections or "servicemetadata" in sections:
            service_metadata = WCS("ServiceMetadata")

            # get the list of enabled formats from the format registry
            formats = filter(
                lambda f: f, getFormatRegistry().getSupportedFormatsWCS()
            )
            service_metadata.extend(
                map(lambda f: WCS("formatSupported", f.mimeType), formats)
            )

            # get a list of supported CRSs from the CRS registry
            supported_crss = crss.getSupportedCRS_WCS(format_function=crss.asURL)
            extension = WCS("Extension")
            service_metadata.append(extension)
            extension.extend(
                map(lambda c: CRS("crsSupported", c), supported_crss)
            )

            caps.append(service_metadata)

        inc_contents = all_sections or "contents" in sections
        inc_coverage_summary = inc_contents or "coveragesummary" in sections
        inc_dataset_series_summary = inc_contents or "datasetseriessummary" in sections
        inc_contents = inc_contents or inc_coverage_summary or inc_dataset_series_summary

        if inc_contents:
            contents = []

            if inc_coverage_summary:
                coverages = []

                # reduce data transfer by only selecting required elements
                # TODO: currently runs into a bug
                #coverages_qs = coverages_qs.only(
                #    "identifier", "real_content_type"
                #)

                for coverage in coverages_qs:
                    coverages.append(
                        WCS("CoverageSummary",
                            WCS("CoverageId", coverage.identifier),
                            WCS("CoverageSubtype", coverage.real_type.__name__)
                        )
                    )
                contents.extend(coverages)

            if inc_dataset_series_summary:
                dataset_series_set = []
                
                # reduce data transfer by only selecting required elements
                # TODO: currently runs into a bug
                #dataset_series_qs = dataset_series_qs.only(
                #    "identifier", "begin_time", "end_time", "footprint"
                #)
                
                for dataset_series in dataset_series_qs:
                    minx, miny, maxx, maxy = dataset_series.extent_wgs84

                    dataset_series_set.append(
                        EOWCS("DatasetSeriesSummary",
                            OWS("WGS84BoundingBox",
                                OWS("LowerCorner", "%f %f" % (miny, minx)),
                                OWS("UpperCorner", "%f %f" % (maxy, maxx)),
                            ),
                            EOWCS("DatasetSeriesId", dataset_series.identifier),
                            GML("TimePeriod",
                                GML("beginPosition", isoformat(dataset_series.begin_time)),
                                GML("endPosition", isoformat(dataset_series.end_time)),
                                **{ns_gml("id"): dataset_series.identifier + "_timeperiod"}
                            )
                        )
                    )

                contents.append(WCS("Extension", *dataset_series_set))

            caps.append(WCS("Contents", *contents))

        root = WCS("Capabilities", *caps, version="2.0.1", updateSequence=conf.update_sequence)
        return root