Hi,
I'm working on creating a modified version of an Esri adapter for parsing XML in GeoEvent processor. I can parse values out from the XML and log them but the sample code will not set values in the GeoEvent. When the values are set either the output is null or a cast exception is returned (java.lang.ClassCastException). String and Geometry values end up being null; longs and integers cause the cast exception. I've tried using objects (i.e., Integer, Long) and primitives; both cause a cast exception. The link to the sample is below, as is the switch that should set the geoEvent values but does not.
Any suggestions welcome!
switch (fieldDefinition.getType())
{
case Integer:
Integer tmp = (Integer)Integer.parseInt(fieldValue);
LOG.info(tmp);
geoEvent.setField(fieldName, tmp);
LOG.info("GeoEvent value stored for " + fieldName + " :" + geoEvent.getField(fieldName));
break;
case Long:
geoEvent.setField(fieldName, Long.parseLong(fieldValue));
LOG.info("GeoEvent value stored for " + fieldName + " :" + geoEvent.getField(fieldName));
break;
case Short:
geoEvent.setField(fieldName, Short.parseShort(fieldValue));
LOG.info("GeoEvent value stored for " + fieldName + " :" + geoEvent.getField(fieldName));
break;
case Double:
geoEvent.setField(fieldName, Double.parseDouble(fieldValue));
LOG.info("GeoEvent value stored for " + fieldName + " :" + geoEvent.getField(fieldName));
break;
case Float:
geoEvent.setProperty(fieldName, Float.parseFloat(fieldValue));
LOG.info("GeoEvent value stored for " + fieldName + " :" + geoEvent.getField(fieldName));
break;
case Boolean:
//geoEvent.setField(fieldName, Boolean.parseBoolean(fieldValue));
geoEvent.setProperty(fieldName, Boolean.parseBoolean(fieldValue));
LOG.info("GeoEvent value stored for" + fieldName + " :" + geoEvent.getField(fieldName));
break;
case Date:
geoEvent.setProperty(fieldName, DateUtil.convert(fieldValue));
LOG.info("GeoEvent value stored for " + fieldName + " :" + geoEvent.getField(fieldName));
break;
case String:
geoEvent.setProperty(fieldName, fieldValue);
LOG.info("GeoEvent value stored for " + fieldName + " :" + geoEvent.getField(fieldName));
break;
case Geometry:
LOG.info("Geometry field received: "+fieldValue);
String geometryString = fieldValue;
if (geometryString.contains(";"))
geometryString = geometryString.substring(0, geometryString.indexOf(';') - 1);
String[] g = geometryString.split(",");
double x = Double.parseDouble(g[0]);
double y = Double.parseDouble(g[1]);
double z = 0;
int wkid = 4326;
Point point = spatial.createPoint(x, y, z, wkid);
// getGeometryId is deprecated
// int geometryID = geoEvent.getGeoEventDefinition().getGeometryId();
String geometryGUID = geoEvent.getGuid();
// updated to use setGeometry without using the .toJson method;
// the new method accepts a geometry object
geoEvent.setGeometry(geometryGUID, point);
Point pt = (Point) geoEvent.getGeometry();
if (pt == null){
LOG.info("Null point geometry");
}
else{
LOG.info("Geometry X value is: " + pt.getX());
}
break;
I figured out the problem while trying to reproduce it on another machine. The setField() method throws the cast error when the GeoEvent definition for the field has a cardinality of many. Changing the cardinality to one fixed the problem. I imagine that setField() would work for a cardinality of many if an array or enum object were used but I haven't tested that.
I also had to update the setGeometry function: passing in just the geometry without the GUID is what is needed.
geoEvent.setGeometry(point);