String namespace = (String)req.getAttributes().get("namespace");
String feature = (String)req.getAttributes().get("feature");
NamespaceInfo ns = myCatalog.getNamespaceByPrefix(namespace);
if ( ns == null ) {
throw new RestletException(
"No such namespace:" + namespace,
Status.CLIENT_ERROR_NOT_FOUND
);
}
FeatureTypeInfo featureType = null;
try {
featureType = myCatalog.getFeatureTypeByName(ns, layer);
} catch (NoSuchElementException e) {
throw new RestletException(
e.getMessage(),
Status.CLIENT_ERROR_NOT_FOUND
);
}
if (!(Boolean)featureType.getMetadata().get("indexingEnabled")){
throw new RestletException(
"Indexing is disabled for this layer (" + ns + ":" + layer + ") "
+ featureType.getMetadata().get("indexingEnabled"),
Status.CLIENT_ERROR_FORBIDDEN
);
}
Query q = new Query();
FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
q.setFilter(ff.id(Collections.singleton(ff.featureId(feature))));
FeatureCollection col = null;
try {
col = featureType.getFeatureSource(null, null).getFeatures(q);
} catch (IOException e) {
throw new RestletException(
e.getMessage(),
Status.SERVER_ERROR_INTERNAL
);
}
if (col.size() != 1) {
throw new RestletException(
"Unexpected results from data query, "
+ "should be exactly one feature with given ID",
Status.SERVER_ERROR_INTERNAL
);
}