@Override public String prefixedName() { return workspace != null ? workspace.getName() + ":" + name : name; }
workspace.setName((String) entry.getKey()); workspace.setIsolated(isolated); catalog.add(workspace);
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; }
/** * Helper method that checks if the provided workspace is visible in the current context. * * <p>This method returns TRUE if the provided workspace is one of the default ones * (NO_WORKSPACE or ANY_WORKSPACE) or if the provided workspace is NULL or is not isolated. If * no OWS service request is in progress TRUE will also be returned. * * <p>If none of the conditions above is satisfied, then if a local workspace exists (i.e. we * are in the context of a virtual service) and if the local workspace matches the provided * workspace TRUE is returned, otherwise FALSE is returned. * * @param workspace the workspace to check for visibility * @return TRUE if the workspace is visible in the current context, otherwise FALSE */ private boolean canSeeWorkspace(WorkspaceInfo workspace) { if (workspace == CatalogFacade.NO_WORKSPACE || workspace == CatalogFacade.ANY_WORKSPACE || workspace == null || !workspace.isIsolated() || Dispatcher.REQUEST.get() == null) { // the workspace content is visible in this context return true; } WorkspaceInfo localWorkspace = getLocalWorkspace(); // the workspace content will be visible only if we are in the context of one // of its virtual services return localWorkspace != null && Objects.equals(localWorkspace.getName(), workspace.getName()); }
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); }
@Test public void testModifyWorkspace() { catalog.add(ws); WorkspaceInfo ws2 = catalog.getWorkspaceByName(ws.getName()); ws2.setName(null); try { catalog.save(ws2); fail("setting name to null should throw exception"); } catch (Exception e) { } ws2.setName("ws2"); WorkspaceInfo ws3 = catalog.getWorkspaceByName(ws.getName()); assertEquals("wsName", ws3.getName()); catalog.save(ws2); ws3 = catalog.getWorkspaceByName(ws2.getName()); assertEquals(ws2, ws3); assertEquals("ws2", ws3.getName()); }
@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); }
expect(ws.getId()).andReturn(wsId).anyTimes(); expect(ws.getName()).andReturn(name).anyTimes(); expect(ws.getMetadata()).andReturn(new MetadataMap()).anyTimes(); expect(catalog.getNamespaceByURI(uri)).andReturn(ns).anyTimes(); ws.accept((CatalogVisitor) anyObject()); expectLastCall() .andAnswer(
@Override public void visit(WorkspaceInfo workspace) { WorkspaceInfo otherWorkspace = otherCatalog.getWorkspace(workspace.getId()); if (otherWorkspace == null) { differences.add(new InfoDiff(workspace, null)); } else if (!(Objects.equals(workspace.getName(), otherWorkspace.getName()) && checkEquals(workspace.getMetadata(), otherWorkspace.getMetadata()))) { differences.add(new InfoDiff(workspace, otherWorkspace)); } }
/** Given a namespace and user, returns it back if the user can access it, null otherwise */ protected <T extends NamespaceInfo> T checkAccess( Authentication user, T ns, MixedModeBehavior mixedModeBehavior) { if (ns == null) return null; // route the security check thru the associated workspace info WorkspaceInfo ws = delegate.getWorkspaceByName(ns.getPrefix()); if (ws == null) { // temporary workaround, build a fake workspace, as we're probably // in between a change of workspace/namespace name ws = delegate.getFactory().createWorkspace(); ws.setName(ns.getPrefix()); } WorkspaceInfo info = checkAccess(user, ws, mixedModeBehavior); if (info == null) return null; else return ns; }
@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()); }
ws.setName("foo"); ws.getMetadata().put("banana", new SweetBanana("Musa acuminata"));
/** * Helper method that will make sure that the workspace associated to the provided namespace has * the same isolation. * * <p>If the associated namespace doesn't exists nothing will be done. * * @param namespace a catalog namespace */ private void syncWorkspaceIsolation(NamespaceInfo namespace) { // get the workspace associated to the namespace, may be NULL WorkspaceInfo workspace = catalog.getWorkspaceByName(namespace.getPrefix()); if (workspace != null && namespace.isIsolated() != workspace.isIsolated()) { // update the workspace isolation workspace.setIsolated(namespace.isIsolated()); catalog.save(workspace); } } }
@Test public void testAddIsolatedWorkspace() { // create isolated workspace WorkspaceInfoImpl workspace = new WorkspaceInfoImpl(); workspace.setName("isolated_workspace"); workspace.setIsolated(true); try { // add it to the catalog catalog.add(workspace); // retrieve the isolated workspace WorkspaceInfo foundWorkspace = catalog.getWorkspaceByName("isolated_workspace"); assertThat(foundWorkspace.isIsolated(), is(true)); } finally { // remove the isolated workspace catalog.remove(workspace); } }
@Test public void testChangeDataStoreWorkspace() throws Exception { addDataStore(); WorkspaceInfo ws2 = catalog.getFactory().createWorkspace(); ws2.setName("newWorkspace"); catalog.add(ws2); ws2 = catalog.getWorkspaceByName(ws2.getName()); DataStoreInfo ds2 = catalog.getDataStoreByName(ds.getName()); ds2.setWorkspace(ws2); catalog.save(ds2); assertNull(catalog.getDataStoreByName(ws, ds2.getName())); assertNotNull(catalog.getDataStoreByName(ws2, ds2.getName())); }
@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()); }
/** * Helper method that will make sure that the namespace associated to the provided workspace has * the same isolation. * * <p>If the associated namespace doesn't exists nothing will be done. * * @param workspace a catalog workspace */ private void syncNamespaceIsolation(WorkspaceInfo workspace) { // get the namespace associated to the workspace, may be NULL NamespaceInfo namespace = catalog.getNamespaceByPrefix(workspace.getName()); if (namespace != null && workspace.isIsolated() != namespace.isIsolated()) { // update the namespace isolation namespace.setIsolated(workspace.isIsolated()); catalog.save(namespace); } }
@Test public void testAddWorkspace() throws Exception { File ws = new File(testData.getDataDirectoryRoot(), "workspaces/acme"); assertFalse(ws.exists()); WorkspaceInfo acme = catalog.getFactory().createWorkspace(); acme.setName("acme"); catalog.add(acme); assertTrue(ws.exists()); }
@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()); }