@Test public void TestSchema() { SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName("test_schema"); builder.setCRS(DefaultGeographicCRS.WGS84); builder.add("the_geom", Point.class); builder.add("other_geom", Point.class); builder.setDefaultGeometry("other_geom"); builder.length(15).add("name", String.class); final SimpleFeatureType type = builder.buildFeatureType(); JSONObj schema = IO.schema(new JSONObj(), type, false); assertEquals("test_schema", schema.get("name")); assertEquals("other_geom", schema.get("defaultGeometry")); }
public static JSONObj schema( JSONObj schema, FeatureType type, boolean details){ if( type != null ){ schema.put("name", type.getName().getLocalPart() ); schema.put("namespace", type.getName().getNamespaceURI() ); schema.put("simple", type instanceof SimpleFeatureType ); if (null != type.getGeometryDescriptor()) { schema.put("defaultGeometry", type.getGeometryDescriptor().getName().getLocalPart()); } JSONArr attributes = schema.putArray("attributes"); for( PropertyDescriptor d : type.getDescriptors() ){ PropertyType t = d.getType(); final String NAME = d.getName().getLocalPart(); String kind; if (d instanceof GeometryDescriptor){ kind = "geometry"; } else if( d instanceof AttributeDescriptor){ kind = "attribute"; } else if (d instanceof AssociationDescriptor){ kind = "association"; } else { kind = "property"; } JSONObj property = attributes.addObject() .put("name", NAME ) .put("property", kind ) .put("type", t.getBinding().getSimpleName() ); if( d instanceof GeometryDescriptor){ GeometryDescriptor g = (GeometryDescriptor) d; proj( property.putObject("proj"), g.getCoordinateReferenceSystem(), null ); } if( details){ property .put("namespace", d.getName().getNamespaceURI() ) .put("description", t.getDescription() ) .put("min-occurs",d.getMinOccurs() ) .put("max-occurs",d.getMaxOccurs() ) .put("nillable",d.isNillable()); int length = FeatureTypes.getFieldLength(d); if( length != FeatureTypes.ANY_LENGTH ){ property.put("length", length ); } if( d instanceof AttributeDescriptor){ AttributeDescriptor a = (AttributeDescriptor) d; property.put("default-value", a.getDefaultValue() ); } if( !t.getRestrictions().isEmpty() ){ JSONArr validate = property.putArray("validate"); for( Filter f : t.getRestrictions() ){ String cql; try { Filter clean = (Filter) f.accept( new DuplicatingFilterVisitor(){ public PropertyName visit(PropertyName e, Object extraData ){ String n = e.getPropertyName(); return getFactory(extraData).property( ".".equals(n) ? NAME : n, e.getNamespaceContext()); } }, null ); cql = ECQL.toCQL(clean); } catch (Throwable ignore ){ ignore.printStackTrace(); cql = f.toString(); } validate.add( cql ); } } } } } return schema; }
IO { public static JSONObj schema( JSONObj schema, FeatureType type, boolean details){ if( type != null ){ schema.put("name", type.getName().getLocalPart() ); schema.put("namespace", type.getName().getNamespaceURI() ); schema.put("simple", type instanceof SimpleFeatureType ); if (null != type.getGeometryDescriptor()) { schema.put("defaultGeometry", type.getGeometryDescriptor().getName().getLocalPart()); } JSONArr attributes = schema.putArray("attributes"); for( PropertyDescriptor d : type.getDescriptors() ){ PropertyType t = d.getType(); final String NAME = d.getName().getLocalPart(); String kind; if (d instanceof GeometryDescriptor){ kind = "geometry"; } else if( d instanceof AttributeDescriptor){ kind = "attribute"; } else if (d instanceof AssociationDescriptor){ kind = "association"; } else { kind = "property"; } JSONObj property = attributes.addObject() .put("name", NAME ) .put("property", kind ) .put("type", t.getBinding().getSimpleName() ); if( d instanceof GeometryDescriptor){ GeometryDescriptor g = (GeometryDescriptor) d; proj( property.putObject("proj"), g.getCoordinateReferenceSystem(), null ); } if( details){ property .put("namespace", d.getName().getNamespaceURI() ) .put("description", t.getDescription() ) .put("min-occurs",d.getMinOccurs() ) .put("max-occurs",d.getMaxOccurs() ) .put("nillable",d.isNillable()); int length = FeatureTypes.getFieldLength(d); if( length != FeatureTypes.ANY_LENGTH ){ property.put("length", length ); } if( d instanceof AttributeDescriptor){ AttributeDescriptor a = (AttributeDescriptor) d; property.put("default-value", a.getDefaultValue() ); } if( !t.getRestrictions().isEmpty() ){ JSONArr validate = property.putArray("validate"); for( Filter f : t.getRestrictions() ){ String cql; try { Filter clean = (Filter) f.accept( new DuplicatingFilterVisitor(){ public PropertyName visit(PropertyName e, Object extraData ){ String n = e.getPropertyName(); return getFactory(extraData).property( ".".equals(n) ? NAME : n, e.getNamespaceContext()); } }, null ); cql = ECQL.toCQL(clean); } catch (Throwable ignore ){ ignore.printStackTrace(); cql = f.toString(); } validate.add( cql ); } } } } } return schema; } }
IO { public static JSONObj schema( JSONObj schema, FeatureType type, boolean details){ if( type != null ){ schema.put("name", type.getName().getLocalPart() ); schema.put("namespace", type.getName().getNamespaceURI() ); schema.put("simple", type instanceof SimpleFeatureType ); if (null != type.getGeometryDescriptor()) { schema.put("defaultGeometry", type.getGeometryDescriptor().getName().getLocalPart()); } JSONArr attributes = schema.putArray("attributes"); for( PropertyDescriptor d : type.getDescriptors() ){ PropertyType t = d.getType(); final String NAME = d.getName().getLocalPart(); String kind; if (d instanceof GeometryDescriptor){ kind = "geometry"; } else if( d instanceof AttributeDescriptor){ kind = "attribute"; } else if (d instanceof AssociationDescriptor){ kind = "association"; } else { kind = "property"; } JSONObj property = attributes.addObject() .put("name", NAME ) .put("property", kind ) .put("type", t.getBinding().getSimpleName() ); if( d instanceof GeometryDescriptor){ GeometryDescriptor g = (GeometryDescriptor) d; proj( property.putObject("proj"), g.getCoordinateReferenceSystem(), null ); } if( details){ property .put("namespace", d.getName().getNamespaceURI() ) .put("description", t.getDescription() ) .put("min-occurs",d.getMinOccurs() ) .put("max-occurs",d.getMaxOccurs() ) .put("nillable",d.isNillable()); int length = FeatureTypes.getFieldLength(d); if( length != FeatureTypes.ANY_LENGTH ){ property.put("length", length ); } if( d instanceof AttributeDescriptor){ AttributeDescriptor a = (AttributeDescriptor) d; property.put("default-value", a.getDefaultValue() ); } if( !t.getRestrictions().isEmpty() ){ JSONArr validate = property.putArray("validate"); for( Filter f : t.getRestrictions() ){ String cql; try { Filter clean = (Filter) f.accept( new DuplicatingFilterVisitor(){ public PropertyName visit(PropertyName e, Object extraData ){ String n = e.getPropertyName(); return getFactory(extraData).property( ".".equals(n) ? NAME : n, e.getNamespaceContext()); } }, null ); cql = ECQL.toCQL(clean); } catch (Throwable ignore ){ ignore.printStackTrace(); cql = f.toString(); } validate.add( cql ); } } } } } return schema; }  }
IO { public static JSONObj schema( JSONObj schema, FeatureType type, boolean details){ if( type != null ){ schema.put("name", type.getName().getLocalPart() ); schema.put("namespace", type.getName().getNamespaceURI() ); schema.put("simple", type instanceof SimpleFeatureType ); if (null != type.getGeometryDescriptor()) { schema.put("defaultGeometry", type.getGeometryDescriptor().getName().getLocalPart()); } JSONArr attributes = schema.putArray("attributes"); for( PropertyDescriptor d : type.getDescriptors() ){ PropertyType t = d.getType(); final String NAME = d.getName().getLocalPart(); String kind; if (d instanceof GeometryDescriptor){ kind = "geometry"; } else if( d instanceof AttributeDescriptor){ kind = "attribute"; } else if (d instanceof AssociationDescriptor){ kind = "association"; } else { kind = "property"; } JSONObj property = attributes.addObject() .put("name", NAME ) .put("property", kind ) .put("type", t.getBinding().getSimpleName() ); if( d instanceof GeometryDescriptor){ GeometryDescriptor g = (GeometryDescriptor) d; proj( property.putObject("proj"), g.getCoordinateReferenceSystem(), null ); } if( details){ property .put("namespace", d.getName().getNamespaceURI() ) .put("description", t.getDescription() ) .put("min-occurs",d.getMinOccurs() ) .put("max-occurs",d.getMaxOccurs() ) .put("nillable",d.isNillable()); int length = FeatureTypes.getFieldLength(d); if( length != FeatureTypes.ANY_LENGTH ){ property.put("length", length ); } if( d instanceof AttributeDescriptor){ AttributeDescriptor a = (AttributeDescriptor) d; property.put("default-value", a.getDefaultValue() ); } if( !t.getRestrictions().isEmpty() ){ JSONArr validate = property.putArray("validate"); for( Filter f : t.getRestrictions() ){ String cql; try { Filter clean = (Filter) f.accept( new DuplicatingFilterVisitor(){ public PropertyName visit(PropertyName e, Object extraData ){ String n = e.getPropertyName(); return getFactory(extraData).property( ".".equals(n) ? NAME : n, e.getNamespaceContext()); } }, null ); cql = ECQL.toCQL(clean); } catch (Throwable ignore ){ ignore.printStackTrace(); cql = f.toString(); } validate.add( cql ); } } } } } return schema; }  static JSONObj proj(JSONObj obj, CoordinateReferenceSystem crs, String srs); static JSONObj bounds(JSONObj obj, org.opengis.geometry.Envelope bbox); static Envelope bounds(JSONObj obj); static CoordinateReferenceSystem crs(JSONObj obj); static String srs(JSONObj obj); static JSONObj workspace(JSONObj obj, WorkspaceInfo workspace, NamespaceInfo namespace, boolean isDefault); static JSONObj layer(JSONObj json, LayerInfo info, HttpServletRequest req); static JSONObj layerDetails(JSONObj obj, PublishedInfo layer, HttpServletRequest req); static JSONObj layerDetails(JSONObj obj, LayerGroupInfo group, HttpServletRequest req); @SuppressWarnings("unchecked") static JSONObj layerDetails(JSONObj obj, LayerInfo layer, HttpServletRequest req); static JSONObj bbox( JSONObj bbox, LayerGroupInfo l ); static JSONObj bbox( JSONObj bbox, ResourceInfo r ); static JSONObj schema( JSONObj schema, FeatureType type, boolean details); static JSONArr feature( JSONArr arr, Feature feature); static JSONArr features( JSONArr arr, FeatureCollection<FeatureType, Feature> features); static JSONObj schemaGrid( JSONObj schema, CoverageInfo info, boolean details ); static JSONObj schemaGrid( JSONObj schema, CoordinateReferenceSystem crs, boolean details); static JSONObj store(JSONObj obj, StoreInfo store, HttpServletRequest req, GeoServer geoServer); static JSONObj storeDetails(JSONObj json, StoreInfo store, HttpServletRequest req, GeoServer geoServer); static JSONObj resource(JSONObj obj, StoreInfo store, String name, GeoServer geoServer); static JSONObj error(JSONObj json, Throwable error); static JSONObj param(JSONObj json, Parameter<?> p); static void param(JSONObj json, Format g); static Object url(HttpServletRequest req, String path, Object ... args); static JSONObj ref(JSONObj obj, Ref ref); }
IO { public static JSONObj schema( JSONObj schema, FeatureType type, boolean details){ if( type != null ){ schema.put("name", type.getName().getLocalPart() ); schema.put("namespace", type.getName().getNamespaceURI() ); schema.put("simple", type instanceof SimpleFeatureType ); if (null != type.getGeometryDescriptor()) { schema.put("defaultGeometry", type.getGeometryDescriptor().getName().getLocalPart()); } JSONArr attributes = schema.putArray("attributes"); for( PropertyDescriptor d : type.getDescriptors() ){ PropertyType t = d.getType(); final String NAME = d.getName().getLocalPart(); String kind; if (d instanceof GeometryDescriptor){ kind = "geometry"; } else if( d instanceof AttributeDescriptor){ kind = "attribute"; } else if (d instanceof AssociationDescriptor){ kind = "association"; } else { kind = "property"; } JSONObj property = attributes.addObject() .put("name", NAME ) .put("property", kind ) .put("type", t.getBinding().getSimpleName() ); if( d instanceof GeometryDescriptor){ GeometryDescriptor g = (GeometryDescriptor) d; proj( property.putObject("proj"), g.getCoordinateReferenceSystem(), null ); } if( details){ property .put("namespace", d.getName().getNamespaceURI() ) .put("description", t.getDescription() ) .put("min-occurs",d.getMinOccurs() ) .put("max-occurs",d.getMaxOccurs() ) .put("nillable",d.isNillable()); int length = FeatureTypes.getFieldLength(d); if( length != FeatureTypes.ANY_LENGTH ){ property.put("length", length ); } if( d instanceof AttributeDescriptor){ AttributeDescriptor a = (AttributeDescriptor) d; property.put("default-value", a.getDefaultValue() ); } if( !t.getRestrictions().isEmpty() ){ JSONArr validate = property.putArray("validate"); for( Filter f : t.getRestrictions() ){ String cql; try { Filter clean = (Filter) f.accept( new DuplicatingFilterVisitor(){ public PropertyName visit(PropertyName e, Object extraData ){ String n = e.getPropertyName(); return getFactory(extraData).property( ".".equals(n) ? NAME : n, e.getNamespaceContext()); } }, null ); cql = ECQL.toCQL(clean); } catch (Throwable ignore ){ ignore.printStackTrace(); cql = f.toString(); } validate.add( cql ); } } } } } return schema; }  static JSONObj proj(JSONObj obj, CoordinateReferenceSystem crs, String srs); static JSONObj bounds(JSONObj obj, org.opengis.geometry.Envelope bbox); static Envelope bounds(JSONObj obj); static CoordinateReferenceSystem crs(JSONObj obj); static String srs(JSONObj obj); static JSONObj workspace(JSONObj obj, WorkspaceInfo workspace, NamespaceInfo namespace, boolean isDefault); static JSONObj layer(JSONObj json, LayerInfo info, HttpServletRequest req); static JSONObj layerDetails(JSONObj obj, PublishedInfo layer, HttpServletRequest req); static JSONObj layerDetails(JSONObj obj, LayerGroupInfo group, HttpServletRequest req); @SuppressWarnings("unchecked") static JSONObj layerDetails(JSONObj obj, LayerInfo layer, HttpServletRequest req); static JSONObj bbox( JSONObj bbox, LayerGroupInfo l ); static JSONObj bbox( JSONObj bbox, ResourceInfo r ); static JSONObj schema( JSONObj schema, FeatureType type, boolean details); static JSONArr feature( JSONArr arr, Feature feature); static JSONArr features( JSONArr arr, FeatureCollection<FeatureType, Feature> features); static JSONObj schemaGrid( JSONObj schema, CoverageInfo info, boolean details ); static JSONObj schemaGrid( JSONObj schema, CoordinateReferenceSystem crs, boolean details); static JSONObj store(JSONObj obj, StoreInfo store, HttpServletRequest req, GeoServer geoServer); static JSONObj storeDetails(JSONObj json, StoreInfo store, HttpServletRequest req, GeoServer geoServer); static JSONObj resource(JSONObj obj, StoreInfo store, String name, GeoServer geoServer); static JSONObj error(JSONObj json, Throwable error); static JSONObj param(JSONObj json, Parameter<?> p); static void param(JSONObj json, Format g); static Object url(HttpServletRequest req, String path, Object ... args); static JSONObj ref(JSONObj obj, Ref ref);  }