private void checkLayerGroupResourceIsInWorkspace(LayerInfo layer, WorkspaceInfo ws) { if (layer == null) return; ResourceInfo r = layer.getResource(); if (r.getStore().getWorkspace() != null && !ws.equals(r.getStore().getWorkspace())) { throw new IllegalArgumentException( "Layer group within a workspace (" + ws.getName() + ") can not contain resources from other workspace: " + r.getStore().getWorkspace().getName()); } }
public <T extends ResourceInfo> List<T> getResourcesByStore(StoreInfo store, Class<T> clazz) { List<T> matches = resources.list(clazz, r -> store.equals(r.getStore())); return ModificationProxy.createList(matches, clazz); }
/** * Retrieve a resource in the the configuration directory of a Resource. An empty path will * retrieve the directory itself. * * @param ri The store * @return A {@link Resource} */ public @Nonnull Resource get(ResourceInfo ri, String... path) { Resource r = get(ri.getStore(), ri.getName(), Paths.path(path)); assert r != null; return r; }
/** * Checks if the provided resource is visible in the current context. * * @param resource the resource to check, may be NULL * @return the resource if visible, otherwise NULL */ private <T extends ResourceInfo> T enforceResourceIsolation(T resource) { if (resource == null) { // nothing to do, the resource is already NULL return null; } // get the resource store StoreInfo store = resource.getStore(); if (store == null) { // since we can't check if the store is visible we let it go return resource; } WorkspaceInfo workspace = store.getWorkspace(); // check if the resource store workspace is visible in this context return canSeeWorkspace(workspace) ? resource : null; }
String findUniqueStyleName(ResourceInfo resource) { String styleName = resource.getStore().getWorkspace().getName() + "_" + resource.getName(); StyleInfo style = catalog.getStyleByName(styleName); int i = 1; while (style != null) { styleName = resource.getStore().getWorkspace().getName() + "_" + resource.getName() + i; style = catalog.getStyleByName(styleName); i++; } return styleName; }
@Override public String prefixedName() { return this.getResource().getStore().getWorkspace().getName() + ":" + getName(); }
/** * Checks if the provided layer is visible in the current context. * * @param layer the layer to check, may be NULL * @return the layer if visible, otherwise NULL */ private <T extends LayerInfo> T enforceLayerIsolation(T layer) { if (layer == null) { // nothing to do, the layer is already NULL return null; } ResourceInfo resource = layer.getResource(); if (resource == null) { // this should not happen, there is not much we can do return layer; } StoreInfo store = resource.getStore(); if (store == null) { // since we can't check if the store is visible we let it go return layer; } WorkspaceInfo workspace = store.getWorkspace(); // check if the layer resource store workspace is visible in this context return canSeeWorkspace(workspace) ? layer : null; }
@Override public void run() { for (int i = 0; i < getStackOverflowCount(); ++i) { target.setStore(source.getStore()); } } };
public <T extends ResourceInfo> T getResourceByStore( StoreInfo store, String name, Class<T> clazz) { T resource = null; NamespaceInfo ns = null; if (store.getWorkspace() != null && store.getWorkspace().getName() != null && (ns = getNamespaceByPrefix(store.getWorkspace().getName())) != null) { resource = resources.findByName(new NameImpl(ns.getId(), name), clazz); if (resource != null && !(store.equals(resource.getStore()))) { return null; } } else { // should not happen, but some broken test code sets up namespaces without equivalent // workspaces // or stores without workspaces resource = resources.findFirst( clazz, r -> name.equals(r.getName()) && store.equals(r.getStore())); } return wrapInModificationProxy(resource, clazz); }
/** * Finds the directory for the resource assuming a 1.x style data directory. * * <p>Something like: * * <pre> * featureTypes/states_shapefile_states * coverages/sfdem_dem * </pre> * * @param resource The resource. * @return The directory for the resource, or null if it could not be found. */ public File findLegacyResourceDir(ResourceInfo resource) throws IOException { StoreInfo store = resource.getStore(); String dirname = store.getName() + "_" + resource.getName(); File dir = null; if (resource instanceof FeatureTypeInfo) { dir = resourceLoader.find("featureTypes", dirname); } else if (resource instanceof CoverageInfo) { dir = resourceLoader.find("coverages", dirname); } return dir != null ? dir : null; }
public boolean hideResource(ResourceInfo resource) { if (LocalPublished.get() != null) { for (LayerInfo l : resource.getCatalog().getLayers(resource)) { if (hideLayer(l)) { return true; } } } return hideWorkspace(resource.getStore().getWorkspace()); }
private int countStores(LayerGroupInfo lg, List<StoreInfo> stores) { List<PublishedInfo> layers = lg.getLayers(); int size = 0; for (PublishedInfo l : layers) { if (l instanceof LayerInfo) { if (stores.contains(((LayerInfo) l).getResource().getStore())) { size++; } } else if (l instanceof LayerGroupInfo) { if (countStores((LayerGroupInfo) l, stores) == ((LayerGroupInfo) l).getLayers().size()) { size++; } } } return size; }
throw new NullPointerException("Resource native name must not be null"); if (resource.getStore() == null) { throw new IllegalArgumentException("Resource must be part of a store"); StoreInfo store = resource.getStore(); ResourceInfo existing = getResourceByStore(store, resource.getName(), ResourceInfo.class); if (existing != null && !existing.getId().equals(resource.getId())) {
getSecuredDecoratorClass().isAssignableFrom(secured.getClass())); final StoreInfo securedStore = secured.getStore(); assertTrue( "Secured ResourceInfo should return a Secured StoreInfo", SecureCatalogImpl.unwrap(secured.getStore()); } catch (Throwable t) { t.printStackTrace(new PrintWriter(sw, true));
final String resourceName = resource.getName(); try { workspace = resource.getStore().getWorkspace().getName(); } catch (Exception e) { LOGGER.log(
expect(r.getTitle()).andReturn(name).anyTimes(); expect(r.getAbstract()).andReturn("abstract about " + name).anyTimes(); expect(r.getStore()).andReturn(s).anyTimes(); expect(r.getNamespace()).andReturn(ns).anyTimes();
@Test public void testCascadeStore() { Catalog catalog = getCatalog(); DataStoreInfo store = (DataStoreInfo) catalog.getLayerByName(getLayerId(LAKES)).getResource().getStore(); new CascadeDeleteVisitor(catalog).visit(store); // that store actually holds all layers, so check we got empty assertEquals(0, catalog.count(LayerInfo.class, Filter.INCLUDE)); assertEquals(0, catalog.count(ResourceInfo.class, Filter.INCLUDE)); assertEquals(0, catalog.count(StoreInfo.class, Filter.INCLUDE)); List<LayerGroupInfo> groups = catalog.getLayerGroups(); assertEquals(0, catalog.count(LayerGroupInfo.class, Filter.INCLUDE)); }