LayerInfo createLayer(ResourceInfo r, String name, NamespaceInfo ns) { String lId = newId(); StyleInfo s = styles.peekLast(); final LayerInfo l = createNiceMock(LayerInfo.class); layers.add(l); expect(l.getId()).andReturn(lId).anyTimes(); expect(l.getName()).andReturn(name).anyTimes(); expect(l.getType()).andReturn(LayerInfo.Type.VECTOR).anyTimes(); expect(l.getResource()).andReturn(r).anyTimes(); expect(l.getDefaultStyle()).andReturn(s).anyTimes(); expect(l.isEnabled()).andReturn(true).anyTimes(); expect(l.isAdvertised()).andReturn(true).anyTimes(); expect(catalog.getLayer(lId)).andReturn(l).anyTimes(); expect(catalog.getLayerByName(name)).andReturn(l).anyTimes(); expect(catalog.getLayerByName(ns.getPrefix() + ":" + name)).andReturn(l).anyTimes(); expect(catalog.getLayerByName(new NameImpl(ns.getPrefix(), name))).andReturn(l).anyTimes(); expect(catalog.getLayerByName(new NameImpl(ns.getURI(), name))).andReturn(l).anyTimes(); expect(catalog.getLayers(r)).andReturn(Arrays.asList(l)).anyTimes(); l.accept((CatalogVisitor) anyObject()); expectLastCall() .andAnswer( new VisitAnswer() { @Override protected void doVisit(CatalogVisitor visitor) { visitor.visit(l); } }) .anyTimes(); callback.onLayer(name, l, this); return l; }
public void validate(LayerInfo lyr, boolean isNew) { if (lyr.isEnabled() == false) { // short-circuit - for disabled layers we don't need to validate // anything because it won't cause service exceptions for anyone return; } if (lyr.getResource() == null || (hasGeometry(lyr) && (lyr.getResource().getSRS() == null || lyr.getResource().getLatLonBoundingBox() == null))) throw new RuntimeException("Layer's resource is not fully configured"); // Resource-dependent checks if (lyr.getType() == PublishedType.RASTER) { if (!(lyr.getResource() instanceof CoverageInfo)) throw new RuntimeException("Layer with type RASTER doesn't have a coverage associated"); CoverageInfo cvinfo = (CoverageInfo) lyr.getResource(); try { cvinfo .getCatalog() .getResourcePool() .getGridCoverageReader(cvinfo, GeoTools.getDefaultHints()); } catch (Throwable t) { throw new RuntimeException("Couldn't connect to raster layer's resource"); } } else if (lyr.getType() == PublishedType.VECTOR) { if (!(lyr.getResource() instanceof FeatureTypeInfo)) throw new RuntimeException("Layer with type VECTOR doesn't have a featuretype associated"); FeatureTypeInfo ftinfo = (FeatureTypeInfo) lyr.getResource(); } else throw new RuntimeException("Layer is neither RASTER nor VECTOR type"); // Style-dependent checks if (hasGeometry(lyr) && (lyr.getDefaultStyle() == null || lyr.getStyles().contains(null))) throw new RuntimeException("Layer has null styles!"); }