}
if (storedQueryId != null) {
buildStoredQueries(eObject, storedQueryId, kvp);
}
else {
throw new WFSException(eObject, "The query should specify either typeName, featureId filter" +
", or a stored query id", "MissingParameterValue");
}
}
}
//filter
if (kvp.containsKey("filter")) {
querySet(eObject, "filter", (List) kvp.get("filter"));
} else if (kvp.containsKey("cql_filter")) {
querySet(eObject, "filter", (List) kvp.get("cql_filter"));
} else if (kvp.containsKey("featureId") || kvp.containsKey("resourceId")) {
//set filter from featureId
List featureIdList = (List) kvp.get("featureId");
featureIdList = featureIdList != null ? featureIdList : (List) kvp.get("resourceId");
Set ids = new HashSet();
for (Iterator i = featureIdList.iterator(); i.hasNext();) {
String fid = (String) i.next();
FeatureId featureId = filterFactory.featureId(fid);
ids.add(featureId);
}
// build a single feature id filter
List filters = Collections.singletonList(filterFactory.id(ids));
querySet(eObject, "filter", filters);
} else if (kvp.containsKey("bbox")) {
//set filter from bbox
Envelope bbox = (Envelope) kvp.get("bbox");
List<Query> queries = GetFeatureRequest.adapt(eObject).getQueries();
List filters = new ArrayList();
for (Iterator<Query> it = queries.iterator(); it.hasNext();) {
Query q = it.next();
List typeName = q.getTypeNames();
Filter filter = null;
if (typeName.size() > 1) {
//TODO: not sure what to do here, just going to and them up
List and = new ArrayList(typeName.size());
for (Iterator t = typeName.iterator(); t.hasNext();) {
and.add(bboxFilter((QName) t.next(), bbox));
}
filter = filterFactory.and(and);
} else {
filter = bboxFilter((QName) typeName.get(0), bbox);
}
filters.add(filter);
}
querySet(eObject, "filter", filters);
}
//aliases
if (kvp.containsKey("aliases")) {
querySet(eObject, "aliases", (List) kvp.get("aliases"));
}
//propertyName
if (kvp.containsKey("propertyName")) {
List<String> propertyNames = new ArrayList<String>();
if( kvp.get("propertyName") != null && kvp.get("propertyName") instanceof List )
{
propertyNames = (List) kvp.get("propertyName");
}
else if( kvp.get("propertyName") != null && kvp.get("propertyName") instanceof String )
{
propertyNames.addAll(KvpUtils.readFlat((String) kvp.get("propertyName")));
}
querySet(eObject, "propertyName", propertyNames);
}
//sortBy
if (kvp.containsKey("sortBy")) {
querySet(eObject, "sortBy", (List) kvp.get("sortBy"));
}
//srsName
if (kvp.containsKey("srsName")) {
querySet(eObject, "srsName",Collections.singletonList((URI)kvp.get("srsName")));
}
//featureversion
if (kvp.containsKey("featureVersion")) {
querySet(eObject, "featureVersion",
Collections.singletonList((String) kvp.get("featureVersion")));
}
GetFeatureRequest req = GetFeatureRequest.adapt(request);
if(kvp.containsKey("format_options")) {
req.getFormatOptions().putAll((Map) kvp.get("format_options"));
}
// sql view params
if(kvp.containsKey("viewParams")) {
if(req.getViewParams() == null) {
req.setViewParams(new ArrayList<Map<String,String>>());
}
// fan out over all layers if necessary
List<Map<String, String>> viewParams = (List<Map<String, String>>) kvp.get("viewParams");
if(viewParams.size() > 0) {
int layerCount = req.getQueries().size();
// if we have just one replicate over all layers
if(viewParams.size() == 1 && layerCount > 1) {
List<Map<String, String>> replacement = new ArrayList<Map<String,String>>();
for (int i = 0; i < layerCount; i++) {
replacement.add(viewParams.get(0));
}
viewParams = replacement;
} else if(viewParams.size() != layerCount) {
String msg = layerCount + " feature types requested, but found " + viewParams.size()
+ " view params specified. ";
throw new WFSException(eObject, msg, getClass().getName());
}
}
req.setViewParams(viewParams);
}