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"); }
public boolean isHomeLocationNotSet(UserAccount userAccount) { try { Validate.notNull(userAccount); Validate.notNull(userAccount.getLocation()); Validate.notNull(userAccount.getLocation().getLatitude()); Validate.notNull(userAccount.getLocation().getLongitude()); } catch (IllegalArgumentException e) { return true; } return false; }
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; }