AnsweredAssumed Answered

geoEvent setField() method throws error or sets null value

Question asked by gyetmanesri-ca-esridist Employee on Sep 12, 2014
Latest reply on Sep 15, 2014 by gyetmanesri-ca-esridist

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!

 

https://github.com/Esri/solutions-geoevent-java/tree/master/solutions-geoevent/adapters/geomessage-adapter

 

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;

Outcomes