@Override public SimpleFeature apply(ImportTask task, DataStore dataStore, SimpleFeature oldFeature, SimpleFeature feature) throws Exception { Object val = feature.getAttribute(field); Date parsed = null; if (val instanceof String) { String s = ((String) val).trim(); if (s.length() > 0) { val = Double.parseDouble( s ); } else { val = null; } } if (val != null) { parsed = parseDate( (Number) val); } feature.setAttribute(field, parsed); return feature; }
@Test public void testIntegerFieldToDateTransform() throws Exception { SimpleFeature f = transform(new IntegerFieldToDateTransform("number"), "number", Integer.class, 1999); GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); cal.setTime((Date) f.getAttribute("number")); assertEquals(1999, cal.get(GregorianCalendar.YEAR)); assertEquals(1, cal.get(GregorianCalendar.MONTH) + 1); // 0-based month! assertEquals(1, cal.get(GregorianCalendar.DAY_OF_MONTH)); }
task.getTransform().add(new IntegerFieldToDateTransform("CAT_ID")); importer.run(context);
@Override public SimpleFeature apply( ImportTask task, DataStore dataStore, SimpleFeature oldFeature, SimpleFeature feature) throws Exception { Object val = oldFeature.getAttribute(field); Date parsed = null; if (val instanceof String) { String s = ((String) val).trim(); if (s.length() > 0) { val = Double.parseDouble(s); } else { val = null; } } if (val != null) { parsed = parseDate((Number) val); } feature.setAttribute(field, parsed); return feature; }