Search in sources :

Example 1 with MessagingException

use of com.esri.ges.messaging.MessagingException in project reverse-geocoder-for-geoevent by Esri.

the class ReverseGeocoderProcessor method augmentGeoEventWithAddress.

private GeoEvent augmentGeoEventWithAddress(GeoEvent geoEvent, String addressJson) throws ConfigurationException, GeoEventDefinitionManagerException, FieldException, JSONException {
    JSONObject jsonObj = new JSONObject(addressJson);
    JSONObject addressJSONObject = jsonObj.getJSONObject("address");
    GeoEvent newGeoEvent = null;
    if (geoEventCreator != null) {
        try {
            GeoEventDefinition edIn = geoEvent.getGeoEventDefinition();
            List<FieldDefinition> fds = new ArrayList<FieldDefinition>();
            fds.add(new DefaultFieldDefinition("Address", FieldType.String));
            fds.add(new DefaultFieldDefinition("Neighborhood", FieldType.String));
            fds.add(new DefaultFieldDefinition("City", FieldType.String));
            fds.add(new DefaultFieldDefinition("Subregion", FieldType.String));
            fds.add(new DefaultFieldDefinition("Region", FieldType.String));
            fds.add(new DefaultFieldDefinition("Postal", FieldType.String));
            fds.add(new DefaultFieldDefinition("PostalExt", FieldType.String));
            fds.add(new DefaultFieldDefinition("CountryCode", FieldType.String));
            fds.add(new DefaultFieldDefinition("Match_addr", FieldType.String));
            fds.add(new DefaultFieldDefinition("Loc_name", FieldType.String));
            GeoEventDefinition edOut = edIn.augment(fds);
            edOut.setName(newGeoEventDefinitionName);
            edOut.setOwner(getId());
            GeoEventDefinitionManager geoEventDefinitionManager = geoEventCreator.getGeoEventDefinitionManager();
            // if (geoEventDefinitionManager.getGeoEventDefinition(newGeoEventDefinitionName) == null)
            // geoEventDefinitionManager.addGeoEventDefinition(edOut);
            // LOGGER.info("Checking for GED: " + edOut.getName());
            String gedGuid = "";
            try {
                Collection<GeoEventDefinition> geoEventDefinitions = geoEventDefinitionManager.searchInRepositoryGeoEventDefinitionByName(newGeoEventDefinitionName);
                // LOGGER.info("Found " + geoEventDefinitions.size() + " GEDs named " + edOut.getName());
                if (geoEventDefinitions == null || geoEventDefinitions.size() == 0) {
                    // LOGGER.info("Didn't find it. Adding GED: " + edOut.getName());
                    geoEventDefinitionManager.addGeoEventDefinition(edOut);
                } else
                    gedGuid = geoEventDefinitions.iterator().next().getGuid();
            } catch (Exception ex) {
                LOGGER.info("Encountered an error checking for this GED: " + edOut.getName() + ". Adding it anyway.");
                geoEventDefinitionManager.addGeoEventDefinition(edOut);
                gedGuid = edOut.getGuid();
            }
            List<Object> fieldValues = new ArrayList<Object>();
            Object value;
            for (int i = 0; i < edIn.getFieldDefinitions().size(); i++) {
                value = geoEvent.getField(i);
                fieldValues.add(value);
            }
            try {
                fieldValues.add(addressJSONObject.get("Address"));
            } catch (Exception ex) {
                fieldValues.add("");
            }
            try {
                fieldValues.add(addressJSONObject.get("Neighborhood"));
            } catch (Exception ex) {
                fieldValues.add("");
            }
            try {
                fieldValues.add(addressJSONObject.get("City"));
            } catch (Exception ex) {
                fieldValues.add("");
            }
            try {
                fieldValues.add(addressJSONObject.get("Subregion"));
            } catch (Exception ex) {
                fieldValues.add("");
            }
            try {
                fieldValues.add(addressJSONObject.get("Region"));
            } catch (Exception ex) {
                fieldValues.add("");
            }
            try {
                fieldValues.add(addressJSONObject.get("Postal"));
            } catch (Exception ex) {
                fieldValues.add("");
            }
            try {
                fieldValues.add(addressJSONObject.get("PostalExt"));
            } catch (Exception ex) {
                fieldValues.add("");
            }
            try {
                fieldValues.add(addressJSONObject.get("CountryCode"));
            } catch (Exception ex) {
                fieldValues.add("");
            }
            try {
                fieldValues.add(addressJSONObject.get("Match_addr"));
            } catch (Exception ex) {
                fieldValues.add("");
            }
            try {
                fieldValues.add(addressJSONObject.get("Loc_name"));
            } catch (Exception ex) {
                fieldValues.add("");
            }
            // LOGGER.info("Creating a Geoevent from GED: " + edOut.getName());
            newGeoEvent = geoEventCreator.create(gedGuid);
            // newGeoEvent = geoEventCreator.create(newGeoEventDefinitionName, definition.getUri().toString());
            for (int i = 0; i < edOut.getFieldDefinitions().size(); i++) {
                try {
                    newGeoEvent.setField(i, fieldValues.get(i));
                } catch (Exception ex) {
                }
            }
            newGeoEvent.setProperty(GeoEventPropertyName.TYPE, "event");
            newGeoEvent.setProperty(GeoEventPropertyName.OWNER_ID, getId());
            newGeoEvent.setProperty(GeoEventPropertyName.OWNER_URI, definition.getUri());
        } catch (MessagingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return newGeoEvent;
}
Also used : MessagingException(com.esri.ges.messaging.MessagingException) GeoEventDefinition(com.esri.ges.core.geoevent.GeoEventDefinition) FieldDefinition(com.esri.ges.core.geoevent.FieldDefinition) DefaultFieldDefinition(com.esri.ges.core.geoevent.DefaultFieldDefinition) ArrayList(java.util.ArrayList) DefaultFieldDefinition(com.esri.ges.core.geoevent.DefaultFieldDefinition) JSONException(org.json.JSONException) GeoEventDefinitionManagerException(com.esri.ges.manager.geoeventdefinition.GeoEventDefinitionManagerException) MalformedURLException(java.net.MalformedURLException) FieldException(com.esri.ges.core.geoevent.FieldException) ConfigurationException(com.esri.ges.core.ConfigurationException) IOException(java.io.IOException) ComponentException(com.esri.ges.core.component.ComponentException) MessagingException(com.esri.ges.messaging.MessagingException) Point(com.esri.core.geometry.Point) GeoEventDefinitionManager(com.esri.ges.manager.geoeventdefinition.GeoEventDefinitionManager) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) GeoEvent(com.esri.ges.core.geoevent.GeoEvent)

Aggregations

Point (com.esri.core.geometry.Point)1 ConfigurationException (com.esri.ges.core.ConfigurationException)1 ComponentException (com.esri.ges.core.component.ComponentException)1 DefaultFieldDefinition (com.esri.ges.core.geoevent.DefaultFieldDefinition)1 FieldDefinition (com.esri.ges.core.geoevent.FieldDefinition)1 FieldException (com.esri.ges.core.geoevent.FieldException)1 GeoEvent (com.esri.ges.core.geoevent.GeoEvent)1 GeoEventDefinition (com.esri.ges.core.geoevent.GeoEventDefinition)1 GeoEventDefinitionManager (com.esri.ges.manager.geoeventdefinition.GeoEventDefinitionManager)1 GeoEventDefinitionManagerException (com.esri.ges.manager.geoeventdefinition.GeoEventDefinitionManagerException)1 MessagingException (com.esri.ges.messaging.MessagingException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1