SnapOperatorAdapter extends SubsetProcessorAdapter { @Override public boolean processSourceProduct(MODE mode, ProgressMonitor pm) throws IOException { pm.setSubTaskName("SNAP Level 2"); try { Configuration conf = getConfiguration(); String processorName = conf.get(JobConfigNames.CALVALUS_L2_OPERATOR); String processorParameters = conf.get(JobConfigNames.CALVALUS_L2_PARAMETERS); Product inputProduct = getInputProduct(); Product sourceProduct; if (getConfiguration().getBoolean(JobConfigNames.CALVALUS_INPUT_SUBSETTING, true)) { sourceProduct = createSubsetFromInput(inputProduct); } else { sourceProduct = inputProduct; } int minWidth = conf.getInt(JobConfigNames.CALVALUS_INPUT_MIN_WIDTH, 0); int minHeight = conf.getInt(JobConfigNames.CALVALUS_INPUT_MIN_HEIGHT, 0); if (sourceProduct.getSceneRasterWidth() < minWidth && sourceProduct.getSceneRasterHeight() < minHeight) { String msgPattern = "The size of the intersection of the product with the region is very small [%d, %d]." + "Processing skipped."; getLogger().info(String.format(msgPattern, sourceProduct.getSceneRasterWidth(), sourceProduct.getSceneRasterHeight())); return false; } Product processedProduct = getProcessedProduct(sourceProduct, processorName, processorParameters); if (getConfiguration().getBoolean(JobConfigNames.CALVALUS_OUTPUT_SUBSETTING, false)) { targetProduct = createSubsetFromOutput(processedProduct); } else { targetProduct = processedProduct; } if (targetProduct == null || targetProduct.getSceneRasterWidth() == 0 || targetProduct.getSceneRasterHeight() == 0) { getLogger().info("Skip processing"); return false; } getLogger().info(String.format("Processed product width = %d height = %d", targetProduct.getSceneRasterWidth(), targetProduct.getSceneRasterHeight())); if (hasInvalidStartAndStopTime(targetProduct)) { copySceneRasterStartAndStopTime(inputProduct, targetProduct, null); } } finally { pm.done(); } return true; } SnapOperatorAdapter(MapContext mapContext); @Override boolean processSourceProduct(MODE mode, ProgressMonitor pm); @Override Product openProcessedProduct(); @Override void saveProcessedProducts(ProgressMonitor pm); @Override void dispose(); static Map<String, Object> getOperatorParameterMap(Product inputProduct, 
                                                              String operatorName, 
                                                              String level2Parameters);  }
@Test public void testInitOfOperatorWithoutL2Parameters() throws Exception { final Product sourceProduct = createSourceProduct(); ProductSplit productSplit = new ProductSplit(null, 42L, new String[0], 0, 0); Configuration conf = new Configuration(); conf.set(JobConfigNames.CALVALUS_INPUT_MIN_WIDTH, "0"); conf.set(JobConfigNames.CALVALUS_INPUT_MIN_HEIGHT, "0"); conf.set(JobConfigNames.CALVALUS_L2_OPERATOR, "InternalTestOp"); TaskAttemptID taskid = new TaskAttemptID(); MapContext mapContext = new MapContextImpl(conf, taskid, null, null, null, null, productSplit); mapContext.getConfiguration().setBoolean("calvalus.snap.setSnapProperties", false); SnapOperatorAdapter snapOperatorAdapter = new SnapOperatorAdapter(mapContext) { @Override public Product getInputProduct() throws IOException { return sourceProduct; } @Override public Rectangle getInputRectangle() throws IOException { return null; } }; snapOperatorAdapter.processSourceProduct(ProcessorAdapter.MODE.EXECUTE, ProgressMonitor.NULL); }
@Test public void testSubset_EmptyRect() throws Exception { Product sourceProduct = createSourceProduct(); ProductSplit productSplit = new ProductSplit(null, 42L, new String[0], 0, 0); SnapOperatorAdapter snapOperatorAdapter = createProcessorAdapter(productSplit, sourceProduct, new Rectangle()); try { snapOperatorAdapter.processSourceProduct(ProcessorAdapter.MODE.EXECUTE, ProgressMonitor.NULL); fail(); } catch (IllegalStateException e) { assertEquals("Can not create an empty subset.", e.getMessage()); } }