GoogleLatitudeUpdater extends AbstractUpdater implements FileUploadSupport { void parseLocation(final ApiKey apiKey, final JsonParser jParser, final List<LocationFacet> locations) throws IOException { LocationFacet locationFacet = new LocationFacet(); if (apiKey!=null) { locationFacet.apiKeyId = apiKey.getId(); locationFacet.guestId = apiKey.getGuestId(); } locationFacet.timeUpdated = System.currentTimeMillis(); locationFacet.source = LocationFacet.Source.GOOGLE_LATITUDE; do { String fieldName = jParser.getCurrentName(); final JsonToken jsonToken = jParser.nextValue(); if (jsonToken.isScalarValue()) { if (fieldName.equals("timestampMs")) { long ts = Long.valueOf(jParser.getText()); locationFacet.timestampMs = ts; locationFacet.start = ts; locationFacet.end = ts; locationFacet.api = 2; } else if (fieldName.equals("accuracy")) { int accuracy = jParser.getIntValue(); locationFacet.accuracy = accuracy; } else if (fieldName.equals("altitude")) { int altitude = jParser.getIntValue(); locationFacet.altitude = altitude; } else if (fieldName.equals("heading")) { int heading = jParser.getIntValue(); locationFacet.heading = heading; } else if (fieldName.equals("latitudeE7")) { int lat = jParser.getIntValue(); locationFacet.latitude = lat/1E7f; } else if (fieldName.equals("longitudeE7")) { int lon = jParser.getIntValue(); locationFacet.longitude = lon/1E7f; } else if (fieldName.equals("velocity")) { int speed = jParser.getIntValue(); locationFacet.speed = speed; } } else { final JsonNode junk = jParser.readValueAsTree(); logger.info("we are not interested in this junk: " + junk.toString()); } } while (jParser.nextToken() != JsonToken.END_OBJECT); locations.add(locationFacet); } GoogleLatitudeUpdater(); @Override void updateConnectorDataHistory(UpdateInfo updateInfo); void updateConnectorData(UpdateInfo updateInfo); @Override void setDefaultChannelStyles(ApiKey apiKey); @Override int importFile(final ApiKey apiKey, final File f);  }
@Test public void testParseLocation() throws Exception { JsonFactory jfactory = new JsonFactory(); JsonParser jParser = jfactory.createJsonParser(new StringReader("{\n" + " \"timestampMs\" : \"1376053800229\",\n" + " \"latitudeE7\" : 508261000,\n" + " \"longitudeE7\" : 43543660,\n" + " \"accuracy\" : 10\n" + " }")); while (jParser.nextToken()!= JsonToken.START_OBJECT); while (jParser.getCurrentName()==null) jParser.nextToken(); GoogleLatitudeUpdater updater = new GoogleLatitudeUpdater(); final ArrayList<LocationFacet> locations = new ArrayList<LocationFacet>(); updater.parseLocation(null, jParser, locations); assertTrue(locations.size()==1); final LocationFacet locationFacet = locations.get(0); assertTrue(locationFacet.timestampMs==1376053800229l); assertTrue(locationFacet.latitude==50.8261000f); assertTrue(locationFacet.longitude==4.3543660f); assertTrue(locationFacet.accuracy==10); }