Skip to content

Commit

Permalink
[GEOS-7908] REST API: Add support for list=all when listing feature t…
Browse files Browse the repository at this point in the history
…ypes

Adds support for a `/workspaces/<ws>/datastores/<ds>/featuretypes[.<format>]` request with the query parameter `list=all`.
  • Loading branch information
mattkrusz committed May 1, 2017
1 parent 3c1acf8 commit 2248c52
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.geotools.util.logging.Logging;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.feature.type.FeatureType;
import org.opengis.feature.type.Name;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.MethodParameter;
Expand Down Expand Up @@ -87,14 +88,15 @@ public Object featureTypesGet(
@PathVariable(required = false) String dataStoreName,
@RequestParam(defaultValue = "configured") String list) {

if ("available".equalsIgnoreCase(list) || "available_with_geom".equalsIgnoreCase(list)) {
if ("available".equalsIgnoreCase(list) || "available_with_geom".equalsIgnoreCase(list)
|| "all".equalsIgnoreCase(list)) {
DataStoreInfo info = getExistingDataStore(workspaceName, dataStoreName);

// flag to control whether to filter out types without geometry
boolean skipNoGeom = "available_with_geom".equalsIgnoreCase(list);

// list of available feature types
List<String> available = new ArrayList<>();
List<String> featureTypes = new ArrayList<>();
try {
DataStore ds = (DataStore) info.getDataStore(null);

Expand All @@ -103,7 +105,7 @@ public Object featureTypesGet(
FeatureTypeInfo ftinfo = catalog.getFeatureTypeByDataStore(info,
featureTypeName);
if (ftinfo == null) {
// not in catalog, add it
// The feature type is not in catalog, so add it to the return list.
// check whether to filter by geometry
if (skipNoGeom) {
try {
Expand All @@ -118,14 +120,17 @@ public Object featureTypesGet(
e);
}
}
available.add(featureTypeName);
featureTypes.add(featureTypeName);
} else if ("all".equalsIgnoreCase(list)) {
// The feature type is already configured, but "all" was specified, so add it to the return list.
featureTypes.add(featureTypeName);
}
}
} catch (IOException e) {
throw new ResourceNotFoundException("Could not load datastore: " + dataStoreName);
}

return new StringsList(available, "featureTypeName");
return new StringsList(featureTypes, "featureTypeName");
} else {
List<FeatureTypeInfo> fts;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,41 @@ void addGeomlessPropertyDataStore(boolean configureFeatureType) throws Exception
put(BASEPATH + "/workspaces/gs/datastores/ngpds/file.properties?" + q, zbytes.toByteArray(),
"application/zip");
}

/**
* Add a property data store with multiple feature types, but only configure the first.
* @param configureFeatureType
* @throws Exception
*/
void addPropertyDataStoreOnlyConfigureFirst() throws Exception {
ByteArrayOutputStream zbytes = new ByteArrayOutputStream();
ZipOutputStream zout = new ZipOutputStream(zbytes);

ByteArrayOutputStream bytes = new ByteArrayOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(bytes));
writer.write("_=name:String,pointProperty:Point\n");
writer.write("pdsa.0='zero'|POINT(0 0)\n");
writer.write("pdsa.1='one'|POINT(1 1)\n");
writer.flush();

zout.putNextEntry(new ZipEntry("pdsa.properties"));
zout.write(bytes.toByteArray());
bytes.reset();

writer.write("_=name:String,pointProperty:Point\n");
writer.write("pdsb.0='two'|POINT(2 2)\n");
writer.write("pdsb.1='trhee'|POINT(3 3)\n");
writer.flush();
zout.putNextEntry(new ZipEntry("pdsb.properties"));
zout.write(bytes.toByteArray());

zout.flush();
zout.close();

String q = "configure=first";
put(BASEPATH + "/workspaces/gs/datastores/pds/file.properties?" + q, zbytes.toByteArray(),
"application/zip");
}

@Test
public void testGetAllByDataStore() throws Exception {
Expand Down Expand Up @@ -156,6 +191,21 @@ public void testGetAllAvailableWithGeometryOnly() throws Exception {
+ "/workspaces/gs/datastores/ngpds/featuretypes.xml?list=available_with_geom");
assertXpathEvaluatesTo("0", "count(//featureTypeName)", dom);
}


/**
* Test that a list of all feature types for a data source are returned when "list=all", including both
* configured and unconfigured ones.
*/
@Test
public void testGetAllByDataStoreWithListAll() throws Exception {
// Create a data store with only the first feature type configured.
addPropertyDataStoreOnlyConfigureFirst();
Document dom = getAsDOM(BASEPATH + "/workspaces/gs/datastores/pds/featuretypes.xml?list=all");
assertEquals(2, dom.getElementsByTagName("featureTypeName").getLength());
assertXpathEvaluatesTo("1", "count(//featureTypeName[text()='pdsa'])", dom);
assertXpathEvaluatesTo("1", "count(//featureTypeName[text()='pdsb'])", dom);
}

@Test
public void testPutAllUnauthorized() throws Exception {
Expand Down

0 comments on commit 2248c52

Please sign in to comment.