@Override @Transactional public void filter() { List<StubhubEvent> stubhubEventsList = stubhubDAO.getStubhubEvents(); // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // Get weekends including Friday of the current year // List<Date>weekendList = Utils.findWeekendsWithFriday(); if (stubhubEventsList != null) { List<Events> eventsList = new ArrayList<Events>(); int batch_size = 0; int pageId = 0; int count = 0, count1 = 0; try { logger.debug("stubhubEventsList:: " + stubhubEventsList.size()); for (StubhubEvent stubhubEvent : stubhubEventsList) { count++; logger.debug("Count:: " + count); // Get weekend date for Event date Date eventDate = Utils.getEventWeekendDates(stubhubEvent.getEvent_date_local()); if (eventDate != null) { count1++; logger.debug("Count1:: " + count1); batch_size++; Events events = new Events(); // events.setChannel(stubhubEvent.getChannel()); events.setCity(stubhubEvent.getCity()); events.setCurrency_code(stubhubEvent.getCurrency_code()); events.setDescription(stubhubEvent.getDescription()); events.setEvent_config_template(stubhubEvent.getEvent_config_template()); events.setEvent_config_template_id(stubhubEvent.getEvent_config_template_id()); events.setEvent_date(stubhubEvent.getEvent_date()); events.setEvent_date_local(stubhubEvent.getEvent_date_local()); events.setEvent_time_local(stubhubEvent.getEvent_time_local()); events.setEvent_date_time_local(stubhubEvent.getEvent_date_time_local()); events.setGenreUrlPath(stubhubBaseUrl + stubhubEvent.getGenreUrlPath()); events.setGeography_parent(stubhubEvent.getGeography_parent()); events.setKeywords_en_US(stubhubEvent.getKeywords_en_US()); events.setLatitude(stubhubEvent.getLatitude()); events.setLongitude(stubhubEvent.getLongitude()); events.setZip(stubhubEvent.getZip()); events.setLeaf(stubhubEvent.getLeaf()); events.setMaxPrice(stubhubEvent.getMaxPrice()); events.setMinPrice(stubhubEvent.getMinPrice()); events.setMaxSeatsTogether(stubhubEvent.getMaxSeatsTogether()); events.setMinSeatsTogether(stubhubEvent.getMinSeatsTogether()); // Get State Description for state code Countrylocation countrylocation = countryLocationDAO.getStateNameByStateCode(stubhubEvent.getState()); if (countrylocation != null) events.setState(countrylocation.getState()); else events.setState(stubhubEvent.getState()); events.setStateCode(stubhubEvent.getState()); events.setTimezone(stubhubEvent.getTimezone()); if (stubhubEvent.getTimezone_id() != null) events.setTimezone_id(Long.parseLong(stubhubEvent.getTimezone_id())); if (events.getTitle() != null && events.getTitle().equals("")) events.setTitle(stubhubEvent.getTitle()); else events.setTitle(stubhubEvent.getDescription()); events.setTotalTickets(stubhubEvent.getTotalTickets()); events.setUrlpath(stubhubBaseUrl + stubhubEvent.getUrlpath()); events.setVenue_config_name(stubhubEvent.getVenue_config_name()); events.setVenue_name(stubhubEvent.getVenue_name()); events.setAncestorGenreDescriptions(stubhubEvent.getAncestorGenreDescriptions()); // events.setPage(community); // events.setImage_url(stubhubEvent.getImage_url()); events.setEventSource("Stubhub"); events.setGenre_parent_name(stubhubEvent.getGenre_parent_name()); events.setChannel(stubhubEvent.getChannel()); Page isPageExist = eventsDAO.getPageByAbout(stubhubEvent.getGenre_parent_name()); logger.debug("Is page Exist " + isPageExist); if (isPageExist == null) { Page page = new Page(); page.setAbout(stubhubEvent.getGenre_parent_name()); page.setTag(stubhubEvent.getAncestorGenreDescriptions()); page.setCreatedtime(new Date()); page.setIsCommunity(true); page.setIsEvent(true); page.setIsOrganization(true); Pagetype pagetype = null; if (stubhubEvent.getChannel().toLowerCase().contains("sports")) { // pagetype = eventsDAO.getPageTypeByName("SPORT"); pagetype = new Pagetype(); pagetype.setPageTypeId(8); } else if (stubhubEvent.getChannel().toLowerCase().contains("theater")) { // pagetype = eventsDAO.getPageTypeByName("THEATER"); pagetype = new Pagetype(); pagetype.setPageTypeId(13); } else if (stubhubEvent.getChannel().toLowerCase().contains("concert")) { // pagetype = eventsDAO.getPageTypeByName("CONCERT"); pagetype = new Pagetype(); pagetype.setPageTypeId(14); } else { // pagetype = eventsDAO.getPageTypeByName("NIGHTLIFE"); pagetype = new Pagetype(); pagetype.setPageTypeId(15); } // User user = userDAO.getUserById(1); User user = new User(); user.setUserId(1); page.setUserByCreatorId(user); page.setUserByOwnerId(user); page.setPagetype(pagetype); page.setSource("Stubhub"); page.setPageUrl(stubhubBaseUrl + stubhubEvent.getGenreUrlPath()); page.setProfilePicture( stubhubImageUrl + stubhubEvent.getGeography_parent() + "/" + stubhubEvent.getImage_url()); // eventsDAO.savePage(page,batch_size); // pageId = eventsDAO.getPageByAbout(stubhubEvent.getGenre_parent_name()); // logger.debug("After save page:: "+pageId); // page.setPageId(pageId); events.setPage(page); } else { events.setPage(isPageExist); } // eventsList.add(events); eventsDAO.saveEvents(events, batch_size); } /*if(count1 > 100) break;*/ } // eventsDAO.saveEvents(eventsList, batch_size); } catch (Exception e) { logger.debug("Error in filter::: " + e.getMessage()); e.printStackTrace(); } } }
/** * This creates combined search result list from business,page and deals * * @param businessList * @param dealsList * @param pageList * @param searchResultList * @return */ private List<SearchResult> getSearchResults( int userId, List<Business> businessList, List<Deals> dealsList, List<Page> pageList, List<Events> eventsList, List<SearchResult> searchResultList, String category, int minPrice, int maxPrice) { // Add results for Events if (eventsList != null) { for (Events events : eventsList) { SearchResult searchResult = new SearchResult(); // Check if event is already favorite or not Eventuserlikes eventProperty = userDAO.getUserEventProperties(userId, events.getEventId()); if (eventProperty != null) { searchResult.setIsFavorite(eventProperty.getIsFavorite()); searchResult.setIsBooked(eventProperty.getIsBooked()); } Page page = events.getPage(); /*List<CommunityReview> communityReviewList = eventsDAO.getCommunityReviewByPageId(page.getPageId()); int rating = 0; int count = 0; if(communityReviewList != null && !communityReviewList.isEmpty()) { for(CommunityReview communityReview:communityReviewList) { rating = rating + communityReview.getRating(); count++; } double avg = (double)rating/count; searchResult.setRating(avg); }*/ logger.debug("events.getPage():: " + events.getPage()); double avgRating = 0.0; if (events.getPage() != null) { avgRating = eventsDAO.getCommunityReviewByPageId(events.getPage().getPageId()); } searchResult.setRating(avgRating); searchResult.setId(events.getEventId()); searchResult.setCity(events.getCity()); searchResult.setName(events.getTitle()); searchResult.setType("Event"); searchResult.setStartDate(events.getEvent_date_time_local().toString()); searchResult.setEndDate(events.getEvent_date_time_local().toString()); // searchResult.setImageUrl(events.getImage_url()); searchResult.setWebsiteUrl(events.getUrlpath()); searchResult.setCategory(page.getPagetype().getPageType()); searchResult.setSource(events.getEventSource()); searchResult.setTimeLine( Utils.getTimeLineForEvent(events.getEvent_date_local(), events.getEvent_time_local())); searchResult.setTimeSlot(events.getEvent_time_local()); String address = events.getVenue_name() + "\n" + events.getCity() + "," + events.getState() + " " + events.getZip(); searchResult.setAddress(address); searchResult.setZipCode(events.getZip()); if (events.getLatitude() != null) searchResult.setLatitude(Double.parseDouble(events.getLatitude())); if (events.getLongitude() != null) searchResult.setLongitude(Double.parseDouble(events.getLongitude())); searchResultList.add(searchResult); } } // Add results for Deals if (dealsList != null) { for (Deals deals : dealsList) { Business business = deals.getBusiness(); SearchResult searchResult = new SearchResult(); // Check if deal is already favorite or not Dealsusage dealProperty = userDAO.getUserDealProperties(userId, deals.getId()); if (dealProperty != null) { searchResult.setIsFavorite(dealProperty.getIsFavorite()); searchResult.setIsBooked(dealProperty.getIsBooked()); } searchResult.setId(deals.getId()); searchResult.setCity(deals.getBusiness().getCity()); searchResult.setName(deals.getTitle()); searchResult.setType("Deal"); searchResult.setStartDate(deals.getStartAt().toString()); searchResult.setEndDate(deals.getEndAt().toString()); searchResult.setImageUrl(deals.getLargeImageUrl()); searchResult.setWebsiteUrl(deals.getDealUrl()); searchResult.setCategory(category); if (business != null) { if (business.getRating() != null) searchResult.setRating(business.getRating()); searchResult.setMerhcantName(business.getName()); } searchResult.setSource(deals.getDealSource()); // Get price and discount Dealoption dealoption = dealsDAO.getDealOptionByDealId(deals.getId(), minPrice, maxPrice); if (dealoption != null) { if (dealoption.getFormattedOriginalPrice() != null) searchResult.setPrice(dealoption.getFormattedOriginalPrice()); else searchResult.setPrice("$" + dealoption.getOriginalPrice()); searchResult.setDiscount(dealoption.getDiscountPercent()); // Get Address of redemption location logger.debug("getting location.........."); if (dealoption.getDealredemptionlocations() != null && !dealoption.getDealredemptionlocations().isEmpty()) { Dealredemptionlocation dealredemptionlocation = (Dealredemptionlocation) dealoption.getDealredemptionlocations().iterator().next(); logger.debug("getting location.........." + dealredemptionlocation); if (dealredemptionlocation != null) { String address = dealredemptionlocation.getName() + "\n" + dealredemptionlocation.getStreetAddress1() + "\n" + dealredemptionlocation.getCity() + "," + dealredemptionlocation.getState() + " " + dealredemptionlocation.getPostalCode(); searchResult.setAddress(address); if (dealredemptionlocation.getLattitude() != null) searchResult.setLatitude(Double.parseDouble(dealredemptionlocation.getLattitude())); if (dealredemptionlocation.getLongitude() != null) searchResult.setLongitude( Double.parseDouble(dealredemptionlocation.getLongitude())); searchResult.setZipCode(dealredemptionlocation.getPostalCode()); } } else { if (business != null) { if (business.getDisplayAddress() != null) searchResult.setAddress( business.getDisplayAddress().replaceAll("[<>\\[\\],-]", "")); if (business.getLattitude() != null) searchResult.setLatitude(Double.parseDouble(business.getLattitude())); if (business.getLongitude() != null) searchResult.setLongitude(Double.parseDouble(business.getLongitude())); searchResult.setZipCode(business.getPostalCode()); } } } searchResultList.add(searchResult); } } // Add results for Community if (pageList != null) { for (Page page : pageList) { SearchResult searchResult = new SearchResult(); // Get recent event date for community Object[] event_date = eventsDAO.getRecentEventDetails(page.getPageId()); if (event_date != null) { Date date = (Date) event_date[0]; searchResult.setStartDate(date.toString()); searchResult.setEndDate(date.toString()); searchResult.setTimeLine(Utils.getTimeLineForEvent(date, event_date[1].toString())); searchResult.setTimeSlot(event_date[1].toString()); if (event_date[2] != null && !event_date[2].toString().trim().equals("")) searchResult.setLatitude(Double.parseDouble(event_date[2].toString())); if (event_date[3] != null && !event_date[3].toString().trim().equals("")) searchResult.setLongitude(Double.parseDouble(event_date[3].toString())); if (event_date[4] != null && !event_date[4].toString().trim().equals("")) searchResult.setZipCode(event_date[4].toString()); } // Check if business is already favorite or not Pageuserlikes pageuserlikes = userDAO.getUserPageProperties(userId, page.getPageId()); if (pageuserlikes != null) { searchResult.setIsFavorite(pageuserlikes.getIsFavorite()); searchResult.setIsBooked(pageuserlikes.getIsBooked()); } searchResult.setId(page.getPageId()); /*List<CommunityReview> communityReviewList = eventsDAO.getCommunityReviewByPageId(page.getPageId()); int rating = 0; int count = 0; if(communityReviewList != null && !communityReviewList.isEmpty()) { for(CommunityReview communityReview:communityReviewList) { rating = rating + communityReview.getRating(); count++; }20 double avg = (double)rating/count; logger.debug("avg rating =>"+avg); searchResult.setRating(avg); } else searchResult.setRating(0);*/ double avgRating = eventsDAO.getCommunityReviewByPageId(page.getPageId()); searchResult.setRating(avgRating); if (page.getBusiness() != null) searchResult.setCity(page.getBusiness().getCity()); searchResult.setName(page.getAbout()); searchResult.setType("Community"); searchResult.setImageUrl(page.getProfilePicture()); searchResult.setWebsiteUrl(page.getPageUrl()); searchResult.setCategory(page.getPagetype().getPageType()); searchResult.setSource(page.getSource()); searchResultList.add(searchResult); } } // Add results for business if (businessList != null) { for (Business business : businessList) { SearchResult searchResult = new SearchResult(); Page page = eventsDAO.getPageByBusinessId(business.getId()); if (page != null) { // Check if business is already favorite or not Pageuserlikes pageuserlikes = userDAO.getUserPageProperties(userId, page.getPageId()); if (pageuserlikes != null) { searchResult.setIsFavorite(pageuserlikes.getIsFavorite()); searchResult.setIsBooked(pageuserlikes.getIsBooked()); } } else { Funboard funboard = funBoardDAO.isFunBoardExists(userId, business.getId(), null); if (funboard != null) searchResult.setIsBooked(true); } searchResult.setId(business.getId()); searchResult.setCity(business.getCity()); searchResult.setName(business.getName()); searchResult.setType("Business"); searchResult.setImageUrl(business.getImageUrl()); searchResult.setWebsiteUrl(business.getWebsiteUrl()); searchResult.setCategory(category); if (business.getRating() != null) searchResult.setRating(business.getRating()); searchResult.setSource(business.getSource()); searchResult.setZipCode(business.getPostalCode()); if (business.getLattitude() != null) searchResult.setLatitude(Double.parseDouble(business.getLattitude())); if (business.getLongitude() != null) searchResult.setLongitude(Double.parseDouble(business.getLongitude())); if (business.getDisplayAddress() != null) searchResult.setAddress(business.getDisplayAddress().replaceAll("[<>\\[\\],-]", "")); searchResultList.add(searchResult); } } return searchResultList; }