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; }
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; }
assertEquals(1, context.getTasks().size()); context.setTargetStore(store);
@Test public void testDateFormatTransform() throws Exception { Catalog cat = getCatalog(); File dir = unpack("shape/ivan.zip"); SpatialFile file = new SpatialFile(new File(dir, "ivan.shp")); file.prepare(); ImportContext context = importer.createContext(file, store); assertEquals(1, context.getTasks().size()); context.setTargetStore(store); ImportTask task = context.getTasks().get(0); task.getTransform().add(new DateFormatTransform("timestamp", "yyyy-MM-dd HH:mm:ss.S")); importer.run(context); assertEquals(ImportContext.State.COMPLETE, context.getState()); FeatureTypeInfo ft = cat.getFeatureTypeByDataStore(store, "ivan"); assertNotNull(ft); SimpleFeatureType schema = (SimpleFeatureType) ft.getFeatureType(); assertTrue( Date.class.isAssignableFrom( schema.getDescriptor("timestamp").getType().getBinding())); FeatureIterator it = ft.getFeatureSource(null, null).getFeatures().features(); try { assertTrue(it.hasNext()); while (it.hasNext()) { SimpleFeature f = (SimpleFeature) it.next(); assertTrue(f.getAttribute("timestamp") instanceof Date); } } finally { it.close(); } }
@Test public void testNumberFormatTransform() throws Exception { Catalog cat = getCatalog(); File dir = unpack("shape/restricted.zip"); SpatialFile file = new SpatialFile(new File(dir, "restricted.shp")); file.prepare(); ImportContext context = importer.createContext(file, store); assertEquals(1, context.getTasks().size()); context.setTargetStore(store); ImportTask task = context.getTasks().get(0); task.getTransform().add(new NumberFormatTransform("cat", Integer.class)); importer.run(context); assertEquals(ImportContext.State.COMPLETE, context.getState()); FeatureTypeInfo ft = cat.getFeatureTypeByDataStore(store, "restricted"); assertNotNull(ft); SimpleFeatureType schema = (SimpleFeatureType) ft.getFeatureType(); assertEquals(Integer.class, schema.getDescriptor("cat").getType().getBinding()); FeatureIterator it = ft.getFeatureSource(null, null).getFeatures().features(); try { assertTrue(it.hasNext()); while (it.hasNext()) { SimpleFeature f = (SimpleFeature) it.next(); assertTrue(f.getAttribute("cat") instanceof Integer); } } finally { it.close(); } }