Package net.opengis.wps10

Examples of net.opengis.wps10.Wps10Factory


        // perform the execution and grab the results
        Map<String, ProcessOutput> outputMap = executeInternal(request);
       
        // build the response
        Wps10Factory f = Wps10Factory.eINSTANCE;
        ExecuteResponseType response = f.createExecuteResponseType();
        response.setLang("en");
        if(request.getBaseUrl() != null) {
          response.setServiceInstance(ResponseUtils.appendQueryString(ResponseUtils.buildURL(request
                .getBaseUrl(), "ows", null, URLType.SERVICE), ""));
        }

        // process
        Name processName = Ows11Util.name(request.getIdentifier());
        ProcessFactory pf = Processors.createProcessFactory(processName);
        final ProcessBriefType process = f.createProcessBriefType();
        response.setProcess(process);
        process.setIdentifier(request.getIdentifier());
        process.setProcessVersion(pf.getVersion(processName));
        process.setTitle(Ows11Util.languageString(pf.getTitle(processName)));
        process.setAbstract(Ows11Util.languageString(pf.getDescription(processName)));

        // status
        response.setStatus(f.createStatusType());
        response.getStatus().setCreationTime(
                Converters.convert(started, XMLGregorianCalendar.class));
        response.getStatus().setProcessSucceeded("Process succeeded.");

        // inputs
        response.setDataInputs(f.createDataInputsType1());
        for (Iterator i = request.getDataInputs().getInput().iterator(); i.hasNext();) {
            InputType input = (InputType) i.next();
            response.getDataInputs().getInput().add(EMFUtils.clone(input, f, true));
        }

        // output definitions
        OutputDefinitionsType outputs = f.createOutputDefinitionsType();
        response.setOutputDefinitions(outputs);

        Map<String, Parameter<?>> outs = pf.getResultInfo(processName, null);
        Map<String, ProcessParameterIO> ppios = new HashMap();

        for (String key : outputMap.keySet()) {
            Parameter p = pf.getResultInfo(processName, null).get(key);
            if (p == null) {
                throw new WPSException("No such output: " + key);
            }

            // find the ppio
            String mime = outputMap.get(key).definition.getMimeType();
            ProcessParameterIO ppio = ProcessParameterIO.find(p, context, mime);
            if (ppio == null) {
                throw new WPSException("Unable to encode output: " + p.key);
            }
            ppios.put(p.key, ppio);

            DocumentOutputDefinitionType output = f.createDocumentOutputDefinitionType();
            outputs.getOutput().add(output);

            output.setIdentifier(Ows11Util.code(p.key));
            if (ppio instanceof ComplexPPIO) {
                output.setMimeType(((ComplexPPIO) ppio).getMimeType());
                if (ppio instanceof BinaryPPIO) {
                    output.setEncoding("base64");
                } else if (ppio instanceof XMLPPIO) {
                    output.setEncoding("utf-8");
                }
            }

            // TODO: better encoding handling + schema
        }

        // process outputs
        ProcessOutputsType1 processOutputs = f.createProcessOutputsType1();
        response.setProcessOutputs(processOutputs);

        for (String key : outputMap.keySet()) {
            OutputDataType output = f.createOutputDataType();
            output.setIdentifier(Ows11Util.code(key));
            output.setTitle(Ows11Util
                    .languageString(pf.getResultInfo(processName, null).get(key).description));
            processOutputs.getOutput().add(output);

            final Object o = outputMap.get(key).object;
            ProcessParameterIO ppio = ppios.get(key);

            if (ppio instanceof ReferencePPIO) {
                // encode as a reference
                OutputReferenceType ref = f.createOutputReferenceType();
                output.setReference(ref);

                ref.setMimeType(outputMap.get(key).definition.getMimeType());
                ref.setHref(((ReferencePPIO) ppio).encode(o).toString());
            } else {
                // encode as data
                DataType data = f.createDataType();
                output.setData(data);

                try {
                  if (ppio instanceof LiteralPPIO) {
                      LiteralDataType literal = f.createLiteralDataType();
                      data.setLiteralData(literal);
 
                      literal.setValue(((LiteralPPIO) ppio).encode(o));
                  } else if (ppio instanceof BoundingBoxPPIO) {
                      BoundingBoxType bbox = ((BoundingBoxPPIO) ppio).encode(o);
                      data.setBoundingBoxData(bbox);
                  } else if (ppio instanceof ComplexPPIO) {
                      ComplexDataType complex = f.createComplexDataType();
                      data.setComplexData(complex);
 
                      ComplexPPIO cppio = (ComplexPPIO) ppio;
                      complex.setMimeType(cppio.getMimeType());
 
View Full Code Here


    public ExecuteResponseType build() {
        ExecuteRequest helper = new ExecuteRequest(request);

        // build the response
        Wps10Factory f = Wps10Factory.eINSTANCE;
        ExecuteResponseType response = f.createExecuteResponseType();
        response.setLang("en");
        if (request.getBaseUrl() != null) {
            response.setServiceInstance(ResponseUtils.appendQueryString(
                    ResponseUtils.buildURL(request.getBaseUrl(), "ows", null, URLType.SERVICE), ""));
        }

        // process
        Name processName = helper.getProcessName();
        ProcessFactory pf = GeoServerProcessors.createProcessFactory(processName);
        final ProcessBriefType process = f.createProcessBriefType();
        response.setProcess(process);
        // damn blasted EMF changes the state of request if we set its identifier on
        // another object! (I guess, following some strict ownership rule...)
        process.setIdentifier((CodeType) EMFUtils.clone(request.getIdentifier(),
                Ows11Factory.eINSTANCE, true));
        process.setProcessVersion(pf.getVersion(processName));
        process.setTitle(Ows11Util.languageString(pf.getTitle(processName)));
        process.setAbstract(Ows11Util.languageString(pf.getDescription(processName)));

        // status
        response.setStatus(f.createStatusType());
        XMLGregorianCalendar gc = Converters.convert(created, XMLGregorianCalendar.class);
        response.getStatus().setCreationTime(gc);
        if (status == null) {
            if (exception != null) {
                setResponseFailed(response, getException(ProcessState.COMPLETED));
            } else if (outputs == null) {
                response.getStatus().setProcessAccepted("Process accepted.");
            } else {
                response.getStatus().setProcessSucceeded("Process succeeded.");
            }
        } else {
            if (status.getPhase() == ProcessState.QUEUED) {
                response.getStatus().setProcessAccepted("Process accepted.");
            } else if (status.getPhase() == ProcessState.RUNNING) {
                ProcessStartedType startedType = f.createProcessStartedType();
                int progressPercent = Math.round(status.getProgress());
                if(progressPercent < 0) {
                    LOGGER.warning("Progress reported is below zero, fixing it to 0: " + progressPercent);
                    progressPercent = 0;
                } else if(progressPercent > 100) {
                    LOGGER.warning("Progress reported is above 100, fixing it to 100: " + progressPercent);
                    progressPercent = 100;
                }
                startedType.setPercentCompleted(new BigInteger(String.valueOf(progressPercent)));
                startedType.setValue(status.getTask());
                response.getStatus().setProcessStarted(startedType);
            } else if (status.getPhase() == ProcessState.COMPLETED) {
                response.getStatus().setProcessSucceeded("Process succeeded.");
            } else {
                ServiceException reportException = getException(status.getPhase());
                setResponseFailed(response, reportException);
            }
        }

        // status location, if asynch
        if (helper.isAsynchronous() && request.getBaseUrl() != null && executionId != null) {
            Map<String, String> kvp = new LinkedHashMap<String, String>();
            kvp.put("service", "WPS");
            kvp.put("version", "1.0.0");
            kvp.put("request", "GetExecutionStatus");
            kvp.put("executionId", executionId);
            response.setStatusLocation(ResponseUtils.buildURL(request.getBaseUrl(), "ows", kvp, URLType.SERVICE));

        }

        // lineage, should be included only if requested, the response should contain it
        // even if the process is not done computing. From the spec:
        // * If lineage is "true" the server shall include in the execute response a complete copy
        // of
        // the DataInputs and OutputDefinition elements _as received in the execute request_.
        // *If lineage is "false" then/ these elements shall be omitted from the response
        if (helper.isLineageRequested()) {
            // inputs
            if (request.getDataInputs() != null && request.getDataInputs().getInput().size() > 0) {
                response.setDataInputs(f.createDataInputsType1());
                for (Iterator i = request.getDataInputs().getInput().iterator(); i.hasNext();) {
                    InputType input = (InputType) i.next();
                    response.getDataInputs().getInput().add(EMFUtils.clone(input, f, true));
                }
            }

            // output definitions, if any was requested explicitly
            List<DocumentOutputDefinitionType> outputList = helper.getRequestedOutputs();
            if (outputList != null) {
                OutputDefinitionsType outputs = f.createOutputDefinitionsType();
                response.setOutputDefinitions(outputs);
                for (DocumentOutputDefinitionType output : outputList) {
                    outputs.getOutput().add(EMFUtils.clone(output, f, true));
                }
            }
        }

        // process outputs
        if (exception == null && outputs != null) {
            ProcessOutputsType1 processOutputs = f.createProcessOutputsType1();
            response.setProcessOutputs(processOutputs);

            Map<String, Parameter<?>> resultInfo = pf.getResultInfo(processName, null);

            if (request.getResponseForm() != null
View Full Code Here

        return response;
    }

    OutputDataType encodeOutput(String key, Parameter<?> outputParam, String mimeType,
            boolean reference) {
        Wps10Factory f = Wps10Factory.eINSTANCE;
        OutputDataType output = f.createOutputDataType();
        output.setIdentifier(Ows11Util.code(key));
        output.setTitle(Ows11Util.languageString(outputParam.description));

        final Object o = outputs.get(key);
        if (mimeType == null) {
            mimeType = getOutputMimeType(key);
        }
        ProcessParameterIO ppio = ProcessParameterIO.find(outputParam, context, mimeType);

        if (ppio == null) {
            throw new WPSException("Don't know how to encode output " + key + " in mime type "
                    + mimeType);
        }

        try {
            if (reference && ppio instanceof ComplexPPIO) {
                // encode as reference
                OutputReferenceType outputReference = f.createOutputReferenceType();
                output.setReference(outputReference);
               
                ComplexPPIO cppio = (ComplexPPIO) ppio;
                File file = resourceManager.getOutputFile(executionId, key + "." + cppio.getFileExtension());
               
                // write out the file
                FileOutputStream fos = null;
                try {
                    fos = new FileOutputStream(file);
                    cppio.encode(o, fos);
                } finally {
                    IOUtils.closeQuietly(fos);
                }
               
                // create the link
                Map<String, String> kvp = new LinkedHashMap<String, String>();
                kvp.put("service", "WPS");
                kvp.put("version", "1.0.0");
                kvp.put("request", "GetExecutionResult");
                kvp.put("executionId", executionId);
                kvp.put("outputId", file.getName());
                if(o instanceof RawData) {
                  RawData rawData = (RawData) o;
                  kvp.put("mimetype", rawData.getMimeType());
                } else {
                  kvp.put("mimetype", cppio.getMimeType());
                }
                outputReference.setHref(ResponseUtils.buildURL(request.getBaseUrl(), "ows", kvp, URLType.SERVICE));
                outputReference.setMimeType(cppio.getMimeType());
            } else {
                // encode as data
                DataType data = f.createDataType();
                output.setData(data);

                if (ppio instanceof LiteralPPIO) {
                    LiteralDataType literal = f.createLiteralDataType();
                    data.setLiteralData(literal);

                    literal.setValue(((LiteralPPIO) ppio).encode(o));
                } else if (ppio instanceof BoundingBoxPPIO) {
                    BoundingBoxType bbox = ((BoundingBoxPPIO) ppio).encode(o);
                    data.setBoundingBoxData(bbox);
                } else if (ppio instanceof ComplexPPIO) {
                    ComplexDataType complex = f.createComplexDataType();
                    data.setComplexData(complex);

                    ComplexPPIO cppio = (ComplexPPIO) ppio;
                    complex.setMimeType(cppio.getMimeType());
View Full Code Here

        }
        return output;
    }

    void setResponseFailed(ExecuteResponseType response, ServiceException reportException) {
        Wps10Factory f = Wps10Factory.eINSTANCE;
        ProcessFailedType failedType = f.createProcessFailedType();
        ExceptionReportType report = Ows11Util.exceptionReport(reportException, verboseExceptions,
                "1.1.0");
        failedType.setExceptionReport(report);
        response.getStatus().setProcessFailed(failedType);
    }
View Full Code Here

        }

        // TODO: add update sequence negotiation

        // encode the response
        Wps10Factory wpsf = Wps10Factory.eINSTANCE;
        Ows11Factory owsf = Ows11Factory.eINSTANCE;

        WPSCapabilitiesType caps = wpsf.createWPSCapabilitiesType();
        caps.setVersion("1.0.0");

        // TODO: make configurable
        caps.setLang("en");

        // ServiceIdentification
        ServiceIdentificationType si = owsf.createServiceIdentificationType();
        caps.setServiceIdentification(si);

        si.getTitle().add(Ows11Util.languageString(wps.getTitle()));
        si.getAbstract().add(Ows11Util.languageString(wps.getAbstract()));

        KeywordsType kw = Ows11Util.keywords(wps.keywordValues());
        ;
        if (kw != null) {
            si.getKeywords().add(kw);
        }

        si.setServiceType(Ows11Util.code("WPS"));
        si.getServiceTypeVersion().add("1.0.0");
        si.setFees(wps.getFees());

        if (wps.getAccessConstraints() != null) {
            si.getAccessConstraints().add(wps.getAccessConstraints());
        }

        // ServiceProvider
        ServiceProviderType sp = owsf.createServiceProviderType();
        caps.setServiceProvider(sp);

        // TODO: set provder name from context
        SettingsInfo settings = wps.getGeoServer().getSettings();
        if (settings.getContact().getContactOrganization() != null) {
            sp.setProviderName(settings.getContact().getContactOrganization());
        } else {
            sp.setProviderName("GeoServer");
        }

        sp.setProviderSite(owsf.createOnlineResourceType());
        sp.getProviderSite().setHref(settings.getOnlineResource());
        sp.setServiceContact(responsibleParty(settings, owsf));

        // OperationsMetadata
        OperationsMetadataType om = owsf.createOperationsMetadataType();
        caps.setOperationsMetadata(om);

        OperationType gco = owsf.createOperationType();
        gco.setName("GetCapabilities");
        gco.getDCP().add(Ows11Util.dcp("wps", request));
        om.getOperation().add(gco);

        OperationType dpo = owsf.createOperationType();
        dpo.setName("DescribeProcess");
        dpo.getDCP().add(Ows11Util.dcp("wps", request));
        om.getOperation().add(dpo);

        OperationType eo = owsf.createOperationType();
        eo.setName("Execute");
        eo.getDCP().add(Ows11Util.dcp("wps", request));
        om.getOperation().add(eo);

        ProcessOfferingsType po = wpsf.createProcessOfferingsType();
        caps.setProcessOfferings(po);

        // gather the process list
        for (ProcessFactory pf : GeoServerProcessors.getProcessFactories()) {
            for (Name name : pf.getNames()) {
                ProcessBriefType p = wpsf.createProcessBriefType();
                p.setProcessVersion(pf.getVersion(name));
                po.getProcess().add(p);

                p.setIdentifier(Ows11Util.code(name));
                p.setTitle(Ows11Util.languageString(pf.getTitle(name)));
                p.setAbstract(Ows11Util.languageString(pf.getDescription(name)));
            }
        }
        // sort it
        ECollections.sort(po.getProcess(), new Comparator() {

            public int compare(Object o1, Object o2) {
                ProcessBriefType pb1 = (ProcessBriefType) o1;
                ProcessBriefType pb2 = (ProcessBriefType) o2;
               
                final String id1 = pb1.getIdentifier().getValue();
                final String id2 = pb2.getIdentifier().getValue();
                return id1.compareTo(id2);
            }
        });

        LanguagesType1 languages = wpsf.createLanguagesType1();
        caps.setLanguages(languages);

        DefaultType2 defaultLanguage = wpsf.createDefaultType2();
        languages.setDefault(defaultLanguage);
        defaultLanguage.setLanguage("en-US");

        LanguagesType supportedLanguages = wpsf.createLanguagesType();
        languages.setSupported(supportedLanguages);
        supportedLanguages.getLanguage().add("en-US");

        return caps;
        // Version detection and alternative invocation if being implemented.
View Full Code Here

    }
   
    @Override
    public Object read(Object request, Map kvp, Map rawKvp) throws Exception {
        ExecuteType execute = (ExecuteType) super.read(request, kvp, rawKvp);
        Wps10Factory factory = Wps10Factory.eINSTANCE;
       
        // grab the process, we need it to parse the data inputs
        Name processName = Ows11Util.name(execute.getIdentifier());
        ProcessFactory pf = GeoServerProcessors.createProcessFactory(processName);
        if (pf == null) {
            throw new WPSException("No such process: " + processName);
        }

        // parse inputs
        List<InputType> inputs = parseDataInputs(pf.getParameterInfo(processName), (String) rawKvp.get("DataInputs"));
        DataInputsType1 input1 = factory.createDataInputsType1();
        input1.getInput().addAll(inputs);
        execute.setDataInputs(input1);
       
        if(rawKvp.containsKey("responseDocument")) {
            execute.setResponseForm(parseResponseDocument(pf.getResultInfo(processName, null), (String) rawKvp.get("responseDocument")));
        } else if(rawKvp.containsKey("rawDataOutput")) {
            execute.setResponseForm(parseRawDataOutput(pf.getResultInfo(processName, null), (String) rawKvp.get("rawDataOutput")));
        } else {
            ResponseFormType responseForm = factory.createResponseFormType();
            responseForm.setResponseDocument(factory.createResponseDocumentType());
            execute.setResponseForm(responseForm);
        }
       
        if("true".equals(kvp.get("storeExecuteResponse"))) {
            if(execute.getResponseForm().getResponseDocument() == null) {
View Full Code Here

        List<IOParam> params = parseIOParameters(inputString);
       
        List<InputType> result = new ArrayList<InputType>();
        for (IOParam ioParam : params) {
            // common
            Wps10Factory factory = Wps10Factory.eINSTANCE;
            InputType it = factory.createInputType();
            it.setIdentifier(Ows11Util.code(ioParam.id));
            it.setData(factory.createDataType());
           
            Parameter<?> gtParam = inputParams.get(ioParam.id);
            if(gtParam == null) {
                throw new WPSException("Unknown data input named '" + ioParam.id + "'");
            }
View Full Code Here

       
        return literal;
    }
   
    ResponseFormType parseResponseDocument(Map<String, Parameter<?>> outputs, String responseDefinition) {
        Wps10Factory factory = Wps10Factory.eINSTANCE;
        List<IOParam> ioParams = parseIOParameters(responseDefinition);
       
        ResponseFormType response = factory.createResponseFormType();
        ResponseDocumentType doc = factory.createResponseDocumentType();
        response.setResponseDocument(doc);
       
        for (IOParam ioParam : ioParams) {
            doc.getOutput().add(parseOutputDefinitionType(outputs, factory, ioParam, true));
        }
View Full Code Here

       
        return odt;
    }
   
    ResponseFormType parseRawDataOutput(Map<String, Parameter<?>> resultInfo, String rawOutputs) {
        Wps10Factory factory = Wps10Factory.eINSTANCE;
        ResponseFormType response = factory.createResponseFormType();
       
        List<IOParam> ioParams = parseIOParameters(rawOutputs);
       
        if(ioParams.size() == 0) {
            return response;
View Full Code Here

        }

        // TODO: add update sequence negotiation

        // encode the response
        Wps10Factory wpsf = Wps10Factory.eINSTANCE;
        Ows11Factory owsf = Ows11Factory.eINSTANCE;

        WPSCapabilitiesType caps = wpsf.createWPSCapabilitiesType();
        caps.setVersion("1.0.0");

        // TODO: make configurable
        caps.setLang("en");

        // ServiceIdentification
        ServiceIdentificationType si = owsf.createServiceIdentificationType();
        caps.setServiceIdentification(si);

        si.getTitle().add(Ows11Util.languageString(wps.getTitle()));
        si.getAbstract().add(Ows11Util.languageString(wps.getAbstract()));

        KeywordsType kw = Ows11Util.keywords(wps.getKeywords());
        ;
        if (kw != null) {
            si.getKeywords().add(kw);
        }

        si.setServiceType(Ows11Util.code("WPS"));
        si.getServiceTypeVersion().add("1.0.0");
        si.setFees(wps.getFees());

        if (wps.getAccessConstraints() != null) {
            si.getAccessConstraints().add(wps.getAccessConstraints());
        }

        // ServiceProvider
        ServiceProviderType sp = owsf.createServiceProviderType();
        caps.setServiceProvider(sp);

        // TODO: set provder name from context
        GeoServerInfo geoServer = wps.getGeoServer().getGlobal();
        if (geoServer.getContact().getContactOrganization() != null) {
            sp.setProviderName(geoServer.getContact().getContactOrganization());
        } else {
            sp.setProviderName("GeoServer");
        }

        sp.setProviderSite(owsf.createOnlineResourceType());
        sp.getProviderSite().setHref(geoServer.getOnlineResource());
        sp.setServiceContact(responsibleParty(geoServer, owsf));

        // OperationsMetadata
        OperationsMetadataType om = owsf.createOperationsMetadataType();
        caps.setOperationsMetadata(om);

        OperationType gco = owsf.createOperationType();
        gco.setName("GetCapabilities");
        gco.getDCP().add(Ows11Util.dcp("wps", request));
        om.getOperation().add(gco);

        OperationType dpo = owsf.createOperationType();
        dpo.setName("DescribeProcess");
        dpo.getDCP().add(Ows11Util.dcp("wps", request));
        om.getOperation().add(dpo);

        OperationType eo = owsf.createOperationType();
        eo.setName("Execute");
        eo.getDCP().add(Ows11Util.dcp("wps", request));
        om.getOperation().add(eo);

        ProcessOfferingsType po = wpsf.createProcessOfferingsType();
        caps.setProcessOfferings(po);

        // gather the process list
        for (ProcessFactory pf : Processors.getProcessFactories()) {
            for (Name name : pf.getNames()) {
                if (!getProcessBlacklist().contains(name)) {
                    ProcessBriefType p = wpsf.createProcessBriefType();
                    p.setProcessVersion(pf.getVersion(name));
                    po.getProcess().add(p);

                    p.setIdentifier(Ows11Util.code(name));
                    p.setTitle(Ows11Util.languageString(pf.getTitle(name)));
                    p.setAbstract(Ows11Util.languageString(pf.getDescription(name)));
                }
            }
        }
        // sort it
        ECollections.sort(po.getProcess(), new Comparator() {

            public int compare(Object o1, Object o2) {
                ProcessBriefType pb1 = (ProcessBriefType) o1;
                ProcessBriefType pb2 = (ProcessBriefType) o2;
               
                final String id1 = pb1.getIdentifier().getValue();
                final String id2 = pb2.getIdentifier().getValue();
                return id1.compareTo(id2);
            }
        });

        LanguagesType1 languages = wpsf.createLanguagesType1();
        caps.setLanguages(languages);

        DefaultType2 defaultLanguage = wpsf.createDefaultType2();
        languages.setDefault(defaultLanguage);
        defaultLanguage.setLanguage("en-US");

        LanguagesType supportedLanguages = wpsf.createLanguagesType();
        languages.setSupported(supportedLanguages);
        supportedLanguages.getLanguage().add("en-US");

        return caps;
        // Version detection and alternative invocation if being implemented.
View Full Code Here

TOP

Related Classes of net.opengis.wps10.Wps10Factory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.