private static void putIfNotNull(Map<String, Product> result, Product product) { if (product != null) { result.put(product.getFileLocation().getAbsolutePath(), product); } }
private boolean alreadyContained(File file) { for (Product sourceProduct : sourceProducts) { File fileLocation = sourceProduct.getFileLocation(); if (fileLocation != null && fileLocation.getAbsolutePath().equals(file.getAbsolutePath())) { return true; } } return false; }
static boolean isProductAlreadyOpened(List<Product> products, File file) { for (Product product : products) { if (product.getFileLocation().getAbsolutePath().equals(file.getAbsolutePath())) { return true; } } return false; }
private String[] getAbsoluteInputProductPaths() { final ArrayList<String> absolutePaths = new ArrayList<String>(); for (List<Product> products : dailyGroupedSourceProducts.values()) { for (Product product : products) { absolutePaths.add(product.getFileLocation().getAbsolutePath()); } } return absolutePaths.toArray(new String[absolutePaths.size()]); }
private String getProductNames(List<Product> dailyGroupedProducts) { final StringWriter stringWriter = new StringWriter(); for (Product dailyGroupedProduct : dailyGroupedProducts) { if (stringWriter.getBuffer().length() > 0) { stringWriter.append(", "); } stringWriter.append(dailyGroupedProduct.getFileLocation().getName()); } return stringWriter.toString(); }
private static URI getFileLocationURI(URI rootURI, Product product) { File file = product.getFileLocation(); return FileUtils.getRelativeUri(rootURI, file); }
private static String getProductLocation(Product product) { final File fileLocation = product.getFileLocation(); if (fileLocation != null) { return fileLocation.getAbsolutePath(); } else { return String.format("Not saved to disk [%s]", product.getName()); } }
private void writeFileHeader(PrintWriter out, Band[] bands) { ProductData.UTC utc = ProductData.UTC.create(new Date(), 0); out.printf("# Exported transect on %s%n", utc.format()); if (bands.length >= 0) { Product product = bands[0].getProduct(); out.printf("# Product name: %s%n", product.getName()); if (product.getFileLocation() != null) { out.printf("# Product file location: %s%n", product.getFileLocation().getAbsolutePath()); } } out.println(); }
/** * Adds the given product to VISAT's internal open product list. * * @param product the product to be added */ public void addProduct(final Product product) { getProductManager().addProduct(product); if (product.getFileLocation() != null) { historyPush(product.getFileLocation()); } }
private boolean isProductAlreadyOpen(File file, ProductManager productManager) { for (int i = 0; i < productManager.getProductCount(); i++) { final Product product = productManager.getProduct(i); final File productFile = product.getFileLocation(); if (file.equals(productFile)) { return true; } } return false; }
@Override public void actionPerformed(ActionEvent e) { final Product product = (Product) productNameComboBox.getSelectedItem(); if (product != null) { if (product.getFileLocation() != null) { productNameComboBox.setToolTipText(product.getFileLocation().getPath()); } else { productNameComboBox.setToolTipText(product.getDisplayName()); } } else { productNameComboBox.setToolTipText("Select a source product."); } } });
private String getDecodeQualification(Product product) { ProductReader reader = product.getProductReader(); if(reader == null) { throw new IllegalStateException("Product has no reader associated!"); } ProductReaderPlugIn readerPlugIn = reader.getReaderPlugIn(); DecodeQualification decodeQualification = readerPlugIn.getDecodeQualification(product.getFileLocation()); return decodeQualification.name(); }
static void writeProduct(Product product) throws IOException { ProductIO.writeProduct(product, product.getFileLocation(), ProductIO.DEFAULT_FORMAT_NAME, false); }
private void bindBandsToFiles(Document dom) { bandDataFiles = DimapProductHelpers.getBandDataFiles(dom, product, getInputDir()); final Band[] bands = product.getBands(); for (final Band band : bands) { if (band instanceof VirtualBand || band instanceof FilterBand) { continue; } final File dataFile = bandDataFiles.get(band); if (dataFile == null || !dataFile.canRead()) { BeamLogManager.getSystemLogger().warning( "DimapProductReader: Unable to read file '" + dataFile + "' referenced by '" + band.getName() + "'."); BeamLogManager.getSystemLogger().warning( "DimapProductReader: Removed band '" + band.getName() + "' from product '" + product.getFileLocation() + "'."); } } }
private String getProductFilename() { String productFilename; if (getProduct().getFileLocation() != null) { productFilename = getProduct().getFileLocation().getName(); } else { productFilename = getProduct().getName() + DimapProductConstants.DIMAP_HEADER_FILE_EXTENSION; } return productFilename; }
@Test public void testNewProductIsDisposed() throws Exception { SourceProductSelector selector = new SourceProductSelector(appContext, "Source"); selector.initProducts(); Product newProduct = new Product("new", "T1", 0, 0); newProduct.setFileLocation(new File("")); selector.setSelectedProduct(newProduct); Assert.assertSame(newProduct, selector.getSelectedProduct()); selector.setSelectedProduct(defaultProducts[0]); Assert.assertSame(defaultProducts[0], selector.getSelectedProduct()); Assert.assertNotNull(newProduct.getFileLocation()); selector.releaseProducts(); Assert.assertNull(newProduct.getFileLocation()); // assert that new product is disposed, because it is not selected }
@Test public void testNewProductIsNotDisposed() throws Exception { SourceProductSelector selector = new SourceProductSelector(appContext, "Source"); selector.initProducts(); selector.setSelectedProduct(defaultProducts[0]); Assert.assertSame(defaultProducts[0], selector.getSelectedProduct()); Product newProduct = new Product("new", "T1", 0, 0); newProduct.setFileLocation(new File("")); selector.setSelectedProduct(newProduct); Assert.assertSame(newProduct, selector.getSelectedProduct()); Assert.assertNotNull(newProduct.getFileLocation()); selector.releaseProducts(); Assert.assertNotNull(newProduct.getFileLocation()); // assert that new product is not disposed while it is selected }
private void performTest(float accuracy) throws IOException { final Product inProduct = writeReadProduct(); assertEquals(outProduct.getName(), inProduct.getName()); assertEquals(outProduct.getProductType(), inProduct.getProductType()); assertEquals(outProduct.getNumBands(), inProduct.getNumBands()); for (int i = 0; i < outProduct.getNumBands(); i++) { assertEquality(outProduct.getBandAt(i), inProduct.getBandAt(i)); } assertEquals(location, inProduct.getFileLocation()); assertNotNull(inProduct.getGeoCoding()); assertEquality(outProduct.getGeoCoding(), inProduct.getGeoCoding(), accuracy); }
@Test public void testWriteReadLatLonGeocoding() throws IOException, TransformException, FactoryException { setGeoCoding(outProduct, WGS_84); final Product inProduct = writeReadProduct(); assertEquals(outProduct.getName(), inProduct.getName()); assertEquals(outProduct.getProductType(), inProduct.getProductType()); assertEquals(outProduct.getNumBands(), inProduct.getNumBands()); assertEquals(outProduct.getBandAt(0).getName(), inProduct.getBandAt(0).getName()); assertEquals(outProduct.getBandAt(0).getDataType(), inProduct.getBandAt(0).getDataType()); assertEquals(outProduct.getBandAt(0).getScalingFactor(), inProduct.getBandAt(0).getScalingFactor(), 1.0e-6); assertEquals(outProduct.getBandAt(0).getScalingOffset(), inProduct.getBandAt(0).getScalingOffset(), 1.0e-6); assertEquals(location, inProduct.getFileLocation()); assertNotNull(inProduct.getGeoCoding()); assertEquality(outProduct.getGeoCoding(), inProduct.getGeoCoding(), 2.0e-5f); }
@Test public void testWriteReadUTMProjection() throws IOException, TransformException, FactoryException { setGeoCoding(outProduct, WGS_84_UTM_ZONE_28S); final Product inProduct = writeReadProduct(); assertEquals(outProduct.getName(), inProduct.getName()); assertEquals(outProduct.getProductType(), inProduct.getProductType()); assertEquals(outProduct.getNumBands(), inProduct.getNumBands()); assertEquals(outProduct.getBandAt(0).getName(), inProduct.getBandAt(0).getName()); assertEquals(outProduct.getBandAt(0).getDataType(), inProduct.getBandAt(0).getDataType()); assertEquals(outProduct.getBandAt(0).getScalingFactor(), inProduct.getBandAt(0).getScalingFactor(), 1.0e-6); assertEquals(outProduct.getBandAt(0).getScalingOffset(), inProduct.getBandAt(0).getScalingOffset(), 1.0e-6); assertEquals(location, inProduct.getFileLocation()); assertNotNull(inProduct.getGeoCoding()); assertEquality(outProduct.getGeoCoding(), inProduct.getGeoCoding(), 2.0e-5f); }