File dsp = TestData.file(this,"datastore.properties");
FileUtils.copyFileToDirectory(dsp, mosaic);
// have the reader harvest it
ImageMosaicFormat format = new ImageMosaicFormat();
ImageMosaicReader reader = format.getReader(mosaic);
SimpleFeatureIterator it = null;
assertNotNull(reader);
try {
String[] names = reader.getGridCoverageNames();
assertEquals(1, names.length);
assertEquals("NO2", names[0]);
// check we have the two granules we expect
GranuleSource source = reader.getGranules("NO2", true);
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
Query q = new Query(Query.ALL);
q.setSortBy(new SortBy[] { ff.sort("time", SortOrder.DESCENDING) });
SimpleFeatureCollection granules = source.getGranules(q);
assertEquals(1, granules.size());
it = granules.features();
assertTrue(it.hasNext());
SimpleFeature f = it.next();
assertEquals("20130101.METOPA.GOME2.NO2.DUMMY.nc", f.getAttribute("location"));
assertEquals(0, f.getAttribute("imageindex"));
assertEquals("2013-01-01T00:00:00.000Z",
ConvertersHack.convert(f.getAttribute("time"), String.class));
it.close();
// now add another netcdf and harvest it
File nc2 = TestData.file(this,"20130116.METOPA.GOME2.NO2.DUMMY.nc");
FileUtils.copyFileToDirectory(nc2, mosaic);
File fileToHarvest = new File(mosaic, "20130116.METOPA.GOME2.NO2.DUMMY.nc");
List<HarvestedSource> harvestSummary = reader.harvest("NO2", fileToHarvest, null);
assertEquals(1, harvestSummary.size());
granules = source.getGranules(q);
assertEquals(2, granules.size());
HarvestedSource hf = harvestSummary.get(0);
assertEquals("20130116.METOPA.GOME2.NO2.DUMMY.nc", ((File) hf.getSource()).getName());
assertTrue(hf.success());
assertEquals(1, reader.getGridCoverageNames().length);
File nc3 = TestData.file(this,"20130108.METOPA.GOME2.NO2.DUMMY.nc");
FileUtils.copyFileToDirectory(nc3, mosaic);
fileToHarvest = new File(mosaic, "20130108.METOPA.GOME2.NO2.DUMMY.nc");
harvestSummary = reader.harvest("NO2", fileToHarvest, null);
assertEquals(1, harvestSummary.size());
hf = harvestSummary.get(0);
assertEquals("20130108.METOPA.GOME2.NO2.DUMMY.nc", ((File) hf.getSource()).getName());
assertTrue(hf.success());
assertEquals(1, reader.getGridCoverageNames().length);
// check that we have 2 times now
granules = source.getGranules(q);
assertEquals(3, granules.size());
it = granules.features();
f = it.next();
assertEquals("20130116.METOPA.GOME2.NO2.DUMMY.nc", f.getAttribute("location"));
assertEquals(0, f.getAttribute("imageindex"));
assertEquals("2013-01-16T00:00:00.000Z",
ConvertersHack.convert(f.getAttribute("time"), String.class));
assertTrue(it.hasNext());
f = it.next();
assertEquals("20130108.METOPA.GOME2.NO2.DUMMY.nc", f.getAttribute("location"));
assertEquals(0, f.getAttribute("imageindex"));
assertEquals("2013-01-08T00:00:00.000Z",
ConvertersHack.convert(f.getAttribute("time"), String.class));
f = it.next();
assertEquals("20130101.METOPA.GOME2.NO2.DUMMY.nc", f.getAttribute("location"));
assertEquals(0, f.getAttribute("imageindex"));
assertEquals("2013-01-01T00:00:00.000Z",
ConvertersHack.convert(f.getAttribute("time"), String.class));
it.close();
} finally {
if (it != null) {
it.close();
}
reader.dispose();
}
}