namespace.setPrefix((String) entry.getKey()); namespace.setURI((String) entry.getValue()); namespace.setIsolated(isolated); catalog.add(namespace); catalog.add(workspace); if (namespace.getURI().equals(namespaces.get(""))) { catalog.setDefaultNamespace(namespace); catalog.setDefaultWorkspace(workspace); + namespace.getPrefix() + "' (" + namespace.getURI() + ")"); LOGGER.info("Default namespace: '" + catalog.getDefaultNamespace().getPrefix() + "'"); } else { LOGGER.warning("No default namespace set.");
/** 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)); }
if (namespace.isIsolated() && !getCatalogCapabilities().supportsIsolatedWorkspaces()) { namespace.getPrefix(), namespace.getURI())); if (isNull(namespace.getPrefix())) { throw new NullPointerException("Namespace prefix must not be null"); if (namespace.getPrefix().equals(DEFAULT)) { throw new IllegalArgumentException( DEFAULT + " is a reserved keyword, can't be used as the namespace prefix"); NamespaceInfo existing = getNamespaceByPrefix(namespace.getPrefix()); if (existing != null && !existing.getId().equals(namespace.getId())) { throw new IllegalArgumentException( "Namespace with prefix '" + namespace.getPrefix() + "' already exists."); if (!namespace.isIsolated()) { existing = getNamespaceByURI(namespace.getURI()); if (existing != null && !existing.getId().equals(namespace.getId())) { throw new IllegalArgumentException( "Namespace with URI '" + namespace.getURI() + "' already exists."); if (isNull(namespace.getURI())) { throw new NullPointerException("Namespace uri must not be null"); new URI(namespace.getURI()); } catch (Exception e) { throw new IllegalArgumentException(
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 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; }
public void setDefaultNamespace(NamespaceInfo defaultNamespace) { if (defaultNamespace != null) { NamespaceInfo ns = getNamespaceByPrefix(defaultNamespace.getPrefix()); if (ns == null) { throw new IllegalArgumentException( "No such namespace: '" + defaultNamespace.getPrefix() + "'"); } else { defaultNamespace = ns; } } facade.setDefaultNamespace(defaultNamespace); }
/** * 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()); }
namespaces.add(ns); expect(ns.getId()).andReturn(nsId).anyTimes(); expect(ns.getName()).andReturn(name).anyTimes(); expect(ns.getPrefix()).andReturn(name).anyTimes(); expect(ns.getMetadata()).andReturn(new MetadataMap()).anyTimes(); expect(ns.getURI()).andReturn(uri).anyTimes(); .anyTimes(); ns.accept((CatalogVisitor) anyObject()); expectLastCall() .andAnswer(
} else { uri = ((NamespaceInfo) info).getURI(); if (newDefault != null) { final WorkspaceInfo ws = catalog .getWorkspaceByName(newDefault.getPrefix()); if (ws != null && !catalog.getDefaultWorkspace().equals(ws)) { catalog.setDefaultWorkspace(ws); final NamespaceInfo ns = catalog .getNamespaceByPrefix(newDefault.getName()); if (ns != null && !catalog.getDefaultNamespace().equals(ns)) { catalog.setDefaultNamespace(ns);
event.getNewValues().get(properties.indexOf("defaultNamespace")); if (newDefault != null) { WorkspaceInfo ws = catalog.getWorkspaceByName(newDefault.getPrefix()); if (ws != null && !catalog.getDefaultWorkspace().equals(ws)) { try { try { editing = true; ns.setPrefix(newName); catalog.save(ns); } finally { if (newDefault != null) { NamespaceInfo ns = catalog.getNamespaceByPrefix(newDefault.getName()); if (ns != null && !catalog.getDefaultNamespace().equals(ns)) { try { editing = true;
ns.setPrefix(name); ns.setURI(uri); ns.setIsolated(isolated); catalog.add(ns); } else { ns.setURI(uri); ns.setIsolated(isolated); catalog.save(ns);
/** * 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); } } }
public void remove(NamespaceInfo namespace) { if (!getResourcesByNamespace(namespace, ResourceInfo.class).isEmpty()) { throw new IllegalArgumentException("Unable to delete non-empty namespace."); } // TODO: remove synchronized block, need transactions synchronized (facade) { facade.remove(namespace); NamespaceInfo defaultNamespace = getDefaultNamespace(); if (namespace.equals(defaultNamespace) || defaultNamespace == null) { List<NamespaceInfo> namespaces = facade.getNamespaces(); defaultNamespace = null; if (!namespaces.isEmpty()) { defaultNamespace = namespaces.get(0); } setDefaultNamespace(defaultNamespace); if (defaultNamespace != null) { WorkspaceInfo defaultWorkspace = getWorkspaceByName(defaultNamespace.getPrefix()); if (defaultWorkspace != null) { setDefaultWorkspace(defaultWorkspace); } } } } removed(namespace); }
@PostMapping( consumes = { MediaType.TEXT_XML_VALUE, MediaType.APPLICATION_XML_VALUE, MediaTypeExtensions.TEXT_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE } ) @ResponseStatus(HttpStatus.CREATED) public ResponseEntity<String> namespacePost( @RequestBody NamespaceInfo namespace, UriComponentsBuilder builder) { catalog.add(namespace); String name = namespace.getName(); LOGGER.info("Added namespace " + name); // JD: we need to keep namespace and workspace in sync, so create a worksapce // if one does not already exists, we can remove this once we get to a point // where namespace is just an attribute on a layer, and not a containing element if (catalog.getWorkspaceByName(namespace.getPrefix()) == null) { WorkspaceInfo ws = catalog.getFactory().createWorkspace(); ws.setName(namespace.getPrefix()); ws.setIsolated(namespace.isIsolated()); catalog.add(ws); } // build the new path UriComponents uriComponents = getUriComponents(name, builder); HttpHeaders headers = new HttpHeaders(); headers.setLocation(uriComponents.toUri()); return new ResponseEntity<>(name, headers, HttpStatus.CREATED); }
@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); }