return super.read(request, kvp, rawKvp);
}
private QueryType readQuery(Map kvp, Object request) throws Exception {
Csw20Factory factory = Csw20Factory.eINSTANCE;
QueryType query = factory.createQueryType();
// parse the type names
String typeNamesString = (String) kvp.get("typeNames");
if(typeNamesString == null) {
throw new ServiceException("Mandatory parameter typeNames is missing", ServiceException.MISSING_PARAMETER_VALUE, "typeNames");
}
NamespaceSupport namespaces = (NamespaceSupport) kvp.get("namespace");
if (namespaces == null) {
// by spec, "NAMSPACE, If not included, all qualified names are in default namespace"
String outputSchema = (String) kvp.get("outputSchema");
if (outputSchema == null || descriptors.get(outputSchema) == null) {
outputSchema = CSW.NAMESPACE;
}
namespaces = descriptors.get( outputSchema).getNamespaceSupport();
}
List<QName> typeNames = resolver.parseQNames(typeNamesString, namespaces);
query.setTypeNames(typeNames);
// handle the element set
ElementSetType elementSet = (ElementSetType) kvp.remove("ELEMENTSETNAME");
if (elementSet != null) {
ElementSetNameType esn = Csw20Factory.eINSTANCE.createElementSetNameType();
esn.setValue(elementSet);
esn.setTypeNames(typeNames);
query.setElementSetName(esn);
}
// and the element names
String elementNamesString = (String) kvp.remove("ELEMENTNAME");
if(elementNamesString != null) {
List<QName> elementNames = resolver.parseQNames(elementNamesString, namespaces);
query.getElementName().addAll(elementNames);
}
// the filter
if (kvp.get(CONSTRAINT) != null) {
query.setConstraint(factory.createQueryConstraintType());
Object language = kvp.get(CONSTRAINTLANGUAGE);
String constraint = (String) kvp.get(CONSTRAINT);
if (CQL_TEXT.equals(language) || language == null) {
Filter filter = null;
try {
filter = CQL.toFilter(constraint);
} catch (Exception e) {
ServiceException se = new ServiceException("Invalid CQL expression: " + constraint,
ServiceException.INVALID_PARAMETER_VALUE, CONSTRAINT);
se.initCause(e);
throw se;
}
query.getConstraint().setCqlText(constraint);
query.getConstraint().setFilter(filter);
} else if (FILTER.equals(language)) {
try {
Parser parser = new Parser(new OGCConfiguration());
parser.setFailOnValidationError(true);
parser.setValidating(true);
parser.getNamespaces().declarePrefix("ogc", OGC.NAMESPACE);
Filter filter = (Filter) parser.parse(new StringReader(constraint));
query.getConstraint().setFilter(filter);
query.getConstraint().setVersion("1.1.0");
} catch(Exception e) {
ServiceException se = new ServiceException("Invalid FILTER 1.1 expression: " + constraint,
ServiceException.INVALID_PARAMETER_VALUE, CONSTRAINT);
se.initCause(e);
throw se;
}
} else {
throw new ServiceException("Invalid constraint language: " + language
+ ", valid values are " + CQL_TEXT + " and " + FILTER,
ServiceException.INVALID_PARAMETER_VALUE, CONSTRAINTLANGUAGE);
}
}
// check if we have to sort the request
if(kvp.get("SORTBY") != null) {
query.setSortBy((SortBy[]) kvp.get("SORTBY"));
}
return query;
}