Example #1
0
  @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();
  }
Example #2
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;
  }