/** * Adds a given elem to the history of the given product. If the products metadata root * does not contain a history entry a new one will be created. * * @param product the product to add the history element. * @param elem the element to add to the products history. If <code>null</code> nothing will be added. */ public static void addElementToHistory(Product product, MetadataElement elem) { Guardian.assertNotNull("product", product); if (elem != null) { final String historyName = Product.HISTORY_ROOT_NAME; final MetadataElement metadataRoot = product.getMetadataRoot(); if (!metadataRoot.containsElement(historyName)) { metadataRoot.addElement(new MetadataElement(historyName)); } final MetadataElement historyElem; historyElem = metadataRoot.getElement(historyName); if (historyElem.containsElement(elem.getName())) { final MetadataElement previousElem = historyElem.getElement(elem.getName()); historyElem.removeElement(previousElem); elem.addElement(previousElem); } historyElem.addElement(elem); } }
private static void createTimeSeriesMetadataStructure(Product tsProduct) { if (!tsProduct.getMetadataRoot().containsElement(TIME_SERIES_ROOT_NAME)) { final MetadataElement timeSeriesRoot = new MetadataElement(TIME_SERIES_ROOT_NAME); final MetadataElement productListElement = new MetadataElement(PRODUCT_LOCATIONS); final MetadataElement sourceProductPathsElement = new MetadataElement(SOURCE_PRODUCT_PATHS); final MetadataElement variablesListElement = new MetadataElement(VARIABLES); timeSeriesRoot.addElement(productListElement); timeSeriesRoot.addElement(sourceProductPathsElement); timeSeriesRoot.addElement(variablesListElement); tsProduct.getMetadataRoot().addElement(timeSeriesRoot); } }
@Test public void testAvoidCopyMetadata() throws Exception { final Product sp = createTestProduct(100, 100); addMetadata(sp); final String[] bandNames = {"radiance_1", "radiance_3"}; SubsetOp op = new SubsetOp(); op.setSourceProduct(sp); op.setBandNames(bandNames); op.setCopyMetadata(false); assertSame(sp, op.getSourceProduct()); assertNotSame(bandNames, op.getBandNames()); Product tp = op.getTargetProduct(); assertEquals(2, tp.getNumBands()); assertNotNull(tp.getBand("radiance_1")); assertNull(tp.getBand("radiance_2")); assertNotNull(tp.getBand("radiance_3")); final MetadataElement root = tp.getMetadataRoot(); assertNotNull(root); assertFalse(root.containsElement("attribRoot")); assertFalse(root.containsElement("meta1")); assertFalse(root.containsElement("meta2")); }
assertNotNull(attribRoot); assertEquals("rootValue", attribRoot.getData().getElemString()); assertTrue(root.containsElement("meta1")); final MetadataAttribute attrib1 = root.getElement("meta1").getAttribute("attrib1"); assertNotNull(attrib1);