@Test public void testMissingNullValuesInCoverageDimensions() throws IOException { CoverageInfo ci = getCatalog().getCoverageByName(getLayerId(MockData.TASMANIA_DEM)); List<CoverageDimensionInfo> dimensions = ci.getDimensions(); // legacy layers have no null value list dimensions.get(0).getNullValues().clear(); getCatalog().save(ci); // and now go back and ask for the reader ci = getCatalog().getCoverageByName(getLayerId(MockData.TASMANIA_DEM)); GridCoverageReader reader = ci.getGridCoverageReader(null, null); GridCoverage2D gc = null; try { // check that we maintain the native info if we don't have any gc = (GridCoverage2D) reader.read(null); assertEquals(-9999d, (Double) gc.getProperty("GC_NODATA"), 0d); } finally { if (gc != null) { RenderedImage ri = gc.getRenderedImage(); if (gc instanceof GridCoverage2D) { ((GridCoverage2D) gc).dispose(true); } if (ri instanceof PlanarImage) { ImageUtilities.disposePlanarImageChain((PlanarImage) ri); } } } }
@Test public void testDropCoverageStore() throws Exception { // build the store Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); CoverageStoreInfo store = cb.buildCoverageStore("dem"); store.setURL(MockData.class.getResource("tazdem.tiff").toExternalForm()); store.setType("GeoTIFF"); cat.add(store); // build the coverage cb.setStore(store); CoverageInfo ci = cb.buildCoverage(); cat.add(ci); // build the layer LayerInfo layer = cb.buildLayer(ci); cat.add(layer); // grab a reader just to inizialize the code ci.getGridCoverage(null, null); ci.getGridCoverageReader(null, GeoTools.getDefaultHints()); // now drop the store CascadeDeleteVisitor visitor = new CascadeDeleteVisitor(cat); visitor.visit(store); // and reload (GEOS-4782 -> BOOM!) getGeoServer().reload(); }
@Test public void testPreserveStructuredReader() throws IOException { // we have to make sure time ranges native name is set to trigger the bug in question CoverageInfo ci = getCatalog().getCoverageByName(getLayerId(TIMERANGES)); assertTrue(ci.getGridCoverageReader(null, null) instanceof StructuredGridCoverage2DReader); String name = ci.getGridCoverageReader(null, null).getGridCoverageNames()[0]; ci.setNativeCoverageName(name); getCatalog().save(ci); ci = getCatalog().getCoverageByName(getLayerId(TIMERANGES)); assertTrue(ci.getGridCoverageReader(null, null) instanceof StructuredGridCoverage2DReader); }
public MockCatalogBuilder coverage(QName qName, String fileName, String srs, Class scope) { scope = scope != null ? scope : getClass(); String cId = newId(); final CoverageStoreInfo cs = coverageStores.peekLast(); NamespaceInfo ns = namespaces.peekLast(); final String name = qName.getLocalPart(); File dir = new File(dataDirRoot, name); dir.mkdir(); try { IOUtils.copy(scope.getResourceAsStream(fileName), new File(dir, fileName)); } catch (IOException e) { throw new RuntimeException(e); } // initialize the mock by actually building a real one first CatalogBuilder cb = new CatalogBuilder(new CatalogImpl()); cb.setStore(cs); GridCoverage2DReader reader = cs.getFormat().getReader(cs.getURL()); if (reader == null) { throw new RuntimeException("No reader for " + cs.getURL()); } CoverageInfo real = null; try { real = cb.buildCoverage(reader, null); } catch (Exception e) { throw new RuntimeException(e); } final CoverageInfo c = createNiceMock(CoverageInfo.class); coverages.add(c); final List<CoverageInfo> coverageList = coverages; if (srs == null) { srs = real.getSRS(); } initResource( c, CoverageInfo.class, cId, name, cs, ns, srs, real.getProjectionPolicy(), real.getNativeBoundingBox(), real.getLatLonBoundingBox()); expect(c.getDefaultInterpolationMethod()) .andReturn(real.getDefaultInterpolationMethod()) .anyTimes(); expect(c.getDimensions()).andReturn(real.getDimensions()).anyTimes(); expect(c.getGrid()).andReturn(real.getGrid()).anyTimes(); expect(c.getInterpolationMethods()).andReturn(real.getInterpolationMethods()).anyTimes(); expect(c.getRequestSRS()).andReturn(real.getRequestSRS()).anyTimes(); expect(c.getResponseSRS()).andReturn(real.getResponseSRS()).anyTimes(); try { expect(c.getGridCoverageReader(null, null)).andReturn(reader).anyTimes(); } catch (IOException e) { } expect(catalog.getCoverageByName(or(eq(name), eq(ns.getPrefix() + ":" + name)))) .andReturn(c) .anyTimes(); expect( catalog.getCoverageByName( or(eq(new NameImpl(ns.getPrefix(), name)), eq(new NameImpl(ns.getURI(), name))))) .andReturn(c) .anyTimes(); expect(catalog.getCoverageByName(ns, name)).andReturn(c).anyTimes(); expect(catalog.getCoverageByName(ns.getPrefix(), name)).andReturn(c).anyTimes(); // expect(catalog.getFeatureTypeByName(or(eq(ns.getPrefix()), eq(ns.getURI())), name)) // .andReturn(ft).anyTimes(); // expect(catalog.getCoverageByStore(cs, name)).andReturn(c).anyTimes(); expect(catalog.getCoveragesByStore(cs)).andReturn(coverageList).anyTimes(); expect(catalog.getCoverageByCoverageStore(cs, name)).andReturn(c).anyTimes(); c.accept((CatalogVisitor) anyObject()); expectLastCall() .andAnswer( new VisitAnswer() { @Override protected void doVisit(CatalogVisitor visitor) { visitor.visit(c); } }) .anyTimes(); callback.onResource(name, c, cs, this); replay(c, createLayer(c, name, ns)); return this; }
public ExtendCoverageExpr(Node node, XmlQuery xq) throws WCPSException { log.trace(node.getNodeName()); Node child; String nodeName; axisList = new ArrayList<DimensionIntervalElement>(); child = node.getFirstChild(); while (child != null) { nodeName = child.getNodeName(); if (nodeName.equals("#" + WCPSConstants.MSG_TEXT)) { child = child.getNextSibling(); continue; } try { coverageExprType = new CoverageExpr(child, xq); coverageInfo = coverageExprType.getCoverageInfo(); super.children.add(coverageExprType); child = child.getNextSibling(); continue; } catch (WCPSException e) { } try { // Start a new axis and save it elem = new DimensionIntervalElement(child, xq, coverageInfo); log.trace(" " + WCPSConstants.MSG_ADD_NEW_AXIS + ": " + elem.getAxisName()); axisList.add(elem); super.children.add(elem); child = elem.getNextNode(); continue; } catch (WCPSException e) { log.error(WCPSConstants.ERRTXT_THIS_WAS_NO_DIM + ": " + child.getNodeName()); } // else unknown element throw new WCPSException( WCPSConstants.ERRTXT_UNKNOWN_NODE_EXTENDCOVERAGE + child.getNodeName()); } dims = coverageInfo.getNumDimensions(); log.trace(" " + WCPSConstants.MSG_NUMBER_OF_DIMENSIONS + ": " + dims); dim = new String[dims]; for (int j = 0; j < dims; ++j) { dim[j] = "*:*"; } Iterator<DimensionIntervalElement> i = axisList.iterator(); DimensionIntervalElement axis; int axisId; int axisLo, axisHi; int order = 0; while (i.hasNext()) { axis = i.next(); axisId = coverageInfo.getDomainIndexByName(axis.getAxisName()); log.trace(" " + WCPSConstants.MSG_AXIS + " " + WCPSConstants.MSG_ID + ": " + axisId); log.trace( " " + WCPSConstants.MSG_AXIS + " " + WCPSConstants.MSG_NAME + ": " + axis.getAxisName()); log.trace(" " + WCPSConstants.MSG_AXIS + " " + WCPSConstants.MSG_COORDS + ": "); axisLo = Integer.parseInt(axis.getLowCoord()); axisHi = Integer.parseInt(axis.getHighCoord()); dim[axisId] = axisLo + ":" + axisHi; coverageInfo.setCellDimension( axisId, new CellDomainElement( BigInteger.valueOf(axisLo), BigInteger.valueOf(axisHi), axis.getAxisName(), order)); order += 1; } }
public CoverageExpr(Node node, XmlQuery xq) throws WCPSException, SecoreException { while ((node != null) && node.getNodeName().equals("#" + WcpsConstants.MSG_TEXT)) { node = node.getNextSibling(); } if (node == null) { throw new WCPSException("CoverageExprType parsing error."); } String nodeName = node.getNodeName(); log.trace(nodeName); simpleCoverage = false; if (nodeName.equals(WcpsConstants.MSG_COVERAGE)) { simpleCoverage = true; childInfo = node.getFirstChild().getNodeValue(); if (!xq.isIteratorDefined(childInfo)) { throw new WCPSException(WcpsConstants.MSG_ITERATOR + " " + childInfo + " not defined"); } Iterator<String> coverages = xq.getCoverages(childInfo); try { info = new CoverageInfo(xq.getMetadataSource().read(coverages.next())); while (coverages.hasNext()) { // Check if all the coverages are compatible CoverageInfo tmp = new CoverageInfo(xq.getMetadataSource().read(coverages.next())); if (!tmp.isCompatible(info)) { throw new WCPSException("Incompatible coverages within the same iterator."); } } } catch (Exception ex) { throw new WCPSException(ex.getMessage(), ex); } log.trace("Found simple coverage definition: " + childInfo + ", " + info.toString()); } else if (nodeName.equals(WcpsConstants.MSG_CRS_TRANSFORM)) { // TODO: implement CrsTransform class child = new CrsTransformCoverageExpr(node, xq); } else if (nodeName.equals(WcpsConstants.MSG_SCALE)) { child = new ScaleCoverageExpr(node, xq); } else if (nodeName.equals(WcpsConstants.MSG_CONSTRUCT)) { child = new ConstructCoverageExpr(node.getFirstChild(), xq); } else if (nodeName.equals(WcpsConstants.MSG_CONST)) { child = new ConstantCoverageExpr(node.getFirstChild(), xq); } else if (nodeName.equals(WcpsConstants.MSG_SWITCH)) { child = new SwitchExpr(node, xq); } // else if (nodeName.equals("variableRef")) // { // child = new VariableReference(node, xq); // } else { // Try one of the groups child = null; String firstMessage = ""; Node childNode = node; while ((childNode != null) && childNode.getNodeName().equals("#" + WcpsConstants.MSG_TEXT)) { childNode = childNode.getNextSibling(); } String n = childNode.getNodeName(); // TODO: not implemented // if (child == null) { // try { // child = new SetMetadataCoverageExpr(node, xq); // log.trace(" " + WcpsConstants.MSG_MATCHED_SET_METADATA); // } catch (WCPSException e) { // child = null; // exMessage = e.getMessage(); // firstMessage = exMessage; // } // } if (child == null) { if (n.equals(WcpsConstants.MSG_RANGE_CONSTRUCTOR) || UnaryOperationCoverageExpr.NODE_NAMES.contains(n) || BinaryOperationCoverageExpr.NODE_NAMES.contains(nodeName)) { try { child = new InducedOperationCoverageExpr(node, xq); log.trace("Matched induced coverage expression operation."); } catch (WCPSException e) { child = null; if (e.getMessage().equals("Method not implemented")) { throw e; } } } } if (child == null) { if (SubsetOperationCoverageExpr.NODE_NAMES.contains(n)) { try { child = new SubsetOperationCoverageExpr(node, xq); log.trace("Matched subset operation."); } catch (WCPSException e) { if (e.getExceptionCode().equals(ExceptionCode.MissingCRS) || e.getExceptionCode().equals(ExceptionCode.InvalidSubsetting)) { throw (e); } child = null; exMessage = exMessage.equals(firstMessage) ? e.getMessage() : exMessage; } } } if (child == null) { try { child = new ScalarExpr(node, xq); this.scalarExpr = true; log.trace("Matched scalar expression."); } catch (WCPSException e) { child = null; exMessage = exMessage.equals(firstMessage) ? e.getMessage() : exMessage; } } } if (!simpleCoverage && (child == null)) { throw new WCPSException( "Invalid coverage Expression, next node: " + node.getNodeName() + " - " + exMessage); } if (info == null) { info = new CoverageInfo(((ICoverageInfo) child).getCoverageInfo()); } if (!(child == null)) { // Keep child for XML tree crawling super.children.add(child); } // Fetch slices, so that we know which axes should be discarded from the computation slices = MiscUtil.childrenOfType(this, SliceCoverageExpr.class); }
@Test public void modificationProxySerializeTest() throws Exception { Catalog catalog = getCatalog(); // workspace WorkspaceInfo ws = catalog.getWorkspaceByName(MockData.CITE_PREFIX); WorkspaceInfo ws2 = serialize(ws); assertSame(ModificationProxy.unwrap(ws), ModificationProxy.unwrap(ws2)); // namespace NamespaceInfo ns = catalog.getNamespaceByPrefix(MockData.CITE_PREFIX); NamespaceInfo ns2 = serialize(ns); assertSame(ModificationProxy.unwrap(ns), ModificationProxy.unwrap(ns2)); // data store and related objects DataStoreInfo ds = catalog.getDataStoreByName(MockData.CITE_PREFIX); DataStoreInfo ds2 = serialize(ds); assertSame(ModificationProxy.unwrap(ds), ModificationProxy.unwrap(ds2)); assertSame( ModificationProxy.unwrap(ds.getWorkspace()), ModificationProxy.unwrap(ds2.getWorkspace())); // coverage store and related objects CoverageStoreInfo cs = catalog.getCoverageStoreByName(MockData.TASMANIA_DEM.getLocalPart()); CoverageStoreInfo cs2 = serialize(cs); assertSame(ModificationProxy.unwrap(cs), ModificationProxy.unwrap(cs2)); assertSame( ModificationProxy.unwrap(cs.getWorkspace()), ModificationProxy.unwrap(cs2.getWorkspace())); // feature type and related objects FeatureTypeInfo ft = catalog.getFeatureTypeByName(getLayerId(MockData.BRIDGES)); FeatureTypeInfo ft2 = serialize(ft); assertSame(ModificationProxy.unwrap(ft), ModificationProxy.unwrap(ft2)); assertSame(ModificationProxy.unwrap(ft.getStore()), ModificationProxy.unwrap(ft2.getStore())); // coverage and related objects CoverageInfo ci = catalog.getCoverageByName(getLayerId(MockData.TASMANIA_DEM)); CoverageInfo ci2 = serialize(ci); assertSame(ModificationProxy.unwrap(ci), ModificationProxy.unwrap(ci2)); assertSame(ModificationProxy.unwrap(ci.getStore()), ModificationProxy.unwrap(ci.getStore())); // style StyleInfo streamsStyle = catalog.getStyleByName("Streams"); StyleInfo si2 = serialize(streamsStyle); assertSame(ModificationProxy.unwrap(streamsStyle), ModificationProxy.unwrap(si2)); // layer and related objects LayerInfo li = catalog.getLayerByName(getLayerId(MockData.BRIDGES)); // ... let's add an extra style li.getStyles().add(streamsStyle); catalog.save(li); LayerInfo li2 = serialize(li); assertSame(ModificationProxy.unwrap(li), ModificationProxy.unwrap(li2)); assertSame( ModificationProxy.unwrap(li.getResource()), ModificationProxy.unwrap(li2.getResource())); assertSame( ModificationProxy.unwrap(li.getDefaultStyle()), ModificationProxy.unwrap(li2.getDefaultStyle())); assertSame( ModificationProxy.unwrap(li.getStyles().iterator().next()), ModificationProxy.unwrap(li2.getStyles().iterator().next())); // try a group layer CatalogBuilder cb = new CatalogBuilder(catalog); LayerGroupInfo lg = catalog.getFactory().createLayerGroup(); lg.getLayers().add(catalog.getLayerByName(getLayerId(MockData.ROAD_SEGMENTS))); lg.getLayers().add(catalog.getLayerByName(getLayerId(MockData.PONDS))); cb.calculateLayerGroupBounds(lg); lg.setName("test-lg"); catalog.add(lg); // ... make sure we get a proxy lg = catalog.getLayerGroupByName("test-lg"); if (lg instanceof SecuredLayerGroupInfo) { lg = ((SecuredLayerGroupInfo) lg).unwrap(LayerGroupInfo.class); } LayerGroupInfo lg2 = serialize(lg); assertSame(ModificationProxy.unwrap(lg), ModificationProxy.unwrap(lg2)); assertSame( ModificationProxy.unwrap(lg.getLayers().get(0)), ModificationProxy.unwrap(lg2.getLayers().get(0))); assertSame( ModificationProxy.unwrap(lg.getLayers().get(1)), ModificationProxy.unwrap(lg2.getLayers().get(1))); // now check a half modified proxy LayerInfo lim = catalog.getLayerByName(getLayerId(MockData.BRIDGES)); // ... let's add an extra style lim.setDefaultStyle(streamsStyle); lim.getStyles().add(streamsStyle); // clone and check LayerInfo lim2 = serialize(lim); assertSame( ModificationProxy.unwrap(lim.getDefaultStyle()), ModificationProxy.unwrap(lim2.getDefaultStyle())); assertSame( ModificationProxy.unwrap(lim.getStyles().iterator().next()), ModificationProxy.unwrap(lim2.getStyles().iterator().next())); // mess a bit with the metadata map too String key = "workspaceKey"; lim.getMetadata().put(key, ws); LayerInfo lim3 = serialize(lim); assertSame(ModificationProxy.unwrap(lim), ModificationProxy.unwrap(lim3)); assertSame( ModificationProxy.unwrap(lim.getMetadata().get(key)), ModificationProxy.unwrap(lim3.getMetadata().get(key))); }