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 Iterable<Topic> parseEventGroups(OptaSportType sport) { Optional<Set<Topic>> eventGroups = utility.parseEventGroups(sport); if (!eventGroups.isPresent()) { log.warn("No event groups mapped to sport {}", sport.name()); return ImmutableList.of(); } else { return eventGroups.get(); } }
private Optional<String> fetchTeamName(SportsTeamData teamData, OptaSportType sportType) { String teamId = teamData.attributes().teamRef(); Optional<Organisation> team = getTeamByUri(utility.createTeamUri(sportType, teamId)); if (!team.isPresent()) { log.error("team {} not present in teams list", teamId); return Optional.absent(); } return Optional.of(team.get().getTitle()); }
@Override public Optional<Organisation> parseOrganisation(SportsTeam team, OptaSportType sport) { Organisation organisation = new Organisation(); organisation.setCanonicalUri(utility.createTeamUri(sport, team.attributes().uId())); organisation.setPublisher(Publisher.OPTA); organisation.setTitle(team.name()); return Optional.of(organisation); }
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)); }
@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); }