Package org.geotools.process

Examples of org.geotools.process.ProcessFactory


                    this.processDescriptionAll();

                    return;
                }

                ProcessFactory pf = Processors.createProcessFactory(identifier);

                if (null == pf) {
                    throw new WPSException("Invalid identifier", "InvalidParameterValue");
                }
View Full Code Here


        Date started = Calendar.getInstance().getTime();
       
        //load the process factory
        CodeType ct = request.getIdentifier();
        Name processName = Ows11Util.name(ct);
        ProcessFactory pf = Processors.createProcessFactory(processName);
        if ( pf == null ) {
            throw new WPSException( "No such process: " + processName );
        }
       
        //parse the inputs for the request
        Map<String, Object> inputs = new HashMap();
       
        for ( Iterator i = request.getDataInputs().getInput().iterator(); i.hasNext(); ) {
            InputType input = (InputType) i.next();
           
            //locate the parameter for this request
            Parameter p = pf.getParameterInfo(processName).get( input.getIdentifier().getValue() );
            if ( p == null ) {
                throw new WPSException( "No such parameter: " + input.getIdentifier().getValue() );
            }
           
            //find the ppio
            ProcessParameterIO ppio = ProcessParameterIO.find( p, context );
            if ( ppio == null ) {
                throw new WPSException( "Unable to decode input: " + input.getIdentifier().getValue() );
            }
           
            //read the data
            Object decoded = null;
            if ( input.getReference() != null ) {
                //this is a reference
                InputReferenceType ref = input.getReference();
               
                //grab the location and method
                String href = ref.getHref();
                MethodType meth = ref.getMethod() != null ? ref.getMethod() : MethodType.GET_LITERAL;
               
                //handle get vs post
                if ( meth == MethodType.POST_LITERAL ) {
                    //post, handle the body
                }
                else {
                    //get, parse kvp
                }
            }
            else {
                //actual data, figure out which type
                DataType data = input.getData();
              
                if ( data.getLiteralData() != null ) {
                    LiteralDataType literal = data.getLiteralData();
                    decoded = ((LiteralPPIO)ppio).decode( literal.getValue() );
                }
                else if ( data.getComplexData() != null ) {
                    ComplexDataType complex = data.getComplexData();
                    decoded = complex.getData().get( 0 );
                    try {
                        decoded = ((ComplexPPIO)ppio).decode( decoded );
                    }
                    catch (Exception e) {
                        throw new WPSException( "Unable to decode input: " + input.getIdentifier().getValue() );
                    }
                }
               
            }
           
            //decode the input
            inputs.put( p.key, decoded );
        }
       
        //execute the process
        Map<String,Object> result = null;
        Throwable error = null;
        try {
            Process p = pf.create(processName);
            result = p.execute( inputs, null );   
        }
        catch( Throwable t ) {
            //save the error to report back
            error = t;
        }
       
        //build the response
        Wps10Factory f = Wps10Factory.eINSTANCE;
        ExecuteResponseType response = f.createExecuteResponseType();
        response.setLang("en");
        response.setServiceInstance(ResponseUtils.appendQueryString(ResponseUtils.buildURL(request.getBaseUrl(), "ows", null, URLType.SERVICE), ""));
      
        //process
        final ProcessBriefType process = f.createProcessBriefType();
        response.setProcess( process );
        process.setIdentifier(ct);
        process.setProcessVersion(pf.getVersion(processName));
        process.setTitle( Ows11Util.languageString( pf.getTitle(processName).toString() ) );
        process.setAbstract( Ows11Util.languageString( pf.getDescription(processName).toString() ) );
      
        //status
        response.setStatus( f.createStatusType() );
        response.getStatus().setCreationTime( Converters.convert( started, XMLGregorianCalendar.class ));
       
        if ( error != null ) {
            ProcessFailedType failure = f.createProcessFailedType();
            response.getStatus().setProcessFailed( failure );
           
            failure.setExceptionReport( Ows11Util.exceptionReport( new ServiceException( error ), wps.getGeoServer().getGlobal().isVerboseExceptions()) );
        }
        else {
            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 : result.keySet() ) {
            Parameter p = pf.getResultInfo(processName, null).get( key );
            if ( p == null ) {
                throw new WPSException( "No such output: " + key );
            }
           
            //find the ppio
            ProcessParameterIO ppio = ProcessParameterIO.find( p, context );
            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() );
            }
           
            //TODO: encoding + schema
        }
       
        //process outputs
        ProcessOutputsType1 processOutputs = f.createProcessOutputsType1();
        response.setProcessOutputs( processOutputs );
       
        for ( String key : result.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 = result.get( key );
            ProcessParameterIO ppio = ppios.get( key );
           
View Full Code Here

        return pds;
    }
   
    void processDescription( CodeType id, ProcessDescriptionsType pds ) {
        Name name = Ows11Util.name(id);
        ProcessFactory pf = Processors.createProcessFactory(name);
        if ( pf == null ) {
            throw new WPSException( "No such process: " + id.getValue() );
        }
       
        ProcessDescriptionType pd = wpsf.createProcessDescriptionType();
        pds.getProcessDescription().add( pd );
       
        pd.setProcessVersion( "1.0.0" );
        pd.setIdentifier( Ows11Util.code( id.getValue() ) );
        pd.setTitle( Ows11Util.languageString(pf.getTitle(name)) );
        pd.setAbstract( Ows11Util.languageString(pf.getDescription(name)) );
       
        //data inputs
        DataInputsType inputs = wpsf.createDataInputsType();
        pd.setDataInputs(inputs);
        dataInputs( inputs, pf, name );
View Full Code Here

    @JSStaticFunction
    public static Process get(Scriptable processNameObj) {
        Process jsProcess = null;
        String[] parts = processNameObj.toString().split(":");
        Name name = new NameImpl(parts[0], parts[1]);
        ProcessFactory factory = Processors.createProcessFactory(name);
        if (factory != null) {
            org.geotools.process.Process process = factory.create(name);
            Scriptable scope = ScriptableObject.getTopLevelScope(processNameObj);
            jsProcess = new Process(scope, factory.getTitle(name),
                    factory.getDescription(name), factory.getParameterInfo(name),
                    factory.getResultInfo(name, null), process);
        }
        return jsProcess;
    }
View Full Code Here

    }
   
    @Test
    public void testSPI() throws Exception {
        NameImpl boundsName = new NameImpl("bean", "Identity");
        ProcessFactory factory = Processors.createProcessFactory(boundsName);
        assertNotNull(factory);
        assertTrue(factory instanceof BeanProcessFactory);

        org.geotools.process.Process buffer = Processors.createProcess(boundsName);
        assertNotNull(buffer);
View Full Code Here

public class GridProcessTest {

    @Test
    public void testDescription() {
        NameImpl gridName = new NameImpl("vec", "Grid");
        ProcessFactory pf = Processors.createProcessFactory(gridName);
        assertNotNull(pf);
        Map<String, Parameter<?>> parameterInfo = pf.getParameterInfo(gridName);
        Parameter<?> modeParam = parameterInfo.get("mode");
        assertEquals(GridMode.class, modeParam.getType());
        assertEquals(GridMode.Rectangular, modeParam.getDefaultValue());
    }
View Full Code Here

    assertTrue(buffered.equals(geom.buffer(1d, 12, BufferParameters.CAP_SQUARE)));
  }

  public void testSPI() throws Exception {
    NameImpl bufferName = new NameImpl("geo", "buffer");
    ProcessFactory factory = Processors.createProcessFactory(bufferName);
    assertNotNull(factory);
    assertTrue(factory instanceof GeometryProcessFactory);
   
    org.geotools.process.Process buffer = Processors.createProcess(bufferName);
    assertNotNull(buffer);
View Full Code Here

            @Override
            public void valueChanged(TreeSelectionEvent e) {
                TreePath path = e.getNewLeadSelectionPath();
                if (path.getLastPathComponent() instanceof Name) {
                    Name name = (Name) path.getLastPathComponent();
                    ProcessFactory factory = (ProcessFactory) path.getParentPath()
                            .getLastPathComponent();
                    updateProcessDesc(factory, name);
                }
            }
        });
View Full Code Here

            @Override
            public Object getChild(Object parent, int index) {
                if (parent == root) {
                    return root.get(index);
                } else if (parent instanceof ProcessFactory) {
                    ProcessFactory factory = (ProcessFactory) parent;
                    return getChildren(factory).get(index);
                }
                return null;
            }

            @Override
            public int getChildCount(Object parent) {
                if (parent == root) {
                    return root.size();
                } else if (parent instanceof ProcessFactory) {
                    ProcessFactory factory = (ProcessFactory) parent;
                    return getChildren(factory).size();
                }
                return 0;
            }

            @Override
            public boolean isLeaf(Object node) {
                if (node == root) {
                    return false;
                } else if (node instanceof ProcessFactory) {
                    return false;
                } else if (node instanceof Name) {
                    return true;
                }
                return true;
            }

            @Override
            public void valueForPathChanged(TreePath path, Object newValue) {
                // our tree is not editable
            }

            @Override
            public int getIndexOfChild(Object parent, Object child) {
                if (parent == root) {
                    return root.indexOf(child);
                } else if (parent instanceof ProcessFactory) {
                    ProcessFactory factory = (ProcessFactory) parent;
                    return getChildren(factory).indexOf(child);
                }
                return 0;
            }
View Full Code Here

     * @return ProcessFactory instance
     */
    private ProcessFactory findProcessFactoryByTitle(String title) {
        Iterator<ProcessFactory> iterator = processFactories.iterator();
        while (iterator.hasNext()) {
            ProcessFactory fac = iterator.next();
            if (fac.getTitle().toString().equalsIgnoreCase(title)) {
                return fac;
            }

        }
        return null;
View Full Code Here

TOP

Related Classes of org.geotools.process.ProcessFactory

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.