    001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/portal/standard/gazetteer/FindChildrenCommand.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.portal.standard.gazetteer;
    037
    038    import java.util.List;
    039    import java.util.Map;
    040    import java.util.UUID;
    041
    042    import org.deegree.datatypes.QualifiedName;
    043    import org.deegree.model.filterencoding.ComplexFilter;
    044    import org.deegree.model.filterencoding.Literal;
    045    import org.deegree.model.filterencoding.Operation;
    046    import org.deegree.model.filterencoding.OperationDefines;
    047    import org.deegree.model.filterencoding.PropertyIsCOMPOperation;
    048    import org.deegree.model.filterencoding.PropertyName;
    049    import org.deegree.ogcbase.PropertyPath;
    050    import org.deegree.ogcbase.SortProperty;
    051    import org.deegree.ogcwebservices.wfs.capabilities.WFSCapabilities;
    052    import org.deegree.ogcwebservices.wfs.operation.GetFeature;
    053    import org.deegree.ogcwebservices.wfs.operation.Query;
    054    import org.deegree.ogcwebservices.wfs.operation.GetFeature.RESULT_TYPE;
    055
    056    /**
    057     * TODO add class documentation here
    058     *
    059     * @author <a href="mailto:name@deegree.org">Andreas Poth</a>
    060     * @author last edited by: $Author: apoth $
    061     *
    062     * @version $Revision: 26614 $, $Date: 2010-09-07 15:55:38 +0200 (Di, 07. Sep 2010) $
    063     */
    064    public class FindChildrenCommand extends AbstractGazetteerCommand {
    065
    066        private String geographicIdentifier;
    067
    068        /**
    069         *
    070         * @param gazetteerAddress
    071         * @param featureType
    072         * @param properties
    073         * @param geographicIdentifier
    074         */
    075        FindChildrenCommand( String gazetteerAddress, QualifiedName featureType, Map<String, String> properties,
    076                             String geographicIdentifier ) {
    077            this.gazetteerAddress = gazetteerAddress;
    078            this.featureType = featureType;
    079            this.geographicIdentifier = geographicIdentifier;
    080            this.properties = properties;
    081        }
    082
    083        /*
    084         * (non-Javadoc)
    085         *
    086         * @see org.deegree.kernel.Command#execute()
    087         */
    088        List<GazetteerItem> execute()
    089                                throws Exception {
    090            if ( !capabilitiesMap.containsKey( gazetteerAddress ) ) {
    091                loadCapabilities();
    092            }
    093            WFSCapabilities capabilities = capabilitiesMap.get( gazetteerAddress );
    094
    095            PropertyName propertyName = new PropertyName( createPropertyPath( properties.get( "ParentIdentifier" ) ) );
    096
    097            PropertyPath sortProperty = createPropertyPath( properties.get( "DisplayName" ) );
    098            SortProperty[] sp = new SortProperty[] { SortProperty.create( sortProperty, "ASC" ) };
    099
    100            Literal literal = new Literal( geographicIdentifier );
    101            Operation operation = new PropertyIsCOMPOperation( OperationDefines.PROPERTYISEQUALTO, propertyName, literal );
    102            ComplexFilter filter = new ComplexFilter( operation );
    103
    104            // create Query and GetFeature request
    105            // select just properties needed to fill result list
    106            PropertyPath[] propertyNames = getResultProperties( properties );
    107
    108            Query query = Query.create( propertyNames, null, sp, null, null, new QualifiedName[] { featureType }, null,
    109                                        null, filter, 500, 0, RESULT_TYPE.RESULTS );
    110            GetFeature getFeature = GetFeature.create( capabilities.getVersion(), UUID.randomUUID().toString(),
    111                                                       RESULT_TYPE.RESULTS, GetFeature.FORMAT_GML3, null, 500, 0, -1, -1,
    112                                                       new Query[] { query } );
    113
    114            // perform GetFeature request and create resulting GazetteerItems list
    115            createItemsList( performGetFeature( capabilities, getFeature ) );
    116            return items;
    117        }
    118
    119    }