public ImportContext createContext(ImportData data, WorkspaceInfo targetWorkspace) throws IOException { return createContext(data, targetWorkspace, null); }
@Override protected ImportContext call(ProgressMonitor monitor) throws Exception { run(context, filter, monitor); return context; }
@Test public void testIllegalNames() throws Exception { File dir = unpack("shape/archsites_epsg_prj.zip"); for (File f : dir.listFiles()) { String ext = FilenameUtils.getExtension(f.getName()); String base = FilenameUtils.getBaseName(f.getName()); f.renameTo(new File(dir, "1-." + ext)); } ImportContext imp = importer.createContext(new Directory(dir)); importer.run(imp); ImportTask task = imp.getTasks().get(0); assertEquals("a_1_", task.getLayer().getName()); assertEquals("a_1_", task.getLayer().getResource().getName()); }
@Test public void testImportCSV() throws Exception { File dir = unpack("csv/locations.zip"); ImportContext context = importer.createContext(new SpatialFile(new File(dir, "locations.csv"))); assertEquals(1, context.getTasks().size()); ImportTask task = context.getTasks().get(0); assertEquals(ImportTask.State.NO_CRS, task.getState()); LayerInfo layer = task.getLayer(); ResourceInfo resource = layer.getResource(); resource.setSRS("EPSG:4326"); assertTrue("Item not ready", importer.prep(task)); assertEquals(ImportTask.State.READY, task.getState()); context.updated(); assertEquals(ImportContext.State.PENDING, context.getState()); importer.run(context); assertEquals(ImportContext.State.COMPLETE, context.getState()); FeatureTypeInfo fti = (FeatureTypeInfo) resource; SimpleFeatureType featureType = (SimpleFeatureType) fti.getFeatureType(); GeometryDescriptor geometryDescriptor = featureType.getGeometryDescriptor(); assertNull("Expecting no geometry", geometryDescriptor); assertEquals(4, featureType.getAttributeCount()); }
if (!doPreTransform(task, task.getData(), tx)) { return; try { currentlyProcessing.put(task.getContext().getId(), task); loadIntoDataStore( task, (DataStoreInfo) task.getStore(), addToCatalog(task); getCatalog() .getResourceByName( featureType.getQualifiedName(), FeatureTypeInfo.class); calculateBounds(resource); harvestImportData(sr, data); addToCatalog(task); if (!canceled && !doPostTransform(task, task.getData(), tx)) { return;
store.setName(findUniqueStoreName(task.getStore())); if (!doPreTransform(task, task.getData(), tx)) { return; addToCatalog(task); getCatalog() .getResourceByName( featureType.getQualifiedName(), FeatureTypeInfo.class); calculateBounds(resource); if (!doPostTransform(task, task.getData(), tx)) { return;
if (!doPreTransform(task, task.getData(), tx)) { return; try { currentlyProcessing.put(task.getContext().getId(), task); loadIntoDataStore(task, (DataStoreInfo)task.getStore(), (VectorFormat) format, (VectorTransformChain) tx); canceled = task.progress().isCanceled(); addToCatalog(task); FeatureTypeInfo resource = getCatalog().getResourceByName( featureType.getQualifiedName(), FeatureTypeInfo.class); if (resource.getNativeBoundingBox().isEmpty() || resource.getMetadata().get("recalculate-bounds") != null) { CatalogBuilder cb = new CatalogBuilder(getCatalog()); ReferencedEnvelope nativeBounds = cb.getNativeBounds(resource); resource.setNativeBoundingBox(nativeBounds); resource.setLatLonBoundingBox(cb.getLatLonBounds(nativeBounds, resource.getCRS())); getCatalog().save(resource); if (!canceled && !doPostTransform(task, task.getData(), tx)) { return;
ImportContext context = (store != null ? importer.createContext(spatialData, ws, store) : importer.createContext(spatialData, ws)); StyleInfo style = importer.getCatalog().getStyleByName(defaultStyle); if (style == null && targetWorkspace != null) { style = importer.getCatalog().getStyleByName(targetWorkspace, defaultStyle); importer.run(context);
@Test public void testImportSpaceInNames() throws Exception { File dir = unpack("shape/spaceInNames.zip"); DataStoreInfo ds = createH2DataStore(null, "spaceInNamesContainer"); ImportContext context = importer.createContext(new SpatialFile(new File(dir, "spaceInNames.shp")), ds); assertEquals(1, context.getTasks().size()); ImportTask task = context.getTasks().get(0); assertEquals(ImportTask.State.NO_CRS, task.getState()); task.getLayer().getResource().setSRS("EPSG:26713"); importer.changed(task); assertEquals(ImportTask.State.READY, task.getState()); assertEquals("spaceInNames", task.getLayer().getResource().getName()); importer.run(context); Catalog cat = getCatalog(); assertNotNull(cat.getLayerByName("spaceInNames")); assertEquals(ImportTask.State.COMPLETE, task.getState()); SimpleFeatureSource fs = (SimpleFeatureSource) cat.getFeatureTypeByName("spaceInNames").getFeatureSource(null, null); SimpleFeature sf = DataUtilities.first(fs.getFeatures()); assertNotNull(sf.getAttribute("WIND_SPEED")); assertNotNull(sf.getAttribute("WIND_DIREC")); }
@Test public void testImportNoCrsLatLonBoundingBox() throws Exception { File dir = unpack("shape/archsites_no_crs.zip"); ImportContext context = importer.createContext(new Directory(dir)); assertEquals(1, context.getTasks().size()); ImportTask task = context.getTasks().get(0); assertEquals(ImportTask.State.NO_CRS, task.getState()); task.getLayer().getResource().setSRS("EPSG:26713"); importer.changed(task); assertEquals(ImportTask.State.READY, task.getState()); ResourceInfo r = task.getLayer().getResource(); assertNotNull(r.getLatLonBoundingBox()); assertNotNull(r.boundingBox()); assertNotNull(r.boundingBox().getCoordinateReferenceSystem()); assertEquals("EPSG:26713", CRS.toSRS(r.boundingBox().getCoordinateReferenceSystem())); // Do the import, verify the changed CRS is preserved when the bounds are calculated importer.doDirectImport(task); assertEquals(ImportTask.State.COMPLETE, task.getState()); r = task.getLayer().getResource(); assertNotNull(r.getLatLonBoundingBox()); assertNotEquals(VectorFormat.EMPTY_BOUNDS, r.getLatLonBoundingBox()); assertNotNull(r.boundingBox()); assertNotEquals(VectorFormat.EMPTY_BOUNDS, r.boundingBox()); assertNotNull(r.boundingBox().getCoordinateReferenceSystem()); assertEquals("EPSG:26713", CRS.toSRS(r.boundingBox().getCoordinateReferenceSystem())); }
File file1 = new File(mosaicFolder, fileName1); assertTrue(file1.exists()); ImportContext context = importer.createContext(new SpatialFile(file1), store); String fileName2 = "NCOM_wattemp_100_20081102T0000000_12.tiff"; File file2 = new File(mosaicFolder, fileName2); importer.update(context, new SpatialFile(file2)); importer.run(context);
break; run(task); directory.archive(getArchiveFile(context)); } catch (Exception ioe) { ioe.printStackTrace();
targetStore = lookupDefaultStore(); && isMultiCoverageInput(format, data)) { CoverageStoreInfo cs = (CoverageStoreInfo) targetStore; GridCoverageReader reader = cs.getGridCoverageReader(null, null); task.setDirect(false); task.setStore(targetStore); prep(task); task.setState(State.READY); task.setError(null); prep(t); tasks.add(t); t.setDirect(direct); t.setStore(targetStore); prep(t); tasks.add(t);
store.setName(findUniqueStoreName(task.getStore())); if (!doPreTransform(task, task.getData(), tx)) { return; addToCatalog(task); if (!doPostTransform(task, task.getData(), tx)) { return;
void run(ImportTask task) throws IOException { if (task.getState() == ImportTask.State.COMPLETE) { return; } task.setState(ImportTask.State.RUNNING); if (task.isDirect()) { //direct import, simply add configured store and layers to catalog doDirectImport(task); } else { //indirect import, read data from the source and into the target datastore doIndirectImport(task); } }
public ImportContext createContext( ImportData data, WorkspaceInfo targetWorkspace, StoreInfo targetStore, ProgressMonitor monitor) throws IOException { ImportContext context = new ImportContext(); context.setProgress(monitor); context.setData(data); if (targetWorkspace == null && targetStore != null) { targetWorkspace = targetStore.getWorkspace(); } if (targetWorkspace == null) { targetWorkspace = catalog.getDefaultWorkspace(); } context.setTargetWorkspace(targetWorkspace); context.setTargetStore(targetStore); init(context); if (!context.progress().isCanceled()) { contextStore.add(context); } // JD: don't think we really need to maintain these, and they aren't persisted // else { // context.setState(ImportContext.State.CANCELLED); // } return context; }