예제 #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);
  }
예제 #2
0
  public Event checkHomeLocation(RequestContext context) {
    // check location values
    UserAccount userAccount = (UserAccount) context.getFlowScope().get("userAccount");
    Location loc = userAccount.getLocation();

    // do we have lat/lon already?
    //		StringUtils.hasLength(loc.getLatitude());
    if (loc.getLatitude() != null && loc.getLongitude() != null) return success();

    try {
      Assert.hasLength(loc.getCity(), "City is empty");
      Assert.hasLength(loc.getStateInitial(), "State is empty");
      //			Assert.hasLength(loc.getZip(), "Zip is empty");
    } catch (IllegalArgumentException e) {
      context
          .getMessageContext()
          .addMessage(new MessageBuilder().error().defaultText(e.getMessage()).build());
      return result("needHomeLocation");
    }

    String homeLoc = loc.getAddress() + " " + loc.getCity() + " " + loc.getStateInitial();

    // get lat/lon from yahoo
    List<YahooPlaceResult> places = yahooPlaceFinderService.searchPlaceResult(homeLoc);
    Location location = userAccount.getLocation();
    if (places.size() > 0) {
      YahooPlaceResult place = places.get(0);
      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 (Exception e) {
        zip = new Zip();
        zip.setZipCode(place.getUzip().toString());
        zip.setLatitude(place.getLatitude().floatValue());
        zip.setLongitude(place.getLongitude().floatValue());
        zip.persist();
      }
      location.setZip(zip);
      userAccount.setWktLocation(place.getLongitude(), place.getLatitude());
      // save
      userAccount = userAccountService.updateUserAccount(userAccount);
      // set to flow
      context.getFlowScope().asMap().put("userAccount", userAccount);
    } else {
      context
          .getMessageContext()
          .addMessage(
              new MessageBuilder()
                  .error()
                  .defaultText("Could not find Lat/Lon. Returned " + places.size() + " places.")
                  .build());
      return result("needHomeLocation");
    }

    return result("needBabysitterAvailableTimes");
  }
예제 #3
0
 public UserAccount findUserAccount(String accountId) {
   Validate.notNull("Missing accountId", accountId);
   UserAccount account = userAccountService.findUserAccount(accountId);
   if (account.getLocation() == null) {
     account.setLocation(new Location());
   }
   return account;
 }