final Map<Object, Object> map = new HashMap<>(); map.put("city", city.getCity()); map.put("continent", city.getContinent()); map.put("country", city.getCountry()); map.put("location", location);
private Record createRecord(final CityResponse city) { if (city == null) { return null; } final Map<String, Object> values = new HashMap<>(); values.put(CitySchema.CITY.getFieldName(), city.getCity().getName()); final Location location = city.getLocation(); values.put(CitySchema.ACCURACY.getFieldName(), location.getAccuracyRadius()); values.put(CitySchema.METRO_CODE.getFieldName(), location.getMetroCode()); values.put(CitySchema.TIMEZONE.getFieldName(), location.getTimeZone()); values.put(CitySchema.LATITUDE.getFieldName(), location.getLatitude()); values.put(CitySchema.LONGITUDE.getFieldName(), location.getLongitude()); values.put(CitySchema.CONTINENT.getFieldName(), city.getContinent().getName()); values.put(CitySchema.POSTALCODE.getFieldName(), city.getPostal().getCode()); values.put(CitySchema.COUNTRY.getFieldName(), createRecord(city.getCountry())); final Object[] subdivisions = new Object[city.getSubdivisions().size()]; int i = 0; for (final Subdivision subdivision : city.getSubdivisions()) { subdivisions[i++] = createRecord(subdivision); } values.put(CitySchema.SUBDIVISIONS.getFieldName(), subdivisions); return new MapRecord(CitySchema.GEO_SCHEMA, values); }
@Override public String getValue(CityResponse response) { return response.getContinent().getCode(); } },
private GeoInfo _getGeoInfo(String ipAddress) { GeoInfo geoInfo = new GeoInfo(); if (ipAddress == null) { return geoInfo; } try{ InetAddress inetAddress = InetAddress.getByName(ipAddress); CityResponse response = reader.city(inetAddress); Country country = response.getCountry(); Continent continent = response.getContinent(); City city = response.getCity(); Postal postal = response.getPostal(); Location location = response.getLocation(); Subdivision subdivision = response.getMostSpecificSubdivision(); geoInfo.setRegion(subdivision.getName()); geoInfo.setCountryIsoCode(country.getIsoCode()); geoInfo.setCountry(country.getName()); geoInfo.setContinent(continent.getCode()); geoInfo.setCity(city.getName()); geoInfo.setPostalCode(postal.getCode()); geoInfo.setLatitude(location.getLatitude()); geoInfo.setLongitude(location.getLongitude()); return geoInfo; } catch(Exception ex){ return null; } }
break; case "region": put(properties,"_region", city.getContinent().getName()); break; case "city":
continent = response.getContinent(); location = response.getLocation(); postal = response.getPostal();