private void addInputProductPathsToMetadata(Product product) { final MetadataElement productsElement = new MetadataElement("Input products"); final String[] absoluteInputProductPaths = getAbsoluteInputProductPaths(); for (int i = 0; i < absoluteInputProductPaths.length; i++) { String inputProductAbsPath = absoluteInputProductPaths[i]; final ProductData pathData = ProductData.createInstance(inputProductAbsPath); final MetadataAttribute pathAttribute = new MetadataAttribute("product_" + i, pathData, true); productsElement.addAttribute(pathAttribute); } product.getMetadataRoot().addElement(productsElement); }
private void addProductMetadata(Map.Entry<String, Product> productEntry) { MetadataElement productElement = tsProduct.getMetadataRoot(). getElement(TIME_SERIES_ROOT_NAME). getElement(SOURCE_PRODUCT_PATHS); ProductData productPath = ProductData.createInstance(productEntry.getKey()); int length = productElement.getElements().length + 1; MetadataElement elem = new MetadataElement(String.format("%s.%s", SOURCE_PRODUCT_PATHS, Integer.toString(length))); elem.addAttribute(new MetadataAttribute(PL_PATH, productPath, true)); productElement.addElement(elem); }
private static void addIDNode(final MetadataElement absRoot, final MetadataElement identNode, final String title, final String tag) { final MetadataAttribute attrib = absRoot.getAttribute(tag); if (attrib == null) return; final String value = title + ": " + attrib.getData().getElemString(); final MetadataElement newAttrib = new MetadataElement(value); identNode.addElement(newAttrib); }
public Object getValueAt(int i) { if (i == NAME_COL_INDEX) { return element.getName(); } else if (i == VALUE_COL_INDEX) { return ""; } else if (i == TYPE_COL_INDEX) { } else if (i == UNIT_COL_INDEX) { } else if (i == DESCR_COL_INDEX) { return element.getDescription() != null ? element.getDescription() : ""; } return ""; }
public MetadataElement createDeepClone() { MetadataElement clone = new MetadataElement(getName()); clone.setDescription(getDescription()); MetadataAttribute[] attributes = getAttributes(); for (MetadataAttribute attribute : attributes) { clone.addAttribute(attribute.createDeepClone()); } MetadataElement[] elements = getElements(); for (MetadataElement element : elements) { clone.addElement(element.createDeepClone()); } return clone; }
private void removeAttributeWithValue(String attributeName, String value, MetadataElement parentElement) { final MetadataElement[] childElements = parentElement.getElements(); for (MetadataElement elem : childElements) { if (elem.getAttributeString(attributeName).equals(value)) { parentElement.removeElement(elem); return; } } }
protected void cloneMetadataElements(MetadataElement sourceRoot, MetadataElement destRoot, int level) { for (int i = 0; i < sourceRoot.getNumElements(); i++) { MetadataElement sourceElement = sourceRoot.getElementAt(i); if (level > 0 || isNodeAccepted(sourceElement.getName())) { MetadataElement element = new MetadataElement(sourceElement.getName()); element.setDescription(sourceElement.getDescription()); destRoot.addElement(element); cloneMetadataElementsAndAttributes(sourceElement, element, level + 1); } } }
/** * Gets an estimated, raw storage size in bytes of this product node. * * @param subsetDef if not <code>null</code> the subset may limit the size returned * * @return the size in bytes. */ @Override public long getRawStorageSize(ProductSubsetDef subsetDef) { if (subsetDef != null && !subsetDef.containsNodeName(getName())) { return 0L; } long size = 0; for (int i = 0; i < getNumElements(); i++) { size += getElementAt(i).getRawStorageSize(subsetDef); } for (int i = 0; i < getNumAttributes(); i++) { size += getAttributeAt(i).getRawStorageSize(subsetDef); } return size; }
private static MetadataElement createIdentificationNodes(final MetadataElement rootElement, final MetadataElement absRoot) { final MetadataElement identNode = new MetadataElement("Identification"); addIDNode(absRoot, identNode, "Mission", "MISSION"); addIDNode(absRoot, identNode, "Type", "PRODUCT_TYPE"); addIDNode(absRoot, identNode, "Acquisition", "first_line_time"); addIDNode(absRoot, identNode, "Pass", "PASS"); addIDNode(absRoot, identNode, "Track", "REL_ORBIT"); addIDNode(absRoot, identNode, "Orbit", "ABS_ORBIT"); final MetadataElement slaveRoot = rootElement.getElement("Slave Metadata"); if (slaveRoot != null) { for (MetadataElement slvElem : slaveRoot.getElements()) { final MetadataElement slvNode = new MetadataElement(slvElem.getName()); addIDNode(slvElem, slvNode, "Mission", "MISSION"); addIDNode(slvElem, slvNode, "Type", "PRODUCT_TYPE"); addIDNode(slvElem, slvNode, "Acquisition", "first_line_time"); addIDNode(slvElem, slvNode, "Pass", "PASS"); addIDNode(slvElem, slvNode, "Track", "REL_ORBIT"); addIDNode(slvElem, slvNode, "Orbit", "ABS_ORBIT"); identNode.addElement(slvNode); } } return identNode; }
public static MetadataElement readVariableDescriptions(final List<Variable> variableList, String elementName, int maxNumValuesRead) { MetadataElement metadataElement = new MetadataElement(elementName); for (Variable variable : variableList) { metadataElement.addElement(createMetadataElement(variable, maxNumValuesRead)); } return metadataElement; }
private static void addSRGRCoefficients(MetadataElement srgrAds, MetadataElement dest) { final MetadataElement srgrListElem = new MetadataElement("SRGR_Coefficients"); dest.addElement(srgrListElem); int listCnt = 1; if (srgrAds.getNumElements() == 0) { addOneSetSRGRCoefficients(srgrAds, srgrListElem, listCnt); } else { for (MetadataElement srgrSrc : srgrAds.getElements()) { addOneSetSRGRCoefficients(srgrSrc, srgrListElem, listCnt++); } } }
private void initGraphMetadata() { final MetadataElement metadataRoot = targetProduct.getMetadataRoot(); MetadataElement targetGraphME = metadataRoot.getElement(PROCESSING_GRAPH_ELEMENT_NAME); if (targetGraphME == null) { targetGraphME = new MetadataElement(PROCESSING_GRAPH_ELEMENT_NAME); metadataRoot.addElement(targetGraphME); } convertOperatorContextToMetadata(this, targetGraphME); }
@Test public void testProductName() throws Exception { String filePath = GPFFacadeTest.class.getResource("test-product.dim").toURI().getPath(); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("file", new File(filePath)); Product p1 = GPF.createProduct("Read", parameters); Product p2 = GPF.createProduct("Foo", GPF.NO_PARAMS, new Product[]{p1}); MetadataElement metadataElement = p2.getMetadataRoot().getElement("Processing_Graph"); MetadataElement sourceElement = null; for (MetadataElement element : metadataElement.getElements()) { if (element.getAttribute("operator").getData().getElemString().equals("Foo")) { sourceElement = element.getElement("sources"); break; } } assertNotNull(sourceElement); assertEquals(1, sourceElement.getNumAttributes()); assertEquals("sourceProduct", sourceElement.getAttributeAt(0).getName()); assertTrue(sourceElement.getAttributeAt(0).getData().getElemString().endsWith("test-product.dim")); }
/** * Copies all metadata elements and attributes of the source element to the target element. * The copied elements and attributes are deeply cloned. * * @param source the source element. * @param target the target element. * * @throws NullPointerException if the source or the target element is {@code null}. */ public static void copyMetadata(MetadataElement source, MetadataElement target) { Assert.notNull(source, "source"); Assert.notNull(target, "target"); for (final MetadataElement element : source.getElements()) { target.addElement(element.createDeepClone()); } for (final MetadataAttribute attribute : source.getAttributes()) { target.addAttribute(attribute.createDeepClone()); } }
private void updateMetadata(Product product) { final MetadataElement graphElement = product.getMetadataRoot().getElement("Processing_Graph"); for (MetadataElement nodeElement : graphElement.getElements()) { if (getSpi().getOperatorAlias().equals(nodeElement.getAttributeString("operator"))) { final MetadataElement sourcesElement = nodeElement.getElement("sources"); for (int i = 0; i < sourceProducts.length; i++) { final String oldIndex = String.valueOf(i + 1); final String newIndex = String.valueOf(sourcesElement.getNumAttributes() + i + 1); final Product sourceProduct = sourceProducts[i]; final String attributeName = getSourceProductId(sourceProduct).replaceFirst(oldIndex, newIndex); final File location = sourceProduct.getFileLocation(); final ProductData attributeValue; if (location == null) { attributeValue = ProductData.createInstance(product.toString()); } else { attributeValue = ProductData.createInstance(location.getPath()); } final MetadataAttribute attribute = new MetadataAttribute(attributeName, attributeValue, true); sourcesElement.addAttribute(attribute); } } } }
/** * Tests the functionality for addAttribute */ public void testAddAttribute() { MetadataElement annot = new MetadataElement("test_me"); MetadataAttribute att; // allow null argument try { annot.addAttribute(null); } catch (IllegalArgumentException e) { fail("IllegalArgumentException null argument is allowed"); } // add an attribute att = new MetadataAttribute("Test1", ProductData.createInstance(ProductData.TYPE_INT32), false); annot.addAttribute(att); assertEquals(1, annot.getNumAttributes()); assertEquals(att, annot.getAttributeAt(0)); }
public void testAssignMetadataTo() throws IOException, IllegalCeosFormatException { final FilePointerRecord record = new FilePointerRecord(_reader, _prefix.length()); final MetadataElement elem = new MetadataElement("elem"); record.assignMetadataTo(elem, "suffix"); assertEquals(0, elem.getNumAttributes()); assertEquals(1, elem.getNumElements()); final MetadataElement recordRoot = elem.getElement("FilePointerRecord suffix"); assertNotNull(recordRoot); assertMetadata(recordRoot); assertEquals(0, recordRoot.getNumElements()); assertEquals(21, recordRoot.getNumAttributes()); }
static String extractProductName(MetadataElement processingGraphElement) { if (processingGraphElement != null) { final MetadataElement nodeElement = processingGraphElement.getElement("node.0"); if (nodeElement != null) { final MetadataElement sourcesElement = nodeElement.getElement("sources"); if (sourcesElement != null) { final MetadataAttribute sourceProductAttribute = sourcesElement.getAttribute("sourceProduct"); if (sourceProductAttribute != null) { return sourceProductAttribute.getData().getElemString(); } } } } return null; } }
/** * GuiTest_DialogAndModalDialog the functionality for getNumAttributes() */ public void testGetNumAttributes() { MetadataElement annot = new MetadataElement("yepp"); MetadataAttribute att = new MetadataAttribute("GuiTest_DialogAndModalDialog", ProductData.createInstance(ProductData.TYPE_INT32), false); // a new object should not have any attributes assertEquals(0, annot.getNumAttributes()); // add one and test again annot.addAttribute(att); assertEquals(1, annot.getNumAttributes()); }
public void testAssignMetadataTo() throws IOException, IllegalCeosFormatException { final BaseRecord record = new BaseRecord(_reader, _prefix.length()); final MetadataElement elem = new MetadataElement("elem"); record.assignMetadataTo(elem, null); assertMetadata(elem); assertEquals(0, elem.getNumElements()); assertEquals(6, elem.getNumAttributes()); }