001package votorola.s.gwt.scene.geo; // Copyright 2011, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE. 002 003import votorola.a.*; 004import votorola.a.trust.*; 005import votorola.g.*; 006import votorola.g.net.*; 007import votorola.s.gwt.scene.feed.ss.*; 008 009 010/** A configurer of bites for the geographic map. 011 */ 012public final class GeomapBiterSS implements Biter 013{ 014 015 016 /** Constructs a GeomapBiterSS. 017 * 018 * @param _traceOrNull the network trace to use throughout the life of this 019 * biter; or null to use none. 020 */ 021 public GeomapBiterSS( final VoteServer.Run run, NetworkTrace _traceOrNull ) 022 { 023 geocoder = run.trustserver().geocoder(); 024 traceOrNull = _traceOrNull; 025 } 026 027 028 // - B i t e r ------------------------------------------------------------------------ 029 030 031 public void configure( final BiteJig bite ) 032 { 033 if( traceOrNull == null ) return; 034 035 for( final PersonJig person: bite.persons() ) 036 { 037 if( person.user() == null ) continue; 038 039 final Geocode geocode; 040 { 041 final TraceNode traceNode; 042 try { traceNode = person.traceNode( traceOrNull ); } 043 catch( votorola.s.gwt.scene.feed.NoSuchItem x ) { continue; } 044 catch( java.sql.SQLException x ) { throw new RuntimeException( x ); } 045 046 final String geohandle = traceNode.getGeohandle(); 047 if( geohandle == null ) continue; 048 049 final String cc = traceNode.getCountryCode(); 050 if( cc == null ) continue; 051 052 try { geocode = geocoder.geocode( Net.ccTLD(cc), geohandle ); } 053 catch( Exception x ) { throw VotorolaRuntimeException.castOrWrapped( x ); } 054 } 055 056 final ResidenceJig residence = person.setResidence(); 057 residence.setLat( (float)Math.toDegrees( geocode.latitude() )); 058 residence.setLon( (float)Math.toDegrees( geocode.longitude() )); 059 } 060 } 061 062 063 064//// P r i v a t e /////////////////////////////////////////////////////////////////////// 065 066 067 private final GoogleGeocoder geocoder; 068 069 070 071 private final NetworkTrace traceOrNull; 072 073 074}