private Brand brandWithSeries(int series) {
   Brand brand = new Brand();
   brand.setSeriesRefs(
       Iterables.limit(
           Iterables.cycle(new SeriesRef(1234L, "uri", "sk", 1, new DateTime(DateTimeZones.UTC))),
           series));
   return brand;
 }
示例#2
0
 private Brand extractSummaryBrand(ProgData progData, String originalURI, Timestamp updatedAt) {
   Brand summaryBrand = new Brand();
   summaryBrand.setCanonicalUri(
       originalURI.replace(Publisher.PA.key(), Publisher.PA_SERIES_SUMMARIES.key()));
   summaryBrand.setPublisher(Publisher.PA_SERIES_SUMMARIES);
   summaryBrand.setLongDescription(progData.getSeriesSummary());
   summaryBrand.setLastUpdated(updatedAt.toDateTimeUTC());
   return summaryBrand;
 }
  @Test
  public void testScoresNullWhenSeriesContainerWithSeriesCountsOutOfRange() {

    final Brand subject = brandWithSeries(5);

    when(contentResolver.findByCanonicalUris(
            ImmutableList.copyOf(Iterables.transform(subject.getSeriesRefs(), SeriesRef.TO_URI))))
        .thenReturn(ResolvedContent.builder().putAll(series(5)).build());

    ScoredCandidates<Container> score =
        scorer.score(subject, ImmutableSet.<Container>of(brandWithSeries(7)), desc());

    assertThat(Iterables.getOnlyElement(score.candidates().values()), is(Score.nullScore()));
  }
  @Test
  @SuppressWarnings("unchecked")
  public void testScoresNullWhenCandidateHasNoSeries() {

    Brand subject = brandWithSeries(1);
    Brand candidate = brandWithSeries(0);

    when(contentResolver.findByCanonicalUris(
            ImmutableList.copyOf(Iterables.transform(subject.getSeriesRefs(), SeriesRef.TO_URI))))
        .thenReturn(ResolvedContent.builder().putAll(series(1)).build());

    ScoredCandidates<Container> score = scorer.score(subject, ImmutableSet.of(candidate), desc());

    assertThat(Iterables.getOnlyElement(score.candidates().values()), is(Score.nullScore()));
    verify(contentResolver).findByCanonicalUris((Iterable<String>) any());
  }
示例#5
0
  private Optional<Brand> getBrand(ProgData progData, Channel channel, Timestamp updatedAt) {

    Optional<Brand> possibleBrand = getBrandWithoutChannel(progData, updatedAt);
    if (possibleBrand.isPresent()) {
      Brand brand = possibleBrand.get();
      brand.setSpecialization(specialization(progData, channel));
      brand.setMediaType(channel.getMediaType());
      setImages(
          progData.getPictures(),
          brand,
          PA_PICTURE_TYPE_BRAND,
          PA_PICTURE_TYPE_SERIES,
          Maybe.<String>nothing());
    }

    return possibleBrand;
  }
  Element createSeriesElem(
      Series series, Brand parent, DateTime originalPublicationDate, String lastModified) {
    Element element = createElement("TVSeason", LAKEVIEW);
    String applicationSpecificData = seriesAtomUri(findTagAlias(series));
    String seriesId = seriesId(series);
    String providerMediaId = providerMediaId(series);
    addIdElements(element, seriesId, providerMediaId);

    if (genericTitlesEnabled) {
      if (series.getSeriesNumber() != null) {
        addTitleElements(element, String.format("Series %d", series.getSeriesNumber()));
      } else if (!Strings.isNullOrEmpty(series.getTitle())) {
        addTitleElements(element, String.format("Series %d", series.getTitle()));
      } else {
        addTitleElements(element, parent.getTitle());
      }
    } else if (Strings.isNullOrEmpty(series.getTitle())
        || series.getTitle().matches("(?i)series \\d+")) {
      addTitleElements(
          element, String.format("%s Series %s", parent.getTitle(), series.getSeriesNumber()));
    } else {
      addTitleElements(element, series.getTitle());
    }

    Set<String> genres =
        Iterables.isEmpty(series.getGenres()) ? parent.getGenres() : series.getGenres();
    appendCommonElements(
        element,
        series,
        originalPublicationDate,
        lastModified,
        applicationSpecificData,
        genres,
        null);

    element.appendChild(
        stringElement("SeasonNumber", LAKEVIEW, String.valueOf(series.getSeriesNumber())));
    element.appendChild(stringElement("SeriesId", LAKEVIEW, brandId(parent)));

    return element;
  }
示例#7
0
  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 Element createBrandElem(
      Brand brand,
      DateTime originalPublicationDate,
      DateTime brandEndDate,
      String lastModified,
      LakeviewContentGroup contentGroup,
      int addedSeasons) {

    Element element = createElement("TVSeries", LAKEVIEW);
    addIdElements(element, brandId(brand), providerMediaId(brand));
    addTitleElements(
        element, Strings.isNullOrEmpty(brand.getTitle()) ? "EMPTY BRAND TITLE" : brand.getTitle());

    appendCommonElements(
        element,
        brand,
        originalPublicationDate,
        lastModified,
        brandAtomUri(findTagAlias(brand)),
        brand.getGenres(),
        null);
    if (addedSeasons > 0) {
      element.appendChild(
          stringElement("TotalNumberOfSeasons", LAKEVIEW, String.valueOf(addedSeasons)));
    }

    element.appendChild(
        stringElement(
            "TotalNumberOfEpisodes", LAKEVIEW, String.valueOf(countEpisodes(contentGroup))));

    if (brand.getPresentationChannel() != null
        && channelResolver.fromKey(brand.getPresentationChannel()).hasValue()) {
      element.appendChild(
          stringElement(
              "Network",
              LAKEVIEW,
              channelResolver.fromKey(brand.getPresentationChannel()).requireValue().getTitle()));
    } else {
      List<Broadcast> broadcasts = extractBroadcasts(contentGroup.episodes());
      if (!broadcasts.isEmpty()) {
        element.appendChild(stringElement("Network", LAKEVIEW, extractNetwork(broadcasts)));
      } else {
        return null;
      }
    }

    if (brandEndDate != null) {
      element.appendChild(
          stringElement("EndYear", LAKEVIEW, String.valueOf(brandEndDate.getYear())));
    }

    return element;
  }
示例#9
0
  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);
  }
示例#10
0
  private Brand getBrandSummary(ProgData progData, Brand brand, Timestamp updatedAt) {
    String uri =
        brand.getCanonicalUri().replace(Publisher.PA.key(), Publisher.PA_SERIES_SUMMARIES.key());
    Maybe<Identified> maybeBrandSummary =
        contentResolver.findByCanonicalUris(ImmutableList.of(uri)).getFirstValue();
    Brand brandSummary;

    if (maybeBrandSummary.isNothing()) {
      brandSummary = new Brand();
      brandSummary.setCanonicalUri(uri);
      brandSummary.setPublisher(Publisher.PA_SERIES_SUMMARIES);
      brandSummary.setEquivalentTo(ImmutableSet.of(LookupRef.from(brand)));
    } else {
      brandSummary = (Brand) maybeBrandSummary.requireValue();
    }

    brandSummary.setLongDescription(progData.getSeriesSummary());
    brandSummary.setLastUpdated(updatedAt.toDateTimeUTC());

    return brandSummary;
  }
示例#11
0
 private Alias generateAliasFor(Brand content) {
   return PaHelper.getBrandAlias(content.getId().toString());
 }
示例#12
0
  @Override
  public ContentHierarchyAndSummaries process(
      ProgData progData, Channel channel, DateTimeZone zone, Timestamp updatedAt) {
    try {
      if (!Strings.isNullOrEmpty(progData.getSeriesId())
          && IGNORED_BRANDS.contains(progData.getSeriesId())) {
        return null;
      }

      Brand brandSummary = null;
      Series seriesSummary = null;

      Optional<Brand> possibleBrand = getBrand(progData, channel, updatedAt);
      if (possibleBrand.isPresent()) {
        Brand originalBrand = possibleBrand.get();
        if (hasBrandSummary(progData)) {
          brandSummary = extractSummaryBrand(progData, originalBrand.getCanonicalUri(), updatedAt);
          brandSummary.setEquivalentTo(ImmutableSet.of(LookupRef.from(originalBrand)));
        }
      }

      Optional<Series> possibleSeries = getSeries(progData, channel, updatedAt);
      if (possibleSeries.isPresent()) {
        Series originalSeries = possibleSeries.get();
        if (hasSeriesSummary(progData)) {
          seriesSummary =
              extractSummarySeries(progData, originalSeries.getCanonicalUri(), updatedAt);
          seriesSummary.setEquivalentTo(ImmutableSet.of(LookupRef.from(originalSeries)));
        }
      }

      ItemAndBroadcast itemAndBroadcast =
          isClosedBrand(possibleBrand)
              ? getClosedEpisode(possibleBrand.get(), progData, channel, zone, updatedAt)
              : getFilmOrEpisode(
                  progData,
                  channel,
                  zone,
                  possibleBrand.isPresent() || possibleSeries.isPresent(),
                  updatedAt);

      Item item = itemAndBroadcast.getItem();
      item.setGenericDescription(isGenericDescription(progData));
      item.setLastUpdated(updatedAt.toDateTimeUTC());

      return new ContentHierarchyAndSummaries(
          possibleBrand,
          possibleSeries,
          item,
          itemAndBroadcast.getBroadcast().requireValue(),
          Optional.fromNullable(brandSummary),
          Optional.fromNullable(seriesSummary));
    } catch (Exception e) {
      e.printStackTrace();
      log.record(
          new AdapterLogEntry(Severity.ERROR)
              .withCause(e)
              .withSource(PaProgrammeProcessor.class)
              .withDescription(e.getMessage()));
    }
    return null;
  }
  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;
  }