use of org.geotoolkit.csw.xml.Query in project geotoolkit by Geomatys.
the class AbstractGetRecords method getResponseStream.
/**
* {@inheritDoc}
*/
@Override
public InputStream getResponseStream() throws IOException {
final URL url = getURL();
URLConnection conec = url.openConnection();
security.secure(conec);
conec.setDoOutput(true);
conec.setRequestProperty("Content-Type", "text/xml");
OutputStream stream = conec.getOutputStream();
stream = security.encrypt(stream);
try {
final Marshaller marsh = POOL.acquireMarshaller();
/*
* Getting typeNames value used to build QueryType object
*/
final List<QName> typNames = new ArrayList<>();
if (typeNames != null) {
typNames.add(TypeNames.valueOf(typeNames));
}
/*
* Getting ElementSetType value used to build QueryType object
*/
ElementSetName esnt = null;
if (elementSetName != null) {
esnt = createElementSetName(version, elementSetName);
}
/*
* Getting SortByType value, default is null
*
* @TODO if sortBy is not null we must creates SortByType instance
* the value can be sortBy=Title:A,Abstract:D where A for ascending order and D for decending.
* see Table 29 - Parameters in GetRecords operation request in document named
* OpenGIS Catalogue Services Specification 2.0.2 -ISO Metadata Application Profile
*
*/
final SortByType sort;
if (sortBy != null) {
String[] fields = sortBy.split(",");
List<SortPropertyType> sortProps = new ArrayList<>();
for (String field : fields) {
String[] split = field.split(":");
SortOrder sortOrder = split.length == 1 ? null : ("D".equals(split[1]) ? DESCENDING : ASCENDING);
sortProps.add(new SortPropertyType(split[0], sortOrder));
}
sort = new SortByType(sortProps);
} else {
sort = null;
}
/*
* Building QueryType from the cql constraint
*/
QueryConstraint qct = null;
if (constraint != null && !constraint.isEmpty()) {
try {
final FilterType filterType;
Filter filter = CQL.parseFilter(constraint, new FilterFactoryImpl());
if (filter instanceof FilterType) {
filterType = (FilterType) filter;
} else {
filterType = new FilterType(filter);
}
qct = createQueryConstraint(version, filterType, constraintLanguageVersion != null ? constraintLanguageVersion : "1.1.0");
} catch (CQLException ex) {
// @TODO maybe use another Exception.
throw new IllegalArgumentException("Constraint cannot be parsed to filter, the constraint parameter value is not in OGC CQL format.", ex);
}
}
final Query queryType = createQuery(version, typNames, esnt, sort, qct);
final DistributedSearch ds = createDistributedSearch(version, hopcount);
final org.geotoolkit.csw.xml.GetRecordsRequest recordsXml = createGetRecord(version, "CSW", resultType, requestId, outputFormat, outputSchema, startPosition, maxRecords, queryType, ds);
marsh.marshal(recordsXml, stream);
POOL.recycle(marsh);
} catch (JAXBException ex) {
throw new IOException(ex);
}
stream.close();
return security.decrypt(conec.getInputStream());
}
Aggregations