/** * Builds a {@link FeatureTypeInfo} from the current datastore and the specified type name * * <p>The resulting object is not added to the catalog, it must be done by the calling code * after the fact. */ public FeatureTypeInfo buildFeatureType(Name typeName) throws Exception { if (store == null || !(store instanceof DataStoreInfo)) { throw new IllegalStateException("Data store not set."); } DataStoreInfo dstore = (DataStoreInfo) store; return buildFeatureType(dstore.getDataStore(null).getFeatureSource(typeName)); }
@Test public void testMetadataFromFeatueSource() throws Exception { CatalogBuilder cb = new CatalogBuilder(getCatalog()); cb.setStore(cb.buildDataStore("fooStore")); FeatureType ft = createMock(FeatureType.class); expect(ft.getName()).andReturn(new NameImpl("foo")).anyTimes(); expect(ft.getCoordinateReferenceSystem()).andReturn(null).anyTimes(); expect(ft.getGeometryDescriptor()).andReturn(null).anyTimes(); replay(ft); ResourceInfo rInfo = createMock(ResourceInfo.class); expect(rInfo.getTitle()).andReturn("foo title"); expect(rInfo.getDescription()).andReturn("foo description"); expect(rInfo.getKeywords()) .andReturn(new LinkedHashSet<String>(Arrays.asList("foo", "bar", "baz", ""))) .anyTimes(); replay(rInfo); FeatureSource fs = createMock(FeatureSource.class); expect(fs.getSchema()).andReturn(ft).anyTimes(); expect(fs.getInfo()).andReturn(rInfo).anyTimes(); expect(fs.getName()).andReturn(ft.getName()).anyTimes(); replay(fs); FeatureTypeInfo ftInfo = cb.buildFeatureType(fs); assertEquals("foo title", ftInfo.getTitle()); assertEquals("foo description", ftInfo.getDescription()); assertTrue(ftInfo.getKeywords().contains(new Keyword("foo"))); assertTrue(ftInfo.getKeywords().contains(new Keyword("bar"))); assertTrue(ftInfo.getKeywords().contains(new Keyword("baz"))); }
@Test public void testGenericStyle() throws Exception { Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getDataStoreByName(MockData.GENERICENTITY.getPrefix())); FeatureTypeInfo fti = cb.buildFeatureType(toName(MockData.GENERICENTITY)); LayerInfo li = cb.buildLayer(fti); // check we assigned the generic style assertEquals("generic", li.getDefaultStyle().getName()); }
@Test public void testGetBoundsFromCRS() throws Exception { Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getDataStoreByName(MockData.LINES.getPrefix())); FeatureTypeInfo fti = cb.buildFeatureType(toName(MockData.LINES)); CoordinateReferenceSystem resourceCRS = fti.getCRS(); assertNotNull(resourceCRS); // make sure the srs is as expected, otherwise the rest of the tests don't make sense assertEquals("EPSG:32615", fti.getSRS()); ReferencedEnvelope crsBounds = cb.getBoundsFromCRS(fti); assertNotNull(crsBounds); CoordinateReferenceSystem exptectedCRS = CRS.decode("EPSG:32615"); assertEquals(new ReferencedEnvelope(CRS.getEnvelope(exptectedCRS)), crsBounds); // if we change the srs when there's no reproject policy, should still be the same bounding // box fti.setSRS("EPSG:4326"); fti.setProjectionPolicy(ProjectionPolicy.NONE); crsBounds = cb.getBoundsFromCRS(fti); assertEquals(new ReferencedEnvelope(CRS.getEnvelope(exptectedCRS)), crsBounds); // if we use reproject policy, bounds should now be different fti.setProjectionPolicy(ProjectionPolicy.FORCE_DECLARED); crsBounds = cb.getBoundsFromCRS(fti); assertNotEquals(new ReferencedEnvelope(CRS.getEnvelope(exptectedCRS)), crsBounds); // should now be 4326 bounds CoordinateReferenceSystem crs4326 = CRS.decode("EPSG:4326"); assertEquals(new ReferencedEnvelope(CRS.getEnvelope(crs4326)), crsBounds); fti.setProjectionPolicy(ProjectionPolicy.REPROJECT_TO_DECLARED); assertEquals(new ReferencedEnvelope(CRS.getEnvelope(crs4326)), crsBounds); }
private LayerInfo buildLayer(QName resourceName) throws Exception { Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); StoreInfo store = cat.getDataStoreByName(resourceName.getPrefix()); cb.setStore(store); ResourceInfo ri = cb.buildFeatureType(toName(resourceName)); ri.setSRS("EPSG:4326"); cb.setupBounds(ri); LayerInfo layer = cat.getFactory().createLayer(); layer.setResource(ri); layer.setName(ri.getName()); layer.setEnabled(true); layer.setType(PublishedType.VECTOR); return layer; }
MockData.CITE_PREFIX, MockData.CITE_PREFIX, DataStoreInfo.class)); FeatureTypeInfo info = builder.buildFeatureType( new NameImpl( MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart()));
cb.setStore(catalog.getDefaultDataStore(defaultWorkspace)); for (Name name : store.getNames()) { FeatureTypeInfo ft = cb.buildFeatureType(name); cb.setupBounds(ft); catalog.add(ft);
@Test public void testFeatureType() throws Exception { // build a feature type (it's already in the catalog, but we just want to // check it's built as expected // LINES is a feature type with a native SRS, so we want the bounds to be there Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getDataStoreByName(MockData.LINES.getPrefix())); FeatureTypeInfo fti = cb.buildFeatureType(toName(MockData.LINES)); // perform basic checks assertEquals("EPSG:32615", fti.getSRS()); assertEquals(CRS.decode("EPSG:32615", true), fti.getCRS()); assertNull(fti.getNativeBoundingBox()); assertNull(fti.getLatLonBoundingBox()); // force bounds computation cb.setupBounds(fti); assertNotNull(fti.getNativeBoundingBox()); assertNotNull(fti.getNativeBoundingBox().getCoordinateReferenceSystem()); assertNotNull(fti.getLatLonBoundingBox()); }
@Test public void testLayerGroupBounds() throws Exception { Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getDataStoreByName(MockData.LINES.getPrefix())); FeatureTypeInfo fti = cb.buildFeatureType(toName(MockData.LINES)); cb.setupBounds(fti); LayerInfo layer = cat.getFactory().createLayer(); layer.setResource(fti); layer.setName(fti.getName()); layer.setEnabled(true); layer.setType(PublishedType.VECTOR); LayerGroupInfo group = cat.getFactory().createLayerGroup(); group.setName("group"); group.getLayers().add(layer); group.getStyles().add(null); assertNull(group.getBounds()); // force bounds computation cb.calculateLayerGroupBounds(group); assertNotNull(group.getBounds()); assertEquals(fti.getNativeBoundingBox(), group.getBounds()); }
FeatureTypeInfo tft = cb.buildFeatureType(featureStore); cat.add(tft); jds.createVirtualTable(vt); FeatureTypeInfo vft = cb.buildFeatureType(jds.getFeatureSource(vt.getName())); vft.getMetadata().put(FeatureTypeInfo.JDBC_VIRTUAL_TABLE, vt); cat.add(vft);
@Test public void testFeatureTypeNoSRS() throws Exception { // build a feature type (it's already in the catalog, but we just want to // check it's built as expected // LINES is a feature type with a native SRS, so we want the bounds to be there Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getDataStoreByName(MockData.BRIDGES.getPrefix())); FeatureTypeInfo fti = cb.buildFeatureType(toName(MockData.BRIDGES)); // perform basic checks, this has no srs, so default one will be set assertEquals(CatalogBuilder.DEFAULT_SRS, fti.getSRS()); assertNull(fti.getNativeCRS()); assertNull(fti.getNativeBoundingBox()); assertNull(fti.getLatLonBoundingBox()); // force bounds computation cb.setupBounds(fti); assertNotNull(fti.getNativeBoundingBox()); assertNull(fti.getNativeBoundingBox().getCoordinateReferenceSystem()); assertNotNull(fti.getLatLonBoundingBox()); }
@Test public void testGeometryless() throws Exception { // build a feature type (it's already in the catalog, but we just want to // check it's built as expected // LINES is a feature type with a native SRS, so we want the bounds to be there Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getDataStoreByName(MockData.GEOMETRYLESS.getPrefix())); FeatureTypeInfo fti = cb.buildFeatureType(toName(MockData.GEOMETRYLESS)); LayerInfo layer = cb.buildLayer(fti); cb.setupBounds(fti); // perform basic checks assertEquals(CatalogBuilder.DEFAULT_SRS, fti.getSRS()); assertNotNull(fti.getNativeBoundingBox()); assertTrue(fti.getNativeBoundingBox().isEmpty()); assertNotNull(fti.getLatLonBoundingBox()); assertFalse(fti.getLatLonBoundingBox().isEmpty()); assertNull(layer.getDefaultStyle()); }
@Test public void testLayerGroupEoBounds() throws Exception { Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getDataStoreByName(MockData.LINES.getPrefix())); FeatureTypeInfo fti = cb.buildFeatureType(toName(MockData.LINES)); cb.setupBounds(fti); LayerInfo layer = cat.getFactory().createLayer(); layer.setResource(fti); layer.setName(fti.getName()); layer.setEnabled(true); layer.setType(PublishedType.VECTOR); LayerGroupInfo group = cat.getFactory().createLayerGroup(); group.setMode(LayerGroupInfo.Mode.EO); group.setName("group_EO"); group.setRootLayer(layer); assertNull(group.getBounds()); // force bounds computation cb.calculateLayerGroupBounds(group); assertNotNull(group.getBounds()); assertEquals(fti.getNativeBoundingBox(), group.getBounds()); }
@Test public void testEmptyBounds() throws Exception { // test the bounds of a single point Catalog cat = getCatalog(); FeatureTypeInfo fti = cat.getFeatureTypeByName(toString(MockData.POINTS)); assertEquals( Point.class, fti.getFeatureType().getGeometryDescriptor().getType().getBinding()); assertEquals(1, fti.getFeatureSource(null, null).getCount(Query.ALL)); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getStoreByName(MockData.CGF_PREFIX, DataStoreInfo.class)); FeatureTypeInfo built = cb.buildFeatureType(fti.getQualifiedName()); cb.setupBounds(built); assertTrue(built.getNativeBoundingBox().getWidth() > 0); assertTrue(built.getNativeBoundingBox().getHeight() > 0); }
FeatureTypeInfo fti = builder.buildFeatureType(getFeatureSource(ds)); LayerInfo layerInfo = builder.buildLayer(fti); setResponsePage(new ResourceConfigurationPage(layerInfo, true));
/** * Either retrieves the corresponding FeatureTypeInfo from the catalog or fakes one with the * necessary information * * @param c */ private FeatureTypeInfo getFeatureTypeInfo(SimpleFeatureType schema) { FeatureTypeInfo ftInfo = catalog.getFeatureTypeByName(schema.getName()); if (ftInfo == null) { // SG the fc might have been generated by the WPS therefore there is no such a thing // inside the GeoServer catalogue final SimpleFeatureSource featureSource = DataUtilities.source(new ListFeatureCollection(schema)); final CatalogBuilder catalogBuilder = new CatalogBuilder(catalog); catalogBuilder.setStore(catalogBuilder.buildDataStore(schema.getName().getLocalPart())); ftInfo = catalogBuilder.buildFeatureType(featureSource); } return ftInfo; }
@Override protected void onSave() { // TODO: check stuff before saving StoredQuery selection = (StoredQuery) storedQueriesDropDown.getDefaultModelObject(); StoredQueryConfiguration config = createStoredQueryConfiguration( parameterProvider.getItems(), selection.storedQueryId); try { DataStoreInfo dsInfo = getCatalog().getStore(storeId, DataStoreInfo.class); WFSDataStore directDs = getContentDataStore(); DataAccess<?, ?> da = dsInfo.getDataStore(null); Name typeName = directDs.addStoredQuery(getNativeName(), config.getStoredQueryId()); CatalogBuilder builder = new CatalogBuilder(getCatalog()); builder.setStore(dsInfo); FeatureTypeInfo fti = builder.buildFeatureType(da.getFeatureSource(typeName)); fti.getMetadata().put(FeatureTypeInfo.STORED_QUERY_CONFIGURATION, config); LayerInfo layerInfo = builder.buildLayer(fti); setResponsePage(new ResourceConfigurationPage(layerInfo, true)); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Failed to create feature type", e); error(new ParamResourceModel("creationFailure", this, e.getMessage()).getString()); } }
@Override protected void onSave() { try { VirtualTable vt = buildVirtualTable(); DataStoreInfo dsInfo = getCatalog().getStore(storeId, DataStoreInfo.class); JDBCDataStore ds = (JDBCDataStore) dsInfo.getDataStore(null); ds.addVirtualTable(vt); CatalogBuilder builder = new CatalogBuilder(getCatalog()); builder.setStore(dsInfo); FeatureTypeInfo fti = builder.buildFeatureType(ds.getFeatureSource(vt.getName())); fti.getMetadata().put(FeatureTypeInfo.JDBC_VIRTUAL_TABLE, vt); LayerInfo layerInfo = builder.buildLayer(fti); setResponsePage(new ResourceConfigurationPage(layerInfo, true)); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Failed to create feature type", e); error(new ParamResourceModel("creationFailure", this, getFirstErrorMessage(e)) .getString()); } }
@Override protected void onSave() { try { VirtualTable vt = buildVirtualTable(); DataStoreInfo dsInfo = getCatalog().getStore(storeId, DataStoreInfo.class); JDBCDataStore ds = (JDBCDataStore) dsInfo.getDataStore(null); ds.createVirtualTable(vt); CatalogBuilder builder = new CatalogBuilder(getCatalog()); builder.setStore(dsInfo); FeatureTypeInfo fti = builder.buildFeatureType(ds.getFeatureSource(vt.getName())); fti.getMetadata().put(FeatureTypeInfo.JDBC_VIRTUAL_TABLE, vt); LayerInfo layerInfo = builder.buildLayer(fti); setResponsePage(new ResourceConfigurationPage(layerInfo, true)); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Failed to create feature type", e); error( new ParamResourceModel("creationFailure", this, getFirstErrorMessage(e)) .getString()); } }
FeatureTypeInfo ft = cb.buildFeatureType(fs); cat.add(ft); ft = cb.buildFeatureType(fs); cat.add(ft);