public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (!(obj instanceof WorkspaceInfo)) return false; final WorkspaceInfo other = (WorkspaceInfo) obj; if (id == null) { if (other.getId() != null) return false; } else if (!id.equals(other.getId())) return false; if (name == null) { if (other.getName() != null) return false; } else if (!name.equals(other.getName())) return false; return true; }
public void setDefaultDataStore(WorkspaceInfo workspace, DataStoreInfo store) { DataStoreInfo old = defaultStores.get(workspace.getId()); // fire modify event before change catalog.fireModified( catalog, Arrays.asList("defaultDataStore"), Arrays.asList(old), Arrays.asList(store)); synchronized (defaultStores) { if (store != null) { defaultStores.put(workspace.getId(), store); } else { defaultStores.remove(workspace.getId()); } } // fire postmodify event after change catalog.firePostModified( catalog, Arrays.asList("defaultDataStore"), Arrays.asList(old), Arrays.asList(store)); }
@Override public StyleInfo getStyleByName(WorkspaceInfo workspace, String name) { if (null == workspace) { throw new NullPointerException("workspace"); } if (null == name) { throw new NullPointerException("name"); } if (workspace == ANY_WORKSPACE) { return getStyleByName(name); } else { Name sn = new NameImpl(workspace == null ? null : workspace.getId(), name); StyleInfo match = styles.findByName(sn, StyleInfo.class); return wrapInModificationProxy(match, StyleInfo.class); } }
private Filter inWorkspace() { WorkspaceInfo localWS = LocalWorkspace.get(); if (localWS == null) return Predicates.acceptAll(); return Predicates.equal("workspace.id", localWS.getId()); }
public WorkspaceAccessLimits getAccessLimits(Authentication user, WorkspaceInfo workspace) { if (user == null) { return null; } final String name = user.getName(); WorkspaceAccessLimits wal = (WorkspaceAccessLimits) getUserMap(name).get(workspace.getId()); if (wal != null) { return wal; } else { return defaultWorkspaceAccessLimits; } }
public <T extends StoreInfo> T getStoreByName( WorkspaceInfo workspace, String name, Class<T> clazz) { T result; if (workspace == ANY_WORKSPACE) { result = stores.findFirst(clazz, s -> name.equals(s.getName())); } else { Name qname = new NameImpl((workspace != null) ? workspace.getId() : null, name); result = stores.findByName(qname, clazz); } return wrapInModificationProxy(result, clazz); }
public ValidationResult validate(WorkspaceInfo workspace, boolean isNew) { if (workspace.isIsolated() && !getCatalogCapabilities().supportsIsolatedWorkspaces()) { // isolated namespaces \ workspaces are not supported by this catalog throw new IllegalArgumentException( String.format( "Workspace '%s' is isolated but isolated workspaces are not supported by this catalog.", workspace.getName())); } if (isNull(workspace.getName())) { throw new NullPointerException("workspace name must not be null"); } if (workspace.getName().equals(DEFAULT)) { throw new IllegalArgumentException( DEFAULT + " is a reserved keyword, can't be used as the workspace name"); } WorkspaceInfo existing = getWorkspaceByName(workspace.getName()); if (existing != null && !existing.getId().equals(workspace.getId())) { throw new IllegalArgumentException( "Workspace named '" + workspace.getName() + "' already exists."); } return postValidate(workspace, isNew); }
@Override public LayerGroupInfo getLayerGroupByName(WorkspaceInfo workspace, String name) { LayerGroupInfo match; if (workspace == NO_WORKSPACE) { match = layerGroups.findByName(new NameImpl(null, name), LayerGroupInfo.class); } else if (ANY_WORKSPACE == workspace) { match = layerGroups.findFirst(LayerGroupInfo.class, lg -> name.equals(lg.getName())); } else { match = layerGroups.findByName( new NameImpl(workspace.getId(), name), LayerGroupInfo.class); } return wrapInModificationProxy(match, LayerGroupInfo.class); }
@Test public void testGetWorkspaceById() { catalog.add(ws); WorkspaceInfo ws2 = catalog.getWorkspace(ws.getId()); assertNotNull(ws2); assertFalse(ws == ws2); assertEquals(ws, ws2); }
@Test public void testAddStyleWithWorkspace() throws Exception { File f = new File(testData.getDataDirectoryRoot(), "workspaces/gs/styles/foostyle.xml"); assertFalse(f.exists()); StyleInfo s = catalog.getFactory().createStyle(); s.setName("foostyle"); s.setFilename("foostyle.sld"); s.setWorkspace(catalog.getDefaultWorkspace()); catalog.add(s); assertTrue(f.exists()); Document dom = dom(f); assertXpathEvaluatesTo(catalog.getDefaultWorkspace().getId(), "/style/workspace/id", dom); }
@Test public void testAddLayerGroupWithWorkspace() throws Exception { File f = file( testData.getDataDirectoryRoot(), "workspaces/acme/layergroups/foolayergroup.xml"); assertFalse(f.exists()); testAddLayer(); LayerGroupInfo lg = catalog.getFactory().createLayerGroup(); lg.setName("foolayergroup"); lg.setWorkspace(catalog.getWorkspaceByName("acme")); lg.getLayers().add(catalog.getLayerByName("foo")); lg.getStyles().add(null); catalog.add(lg); assertTrue(f.exists()); Document dom = dom(f); assertXpathEvaluatesTo( catalog.getWorkspaceByName("acme").getId(), "/layerGroup/workspace/id", dom); }
@Test public void testCoverageStore() throws Exception { Catalog catalog = new CatalogImpl(); CatalogFactory cFactory = catalog.getFactory(); WorkspaceInfo ws = cFactory.createWorkspace(); ws.setName("foo"); CoverageStoreInfo cs1 = cFactory.createCoverageStore(); cs1.setName("bar"); cs1.setWorkspace(ws); ByteArrayOutputStream out = out(); persister.save(cs1, out); CoverageStoreInfo ds2 = persister.load(in(out), CoverageStoreInfo.class); assertEquals("bar", ds2.getName()); assertNotNull(ds2.getWorkspace()); assertEquals("foo", ds2.getWorkspace().getId()); Document dom = dom(in(out)); assertEquals("coverageStore", dom.getDocumentElement().getNodeName()); }
@Test public void testDataStore() throws Exception { Catalog catalog = new CatalogImpl(); CatalogFactory cFactory = catalog.getFactory(); WorkspaceInfo ws = cFactory.createWorkspace(); ws.setName("foo"); DataStoreInfo ds1 = cFactory.createDataStore(); ds1.setName("bar"); ds1.setWorkspace(ws); ByteArrayOutputStream out = out(); persister.save(ds1, out); DataStoreInfo ds2 = persister.load(in(out), DataStoreInfo.class); assertEquals("bar", ds2.getName()); assertNotNull(ds2.getWorkspace()); assertEquals("foo", ds2.getWorkspace().getId()); Document dom = dom(in(out)); assertEquals("dataStore", dom.getDocumentElement().getNodeName()); }
@Test public void testDataStoreReferencedByName() throws Exception { Catalog catalog = new CatalogImpl(); CatalogFactory cFactory = catalog.getFactory(); WorkspaceInfo ws = cFactory.createWorkspace(); ws.setName("foo"); DataStoreInfo ds1 = cFactory.createDataStore(); ds1.setName("bar"); ds1.setWorkspace(ws); catalog.detach(ds1); ((DataStoreInfoImpl) ds1).setId(null); ByteArrayOutputStream out = out(); XStreamPersister persister = new XStreamPersisterFactory().createXMLPersister(); persister.setReferenceByName(true); persister.save(ds1, out); DataStoreInfo ds2 = persister.load(in(out), DataStoreInfo.class); assertEquals("bar", ds2.getName()); assertNotNull(ds2.getWorkspace()); assertEquals("foo", ds2.getWorkspace().getId()); Document dom = dom(in(out)); assertEquals("dataStore", dom.getDocumentElement().getNodeName()); }
@Test public void testCoverageStoreReferencedByName() throws Exception { Catalog catalog = new CatalogImpl(); CatalogFactory cFactory = catalog.getFactory(); WorkspaceInfo ws = cFactory.createWorkspace(); ws.setName("foo"); CoverageStoreInfo cs1 = cFactory.createCoverageStore(); cs1.setName("bar"); cs1.setWorkspace(ws); catalog.detach(cs1); ((CoverageStoreInfoImpl) cs1).setId(null); ByteArrayOutputStream out = out(); XStreamPersister persister = new XStreamPersisterFactory().createXMLPersister(); persister.setReferenceByName(true); persister.save(cs1, out); CoverageStoreInfo ds2 = persister.load(in(out), CoverageStoreInfo.class); assertEquals("bar", ds2.getName()); assertNotNull(ds2.getWorkspace()); assertEquals("foo", ds2.getWorkspace().getId()); Document dom = dom(in(out)); assertEquals("coverageStore", dom.getDocumentElement().getNodeName()); }
@Test public void testWMSStore() throws Exception { Catalog catalog = new CatalogImpl(); CatalogFactory cFactory = catalog.getFactory(); WorkspaceInfo ws = cFactory.createWorkspace(); ws.setName("foo"); WMSStoreInfo wms1 = cFactory.createWebMapServer(); wms1.setName("bar"); wms1.setWorkspace(ws); wms1.setCapabilitiesURL("http://fake.host/wms?request=GetCapabilities&service=wms"); ByteArrayOutputStream out = out(); persister.save(wms1, out); WMSStoreInfo wms2 = persister.load(in(out), WMSStoreInfo.class); assertEquals("bar", wms2.getName()); assertEquals(WMSStoreInfoImpl.DEFAULT_MAX_CONNECTIONS, wms2.getMaxConnections()); assertEquals(WMSStoreInfoImpl.DEFAULT_CONNECT_TIMEOUT, wms2.getConnectTimeout()); assertEquals(WMSStoreInfoImpl.DEFAULT_READ_TIMEOUT, wms2.getReadTimeout()); assertNotNull(wms2.getWorkspace()); assertEquals("foo", wms2.getWorkspace().getId()); Document dom = dom(in(out)); assertEquals("wmsStore", dom.getDocumentElement().getNodeName()); }
@Test public void testWorkspaceStyle() throws Exception { Catalog catalog = new CatalogImpl(); CatalogFactory cFactory = catalog.getFactory(); WorkspaceInfo ws = cFactory.createWorkspace(); ws.setName("foo"); StyleInfo s1 = cFactory.createStyle(); s1.setName("bar"); s1.setFilename("bar.sld"); s1.setWorkspace(ws); ByteArrayOutputStream out = out(); persister.save(s1, out); ByteArrayInputStream in = in(out); StyleInfo s2 = persister.load(in, StyleInfo.class); assertEquals("bar", s2.getName()); assertNotNull(s2.getWorkspace()); assertEquals("foo", s2.getWorkspace().getId()); Document dom = dom(in(out)); assertEquals("style", dom.getDocumentElement().getNodeName()); catalog.add(ws); catalog.add(s2); // Make sure the catalog resolves the workspace assertEquals("foo", s2.getWorkspace().getName()); }
@Test public void testWMSStoreReferencedByName() throws Exception { Catalog catalog = new CatalogImpl(); CatalogFactory cFactory = catalog.getFactory(); WorkspaceInfo ws = cFactory.createWorkspace(); ws.setName("foo"); WMSStoreInfo wms1 = cFactory.createWebMapServer(); wms1.setName("bar"); wms1.setWorkspace(ws); wms1.setCapabilitiesURL("http://fake.host/wms?request=GetCapabilities&service=wms"); catalog.detach(wms1); ((WMSStoreInfoImpl) wms1).setId(null); ByteArrayOutputStream out = out(); XStreamPersister persister = new XStreamPersisterFactory().createXMLPersister(); persister.setReferenceByName(true); persister.save(wms1, out); WMSStoreInfo wms2 = persister.load(in(out), WMSStoreInfo.class); assertEquals("bar", wms2.getName()); assertEquals(WMSStoreInfoImpl.DEFAULT_MAX_CONNECTIONS, wms2.getMaxConnections()); assertEquals(WMSStoreInfoImpl.DEFAULT_CONNECT_TIMEOUT, wms2.getConnectTimeout()); assertEquals(WMSStoreInfoImpl.DEFAULT_READ_TIMEOUT, wms2.getReadTimeout()); assertNotNull(wms2.getWorkspace()); assertEquals("foo", wms2.getWorkspace().getId()); Document dom = dom(in(out)); assertEquals("wmsStore", dom.getDocumentElement().getNodeName()); }
@Test public void testModifySettingsChangeWorkspace() throws Exception { testAddSettings(); WorkspaceInfo ws1 = catalog.getWorkspaceByName("acme"); WorkspaceInfo ws2 = catalog.getFactory().createWorkspace(); ws2.setName("foo"); catalog.add(ws2); SettingsInfo settings = getGeoServer().getSettings(ws1); settings.setWorkspace(ws2); getGeoServer().save(settings); File f = catalog.getResourceLoader().find("workspaces", ws1.getName(), "settings.xml"); assertNull(f); f = catalog.getResourceLoader().find("workspaces", ws2.getName(), "settings.xml"); assertNotNull(f); Document dom = dom(f); assertXpathEvaluatesTo(ws2.getId(), "/settings/workspace/id", dom); }