public NamespaceWorkspaceConsistencyListener(Catalog catalog) { this.catalog = catalog; catalog.addListener(this); }
public void addListener(CatalogListener listener) { delegate.addListener(listener); }
public void addListener(CatalogListener listener) { delegate.addListener(listener); }
public void addListener(CatalogListener listener) { delegate.addListener(listener); }
public LayerGroupContainmentCache(Catalog catalog) { this.catalog = catalog; catalog.addListener(new CatalogChangeListener()); buildLayerGroupCaches(); }
public UpdateSequenceListener(GeoServer geoServer) { this.geoServer = geoServer; geoServer.getCatalog().addListener(this); geoServer.addListener(this); }
protected void loadCatalog(Catalog catalog, XStreamPersister xp) throws Exception { catalog.setResourceLoader(resourceLoader); readCatalog(catalog, xp); if (!legacy) { // add the listener which will persist changes catalog.addListener(new GeoServerConfigPersister(resourceLoader, xp)); catalog.addListener(new GeoServerResourcePersister(catalog.getResourceLoader())); } }
@Override protected void initializeStyles(Catalog catalog, XStreamPersister xp) throws IOException { // add a persister temporarily in case the styles don't exist on disk GeoServerConfigPersister cp = new GeoServerConfigPersister(resourceLoader, xp); GeoServerResourcePersister rp = new GeoServerResourcePersister(resourceLoader); catalog.addListener(cp); catalog.addListener(rp); super.initializeStyles(catalog, xp); catalog.removeListener(cp); catalog.removeListener(rp); } }
public void setCatalog(Catalog catalog) { this.catalog = catalog; this.repository = new CatalogRepository(catalog); catalog.removeListeners(CacheClearingListener.class); catalog.addListener(new CacheClearingListener()); }
protected void readCatalog(Catalog catalog, XStreamPersister xp) throws Exception { // we are going to synch up the catalogs and need to preserve listeners, // but these two fellas are attached to the new catalog as well catalog.removeListeners(ResourcePool.CacheClearingListener.class); catalog.removeListeners(GeoServerConfigPersister.class); catalog.removeListeners(GeoServerResourcePersister.class); List<CatalogListener> listeners = new ArrayList<CatalogListener>(catalog.getListeners()); // look for catalog.xml, if it exists assume we are dealing with // an old data directory Resource f = resourceLoader.get("catalog.xml"); if (!Resources.exists(f)) { // assume 2.x style data directory CatalogImpl catalog2 = (CatalogImpl) readCatalog(xp); // make to remove the old resource pool catalog listener ((CatalogImpl) catalog).sync(catalog2); } else { // import old style catalog, register the persister now so that we start // with a new version of the catalog CatalogImpl catalog2 = (CatalogImpl) readLegacyCatalog(f, xp); ((CatalogImpl) catalog).sync(catalog2); } // attach back the old listeners for (CatalogListener listener : listeners) { catalog.addListener(listener); } }
@Test public void testStyleEvents() { TestListener l = new TestListener(); catalog.addListener(l); assertTrue(l.added.isEmpty()); catalog.add(s); assertEquals(1, l.added.size()); assertEquals(s, l.added.get(0).getSource()); StyleInfo s2 = catalog.getStyleByName(s.getName()); s2.setFilename("changed"); assertTrue(l.modified.isEmpty()); assertTrue(l.postModified.isEmpty()); catalog.save(s2); assertEquals(1, l.modified.size()); assertEquals(s2, l.modified.get(0).getSource()); assertTrue(l.modified.get(0).getPropertyNames().contains("filename")); assertTrue(l.modified.get(0).getOldValues().contains("styleFilename")); assertTrue(l.modified.get(0).getNewValues().contains("changed")); assertEquals(1, l.postModified.size()); assertEquals(s2, l.postModified.get(0).getSource()); assertTrue(l.postModified.get(0).getPropertyNames().contains("filename")); assertTrue(l.postModified.get(0).getOldValues().contains("styleFilename")); assertTrue(l.postModified.get(0).getNewValues().contains("changed")); assertTrue(l.removed.isEmpty()); catalog.remove(s2); assertEquals(1, l.removed.size()); assertEquals(s2, l.removed.get(0).getSource()); }
@Test public void testLayerEvents() { addFeatureType(); addStyle(); TestListener tl = new TestListener(); catalog.addListener(tl); assertTrue(tl.added.isEmpty()); catalog.add(l); assertEquals(1, tl.added.size()); assertEquals(l, tl.added.get(0).getSource()); LayerInfo l2 = catalog.getLayerByName(l.getName()); l2.setPath("newPath"); assertTrue(tl.modified.isEmpty()); catalog.save(l2); assertEquals(1, tl.modified.size()); assertEquals(l2, tl.modified.get(0).getSource()); assertTrue(tl.modified.get(0).getPropertyNames().contains("path")); assertTrue(tl.modified.get(0).getOldValues().contains(null)); assertTrue(tl.modified.get(0).getNewValues().contains("newPath")); assertEquals(1, tl.postModified.size()); assertEquals(l2, tl.postModified.get(0).getSource()); assertTrue(tl.postModified.get(0).getPropertyNames().contains("path")); assertTrue(tl.postModified.get(0).getOldValues().contains(null)); assertTrue(tl.postModified.get(0).getNewValues().contains("newPath")); assertTrue(tl.removed.isEmpty()); catalog.remove(l2); assertEquals(1, tl.removed.size()); assertEquals(l2, tl.removed.get(0).getSource()); }
@Test public void testChangeNamespace() { Catalog cat = createMock(Catalog.class); cat.addListener((CatalogListener) anyObject()); expectLastCall(); WorkspaceInfo ws = createMock(WorkspaceInfo.class); ws.setName("abcd"); expectLastCall(); expect(cat.getWorkspaceByName("gs")).andReturn(ws); cat.save(ws); expectLastCall(); NamespaceInfo ns = createNiceMock(NamespaceInfo.class); CatalogModifyEvent e = createNiceMock(CatalogModifyEvent.class); expect(e.getSource()).andReturn(ns).anyTimes(); expect(e.getPropertyNames()).andReturn(Arrays.asList("prefix")); expect(e.getOldValues()).andReturn((List) Arrays.asList("gs")); expect(e.getNewValues()).andReturn((List) Arrays.asList("abcd")); replay(e, ws, ns, cat); new NamespaceWorkspaceConsistencyListener(cat).handleModifyEvent(e); verify(ws, cat); }
@Test public void testModifyMetadata() { // set default namespace addNamespace(); addDataStore(); TestListener l = new TestListener(); catalog.addListener(l); FeatureTypeInfo ft = catalog.getFactory().createFeatureType(); ft.setName("ftName"); ft.setDescription("ftDescription"); ft.setStore(ds); assertTrue(l.added.isEmpty()); catalog.add(ft); assertEquals(1, l.added.size()); assertEquals(ft, l.added.get(0).getSource()); ft = catalog.getFeatureTypeByName("ftName"); ft.getMetadata().put("newValue", "abcd"); MetadataMap newMetadata = new MetadataMap(ft.getMetadata()); catalog.save(ft); assertEquals(1, l.modified.size()); assertEquals(ft, l.modified.get(0).getSource()); assertTrue(l.modified.get(0).getPropertyNames().contains("metadata")); assertTrue(l.modified.get(0).getOldValues().contains(new MetadataMap())); assertTrue(l.modified.get(0).getNewValues().contains(newMetadata)); }
@Test public void testChangeWorkspace() { Catalog cat = createMock(Catalog.class); cat.addListener((CatalogListener) anyObject()); expectLastCall(); NamespaceInfo ns = createMock(NamespaceInfo.class); ns.setPrefix("abcd"); expectLastCall(); expect(cat.getNamespaceByPrefix("gs")).andReturn(ns); cat.save(ns); expectLastCall(); WorkspaceInfo ws = createNiceMock(WorkspaceInfo.class); CatalogModifyEvent e = createNiceMock(CatalogModifyEvent.class); expect(e.getSource()).andReturn(ws).anyTimes(); expect(e.getPropertyNames()).andReturn(Arrays.asList("name")); expect(e.getOldValues()).andReturn((List) Arrays.asList("gs")); expect(e.getNewValues()).andReturn((List) Arrays.asList("abcd")); replay(e, ws, ns, cat); new NamespaceWorkspaceConsistencyListener(cat).handleModifyEvent(e); verify(ns, cat); }
@Test public void testChangeDefaultWorkspace() { Catalog cat = createMock(Catalog.class); cat.addListener((CatalogListener) anyObject()); expectLastCall(); NamespaceInfo def = createNiceMock(NamespaceInfo.class); expect(cat.getDefaultNamespace()).andReturn(def); NamespaceInfo ns = createNiceMock(NamespaceInfo.class); expect(cat.getNamespaceByPrefix("abcd")).andReturn(ns); cat.setDefaultNamespace(ns); expectLastCall(); WorkspaceInfo ws = createNiceMock(WorkspaceInfo.class); expect(ws.getName()).andReturn("abcd"); CatalogModifyEvent e = createNiceMock(CatalogModifyEvent.class); expect(e.getSource()).andReturn(cat).anyTimes(); expect(e.getPropertyNames()).andReturn(Arrays.asList("defaultWorkspace")); expect(e.getNewValues()).andReturn((List) Arrays.asList(ws)); replay(ns, ws, e, cat); new NamespaceWorkspaceConsistencyListener(cat).handleModifyEvent(e); verify(ns, ws, cat); }
@Test public void testChangeDefaultNamespace() { Catalog cat = createMock(Catalog.class); cat.addListener((CatalogListener) anyObject()); expectLastCall(); WorkspaceInfo def = createNiceMock(WorkspaceInfo.class); expect(cat.getDefaultWorkspace()).andReturn(def); WorkspaceInfo ws = createNiceMock(WorkspaceInfo.class); expect(cat.getWorkspaceByName("abcd")).andReturn(ws); cat.setDefaultWorkspace(ws); expectLastCall(); NamespaceInfo ns = createNiceMock(NamespaceInfo.class); expect(ns.getPrefix()).andReturn("abcd"); CatalogModifyEvent e = createNiceMock(CatalogModifyEvent.class); expect(e.getSource()).andReturn(cat).anyTimes(); expect(e.getPropertyNames()).andReturn(Arrays.asList("defaultNamespace")); expect(e.getNewValues()).andReturn((List) Arrays.asList(ns)); replay(ns, ws, e, cat); new NamespaceWorkspaceConsistencyListener(cat).handleModifyEvent(e); verify(ns, ws, cat); }
@Test public void testChangeNamespaceURI() { Catalog cat = createMock(Catalog.class); cat.addListener((CatalogListener) anyObject()); expectLastCall(); NamespaceInfo ns = createNiceMock(NamespaceInfo.class); expect(ns.getPrefix()).andReturn("foo"); expect(ns.getURI()).andReturn("http://foo.org"); WorkspaceInfo ws = createNiceMock(WorkspaceInfo.class); expect(cat.getWorkspaceByName("foo")).andReturn(ws); DataStoreInfo ds = createNiceMock(DataStoreInfo.class); expect(cat.getDataStoresByWorkspace(ws)).andReturn(Arrays.asList(ds)); HashMap params = new HashMap(); params.put("namespace", "http://bar.org"); expect(ds.getConnectionParameters()).andReturn(params).anyTimes(); cat.save(hasNamespace("http://foo.org")); expectLastCall(); CatalogPostModifyEvent e = createNiceMock(CatalogPostModifyEvent.class); expect(e.getSource()).andReturn(ns).anyTimes(); expect(ns.getPrefix()).andReturn("foo"); expect(cat.getWorkspaceByName("foo")).andReturn(ws); replay(ds, ws, ns, e, cat); new NamespaceWorkspaceConsistencyListener(cat).handlePostModifyEvent(e); verify(cat); }
@Test public void testExceptionThrowingListener() throws Exception { ExceptionThrowingListener l = new ExceptionThrowingListener(); catalog.addListener(l); l.throwCatalogException = false; WorkspaceInfo ws = catalog.getFactory().createWorkspace(); ws.setName("foo"); // no exception thrown back catalog.add(ws); l.throwCatalogException = true; ws = catalog.getFactory().createWorkspace(); ws.setName("bar"); try { catalog.add(ws); fail(); } catch (CatalogException ce) { // good } }
protected void createConfig() { GeoServerImpl geoServer = new GeoServerImpl(); geoServer.addListener( new GeoServerConfigPersister( new GeoServerResourceLoader(data), createXStreamPersister())); catalog.addListener(new GeoServerResourcePersister(catalog.getResourceLoader())); GeoServerInfo global = geoServer.getFactory().createGlobal(); geoServer.setGlobal(global); addSettings(null, geoServer); LoggingInfo logging = geoServer.getFactory().createLogging(); geoServer.setLogging(logging); }