*/
private GeoPojo getEntityGeo(GeoSpecPojo gsp, DocumentPojo f, String field)
{
try
{
GeoPojo g = null;
Double dLat = (double) 0;
Double dLon = (double) 0;
if (gsp != null)
{
String latValue = null;
String lonValue = null;
// The GeoSpecPojo already has lat and lon so we just need to retrieve the values
if ((gsp.getLat() != null) && (gsp.getLon() != null)) {
if (JavaScriptUtils.containsScript(gsp.getLat()))
{
latValue = (String)getValueFromScript(gsp.getLat(), null, null);
}
else
{
latValue = getFormattedTextFromField(gsp.getLat(), field);
}
if (JavaScriptUtils.containsScript(gsp.getLon()))
{
lonValue = (String)getValueFromScript(gsp.getLon(), null, null);
}
else
{
lonValue = getFormattedTextFromField(gsp.getLon(), field);
}
if (latValue != null && lonValue != null)
{
dLat = Double.parseDouble(latValue);
dLon = Double.parseDouble(lonValue);
}
}
else
{
String city, region, country, countryCode = null;
// Create a GeoReferencePojo from the GeoSpec object
GeoFeaturePojo gfp = new GeoFeaturePojo();
if (gsp.getCity() != null)
{
if (JavaScriptUtils.containsScript(gsp.getCity()))
{
city = (String)getValueFromScript(gsp.getCity(), null, null);
}
else
{
city = getFormattedTextFromField(gsp.getCity(), null);
}
gfp.setCity(city);
gfp.setSearch_field(city);
}
if (gsp.getStateProvince() != null)
{
if (JavaScriptUtils.containsScript(gsp.getStateProvince()))
{
region = (String)getValueFromScript(gsp.getStateProvince(), null, null);
}
else
{
region = getFormattedTextFromField(gsp.getStateProvince(), null);
}
gfp.setRegion(region);
if (gfp.getSearch_field() == null) gfp.setSearch_field(region);
}
if (gsp.getCountry() != null)
{
if (JavaScriptUtils.containsScript(gsp.getCountry()))
{
country = (String)getValueFromScript(gsp.getCountry(), null, null);
}
else
{
country = getFormattedTextFromField(gsp.getCountry(), null);
}
gfp.setCountry(country);
if (gfp.getSearch_field() == null) gfp.setSearch_field(country);
}
if (gsp.getCountryCode() != null)
{
if (JavaScriptUtils.containsScript(gsp.getCountryCode()))
{
countryCode = (String)getValueFromScript(gsp.getCountryCode(), null, null);
}
else
{
countryCode = getFormattedTextFromField(gsp.getCountryCode(), null);
}
gfp.setCountry_code(countryCode);
// (Don't set to search field for country code - it will be equal to country...)
}
// Send the GeoReferencePojo to enrichGeoInfo to attempt to get lat and lon values
boolean bStrictMatch = (null == gsp.getStrictMatch()) || gsp.getStrictMatch();
List<GeoFeaturePojo> gList = GeoReference.enrichGeoInfo(gfp, bStrictMatch, true, 1);
GeoFeaturePojo firstGeo = gList.get(0);
latValue = firstGeo.getGeoindex().lat.toString();
lonValue = firstGeo.getGeoindex().lon.toString();
gsp.setOntology_type(firstGeo.getOntology_type());
// Set lat and long in DocGeo if possible
dLat = Double.parseDouble(latValue);
dLon = Double.parseDouble(lonValue);
}
}
if (dLat != 0 && dLon !=0)
{
g = new GeoPojo();
g.lat = dLat;
g.lon = dLon;
}
return g;
}
catch (Exception e) // If alternatives are specified we can try them instead
{
if (null != gsp.getAlternatives()) {
for (GeoSpecPojo altIn: gsp.getAlternatives()) {
GeoPojo altOut = getEntityGeo(altIn, f, field);
if (null != altOut) {
gsp.setOntology_type(altIn.getOntology_type());
return altOut;
}
}