private void stitch( Iterable<Episode> subjectsChildren, Map<String, EquivalenceSummary> summaryMap, Multimap<Container, Episode> equivalentsChildren, ReadableDescription desc) { for (Episode episode : subjectsChildren) { EquivalenceSummary summary = summaryMap.get(episode.getCanonicalUri()); if (summary != null) { stitch(episode, summary, equivalentsChildren, desc); } } }
private void stitch( Episode subjectEpisode, EquivalenceSummary equivalenceSummary, Multimap<Container, Episode> equivalentsChildren, ReadableDescription desc) { String subjectUri = subjectEpisode.getCanonicalUri(); desc.startStage(subjectUri); Map<Publisher, ContentRef> equivalents = equivalenceSummary.getEquivalents(); Set<ContentRef> additionalEquivs = Sets.newHashSet(); for (Entry<Container, Collection<Episode>> contentHierarchy : equivalentsChildren.asMap().entrySet()) { Container container = contentHierarchy.getKey(); for (Episode equivChild : contentHierarchy.getValue()) { if (matchingSequenceNumbers(subjectEpisode, equivChild)) { Publisher publisher = equivChild.getPublisher(); ContentRef existingEquiv = equivalents.get(publisher); if (existingEquiv != null) { desc.appendText( "existing strong equiv %s not overwritten by %s", existingEquiv, equivChild); } else { desc.appendText("adding %s (%s)", equivChild, container); additionalEquivs.add(ContentRef.valueOf(equivChild)); } break; } } } if (!additionalEquivs.isEmpty()) { additionalEquivs.addAll(equivalents.values()); lookupWriter.writeLookup(ContentRef.valueOf(subjectEpisode), additionalEquivs, publishers); } desc.finishStage(); }
Element createEpisodeElem( Episode episode, Brand container, Series series, DateTime originalPublicationDate, String lastModified) { Element element = createElement("TVEpisode", LAKEVIEW); Comment comment = new Comment("Atlas ID: " + episode.getCanonicalUri()); element.appendChild(comment); String assetId = extractAssetId(episode); String programmedId = extractProgrammedId(episode); String applicationSpecificData = episodeAtomUri(brandAtomUri(findTagAlias(container)), programmedId); String providerMediaId; if (series != null) { providerMediaId = providerMediaId(series) + "#" + assetId; } else { providerMediaId = providerMediaId(container) + "#" + assetId; } addIdElements(element, episodeId(episode), providerMediaId); if (genericTitlesEnabled) { if (episode.getEpisodeNumber() != null) { addTitleElements(element, String.format("Episode %d", episode.getEpisodeNumber())); } else if (!Strings.isNullOrEmpty(episode.getTitle())) { addTitleElements(element, episode.getTitle()); } else { addTitleElements(element, container.getTitle()); } } else if (Strings.isNullOrEmpty(episode.getTitle()) || episode.getTitle().matches("(?i)(series \\d+)? episode \\d+")) { addTitleElements( element, String.format( "%s Series %s Episode %s", container.getTitle(), episode.getSeriesNumber(), episode.getEpisodeNumber())); } else { addTitleElements(element, episode.getTitle()); } Element instances = createElement("Instances", LAKEVIEW); Element videoInstance = createElement("VideoInstance", LAKEVIEW); Element availabilities = createElement("Availabilities", LAKEVIEW); Element availability = createAvailabilityElement(episode, "Xbox360", PROVIDER_ID); if (addXboxOneAvailability) { availabilities.appendChild( createAvailabilityElement(episode, "XboxOne", XBOX_ONE_PROVIDER_ID)); } availabilities.appendChild(availability); videoInstance.appendChild(availabilities); videoInstance.appendChild(stringElement("ResolutionFormat", LAKEVIEW, "SD")); videoInstance.appendChild(stringElement("DeliveryFormat", LAKEVIEW, "Streaming")); videoInstance.appendChild(stringElement("PrimaryAudioLanguage", LAKEVIEW, "en-GB")); videoInstance.appendChild(stringElement("VideoInstanceType", LAKEVIEW, "Full")); instances.appendChild(videoInstance); appendCommonElements( element, episode, originalPublicationDate, lastModified, applicationSpecificData, episode.getGenres(), instances); element.appendChild( stringElement("EpisodeNumber", LAKEVIEW, String.valueOf(episode.getEpisodeNumber()))); element.appendChild( stringElement("DurationInSeconds", LAKEVIEW, String.valueOf(duration(episode)))); element.appendChild(stringElement("SeriesId", LAKEVIEW, brandId(container))); if (episode.getSeriesRef() != null) { element.appendChild(stringElement("SeasonId", LAKEVIEW, seriesId(series))); } return element; }