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);
}