    001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/ogcwebservices/wps/describeprocess/DescribeProcessRequestHandler.java $
    002    /*----------------------------------------------------------------------------
    003     This file is part of deegree, http://deegree.org/
    004     Copyright (C) 2001-2009 by:
    005       Department of Geography, University of Bonn
    006     and
    007       lat/lon GmbH
    008
    009     This library is free software; you can redistribute it and/or modify it under
    010     the terms of the GNU Lesser General Public License as published by the Free
    011     Software Foundation; either version 2.1 of the License, or (at your option)
    012     any later version.
    013     This library is distributed in the hope that it will be useful, but WITHOUT
    014     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    015     FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
    016     details.
    017     You should have received a copy of the GNU Lesser General Public License
    018     along with this library; if not, write to the Free Software Foundation, Inc.,
    019     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    020
    021     Contact information:
    022
    023     lat/lon GmbH
    024     Aennchenstr. 19, 53177 Bonn
    025     Germany
    026     http://lat-lon.de/
    027
    028     Department of Geography, University of Bonn
    029     Prof. Dr. Klaus Greve
    030     Postfach 1147, 53001 Bonn
    031     Germany
    032     http://www.geographie.uni-bonn.de/deegree/
    033
    034     e-mail: info@deegree.org
    035    ----------------------------------------------------------------------------*/
    036    package org.deegree.ogcwebservices.wps.describeprocess;
    037
    038    import java.util.ArrayList;
    039    import java.util.List;
    040    import java.util.Map;
    041
    042    import org.deegree.datatypes.Code;
    043    import org.deegree.framework.log.ILogger;
    044    import org.deegree.framework.log.LoggerFactory;
    045    import org.deegree.ogcwebservices.InvalidParameterValueException;
    046    import org.deegree.ogcwebservices.OGCWebServiceException;
    047    import org.deegree.ogcwebservices.wps.WPService;
    048    import org.deegree.ogcwebservices.wps.configuration.WPSConfiguration;
    049    import org.deegree.ogcwebservices.wps.execute.Process;
    050
    051    /**
    052     * DescribeProcessRequestHandler.java
    053     *
    054     * Created on 10.03.2006. 12:06:58h
    055     *
    056     * @author <a href="mailto:christian@kiehle.org">Christian Kiehle</a>
    057     * @author <a href="mailto:christian.heier@gmx.de">Christian Heier</a>
    058     *
    059     * @version 1.0.
    060     *
    061     * @since 2.0
    062     */
    063
    064    public class DescribeProcessRequestHandler {
    065
    066        private static ILogger LOG = LoggerFactory.getLogger( DescribeProcessRequestHandler.class );
    067
    068        private WPService wpService = null;
    069
    070        /**
    071         *
    072         * @param wpService
    073         */
    074        public DescribeProcessRequestHandler( WPService wpService ) {
    075            this.wpService = wpService;
    076        }
    077
    078        /**
    079         *
    080         * @param describeProcessRequest
    081         * @return the describtion of the process.
    082         * @throws OGCWebServiceException
    083         */
    084        public ProcessDescriptions handleRequest( DescribeProcessRequest describeProcessRequest )
    085                                throws OGCWebServiceException {
    086
    087            // Get configuration from current wps instance
    088            WPSConfiguration wpsConfiguration = wpService.getConfiguration();
    089
    090            // Get the map of registered Processes from wps configuration
    091            Map<String, Process> processesMap = wpsConfiguration.getRegisteredProcesses();
    092
    093            // Get list of requested process descriptions from
    094            // wpsDescribeProcessRequest
    095            List<Code> requestedProcessesList = describeProcessRequest.getIdentifier();
    096
    097            // Prepare list of process description to return
    098            List<ProcessDescription> processDescriptionList = new ArrayList<ProcessDescription>();
    099
    100            // If the requested process is registered in current wps instance add it to processDescriptions, otherwise throw
    101            // exception
    102            int requestedProcessesSize = requestedProcessesList.size();
    103            for ( int i = 0; i < requestedProcessesSize; i++ ) {
    104
    105                Code requestedProcess = requestedProcessesList.get( i );
    106
    107                String identifier = requestedProcess.getCode().toUpperCase();
    108
    109                if ( processesMap.containsKey( identifier ) ) {
    110
    111                    Process process = processesMap.get( identifier );
    112
    113                    ProcessDescription processDescription = process.getProcessDescription();
    114                    processDescriptionList.add( i, processDescription );
    115
    116                } else {
    117                    String msg = "Process '" + identifier + "' is not supported by this WPS.";
    118                    LOG.logError( msg );
    119                    throw new InvalidParameterValueException( "Identifier", msg );
    120                }
    121            }
    122            return new ProcessDescriptions( processDescriptionList );
    123        }
    124
    125    }