Example #1
0
    def _construct_doc(self):
        doc = WPS.ExecuteResponse()
        doc.attrib['{http://www.w3.org/2001/XMLSchema-instance}schemaLocation'] = \
            'http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsExecute_response.xsd'
        doc.attrib['service'] = 'WPS'
        doc.attrib['version'] = '1.0.0'
        doc.attrib['{http://www.w3.org/XML/1998/namespace}lang'] = 'en-US'
        doc.attrib['serviceInstance'] = '%s%s' % (config.get_config_value(
            'server', 'url'), '?service=WPS&request=GetCapabilities')

        if self.status >= STATUS.STORE_STATUS:
            if self.process.status_location:
                doc.attrib['statusLocation'] = self.process.status_url

        # Process XML
        process_doc = WPS.Process(OWS.Identifier(self.process.identifier),
                                  OWS.Title(self.process.title))
        if self.process.abstract:
            process_doc.append(OWS.Abstract(self.process.abstract))
        # TODO: See Table 32 Metadata in OGC 06-121r3
        # for m in self.process.metadata:
        #    process_doc.append(OWS.Metadata(m))
        if self.process.profile:
            process_doc.append(OWS.Profile(self.process.profile))
        process_doc.attrib[
            '{http://www.opengis.net/wps/1.0.0}processVersion'] = self.process.version

        doc.append(process_doc)

        # Status XML
        # return the correct response depending on the progress of the process
        if self.status == STATUS.STORE_AND_UPDATE_STATUS:
            if self.status_percentage == 0:
                self.message = 'PyWPS Process %s accepted' % self.process.identifier
                status_doc = self._process_accepted()
                doc.append(status_doc)
                return doc
            elif self.status_percentage > 0:
                status_doc = self._process_started()
                doc.append(status_doc)
                return doc

        # check if process failed and display fail message
        if self.status_percentage == -1:
            status_doc = self._process_failed()
            doc.append(status_doc)
            return doc

        # TODO: add paused status

        if self.status == STATUS.DONE_STATUS:
            status_doc = self._process_succeeded()
            doc.append(status_doc)

            # DataInputs and DataOutputs definition XML if lineage=true
            if self.wps_request.lineage == 'true':
                try:
                    # TODO: stored process has ``pywps.inout.basic.LiteralInput``
                    # instead of a ``pywps.inout.inputs.LiteralInput``.
                    data_inputs = [
                        self.wps_request.inputs[i][0].execute_xml()
                        for i in self.wps_request.inputs
                    ]
                    doc.append(WPS.DataInputs(*data_inputs))
                except Exception as e:
                    LOGGER.error(
                        "Failed to update lineage for input parameter. %s", e)

                output_definitions = [
                    self.outputs[o].execute_xml_lineage() for o in self.outputs
                ]
                doc.append(WPS.OutputDefinitions(*output_definitions))

            # Process outputs XML
            output_elements = [
                self.outputs[o].execute_xml() for o in self.outputs
            ]
            doc.append(WPS.ProcessOutputs(*output_elements))
        return doc
Example #2
0
    def _construct_doc(self):
        doc = WPS.ExecuteResponse()
        doc.attrib[
            '{http://www.w3.org/2001/XMLSchema-instance}schemaLocation'] = 'http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsDescribeProcess_response.xsd'
        doc.attrib['service'] = 'WPS'
        doc.attrib['version'] = '1.0.0'
        doc.attrib['{http://www.w3.org/XML/1998/namespace}lang'] = 'en-US'
        doc.attrib['serviceInstance'] = '%s:%s%s' % (
            config.get_config_value('wps', 'serveraddress'),
            config.get_config_value('wps', 'serverport'),
            '/wps?service=wps&request=getcapabilities')

        if self.status >= self.STORE_STATUS:
            if self.process.status_location:
                doc.attrib['statusLocation'] = self.process.status_url

        # Process XML
        process_doc = WPS.Process(OWS.Identifier(self.process.identifier),
                                  OWS.Title(self.process.title))
        if self.process.abstract:
            process_doc.append(OWS.Abstract(self.process.abstract))
        # TODO: See Table 32 Metadata in OGC 06-121r3
        #for m in self.process.metadata:
        #    process_doc.append(OWS.Metadata(m))
        if self.process.profile:
            process_doc.append(OWS.Profile(self.process.profile))
        if self.process.wsdl:
            process_doc.append(OWS.WSDL(self.process.wsdl))
        process_doc.attrib[
            '{http://www.opengis.net/wps/1.0.0}processVersion'] = self.process.version

        doc.append(process_doc)

        # Status XML
        # return the correct response depending on the progress of the process
        if self.status >= self.STORE_AND_UPDATE_STATUS:
            if self.status_percentage == 0:
                self.message = 'PyWPS Process %s accepted' % self.process.identifier
                status_doc = self._process_accepted()
                doc.append(status_doc)
                self.write_response_doc(doc)
                return doc
            elif 0 < self.status_percentage < 100:
                status_doc = self._process_started()
                doc.append(status_doc)
                return doc

        # check if process failed and display fail message
        if self.status_percentage == -1:
            status_doc = self._process_failed()
            doc.append(status_doc)
            return doc

        # TODO: add paused status

        status_doc = self._process_succeeded()
        doc.append(status_doc)

        # DataInputs and DataOutputs definition XML if lineage=true
        if self.wps_request.lineage == 'true':
            data_inputs = [
                self.wps_request.inputs[i][0].execute_xml()
                for i in self.wps_request.inputs
            ]
            doc.append(WPS.DataInputs(*data_inputs))

            output_definitions = [
                self.outputs[o].execute_xml_lineage() for o in self.outputs
            ]
            doc.append(WPS.OutputDefinitions(*output_definitions))

        # Process outputs XML
        output_elements = [self.outputs[o].execute_xml() for o in self.outputs]
        doc.append(WPS.ProcessOutputs(*output_elements))
        return doc