All pastes #2121358 Raw Edit

Unnamed

public java v1 · immutable
#2121358 ·published 2012-02-24 18:17 UTC
rendered paste body
public View executeSpringForFeeds(HttpServletRequest request, HttpServletResponse response,			@PathVariable("neighborhoodId") String neighborhoodIdStr) {		// get the currently logged in user		IUnifiedAuthenticator uauth = (IUnifiedAuthenticator)request.getAttribute(IUnifiedAuthenticator.UNIFIED_AUTH_REQUEST_ATT);		Login login = uauth.getLogin();				// Do we have a neighborhood? Get the neighborhood ID from the query string.		Long neighborhoodId = Long.parseLong(neighborhoodIdStr.trim());		Neighborhood neighborhood = NeighborhoodRODAO.get(neighborhoodId);				RegionId regionId = new RegionId(RegionType.NEIGHBORHOOD, neighborhoodId);				// Serialize to JSON		String json = "";				List<FeedItem> feedItems = new ArrayList<FeedItem>();				try {			List<Listing> allPropertyListings = Lists.newArrayList();			String mlsServerBase ="mlsPhotoServerBaseUrl"; 						// Populate new homes feed items			List<SearchResultListing> newHomeItems = getSearchResultForNeighborhood(OrderBy.ADDED, regionId, login);			for(SearchResultItem sri : newHomeItems) {				FeedItem fi = new FeedItem();				fi.type = "newHome";				fi.date = sri.getListing().getListingAddedDate();				fi.data = Maps.newHashMap();				fi.data.put("listingAgentName", sri.getListing().getListingAgent() != null ? sri.getListing().getListingAgent().getName() : "Scott Nagel");				fi.data.put("listingPropertyType", sri.getListing().getPropertyType().getName());				fi.data.put("listingAddressStreet", sri.getListing().getAddress().getFullDisplayString());				fi.data.put("listingPhoto", ListingPhotoHelper.findPrimaryMidsizePhotoUrl(sri.getListing(), mlsServerBase));				feedItems.add(fi);								allPropertyListings.add(sri.getListing());			}						// Populate upcoming open homes feed items			List<SearchResultListing> openHouseItems = getSearchResultForNeighborhood(OrderBy.OPEN_HOUSE, regionId, login);			for(SearchResultListing sri : openHouseItems) {				FeedItem fi = new FeedItem();				fi.type = "openHouseHome";				fi.date = sri.getLastUpdatedDate();				fi.data = Maps.newHashMap();				fi.data.put("listingNextOpenHouseStart", sri.getNextOpenHouseStart().toString());				fi.data.put("listingNextOpenHouseEnd", sri.getNextOpenHouseEnd().toString());				fi.data.put("listingAddressStreet", sri.getListing().getAddress().getFullDisplayString());				fi.data.put("listingPhoto", ListingPhotoHelper.findPrimaryMidsizePhotoUrl(sri.getListing(), mlsServerBase));				feedItems.add(fi);				allPropertyListings.add(sri.getListing());            }						// Populate price reduced feed items			List<SearchResultListing> priceReducedItems = getSearchResultForNeighborhood(OrderBy.REDUCED, regionId, login);			for(SearchResultListing sri : priceReducedItems) {				allPropertyListings.add(sri.getListing());				FeedItem fi = new FeedItem();				fi.type = "priceReducedHome";				fi.date = sri.getListing().getLastPriceReductionDate();				fi.data = Maps.newHashMap();				fi.data.put("listingOldPrice", sri.getOriginalPrice());				fi.data.put("listingNewPrice", sri.getListingPrice());				fi.data.put("listingAddressStreet", sri.getListing().getAddress().getFullStreetString());				fi.data.put("listingPhoto", ListingPhotoHelper.findPrimaryMidsizePhotoUrl(sri.getListing(), mlsServerBase));				feedItems.add(fi);			}						// Populate recently sold feed items			List<SearchResultProperty> recentlySoldItems = getSearchResultForNeighborhoodSales(regionId, login);			for(SearchResultProperty srp : recentlySoldItems) {				allPropertyListings.add(srp.getListing());				FeedItem fi = new FeedItem();				fi.type = "recentlySoldHome";				fi.date = srp.getLastSaleDate();				fi.data = Maps.newHashMap();				fi.data.put("listingSoldPrice", srp.getLastSalePrice());				fi.data.put("listingAddressStreet", srp.getListing().getAddress().getFullStreetString());				fi.data.put("listingPhoto", ListingPhotoHelper.findPrimaryMidsizePhotoUrl(srp.getListing(), mlsServerBase));				feedItems.add(fi);			}						feedItems.addAll(nbrhoodDealHelper.getRecentDealsInNeighborhood(neighborhood));			feedItems.addAll(nbrhoodDealHelper.getRecentListingActivationsInNeighborhood(neighborhood));												for ( Listing listing : allPropertyListings ) {				// Loop through all the listings in the searches above and extract the ones that are favorited				List<FavoriteProperty> favorites = favoritePropertyDAO.findAllByPropertyId(listing.getProperty().getId());								if ( favorites != null && favorites.size() > 0 ) {					Date mostRecent = favorites.get(0).getCreated();					for ( FavoriteProperty favs : favorites ) {						if ( mostRecent == null || favs.getCreated().after(mostRecent) ) {							mostRecent = favs.getCreated();						}					}									// Add one favorite feed item per listing					FeedItem fi = new FeedItem();					fi.type = "favorite";					fi.date = mostRecent;					fi.data = Maps.newHashMap();					fi.data.put("listingId", listing.getId()); 					fi.data.put("numTotalFavorites", favorites.size());					fi.data.put("listingAddressStreet", listing.getAddress().getFullStreetString());					fi.data.put("listingPhoto", ListingPhotoHelper.findPrimaryMidsizePhotoUrl(listing, mlsServerBase));					feedItems.add(fi);				}								// Loop through all the listings above and extract the ones that have tours				List<TourItem> tourItems = tourItemDAO.findAllByListing(listing);				for ( TourItem tour : tourItems ) {					FeedItem fi2 = new FeedItem();					fi2.type = "tour";					fi2.date = tour.getCreatedDate();					fi2.data = Maps.newHashMap();					fi2.data.put("listingId", listing.getId());					fi2.data.put("listingAddressStreet", listing.getAddress().getFullStreetString());					fi2.data.put("listingPhoto", ListingPhotoHelper.findPrimaryMidsizePhotoUrl(listing, mlsServerBase));					fi2.data.put("touringAgentName", tour.getTour().getAgent() != null ? tour.getTour().getAgent().getPerson().getName() : "Scott Nagel");					feedItems.add(fi2);				}			}		} catch (SearchException e) {			// TODO Auto-generated catch block			e.printStackTrace();		}				// Sort our feed items		Collections.sort(feedItems);		Map<String, Object> data = Maps.newHashMap();		data.put("data", feedItems);		json = new Gson().toJson(data);		return new CommentFilteredJSONView(new ApiResult(Code.NO_ERROR, "Success.", json));	}