Search in sources :

Example 6 with Subdivision

use of com.maxmind.geoip2.record.Subdivision in project nutch by apache.

the class GeoIPDocumentCreator method createDocFromCityDb.

public static NutchDocument createDocFromCityDb(String serverIp, NutchDocument doc, DatabaseReader reader) throws UnknownHostException, IOException, GeoIp2Exception {
    doc.add("ip", serverIp);
    CityResponse response = reader.city(InetAddress.getByName(serverIp));
    City city = response.getCity();
    // 'Minneapolis'
    doc.add("cityName", city.getName());
    // 50
    doc.add("cityConfidence", city.getConfidence());
    doc.add("cityGeoNameId", city.getGeoNameId());
    Continent continent = response.getContinent();
    doc.add("continentCode", continent.getCode());
    doc.add("continentGeoNameId", continent.getGeoNameId());
    doc.add("continentName", continent.getName());
    Country country = response.getCountry();
    // 'US'
    doc.add("countryIsoCode", country.getIsoCode());
    // 'United States'
    doc.add("countryName", country.getName());
    // 99
    doc.add("countryConfidence", country.getConfidence());
    doc.add("countryGeoName", country.getGeoNameId());
    Location location = response.getLocation();
    // 44.9733,
    doc.add("latLon", location.getLatitude() + "," + location.getLongitude());
    // -93.2323
    // 3
    doc.add("accRadius", location.getAccuracyRadius());
    // 'America/Chicago'
    doc.add("timeZone", location.getTimeZone());
    doc.add("metroCode", location.getMetroCode());
    Postal postal = response.getPostal();
    // '55455'
    doc.add("postalCode", postal.getCode());
    // 40
    doc.add("postalConfidence", postal.getConfidence());
    RepresentedCountry rCountry = response.getRepresentedCountry();
    doc.add("countryType", rCountry.getType());
    Subdivision subdivision = response.getMostSpecificSubdivision();
    // 'Minnesota'
    doc.add("subDivName", subdivision.getName());
    // 'MN'
    doc.add("subDivIdoCode", subdivision.getIsoCode());
    // 90
    doc.add("subDivConfidence", subdivision.getConfidence());
    doc.add("subDivGeoNameId", subdivision.getGeoNameId());
    return doc;
}
Also used : CityResponse(com.maxmind.geoip2.model.CityResponse) Continent(com.maxmind.geoip2.record.Continent) RepresentedCountry(com.maxmind.geoip2.record.RepresentedCountry) RepresentedCountry(com.maxmind.geoip2.record.RepresentedCountry) Country(com.maxmind.geoip2.record.Country) City(com.maxmind.geoip2.record.City) Subdivision(com.maxmind.geoip2.record.Subdivision) Postal(com.maxmind.geoip2.record.Postal) Location(com.maxmind.geoip2.record.Location)

Aggregations

Subdivision (com.maxmind.geoip2.record.Subdivision)6 Location (com.maxmind.geoip2.record.Location)5 CityResponse (com.maxmind.geoip2.model.CityResponse)4 City (com.maxmind.geoip2.record.City)4 Continent (com.maxmind.geoip2.record.Continent)4 Country (com.maxmind.geoip2.record.Country)4 HashMap (java.util.HashMap)4 Postal (com.maxmind.geoip2.record.Postal)3 IOException (java.io.IOException)3 AddressNotFoundException (com.maxmind.geoip2.exception.AddressNotFoundException)2 GeoIp2Exception (com.maxmind.geoip2.exception.GeoIp2Exception)2 RepresentedCountry (com.maxmind.geoip2.record.RepresentedCountry)2 InetAddress (java.net.InetAddress)2 CountryResponse (com.maxmind.geoip2.model.CountryResponse)1 InsightsResponse (com.maxmind.geoip2.model.InsightsResponse)1 Traits (com.maxmind.geoip2.record.Traits)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 FlowFile (org.apache.nifi.flowfile.FlowFile)1