private Item getBasicFilmWithoutBroadcast(ProgData progData) { ImmutableList.Builder<String> uris = ImmutableList.builder(); Optional<String> rtFilmIdentifier = rtFilmIdentifierFor(progData); // Previously when constructing the uri we would failover to ProgId if the rtFilmIdentifier // was missing but still write to the same namespace. To avoid creating duplicates we have // to replicate this old behavior and use the rtFilmIdentifier for resolution when its // available String legacyFilmUri = rtFilmIdentifier.isPresent() ? PaHelper.getLegacyFilmUri(rtFilmIdentifier.get()) : PaHelper.getLegacyFilmUri(progData.getProgId()); uris.add(legacyFilmUri); uris.add(PaHelper.getAlias(progData.getProgId())); uris.add(PaHelper.getFilmUri(identifierFor(progData))); Map<String, Identified> resolvedContent = contentResolver.findByUris(uris.build()).asResolvedMap(); Film film = getFilmFromResolvedContent(progData, resolvedContent, legacyFilmUri); if (progData.getFilmYear() != null && MoreStrings.containsOnlyAsciiDigits(progData.getFilmYear())) { film.setYear(Integer.parseInt(progData.getFilmYear())); } return film; }
private Optional<Brand> getBrandWithoutChannel(ProgData progData, Timestamp updatedAt) { String brandId = progData.getSeriesId(); if (Strings.isNullOrEmpty(brandId) || Strings.isNullOrEmpty(brandId.trim())) { return Optional.absent(); } String brandUri = PaHelper.getBrandUri(brandId); Alias brandAlias = PaHelper.getBrandAlias(brandId); Maybe<Identified> possiblePrevious = contentResolver.findByCanonicalUris(ImmutableList.of(brandUri)).getFirstValue(); Brand brand = possiblePrevious.hasValue() ? (Brand) possiblePrevious.requireValue() : new Brand(brandUri, "pa:b-" + brandId, Publisher.PA); brand.addAlias(brandAlias); brand.setTitle(progData.getTitle()); brand.setDescription(Strings.emptyToNull(progData.getSeriesSynopsis())); setCertificate(progData, brand); setGenres(progData, brand); setTopicRefs(brand); if (isClosedBrand(Optional.of(brand))) { brand.setScheduleOnly(true); } brand.setLastUpdated(updatedAt.toDateTimeUTC()); return Optional.of(brand); }
private ItemAndBroadcast getFilm( ProgData progData, Channel channel, DateTimeZone zone, Timestamp updatedAt) { String filmUri = PaHelper.getFilmUri(identifierFor(progData)); Maybe<Identified> possiblePreviousData = contentResolver.findByCanonicalUris(ImmutableList.of(filmUri)).getFirstValue(); Film film; if (possiblePreviousData.hasValue()) { Identified previous = possiblePreviousData.requireValue(); if (previous instanceof Film) { film = (Film) previous; } else { film = new Film(); Item.copyTo((Episode) previous, film); } } else { film = getBasicFilm(progData); } film.addAlias(PaHelper.getFilmAlias(identifierFor(progData))); Optional<String> rtFilmIdentifier = rtFilmIdentifierFor(progData); if (rtFilmIdentifier.isPresent()) { film.addAlias(PaHelper.getRtFilmAlias(rtFilmIdentifier.get())); } film.setAliasUrls(ImmutableSet.of(PaHelper.getAlias(progData.getProgId()))); Broadcast broadcast = setCommonDetails(progData, channel, zone, film, updatedAt); if (progData.getFilmYear() != null && MoreStrings.containsOnlyAsciiDigits(progData.getFilmYear())) { film.setYear(Integer.parseInt(progData.getFilmYear())); } return new ItemAndBroadcast(film, Maybe.just(broadcast)); }
private Item getBasicEpisodeWithoutBroadcast(ProgData progData, boolean isEpisode) { String episodeUri = PaHelper.getEpisodeUri(identifierFor(progData)); Maybe<Identified> possiblePrevious = contentResolver.findByCanonicalUris(ImmutableList.of(episodeUri)).getFirstValue(); Item item; if (possiblePrevious.hasValue()) { Item previous = (Item) possiblePrevious.requireValue(); if (!(previous instanceof Episode) && isEpisode) { String message = String.format( "%s resolved as %s being ingested as Episode", episodeUri, previous.getClass().getSimpleName()); adapterLog.record(warnEntry().withSource(getClass()).withDescription(message)); log.info(message); item = convertItemToEpisode(previous); } else if (previous instanceof Episode && !isEpisode) { String message = String.format( "%s resolved as %s being ingested as Item", episodeUri, previous.getClass().getSimpleName()); adapterLog.record(errorEntry().withSource(getClass()).withDescription(message)); log.info(message); item = new Item(); Item.copyTo(previous, item); } else { item = previous; } } else { item = getBasicEpisode(progData, isEpisode); } if (SCHEDULED_ONLY_EPISODE.equals(episodeUri)) { item.setScheduleOnly(true); } item.addAlias(PaHelper.getEpisodeAlias(identifierFor(progData))); try { if (item instanceof Episode) { Episode episode = (Episode) item; episode.setSpecial(getBooleanValue(progData.getAttr().getSpecial())); episode.setEpisodeNumber(episodeNumber(progData)); episode.setSeriesNumber(seriesNumber(progData)); } } catch (NumberFormatException e) { // sometimes we don't get valid numbers log.warn("Failed to parse a numeric field for PA episode {}", episodeUri, e); } return item; }
private Optional<Series> getSeriesWithoutChannel(ProgData progData, Timestamp updatedAt) { if (Strings.isNullOrEmpty(progData.getSeriesNumber()) || Strings.isNullOrEmpty(progData.getSeriesId())) { return Optional.absent(); } String seriesUri = PaHelper.getSeriesUri(progData.getSeriesId(), progData.getSeriesNumber()); Alias seriesAlias = PaHelper.getSeriesAlias(progData.getSeriesId(), progData.getSeriesNumber()); Maybe<Identified> possiblePrevious = contentResolver.findByCanonicalUris(ImmutableList.of(seriesUri)).getFirstValue(); Series series = possiblePrevious.hasValue() ? (Series) possiblePrevious.requireValue() : new Series( seriesUri, "pa:s-" + progData.getSeriesId() + "-" + progData.getSeriesNumber(), Publisher.PA); series.addAlias(seriesAlias); if (progData.getEpisodeTotal() != null && progData.getEpisodeTotal().trim().length() > 0) { try { series.setTotalEpisodes(Integer.parseInt(progData.getEpisodeTotal().trim())); } catch (NumberFormatException e) { adapterLog.record( warnEntry() .withCause(e) .withSource(getClass()) .withDescription( "Couldn't parse episode_total %s", progData.getEpisodeTotal().trim())); } } if (progData.getSeriesNumber() != null && progData.getSeriesNumber().trim().length() > 0) { try { series.withSeriesNumber(Integer.parseInt(progData.getSeriesNumber().trim())); } catch (NumberFormatException e) { adapterLog.record( warnEntry() .withCause(e) .withSource(getClass()) .withDescription( "Couldn't parse series_number %s", progData.getSeriesNumber().trim())); } } series.setPublisher(Publisher.PA); setCertificate(progData, series); setGenres(progData, series); setTopicRefs(series); series.setLastUpdated(updatedAt.toDateTimeUTC()); return Optional.of(series); }
private Film getBasicFilm(ProgData progData) { Film film = new Film( PaHelper.getFilmUri(identifierFor(progData)), PaHelper.getEpisodeCurie(identifierFor(progData)), Publisher.PA); setBasicDetails(progData, film); return film; }
private ItemAndBroadcast getEpisode( ProgData progData, Channel channel, DateTimeZone zone, boolean isEpisode, Timestamp updatedAt) { String episodeUri = PaHelper.getEpisodeUri(identifierFor(progData)); Maybe<Identified> possiblePrevious = contentResolver.findByCanonicalUris(ImmutableList.of(episodeUri)).getFirstValue(); Item item; if (possiblePrevious.hasValue()) { item = (Item) possiblePrevious.requireValue(); if (!(item instanceof Episode) && isEpisode) { log.record( warnEntry() .withSource(getClass()) .withDescription( "%s resolved as %s being ingested as Episode", episodeUri, item.getClass().getSimpleName())); item = convertItemToEpisode(item); } else if (item instanceof Episode && !isEpisode) { log.record( errorEntry() .withSource(getClass()) .withDescription( "%s resolved as %s being ingested as Item", episodeUri, item.getClass().getSimpleName())); } } else { item = getBasicEpisode(progData, isEpisode); } item.addAlias(PaHelper.getEpisodeAlias(identifierFor(progData))); Broadcast broadcast = setCommonDetails(progData, channel, zone, item, updatedAt); try { if (item instanceof Episode) { Episode episode = (Episode) item; episode.setSpecial(getBooleanValue(progData.getAttr().getSpecial())); episode.setEpisodeNumber(episodeNumber(progData)); episode.setSeriesNumber(seriesNumber(progData)); } } catch (NumberFormatException e) { // sometimes we don't get valid numbers // log. } return new ItemAndBroadcast(item, Maybe.just(broadcast)); }
private void setCommonDetails(ProgData progData, Item episode, Optional<Channel> channel) { // Currently Welsh channels have Welsh titles/descriptions which flip the English ones, // resulting in many writes. We'll only take the Welsh title if we don't // already have a title from another channel boolean isWelshChannel = channel.isPresent() && channel.get().getUri().contains("wales"); if (episode.getTitle() == null || !isWelshChannel) { if (progData.getEpisodeTitle() != null) { episode.setTitle(progData.getEpisodeTitle()); } else { episode.setTitle(progData.getTitle()); } } setDescription(progData, episode, isWelshChannel); if (channel.isPresent()) { episode.setMediaType(channel.get().getMediaType()); episode.setSpecialization(specialization(progData, channel.get())); } setGenres(progData, episode); setTopicRefs(episode); if (progData.getCountry() != null) { episode.setCountriesOfOrigin(countryMap.parseCountries(progData.getCountry())); } if (progData.getAttr() != null) { episode.setBlackAndWhite(getBooleanValue(progData.getAttr().getBw())); } episode.setPeople(people(progData)); setCertificate(progData, episode); // Adding a film alias only used to happen when type was film. Previously this was // decided based on the existence of the field rt_filmnumber. That's faulty, though, // so we changed it to use the film flag. In order to maintain backward-compatibilty // and only set the film alias when a rt_filmnumber value exists, we make that // check here. Optional<String> rtFilmIdentifier = rtFilmIdentifierFor(progData); if (rtFilmIdentifier.isPresent()) { episode.addAliasUrl(PaHelper.getLegacyFilmUri(rtFilmIdentifier.get())); episode.addAlias(PaHelper.getLegacyFilmAlias(rtFilmIdentifier.get())); } episode.addAliasUrl(PaHelper.getAlias(progData.getProgId())); episode.addAlias(PaHelper.getNewFilmAlias(identifierFor(progData))); }
private Broadcast broadcast( ProgData progData, Channel channel, DateTimeZone zone, Timestamp updateAt) { Duration duration = Duration.standardMinutes(Long.valueOf(progData.getDuration())); DateTime transmissionTime = getTransmissionTime(progData.getDate(), progData.getTime(), zone); Broadcast broadcast = new Broadcast(channel.getUri(), transmissionTime, duration) .withId(PaHelper.getBroadcastId(progData.getShowingId())); if (progData.getAttr() != null) { broadcast.setRepeat(isRepeat(channel, progData.getAttr())); broadcast.setSubtitled(getBooleanValue(progData.getAttr().getSubtitles())); broadcast.setSigned(getBooleanValue(progData.getAttr().getSignLang())); broadcast.setAudioDescribed(getBooleanValue(progData.getAttr().getAudioDes())); broadcast.setHighDefinition(getBooleanValue(progData.getAttr().getHd())); broadcast.setWidescreen(getBooleanValue(progData.getAttr().getWidescreen())); broadcast.setLive(getBooleanValue(progData.getAttr().getLive())); broadcast.setSurround(getBooleanValue(progData.getAttr().getSurround())); broadcast.setPremiere(getBooleanValue(progData.getAttr().getPremiere())); Boolean newSeries = getBooleanValue(progData.getAttr().getNewSeries()); Boolean newEpisode = getBooleanValue(progData.getAttr().getNewEpisode()); broadcast.setNewSeries(newSeries); broadcast.setNewEpisode(isNewEpisode(newSeries, newEpisode)); } broadcast.setLastUpdated(updateAt.toDateTimeUTC()); return broadcast; }
private Item getBasicEpisode(ProgData progData, boolean isEpisode) { Item item = isEpisode ? new Episode() : new Item(); item.setCanonicalUri(PaHelper.getEpisodeUri(identifierFor(progData))); item.setCurie("pa:e-" + identifierFor(progData)); item.setPublisher(Publisher.PA); setBasicDetails(progData, item); return item; }
@Override public Optional<ContentHierarchyAndSummaries> process( ProgData progData, Channel channel, DateTimeZone zone, Timestamp updatedAt) { try { log.trace("Channel: {} ProgData: {} UpdatedAt: {}", channel, progData, updatedAt); if (shouldNotProcess(progData)) { return Optional.absent(); } Optional<Brand> possibleBrand = getBrand(progData, channel, updatedAt); Brand brandSummary = null; if (possibleBrand.isPresent() && hasBrandSummary(progData)) { brandSummary = getBrandSummary(progData, possibleBrand.get(), updatedAt); } Optional<Series> possibleSeries = getSeries(progData, channel, updatedAt); Series seriesSummary = null; if (possibleSeries.isPresent() && hasSeriesSummary(progData)) { seriesSummary = getSeriesSummary(progData, possibleSeries.get(), updatedAt); } boolean isEpisode = possibleBrand.isPresent() || possibleSeries.isPresent(); ItemAndBroadcast itemAndBroadcast = isClosedBrand(possibleBrand) ? getClosedEpisode(progData, channel, zone, updatedAt) : getFilmOrEpisode(progData, channel, zone, isEpisode, updatedAt); Item item = itemAndBroadcast.getItem(); // TODO: there is an unknown bug preventing this from working (MBST-17174) if (!isEpisode) { item.setParentRef(null); } item.setGenericDescription(isGenericDescription(progData)); item.addAlias(PaHelper.getProgIdAlias(progData.getProgId())); item.setLastUpdated(updatedAt.toDateTimeUTC()); return Optional.of( new ContentHierarchyAndSummaries( possibleBrand, possibleSeries, item, itemAndBroadcast.getBroadcast().requireValue(), Optional.fromNullable(brandSummary), Optional.fromNullable(seriesSummary))); } catch (Exception e) { log.error("Failed to process PA programme data", e); adapterLog.record( new AdapterLogEntry(Severity.ERROR) .withCause(e) .withSource(PaProgrammeProcessor.class) .withDescription(e.getMessage())); } return Optional.absent(); }
private Optional<Brand> getBrand(ProgData progData, Channel channel, Timestamp updatedAt) { String brandId = progData.getSeriesId(); if (Strings.isNullOrEmpty(brandId) || Strings.isNullOrEmpty(brandId.trim())) { return Optional.absent(); } String brandUri = PaHelper.getBrandUri(brandId); Alias brandAlias = PaHelper.getBrandAlias(brandId); Maybe<Identified> possiblePrevious = contentResolver.findByCanonicalUris(ImmutableList.of(brandUri)).getFirstValue(); Brand brand = possiblePrevious.hasValue() ? (Brand) possiblePrevious.requireValue() : new Brand(brandUri, "pa:b-" + brandId, Publisher.PA); brand.addAlias(brandAlias); brand.setTitle(progData.getTitle()); brand.setDescription(Strings.emptyToNull(progData.getSeriesSynopsis())); brand.setSpecialization(specialization(progData, channel)); brand.setMediaType(channel.getMediaType()); setCertificate(progData, brand); setGenres(progData, brand); selectImages( progData.getPictures(), brand, PA_PICTURE_TYPE_BRAND, PA_PICTURE_TYPE_SERIES, Maybe.<String>nothing()); if (isClosedBrand(Optional.of(brand))) { brand.setScheduleOnly(true); } brand.setLastUpdated(updatedAt.toDateTimeUTC()); return Optional.of(brand); }
private Alias generateAliasFor(Item content) { return PaHelper.getAliasItem(content.getId().toString()); }
private Alias generateAliasFor(Film content) { return PaHelper.getFilmAlias(content.getId().toString()); }
private Alias generateAliasFor(Episode content) { return PaHelper.getEpisodeAlias(content.getId().toString()); }
private Alias generateAliasFor(Series content) { return PaHelper.getSeriesAlias( content.getId().toString(), content.getSeriesNumber().toString()); }
private Alias generateAliasFor(Brand content) { return PaHelper.getBrandAlias(content.getId().toString()); }