private Optional<Topic> createOrResolveVenue(SportsMatchData match) { String location = getVenueData(match.stats()); Optional<Topic> value = utility.createOrResolveVenue(location); if (!value.isPresent()) { log.error("Unable to resolve location: {}", location); } return value; }
private Optional<String> createTitle(SportsMatchData match, OptaSportType sportType) { Optional<String> team1 = fetchTeamName(match.teamData().get(0), sportType); Optional<String> team2 = fetchTeamName(match.teamData().get(1), sportType); if (!team1.isPresent() || !team2.isPresent()) { return Optional.absent(); } return Optional.of(team1.get() + " vs " + team2.get()); }
private Optional<DateTime> parseStartTime(SportsMatchData match, OptaSportType sport) { String dateStr = match.matchInformation().date().date(); Optional<DateTimeZone> timeZone = utility.fetchTimeZone(sport); if (!timeZone.isPresent()) { log.error("No time zone mapping found for sport {}", sport); return Optional.absent(); } return Optional.of(DATE_TIME_FORMATTER.withZone(timeZone.get()).parseDateTime(dateStr)); }
private Iterable<Organisation> parseOrganisations( SportsMatchData match, final OptaSportType sportType) { Iterable<Organisation> organisations = Iterables.transform( match.teamData(), new Function<SportsTeamData, Organisation>() { @Override public Organisation apply(SportsTeamData input) { return getTeamByUri(utility.createTeamUri(sportType, input.attributes().teamRef())) .orNull(); } }); return Iterables.filter(organisations, Predicates.notNull()); }
@Override public Optional<Event> parseEvent(SportsMatchData match, OptaSportType sport) { Optional<String> title = createTitle(match, sport); if (!title.isPresent()) { return Optional.absent(); } Optional<DateTime> startTime = parseStartTime(match, sport); if (!startTime.isPresent()) { log.error("Unable to identify start time for {}", title.get()); return Optional.absent(); } Optional<Topic> venue = createOrResolveVenue(match); if (!venue.isPresent()) { log.error("Unable to identify venue for {} on {}", title.get(), startTime.get().toString()); return Optional.absent(); } Optional<DateTime> endTime = utility.createEndTime(sport, startTime.get()); if (!endTime.isPresent()) { log.error("No duration mapping exists for sport {}", sport.name()); return Optional.absent(); } Event event = Event.builder() .withTitle(title.get()) .withPublisher(Publisher.OPTA) .withVenue(venue.get()) .withStartTime(startTime.get()) .withEndTime(endTime.get()) .withOrganisations(parseOrganisations(match, sport)) .withEventGroups(parseEventGroups(sport)) .build(); event.setCanonicalUri(utility.createEventUri(match.attributes().uId())); return Optional.of(event); }