@Override public String getName() { if (resource == null) { return name; } return resource.getName(); }
/** * Returns true if the layer should be hidden, false otherwise * * <ol> * <li>has a request * <li>is a GetCapabilities request * <li>is not for a layer-specific virtual service * </ol> */ boolean checkCapabilitiesRequest(ResourceInfo resource) { Request request = Dispatcher.REQUEST.get(); if (request != null) { if ("GetCapabilities".equalsIgnoreCase(request.getRequest())) { String resourceContext = resource.getNamespace().getPrefix() + "/" + resource.getName(); return !resourceContext.equalsIgnoreCase(request.getContext()); } } return false; }
String findUniqueStyleName(ResourceInfo resource, WorkspaceInfo workspace) { String styleName = resource.getName(); StyleInfo style = catalog.getStyleByName(workspace, styleName); int i = 1; while (style != null) { styleName = resource.getName() + i; style = catalog.getStyleByName(workspace, styleName); i++; } return styleName; }
@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; }
/** Initializes basic resource info. */ private void initResourceInfo(ResourceInfo resInfo) throws Exception { // set the name if (resInfo.getNativeName() == null && resInfo.getName() != null) { resInfo.setNativeName(resInfo.getName()); } if (resInfo.getNativeName() != null && resInfo.getName() == null) { resInfo.setName(resInfo.getNativeName()); } }
public ValidationResult validate(ResourceInfo resource, boolean isNew) { if (isNull(resource.getName())) { throw new NullPointerException("Resource name must not be null"); ResourceInfo existing = getResourceByStore(store, resource.getName(), ResourceInfo.class); if (existing != null && !existing.getId().equals(resource.getId())) { String msg = "Resource named '" + resource.getName() + "' already exists in store: '" + store.getName() existing = getResourceByName(namespace, resource.getName(), ResourceInfo.class); if (existing != null && !existing.getId().equals(resource.getId())) { String msg = "Resource named '" + resource.getName() + "' already exists in namespace: '" + namespace.getPrefix()
private void renameResource(ResourceInfo r, String newName) throws IOException { LOGGER.fine("Renaming resource " + r.getName() + " to " + newName); Resource directory = dd.get(r); renameRes(directory, newName); }
public void add(ResourceInfo resource) { if (resource.getNamespace() == null) { // default to default namespace resource.setNamespace(getDefaultNamespace()); } if (resource.getNativeName() == null) { resource.setNativeName(resource.getName()); } ResourceInfo resolved = resolve(resource); validate(resolved, true); ResourceInfo added = facade.add(resolved); added(added); }
/** * 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; }
if (null == getResourceByName(ns, layer.getResource().getName(), ResourceInfo.class)) { throw new IllegalStateException( "Found no resource named "
public <T extends ResourceInfo> T getResourceByName( NamespaceInfo namespace, String name, Class<T> clazz) { T result; if (namespace == ANY_NAMESPACE) { result = resources.findFirst(clazz, r -> name.equals(r.getName())); } else { Name qname = new NameImpl(namespace != null ? namespace.getId() : null, name); result = resources.findByName(qname, clazz); } return wrapInModificationProxy(result, clazz); }
/** * Given a {@link FeatureTypeInfo} and a user, returns it back if the user can access it in * write mode, makes it read only if the user can access it in read only mode, returns null * otherwise */ protected <T extends ResourceInfo> T checkAccess( Authentication user, T info, MixedModeBehavior mixedModeBehavior) { // handle null case if (info == null) return null; // first off, handle the case where the user cannot even read the data WrapperPolicy policy = buildWrapperPolicy(user, info, info.getName(), mixedModeBehavior); // handle the modes that do not require wrapping if (policy.level == AccessLevel.HIDDEN) return null; else if (policy.level == AccessLevel.READ_WRITE && policy.getLimits() == null) return info; // otherwise we are in a mixed case where the user can read but not write, or // cannot read but is allowed by the operation mode to access the metadata return (T) SecuredObjects.secure(info, policy); }
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; }
/** * 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 <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); }
public LayerInfo buildLayer(ResourceInfo resource) { LayerInfo layer = catalog.getFactory().createLayer(); layer.setResource(resource); layer.setName(resource.getName()); layer.setEnabled(true); // setup the layer type if (layer.getResource() instanceof FeatureTypeInfo) { layer.setType(PublishedType.VECTOR); } else if (layer.getResource() instanceof CoverageInfo) { layer.setType(PublishedType.RASTER); } else if (layer.getResource() instanceof WMTSLayerInfo) { layer.setType(PublishedType.WMTS); } else if (layer.getResource() instanceof WMSLayerInfo) { layer.setType(PublishedType.WMS); } return layer; }
@Test public void testProxyBehaviour() throws Exception { testAddLayer(); // l = catalog.getLayerByName( "layerName"); LayerInfo l = catalog.getLayerByName(ft.getName()); assertTrue(l instanceof Proxy); ResourceInfo r = l.getResource(); assertTrue(r instanceof Proxy); String oldName = ft.getName(); r.setName("changed"); catalog.save(r); assertNull(catalog.getLayerByName(oldName)); l = catalog.getLayerByName(r.getName()); assertNotNull(l); assertEquals("changed", l.getResource().getName()); }
private LayerInfo buildLayer(QName resourceName) throws Exception { Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); StoreInfo store = cat.getDataStoreByName(resourceName.getPrefix()); cb.setStore(store); ResourceInfo ri = cb.buildFeatureType(toName(resourceName)); ri.setSRS("EPSG:4326"); cb.setupBounds(ri); LayerInfo layer = cat.getFactory().createLayer(); layer.setResource(ri); layer.setName(ri.getName()); layer.setEnabled(true); layer.setType(PublishedType.VECTOR); return layer; }
l = persister.load(in(out), LayerInfo.class); assertEquals(l.getResource().getName(), l.getName()); assertEquals(ft, l.getResource()); assertEquals(s, l.getDefaultStyle());