Exemplo n.º 1
0
  public UserAccount fillLocationFromFacebook(UserAccount userAccount) {
    Reference fbhome = facebook.userOperations().getUserProfile().getHometown();
    String loca = "";
    // FIXME move to "submit"
    if (fbhome != null) {
      List<YahooPlaceResult> places = yahooPlaceFinderService.searchPlaceResult(fbhome.getName());
      Location location = new Location();
      if (places.size() > 0) {
        YahooPlaceResult place = places.get(0);
        location.setCity(place.getCity());
        location.setLatitude(place.getLatitude().floatValue());
        location.setLongitude(place.getLongitude().floatValue());
        location.setStateInitial(place.getStateCode());
        Zip zip = null;
        try {
          zip = Zip.findZipsByZipCode(place.getUzip().toString()).getSingleResult();
        } catch (NoResultException e) {
          zip = new Zip();
          zip.setZipCode(place.getUzip().toString());
          zip.setLatitude(place.getLatitude().floatValue());
          zip.setLongitude(place.getLongitude().floatValue());
          zip.persist();
        }
        location.setZip(zip);

        // POINT( LON LAT )
        //				userAccount.setWkt("POINT( " + place.getLongitude() + " " + place.getLatitude() + "
        // )");
        userAccount.setWktLocation(place.getLongitude(), place.getLatitude());
      }
      userAccount.setLocation(location);
    }
    return userAccountService.updateUserAccount(userAccount);
  }