diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureTypeEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureTypeEncoder.java index d55e528..9332804 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureTypeEncoder.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureTypeEncoder.java @@ -27,6 +27,7 @@ package it.geosolutions.geoserver.rest.encoder.feature; import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder; import it.geosolutions.geoserver.rest.encoder.metadata.GSFeatureDimensionInfoEncoder; +import it.geosolutions.geoserver.rest.encoder.metadata.GSVirtualTableEncoder; import org.jdom.Element; @@ -51,15 +52,67 @@ public class GSFeatureTypeEncoder extends GSResourceEncoder { /** * @param key * @param dimensionInfo + * + * @deprecated Replaced by + * {@link #addMetadataDimension(String, GSFeatureDimensionInfoEncoder)} */ + @Deprecated protected void addMetadata(String key, GSFeatureDimensionInfoEncoder dimensionInfo) { super.addMetadata(key, dimensionInfo); } - + + /** + * + * @param key + * @param dimensionInfo + */ + protected void addMetadataDimension(String key, GSFeatureDimensionInfoEncoder dimensionInfo) { + super.addMetadata(key, dimensionInfo); + } + + /** + * + * @param key + * @param dimensionInfo + * + * @deprecated Replaced by + * {@link #setMetadataDimension(String, GSFeatureDimensionInfoEncoder)} + */ + @Deprecated public void setMetadata(String key, GSFeatureDimensionInfoEncoder dimensionInfo) { super.setMetadata(key, dimensionInfo); } + + /** + * + * @param key + * @param dimensionInfo + */ + public void setMetadataDimension(String key, GSFeatureDimensionInfoEncoder dimensionInfo) { + super.setMetadata(key, dimensionInfo); + } + + /** + * Add a VirtualTable (SQL View feature type) + * + * @param virtualtable + */ + protected void addMetadataVirtualTable( + final GSVirtualTableEncoder virtualtable) { + super.addMetadata("JDBC_VIRTUAL_TABLE", virtualtable); + } + + /** + * Set a VirtualTable (SQL View feature type) + * + * @param virtualtable + */ + public void setMetadataVirtualTable(final GSVirtualTableEncoder virtualtable) { + super.setMetadata("JDBC_VIRTUAL_TABLE", virtualtable); + } + + /** * delete a keyword from the list * diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/GSVirtualTableEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/GSVirtualTableEncoder.java new file mode 100644 index 0000000..ddaaa58 --- /dev/null +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/GSVirtualTableEncoder.java @@ -0,0 +1,199 @@ +/* + * GeoServer-Manager - Simple Manager Library for GeoServer + * + * Copyright (C) 2007,2011 GeoSolutions S.A.S. + * http://www.geo-solutions.it + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package it.geosolutions.geoserver.rest.encoder.metadata; + +import java.util.ArrayList; +import java.util.List; + +import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder; + +/** + * GSVirtualTableEncoder - Encodes a metadata VirtualTable for a GeoServer + * featureType, as follows: + * + *
+ * {
+ * 	@code
+ * 	// Set-up the vtGeom
+ * 	final GSVirtualTableGeomEncoder vtGeom = new GSVirtualTableGeomEncoder();
+ * 	vtGeom.setup("the_geom", "MultiPolygon", "4326");
+ * 
+ * 	// Set-up 2 virtual table parameters
+ * 	final GSVirtualTableParamEncoder vtParam1 = new GSVirtualTableParamEncoder();
+ * 	vtParam1.setup("fieldname1", "default_value1", "^[\\w\\d\\s]+$");
+ * 	final GSVirtualTableParamEncoder vtParam2 = new GSVirtualTableParamEncoder();
+ * 	vtParam2.setup("fieldname2", "default_value2", "^[\\w\\d\\s]+$");
+ * 
+ * 	// sql
+ * 	String sql = "select the_geom, id, field1, field2 from mytable where field1 = '%fieldname1%' and field2 = '%fieldname2%'";
+ * 
+ * 	// Set-up the virtual table
+ * 	final GSVirtualTableEncoder vte = new GSVirtualTableEncoder();
+ * 	vte.setup("mysqlview", sql, Arrays.asList("id"), Arrays.asList(vtGeom),
+ * 			Arrays.asList(vtParam1, vtParam2));
+ * }
+ * 
+ * + * For this example, the XML output is: + * + *
+ * {@code
+ * 
+ * 	mysqlview
+ * 	select the_geom, id, field1, field2 from mytable where field1 = '%fieldname1%' and field2 = '%fieldname2%'
+ * 	id
+ * 	
+ * 		the_geom
+ * 		MultiPolygon
+ * 		4326
+ * 	
+ * 	
+ * 		fieldname1
+ * 		default_value1
+ * 		^[\w\d\s]+$
+ * 	
+ * 	
+ * 		fieldname2
+ * 		default_value2
+ * 		^[\w\d\s]+$
+ * 	
+ * 
+ * }
+ * 
+ * + * @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | + * emmanuel.blondel@fao.org + * + */ +public class GSVirtualTableEncoder extends PropertyXMLEncoder { + + private String name; + private String sql; + private List keyColumns; + private List geomEncList; + private List paramEncList; + + /** + * Constructs a GSVirtualTableEncoder + */ + public GSVirtualTableEncoder() { + super("virtualTable"); + } + + /** + * Set-up quickly a GSVirtualTableEncoder. This unique entry point to set-up + * is aimed to ensure that the order of metadata elements is well + * maintained, and avoid errors at publication time in Geoserver. + * + * @param name + * (must be the same as the featureType name) + * @param sql + * @param keyColumns + * @param geomEncList + * @param paramEncList + */ + public void setup(String name, String sql, List keyColumns, + List geomEncList, + List paramEncList) { + + this.getRoot().removeContent(); + + this.name = name; + this.sql = sql; + set("name", this.name); + set("sql", this.sql); + + if (keyColumns != null) { + this.keyColumns = new ArrayList(); + this.keyColumns.addAll(keyColumns); + for (String pk : this.keyColumns) { + add("keyColumn", pk); + } + + } + + if (geomEncList != null) { + this.geomEncList = new ArrayList(); + this.geomEncList.addAll(geomEncList); + for (GSVirtualTableGeomEncoder geomEnc : this.geomEncList) { + addContent(geomEnc.getRoot()); + } + } + + if (paramEncList != null) { + this.paramEncList = new ArrayList(); + this.paramEncList.addAll(paramEncList); + for (GSVirtualTableParamEncoder paramEnc : this.paramEncList) { + addContent(paramEnc.getRoot()); + } + ; + } + + } + + /** + * get Name + * + * @return the name of the virtual table + */ + public String getName() { + return this.name; + } + + /** + * get SQL query + * + * @return the sql query of the virtual table + */ + public String getSql() { + return this.sql; + } + + /** + * get the list of GSVirtualTableGeomEncoder + * + * @return + */ + public List getVirtualTableGeomEncoderList() { + return this.geomEncList; + } + + /** + * get the list of VirtualTableParamEncoder + * + * @return + */ + public List getVirtualTableParamEncoderList() { + return this.paramEncList; + } + + // TODO (eventually) utils method to check consistency between SQL view + // params provided by the sql string + // and the virtual table parameters set up in parallel + public boolean checkVirtualTableParams() { + return false; + } + +} diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/GSVirtualTableGeomEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/GSVirtualTableGeomEncoder.java new file mode 100644 index 0000000..d7c0a25 --- /dev/null +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/GSVirtualTableGeomEncoder.java @@ -0,0 +1,132 @@ +/* + * GeoServer-Manager - Simple Manager Library for GeoServer + * + * Copyright (C) 2007,2011 GeoSolutions S.A.S. + * http://www.geo-solutions.it + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package it.geosolutions.geoserver.rest.encoder.metadata; + +import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils; +import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder; + +import java.util.Map; +import java.util.Map.Entry; + +import org.jdom.Element; + +/** + * GSVirtualTableGeomEncoder - Encodes a metadata VirtualTable geometry for a + * GeoServer featureType, as follows: + * + *
+ * {
+ * 	@code
+ * 	final GSVirtualTableGeomEncoder vtGeom = new GSVirtualTableGeomEncoder();
+ * 	vtGeom.setup("the_geom", "MultiPolygon", "4326");
+ * }
+ * 
+ * + * For this example, the XML output is: + * + *
+ * {@code
+ * 
+ * 	the_geom
+ * 	MultiPolygon
+ * 	4326
+ * 
+ * }
+ * 
+ * + * @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | + * emmanuel.blondel@fao.org + * + */ +public class GSVirtualTableGeomEncoder extends PropertyXMLEncoder { + + /** + * Constructs a GSVirtualTableGeomEncoder + * + */ + public GSVirtualTableGeomEncoder() { + super("geometry"); + } + + /** + * Set-up quickly a GSVirtualTableGeomEncoder + * + * @param name + * @param geometryType + * @param srid + */ + public void setup(String name, String geometryType, String srid) { + set(VirtualTableGeometry.name.name(), name); + set(VirtualTableGeometry.type.name(), geometryType); + set(VirtualTableGeometry.srid.name(), srid); + } + + /** + * Set-up a GSVirtualTableGeomEncoder + * + * @param vtGeometryMembers + */ + public void setup(Map vtGeometryMembers) { + for (Entry vtGeomMember : vtGeometryMembers + .entrySet()) { + set(vtGeomMember.getKey().toString(), vtGeomMember.getValue()); + } + } + + /** + * Set a VirtualTable Geometry member + * + * @param type + * @param value + */ + public void setVirtualTableGeometryMember(VirtualTableGeometry type, + String value) { + set(type.toString(), value); + } + + /** + * Deletes a VirtualTableGeometry member + * + * @param type + * @return + */ + public boolean delVirtualTableGeometryMember(VirtualTableGeometry type) { + return ElementUtils.remove(this.getRoot(), get(type.toString())); + } + + /** + * Get the VirtualTableGeometry member value + * + * @param type + * @return + */ + public String getVirtualTableGeometryMember(VirtualTableGeometry type) { + Element el = get(type.toString()); + if (el != null) + return el.getTextTrim(); + else + return null; + } +} \ No newline at end of file diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/GSVirtualTableParamEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/GSVirtualTableParamEncoder.java new file mode 100644 index 0000000..9faae16 --- /dev/null +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/GSVirtualTableParamEncoder.java @@ -0,0 +1,131 @@ +/* + * GeoServer-Manager - Simple Manager Library for GeoServer + * + * Copyright (C) 2007,2011 GeoSolutions S.A.S. + * http://www.geo-solutions.it + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package it.geosolutions.geoserver.rest.encoder.metadata; + +import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils; +import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder; + +import java.util.Map; +import java.util.Map.Entry; + +import org.jdom.Element; + +/** + * GSVirtualTableParamEncoder - Encodes a metadata VirtualTable parameter for a + * GeoServer featureType, as follows: + * + *
+ * {
+ * 	@code
+ * 	final GSVirtualTableParamEncoder vtParam = new GSVirtualTableParamEncoder();
+ * 	vtParam.setup("fieldname", "default_value", "^[\\w\\d\\s]+$");
+ * }
+ * 
+ * + * For this example, the XML output is: + * + *
+ * {@code
+ * 
+ * 	fieldname
+ * 	default_value
+ * 	^[\w\d\s]+$
+ * 
+ * }
+ * 
+ * + * @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | + * emmanuel.blondel@fao.org + * + */ +public class GSVirtualTableParamEncoder extends PropertyXMLEncoder { + + /** + * Constructs a GSVirtualTableParamEncoder + */ + public GSVirtualTableParamEncoder() { + super("parameter"); + } + + /** + * Set-up quickly a VirtualTable parameter + * + * @param name + * @param defaultValue + * @param regexpValidator + */ + public void setup(String name, String defaultValue, String regexpValidator) { + set(VirtualTableParameter.name.name(), name); + set(VirtualTableParameter.defaultValue.name(), defaultValue); + set(VirtualTableParameter.regexpValidator.name(), regexpValidator); + } + + /** + * Set-up a VirtualTable parameter + * + * @param vtParamMembers + */ + public void setup(Map vtParamMembers) { + for (Entry vtParamMember : vtParamMembers + .entrySet()) { + set(vtParamMember.getKey().toString(), vtParamMember.getValue()); + } + } + + /** + * Set a VirtualTableParameter member + * + * @param type + * @param value + */ + public void setVirtualTableParamMember(VirtualTableParameter type, + String value) { + set(type.toString(), value); + } + + /** + * Deletes a VirtualTableParameter member + * + * @param type + * @return + */ + public boolean delVirtualTableParamMember(VirtualTableParameter type) { + return ElementUtils.remove(this.getRoot(), get(type.toString())); + } + + /** + * Get a VirtualTableParameter member + * + * @param type + * @return + */ + public String getVirtualTableParamMember(VirtualTableParameter type) { + Element el = get(type.toString()); + if (el != null) + return el.getTextTrim(); + else + return null; + } +} \ No newline at end of file diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/VirtualTableGeometry.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/VirtualTableGeometry.java new file mode 100644 index 0000000..0b19462 --- /dev/null +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/VirtualTableGeometry.java @@ -0,0 +1,36 @@ +/* + * GeoServer-Manager - Simple Manager Library for GeoServer + * + * Copyright (C) 2007,2011 GeoSolutions S.A.S. + * http://www.geo-solutions.it + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package it.geosolutions.geoserver.rest.encoder.metadata; + +/** + * Enumeration of Virtual Table geometry members + * + * @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | + * emmanuel.blondel@fao.org + * + */ +public enum VirtualTableGeometry { + name, type, srid +} diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/VirtualTableParameter.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/VirtualTableParameter.java new file mode 100644 index 0000000..2adac0b --- /dev/null +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/VirtualTableParameter.java @@ -0,0 +1,37 @@ +/* + * GeoServer-Manager - Simple Manager Library for GeoServer + * + * Copyright (C) 2007,2011 GeoSolutions S.A.S. + * http://www.geo-solutions.it + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package it.geosolutions.geoserver.rest.encoder.metadata; + +/** + * Enumeration of SQL View featureType virtual table parameter members + * + * @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | + * emmanuel.blondel@fao.org + * + */ +public enum VirtualTableParameter { + name, defaultValue, regexpValidator + +}