public void addTask(ImportTask task) { task.setId(taskid++); task.setContext(this); this.tasks.add(task); // apply the default transformations TransformChain chain = task.getTransform(); for (ImportTransform tx : defaultTransforms) { if (chain instanceof RasterTransformChain && tx instanceof RasterTransform) { chain.add(tx); } else if (chain instanceof VectorTransformChain && tx instanceof VectorTransform) { chain.add(tx); } } }
boolean doPostTransform(ImportTask task, ImportData data, TransformChain tx) { try { tx.post(task, data); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Error occured during post transform", e); task.setError(e); task.setState(ImportTask.State.ERROR); return false; } return true; }
boolean doPreTransform(ImportTask task, ImportData data, TransformChain tx) { try { tx.pre(task, data); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Error occured during pre transform", e); task.setError(e); task.setState(ImportTask.State.ERROR); return false; } return true; }
assertEquals("archsites", task.getLayer().getResource().getName()); TransformChain transformChain = task.getTransform(); transformChain.add(new PostScriptTransform("test.sh", Collections.emptyList())); importer.run(context);
boolean doPreTransform(ImportTask task, ImportData data, TransformChain tx) { try { tx.pre(task, data); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Error occured during pre transform", e); task.setError(e); task.setState(ImportTask.State.ERROR); return false; } return true; }
boolean doPostTransform(ImportTask task, ImportData data, TransformChain tx) { try { tx.post(task, data); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Error occured during post transform", e); task.setError(e); task.setState(ImportTask.State.ERROR); return false; } return true; }
task.getTransform().add(new IntegerFieldToDateTransform("CAT_ID")); importer.run(context);
transformChain.add(new DescriptionLimitingTransform()); importer.run(context); Exception error = task.getError();
@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(); } }
item.getTransform().add(new ReprojectTransform(CRS.decode("EPSG:4326"))); importer.run(context);
@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(); } }
task.getTransform().add(gad);
task.getTransform().add(gtx);
task.getTransform().add(warp);
transformChain.add(new AttributesToPointGeometryTransform("LAT", "LON")); assertEquals(ImportTask.State.NO_CRS, task.getState());