Skip to content

Commit

Permalink
[GEOS-8918] [GEOS-8919] Relax existing constraints on complex feature…
Browse files Browse the repository at this point in the history
… layer names

* [GEOS-8918] It should be possible to name complex features layers with an alias

* [GEOS-8919] It should not be mandatory to use always use the full resource name when querying a complex feature type

* [GEOS-8919] Review Fixes.
  • Loading branch information
fernandor777 authored and aaime committed May 24, 2019
1 parent a0db4a6 commit 317bd5d
Show file tree
Hide file tree
Showing 10 changed files with 470 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,24 @@ public abstract class AbstractAppSchemaMockData extends SystemTestData
});

/** Use FeatureTypeInfo constants for srs handling as values */
private static final String KEY_SRS_HANDLINGS = "srsHandling";
static final String KEY_SRS_HANDLINGS = "srsHandling";

/** The feature type alias, a string */
private static final String KEY_ALIAS = "alias";
static final String KEY_ALIAS = "alias";

/** The style name */
private static final String KEY_STYLE = "style";
static final String KEY_STYLE = "style";

/** The srs code (a number) for this layer */
private static final String KEY_SRS_NUMBER = "srs";
static final String KEY_SRS_NUMBER = "srs";

/** The lon/lat envelope as a JTS Envelope */
private static final String KEY_LL_ENVELOPE = "ll_envelope";
static final String KEY_LL_ENVELOPE = "ll_envelope";

/** The native envelope as a JTS Envelope */
private static final String KEY_NATIVE_ENVELOPE = "native_envelope";
static final String KEY_NATIVE_ENVELOPE = "native_envelope";

private static final Envelope DEFAULT_ENVELOPE = new Envelope(-180, 180, -90, 90);
static final Envelope DEFAULT_ENVELOPE = new Envelope(-180, 180, -90, 90);

/** Map of data store name to data store connection parameters map. */
private final Map<String, Map<String, Serializable>> datastoreParams =
Expand All @@ -131,7 +131,7 @@ public abstract class AbstractAppSchemaMockData extends SystemTestData
private File styles;

/** the 'featureTypes' directory, under 'data' */
private File featureTypesBaseDir;
protected File featureTypesBaseDir;

/**
* Pair of property file name and feature type directory to create db tables for online tests
Expand Down Expand Up @@ -271,7 +271,7 @@ private void copyFileToFeatureTypeDir(String namespacePrefix, String typeName, S
}
}

private String getFileNamePart(String fileName) {
protected String getFileNamePart(String fileName) {
if (fileName.indexOf(File.separator) > 0) {
return fileName.substring(fileName.lastIndexOf(File.separator) + 1, fileName.length());
} else {
Expand Down Expand Up @@ -411,6 +411,7 @@ private static void writeInfoFile(
FileWriter writer = new FileWriter(info);
writer.write("<featureType datastore=\"" + dataStoreName + "\">");
writer.write("<name>" + typeName + "</name>");
writer.write("<nativeName>" + typeName + "</nativeName>");
if (params.get(KEY_ALIAS) != null)
writer.write("<alias>" + params.get(KEY_ALIAS) + "</alias>");
writer.write("<SRS>" + params.get(KEY_SRS_NUMBER) + "</SRS>");
Expand Down Expand Up @@ -467,7 +468,7 @@ private static void writeInfoFile(
* @param dataStoreName data store name
*/
@SuppressWarnings("serial")
private static Map<String, Serializable> buildAppSchemaDatastoreParams(
protected static Map<String, Serializable> buildAppSchemaDatastoreParams(
final String namespacePrefix,
final String typeName,
final String mappingFileName,
Expand Down Expand Up @@ -587,7 +588,7 @@ public void addStyle(String styleId, String fileName) {
* @param namespacePrefix
* @param params
*/
private void addDataStore(
protected void addDataStore(
String dataStoreName, String namespacePrefix, Map<String, Serializable> params) {
datastoreParams.put(dataStoreName, params);
datastoreNamespacePrefixes.put(dataStoreName, namespacePrefix);
Expand Down Expand Up @@ -632,7 +633,7 @@ protected void removeNamespace(String namespacePrefix) {
* @param typeName local name of the WFS feature type
* @return name of the data store for the feature type
*/
protected static String getDataStoreName(String namespacePrefix, String typeName) {
protected String getDataStoreName(String namespacePrefix, String typeName) {
return namespacePrefix + "_" + typeName;
}

Expand All @@ -652,7 +653,7 @@ protected File getFeatureTypesBaseDir() {
* @param typeName local name of the WFS feature type
* @return directory that contains the mapping and property files
*/
private static File getFeatureTypeDir(
protected File getFeatureTypeDir(
File featureTypesBaseDir, String namespacePrefix, String typeName) {
return new File(featureTypesBaseDir, getDataStoreName(namespacePrefix, typeName));
}
Expand All @@ -666,7 +667,7 @@ private static File getFeatureTypeDir(
* @param supportFileNames names of the support files, such as properties files, for this
* feature type
*/
private void copyMappingAndSupportFiles(
protected void copyMappingAndSupportFiles(
String namespacePrefix,
String typeName,
String mappingFileName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,13 +617,12 @@ protected NestedFilterToSQL createNestedFilterEncoder(FeatureTypeMapping mapping
}

/**
* Returns xml String from Document Object
* Utility method that converts a XML document object to a string.
*
* @param document
* @return
* @throws TransformerException
* @param document Xml Document to parse
* @return String representation of xml document
*/
protected String toString(Document document) throws TransformerException {
protected static String toString(Document document) throws TransformerException {
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package org.geoserver.test;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.geoserver.data.test.MockData;
import org.locationtech.jts.geom.Envelope;

/** Mock data for testing Type Alias on complex features. */
public class AliasStationsMockData extends StationsMockData {

private String layerNamePrefix;

@Override
public void addContent() {
setLayerNamePrefix("lyr");
super.addContent();
}

private String getLayerName(String typeName) {
if (layerNamePrefix != null) return layerNamePrefix + "_" + typeName;
return typeName;
}

@Override
public void addFeatureType(
String namespacePrefix,
String typeName,
String mappingFileName,
String... supportFileNames) {
File featureTypeDir = getFeatureTypeDir(featureTypesBaseDir, namespacePrefix, typeName);
String dataStoreName = getDataStoreName(namespacePrefix, typeName);
try {
writeInfoFileInternal(namespacePrefix, typeName, featureTypeDir, dataStoreName);
copyMappingAndSupportFiles(
namespacePrefix, typeName, mappingFileName, supportFileNames);
// if mappingFileName contains directory, eg, dir1/dir2/file.xml, we will ignore the
// directory from here on
addDataStore(
dataStoreName,
namespacePrefix,
AbstractAppSchemaMockData.buildAppSchemaDatastoreParams(
namespacePrefix,
typeName,
getFileNamePart(mappingFileName),
featureTypesBaseDir,
dataStoreName));
} catch (Exception e) {
throw new RuntimeException(e);
}
}

/**
* Write an info.xml file describing a feature type to the feature type directory.
*
* <p>Stolen from {@link MockData}.
*
* @param namespacePrefix namespace prefix of the WFS feature type
* @param typeName namespace prefix of the WFS feature type
* @param featureTypeDir feature type directory
* @param dataStoreName data store directory name
*/
protected void writeInfoFileInternal(
String namespacePrefix, String typeName, File featureTypeDir, String dataStoreName) {
// prepare extra params default
Map<String, Object> params = new HashMap<String, Object>();
params.put(KEY_STYLE, "Default");
params.put(KEY_SRS_HANDLINGS, 2);
params.put(KEY_ALIAS, null);
Integer srs = 4326;
params.put(KEY_SRS_NUMBER, srs);
try {
featureTypeDir.mkdir();
File info = new File(featureTypeDir, "info.xml");
info.delete();
info.createNewFile();
FileWriter writer = new FileWriter(info);
writer.write("<featureType datastore=\"" + dataStoreName + "\">");
writer.write("<name>" + getLayerName(typeName) + "</name>");
writer.write("<nativeName>" + typeName + "</nativeName>");
if (params.get(KEY_ALIAS) != null)
writer.write("<alias>" + params.get(KEY_ALIAS) + "</alias>");
writer.write("<SRS>" + params.get(KEY_SRS_NUMBER) + "</SRS>");
// this mock type may have wrong SRS compared to the actual one in the property files...
// let's configure SRS handling not to alter the original one, and have 4326 used only
// for capabilities
writer.write("<SRSHandling>" + params.get(KEY_SRS_HANDLINGS) + "</SRSHandling>");
writer.write("<title>" + typeName + "</title>");
writer.write("<abstract>abstract about " + typeName + "</abstract>");
writer.write("<numDecimals value=\"8\"/>");
writer.write("<keywords>" + typeName + "</keywords>");
Envelope llEnvelope = (Envelope) params.get(KEY_LL_ENVELOPE);
if (llEnvelope == null) llEnvelope = DEFAULT_ENVELOPE;
writer.write(
"<latLonBoundingBox dynamic=\"false\" minx=\""
+ llEnvelope.getMinX()
+ "\" miny=\""
+ llEnvelope.getMinY()
+ "\" maxx=\""
+ llEnvelope.getMaxX()
+ "\" maxy=\""
+ llEnvelope.getMaxY()
+ "\"/>");
Envelope nativeEnvelope = (Envelope) params.get(KEY_NATIVE_ENVELOPE);
if (nativeEnvelope != null)
writer.write(
"<nativeBBox dynamic=\"false\" minx=\""
+ nativeEnvelope.getMinX()
+ "\" miny=\""
+ nativeEnvelope.getMinY()
+ "\" maxx=\""
+ nativeEnvelope.getMaxX()
+ "\" maxy=\""
+ nativeEnvelope.getMaxY()
+ "\"/>");
String style = (String) params.get(KEY_STYLE);
if (style == null) style = "Default";
writer.write("<styles default=\"" + style + "\"/>");
writer.write("</featureType>");
writer.flush();
writer.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

@Override
protected String getDataStoreName(String namespacePrefix, String typeName) {
return namespacePrefix + "_" + getLayerName(typeName);
}

/**
* Prefix for layer name, to test name vs nativeName
*
* @return layer name prefix
*/
public String getLayerNamePrefix() {
return layerNamePrefix;
}

public void setLayerNamePrefix(String layerNamePrefix) {
this.layerNamePrefix = layerNamePrefix;
}
}

0 comments on commit 317bd5d

Please sign in to comment.