001 //$HeadURL: svn+ssh://mschneider@svn.wald.intevation.org/deegree/base/trunk/src/org/deegree/ogcwebservices/wfs/operation/GetFeature.java $
002 /*---------------- FILE HEADER ------------------------------------------
003
004 This file is part of deegree.
005 Copyright (C) 2001-2008 by:
006 EXSE, Department of Geography, University of Bonn
007 http://www.giub.uni-bonn.de/deegree/
008 lat/lon GmbH
009 http://www.lat-lon.de
010
011 This library is free software; you can redistribute it and/or
012 modify it under the terms of the GNU Lesser General Public
013 License as published by the Free Software Foundation; either
014 version 2.1 of the License, or (at your option) any later version.
015
016 This library is distributed in the hope that it will be useful,
017 but WITHOUT ANY WARRANTY; without even the implied warranty of
018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019 Lesser General Public License for more details.
020
021 You should have received a copy of the GNU Lesser General Public
022 License along with this library; if not, write to the Free Software
023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024
025 Contact:
026
027 Andreas Poth
028 lat/lon GmbH
029 Aennchenstraße 19
030 53177 Bonn
031 Germany
032 E-Mail: poth@lat-lon.de
033
034 Prof. Dr. Klaus Greve
035 Department of Geography
036 University of Bonn
037 Meckenheimer Allee 166
038 53115 Bonn
039 Germany
040 E-Mail: greve@giub.uni-bonn.de
041
042 ---------------------------------------------------------------------------*/
043 package org.deegree.ogcwebservices.wfs.operation;
044
045 import java.util.ArrayList;
046 import java.util.HashMap;
047 import java.util.Map;
048
049 import org.deegree.datatypes.QualifiedName;
050 import org.deegree.framework.log.ILogger;
051 import org.deegree.framework.log.LoggerFactory;
052 import org.deegree.i18n.Messages;
053 import org.deegree.io.datastore.schema.MappedFeatureType;
054 import org.deegree.model.filterencoding.FeatureFilter;
055 import org.deegree.model.filterencoding.FeatureId;
056 import org.deegree.model.filterencoding.Filter;
057 import org.deegree.ogcbase.PropertyPath;
058 import org.deegree.ogcbase.PropertyPathFactory;
059 import org.deegree.ogcwebservices.InconsistentRequestException;
060 import org.deegree.ogcwebservices.InvalidParameterValueException;
061 import org.deegree.ogcwebservices.wfs.XMLFactory;
062 import org.deegree.ogcwebservices.wfs.configuration.WFSConfiguration;
063
064 /**
065 * "Proxy" GetFeature request object, only created by {@link GetFeature#create(Map)} if the FEATUREID parameter is used
066 * without TYPENAME parameter.
067 * <p>
068 * It is augmented with information from the {@link WFSConfiguration} to retrieve the names of the associated feature
069 * types.
070 *
071 * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider</a>
072 * @author last edited by: $Author: apoth $
073 *
074 * @version $Revision: 9345 $, $Date: 2007-12-27 16:22:25 +0000 (Do, 27 Dez 2007) $
075 */
076 public class AugmentableGetFeature extends GetFeature {
077
078 private static final long serialVersionUID = -3001702206522611997L;
079
080 private static final ILogger LOG = LoggerFactory.getLogger( AugmentableGetFeature.class );
081
082 private Map<String, String> kvp;
083
084 /**
085 * Creates a new <code>AugmentableGetFeature</code> instance.
086 *
087 * @param version
088 * request version
089 * @param id
090 * id of the request
091 * @param handle
092 * @param resultType
093 * desired result type (results | hits)
094 * @param outputFormat
095 * requested result format
096 * @param maxFeatures
097 * @param startPosition
098 * deegree specific parameter defining where to start considering features
099 * @param traverseXLinkDepth
100 * @param traverseXLinkExpiry
101 * @param queries
102 * @param vendorSpecificParam
103 */
104 AugmentableGetFeature( String version, String id, String handle, RESULT_TYPE resultType, String outputFormat,
105 int maxFeatures, int startPosition, int traverseXLinkDepth, int traverseXLinkExpiry,
106 Query[] queries, Map<String, String> vendorSpecificParam ) {
107 super( version, id, handle, resultType, outputFormat, maxFeatures, startPosition, traverseXLinkDepth,
108 traverseXLinkExpiry, queries, vendorSpecificParam );
109 this.kvp = vendorSpecificParam;
110 }
111
112 /**
113 * Augments the KVP request with the needed information from the {@link WFSConfiguration}.
114 *
115 * @param config
116 * @throws InconsistentRequestException
117 * @throws InvalidParameterValueException
118 */
119 public void augment( WFSConfiguration config )
120 throws InconsistentRequestException, InvalidParameterValueException {
121
122 // SRSNAME
123 String srsName = kvp.get( "SRSNAME" );
124
125 // FEATUREVERSION
126 String featureVersion = kvp.get( "FEATUREVERSION" );
127
128 // TYPENAME
129 QualifiedName[] typeNames = extractTypeNames( kvp );
130 if ( typeNames.length == 0 ) {
131 // FEATUREID must be given
132 String featureId = kvp.get( "FEATUREID" );
133 if ( featureId == null ) {
134 String msg = Messages.getMessage( "WFS_TYPENAME+FID_PARAMS_MISSING" );
135 throw new InvalidParameterValueException( msg );
136 }
137
138 // ensure that the WFS has unique feature prefixes
139 if ( !config.hasUniquePrefixMapping() ) {
140 String msg = Messages.get( "WFS_CONF_FT_PREFICES_NOT_UNIQUE" );
141 throw new InconsistentRequestException( msg );
142 }
143
144 // maps feature type to ids that must be fetched for it
145 Map<MappedFeatureType, ArrayList<FeatureId>> ftToFids = new HashMap<MappedFeatureType, ArrayList<FeatureId>>();
146 String[] featureIds = featureId.split( "," );
147 for ( String fid : featureIds ) {
148 MappedFeatureType ft = config.getFeatureType( fid );
149 if ( ft == null ) {
150 String msg = Messages.get( "WFS_CONF_FT_PREFIX_UNKNOWN", fid );
151 throw new InconsistentRequestException( msg );
152 }
153 ArrayList<FeatureId> fidList = ftToFids.get( ft );
154 if ( fidList == null ) {
155 fidList = new ArrayList<FeatureId>();
156 }
157 fidList.add( new FeatureId( fid ) );
158 ftToFids.put( ft, fidList );
159 }
160
161 // build a Query instance for each requested feature type
162 queries = new ArrayList<Query>( ftToFids.size() );
163 for ( MappedFeatureType ft : ftToFids.keySet() ) {
164 QualifiedName ftName = ft.getName();
165 ArrayList<FeatureId> fids = ftToFids.get( ft );
166 Filter filter = new FeatureFilter( fids );
167 QualifiedName[] ftNames = new QualifiedName[] { ftName };
168 PropertyPath path = PropertyPathFactory.createPropertyPath( ftName );
169 PropertyPath[] properties = new PropertyPath[] { path };
170 queries.add( new Query( properties, null, null, null, featureVersion, ftNames, null, srsName, filter,
171 resultType, maxFeatures, startPosition ) );
172 }
173 }
174
175 if ( LOG.getLevel() == LOG.LOG_DEBUG ) {
176 try {
177 GetFeatureDocument doc = XMLFactory.export( this );
178 doc.prettyPrint( System.out );
179 } catch ( Exception e ) {
180 e.printStackTrace();
181 }
182 }
183 }
184 }