/** * Loads all namespaces from persistent storage that match the provided uri. * * @param uri The uri of the namespace. * @return The namespace, or <code>null</code> if no such namespace exists */ default List<NamespaceInfo> getNamespacesByURI(String uri) { return getNamespaces() .stream() .filter(namespace -> namespace.getURI().equals(uri)) .collect(Collectors.toList()); }
public boolean equals(Object obj) { if (obj == null) { return false; } if (!(obj instanceof NamespaceInfo)) { return false; } final NamespaceInfo other = (NamespaceInfo) obj; if (prefix == null) { if (other.getPrefix() != null) return false; } else if (!prefix.equals(other.getPrefix())) return false; if (uri == null) { if (other.getURI() != null) return false; } else if (!uri.equals(other.getURI())) return false; return true; } }
@Override public List<NamespaceInfo> getNamespacesByURI(String uri) { List<NamespaceInfo> found = namespaces.list( NamespaceInfo.class, namespaceInfo -> namespaceInfo.getURI().equals(uri)); return ModificationProxy.createList(found, NamespaceInfo.class); }
public NamespaceInfo getNamespaceByURI(String uri) { NamespaceInfo result = namespaces.findFirst(NamespaceInfo.class, ns -> uri.equals(ns.getURI())); return wrapInModificationProxy(result, NamespaceInfo.class); }
/** * If a local workspace is set (i.e. we are in the context of a virtual service) and if the URI * of the provided namespace matches the local workspace associate namespace URI, we return the * namespace associated with the current local workspace, otherwise NULL is returned. * * @param namespace the namespace we will try to match against the local workspace * @return the namespace associated with the local workspace if matched, otherwise NULL */ private NamespaceInfo tryMatchLocalNamespace(NamespaceInfo namespace) { WorkspaceInfo localWorkspace = getLocalWorkspace(); if (localWorkspace != null) { // get the namespace for the current local workspace NamespaceInfo localNamespace = facade.getNamespaceByPrefix(localWorkspace.getName()); if (localNamespace != null && Objects.equals(localNamespace.getURI(), namespace.getURI())) { // the URIs match, let's return the local workspace namespace return localNamespace; } } // the provided namespace doesn't match the local workspace namespace return null; }
@Override public NamespaceInfo getNamespaceByURI(String uri) { NamespaceInfo localNamespace = getLocalNamespace(); if (localNamespace != null && Objects.equals(localNamespace.getURI(), uri)) { // local workspace namespace URI is equal to the provided URI return localNamespace; } // let's see if there is any global namespace matching the provided uri for (NamespaceInfo namespace : facade.getNamespacesByURI(uri)) { if (!namespace.isIsolated()) { // we found a global namespace return namespace; } } // no global namespace found return null; }
@Override public DataAccess answer() throws Throwable { return new PropertyDataStore(propDir, ns.getURI()); } })
/** @see org.geoserver.catalog.ResourceInfo#getQualifiedName() */ public Name getQualifiedName() { return new NameImpl(getNamespace().getURI(), getName()); }
/** @see org.geoserver.catalog.ResourceInfo#getQualifiedNativeName() */ public Name getQualifiedNativeName() { return new NameImpl(getNamespace().getURI(), getNativeName()); }
@Override public Object visit(Id filter, Object data) { for (Identifier id : filter.getIdentifiers()) { if (id instanceof FeatureId) { FeatureId fid = (FeatureId) id; if (fid.getID() != null) { String[] split = fid.getID().split("\\."); if (split.length > 1) { ResourceInfo r = catalog.getResourceByName(split[0], ResourceInfo.class); if (r != null) { typeNames.add(new QName(r.getNamespace().getURI(), r.getName())); } } } } } return data; }
/** * Get the QName for a layer specified by the layername that would be used in a request. * * @param typename the layer name for the type */ protected QName resolveLayerName(String typename) { int i = typename.indexOf(":"); String prefix = typename.substring(0, i); String name = typename.substring(i + 1); NamespaceInfo ns = getCatalog().getNamespaceByPrefix(prefix); QName qname = new QName(ns.getURI(), name, ns.getPrefix()); return qname; }
/** * Get the QName for a layer specified by the layername that would be used in a request. * * @param typename the layer name for the type */ protected QName resolveLayerName(String typename) { int i = typename.indexOf(":"); String prefix = typename.substring(0, i); String name = typename.substring(i + 1); NamespaceInfo ns = getCatalog().getNamespaceByPrefix(prefix); QName qname = new QName(ns.getURI(), name, ns.getPrefix()); return qname; }
/** Takes care of keeping the stores namespace URI in synch with namespace changes */ public void handlePostModifyEvent(CatalogPostModifyEvent event) { if (event.getSource() instanceof NamespaceInfo) { NamespaceInfo ns = (NamespaceInfo) event.getSource(); String namespaceURI = ns.getURI(); WorkspaceInfo ws = catalog.getWorkspaceByName(ns.getPrefix()); if (ws != null) { List<DataStoreInfo> stores = catalog.getDataStoresByWorkspace(ws); if (stores.size() > 0) { for (DataStoreInfo store : stores) { String oldURI = (String) store.getConnectionParameters().get("namespace"); if (oldURI != null && !namespaceURI.equals(oldURI)) { store.getConnectionParameters().put("namespace", namespaceURI); catalog.save(store); } } } } } // synchronize isolation if needed syncIsolation(event.getSource()); }
/** Helper method that checks that the provided namespace has the expected content. */ protected void checkNamespace( NamespaceInfo namespace, String expectedPrefix, String expectedNamespaceUri, boolean expectedIsolation) { assertThat(namespace, notNullValue()); assertThat(namespace.getPrefix(), is(expectedPrefix)); assertThat(namespace.getName(), is(expectedPrefix)); assertThat(namespace.getURI(), is(expectedNamespaceUri)); assertThat(namespace.isIsolated(), is(expectedIsolation)); }
@Override public LayerInfo getLayerByName(String name) { if (LocalWorkspace.get() != null) { String wsName = LocalWorkspace.get().getName(); // prefix the unqualified name if (name.contains(":")) { // name already prefixed, ensure it is prefixed with the correct one if (name.startsWith(wsName + ":")) { // good to go, just pass call through return wrap(super.getLayerByName(name)); } } // prefix it explicitly NamespaceInfo ns = super.getNamespaceByPrefix(LocalWorkspace.get().getName()); LayerInfo layer = super.getLayerByName(new NameImpl(ns.getURI(), name)); return wrap(layer); } return super.getLayerByName(name); }
@Test public void testGetNamespaceByURI() { catalog.add(ns); NamespaceInfo ns2 = catalog.getNamespaceByURI(ns.getURI()); assertNotNull(ns2); assertFalse(ns == ns2); assertEquals(ns, ns2); }
@Test public void testLookupFreshlyAdded() { Catalog catalog = getCatalog(); CatalogBuilder cb = new CatalogBuilder(getCatalog()); String nsURI = catalog.getDefaultNamespace().getURI(); URL buildings = MockData.class.getResource("Buildings.properties"); File testData = URLs.urlToFile(buildings).getParentFile(); DataStoreInfo storeInfo = cb.buildDataStore("freshOffTheBoat"); storeInfo.getConnectionParameters().put("directory", testData); storeInfo.getConnectionParameters().put("namespace", nsURI); catalog.save(storeInfo); CatalogRepository repository = getCatalog().getResourcePool().getRepository(); DataStore store = repository.dataStore(new NameImpl("freshOffTheBoat")); assertNotNull(store); } }
@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 testWorkspaceRemoveAndReadd() { // remove all workspaces Catalog catalog = getCatalog(); NamespaceInfo defaultNamespace = catalog.getDefaultNamespace(); WorkspaceInfo defaultWs = catalog.getDefaultWorkspace(); List<WorkspaceInfo> workspaces = catalog.getWorkspaces(); CascadeDeleteVisitor visitor = new CascadeDeleteVisitor(catalog); for (WorkspaceInfo ws : workspaces) { visitor.visit(ws); } assertEquals(0, catalog.getWorkspaces().size()); assertEquals(0, catalog.getNamespaces().size()); // add back one (this would NPE) catalog.add(defaultNamespace); catalog.add(defaultWs); assertEquals(1, catalog.getWorkspaces().size()); assertEquals(1, catalog.getNamespaces().size()); // get back by name (this would NPE too) assertNotNull(catalog.getNamespaceByURI(defaultNamespace.getURI())); }
@Test public void testGetFeatureTypeByName() { addFeatureType(); FeatureTypeInfo ft2 = catalog.getFeatureTypeByName(ft.getName()); assertNotNull(ft2); assertFalse(ft == ft2); assertEquals(ft, ft2); NamespaceInfo ns2 = catalog.getFactory().createNamespace(); ns2.setPrefix("ns2Prefix"); ns2.setURI("ns2URI"); catalog.add(ns2); FeatureTypeInfo ft3 = catalog.getFactory().createFeatureType(); ft3.setName("ft3Name"); ft3.setStore(ds); ft3.setNamespace(ns2); catalog.add(ft3); FeatureTypeInfo ft4 = catalog.getFeatureTypeByName(ns2.getPrefix(), ft3.getName()); assertNotNull(ft4); assertFalse(ft4 == ft3); assertEquals(ft3, ft4); ft4 = catalog.getFeatureTypeByName(ns2.getURI(), ft3.getName()); assertNotNull(ft4); assertFalse(ft4 == ft3); assertEquals(ft3, ft4); }