Search in sources :

Example 1 with Broadcast

use of org.atlasapi.content.Broadcast in project atlas-deer by atlasapi.

the class BroadcastWriter method write.

@Override
public void write(ResolvedBroadcast entity, FieldWriter writer, OutputContext ctxt) throws IOException {
    Broadcast broadcast = entity.getBroadcast();
    ResolvedChannel resolvedChannel = entity.getResolvedChannel();
    ImmutableList.Builder<Alias> aliases = ImmutableList.builder();
    Alias idAlias = aliasMapping.apply(broadcast);
    if (idAlias != null) {
        aliases.add(idAlias);
    }
    aliases.addAll(broadcast.getAliases());
    writer.writeList(aliasWriter, aliases.build(), ctxt);
    writer.writeField("transmission_time", broadcast.getTransmissionTime());
    writer.writeField("transmission_end_time", broadcast.getTransmissionEndTime());
    writer.writeField("broadcast_duration", Ints.saturatedCast(broadcast.getBroadcastDuration().getStandardSeconds()));
    writer.writeField("broadcast_on", codec.encode(resolvedChannel.getChannel().getId().toBigInteger()));
    // this includes the whole channel object in each broadcast.
    if (contextHasAnnotation(ctxt, Annotation.BROADCAST_CHANNEL)) {
        writer.writeObject(channelWriter, resolvedChannel, ctxt);
    }
    writer.writeField("schedule_date", broadcast.getScheduleDate());
    writer.writeField("repeat", broadcast.getRepeat());
    writer.writeField("subtitled", broadcast.getSubtitled());
    writer.writeField("signed", broadcast.getSigned());
    writer.writeField("audio_described", broadcast.getAudioDescribed());
    writer.writeField("high_definition", broadcast.getHighDefinition());
    writer.writeField("widescreen", broadcast.getWidescreen());
    writer.writeField("surround", broadcast.getSurround());
    writer.writeField("live", broadcast.getLive());
    writer.writeField("premiere", broadcast.getPremiere());
    writer.writeField("continuation", broadcast.getContinuation());
    writer.writeField("new_series", broadcast.getNewSeries());
    writer.writeField("new_episode", broadcast.getNewEpisode());
    writer.writeField("new_one_off", broadcast.getNewOneOff());
    writer.writeField("revised_repeat", broadcast.getRevisedRepeat());
    if (!broadcast.getBlackoutRestriction().isPresent()) {
        writer.writeField("blackout_restriction", null);
    } else {
        writer.writeObject(blackoutRestrictionWriter, broadcast.getBlackoutRestriction().get(), ctxt);
    }
}
Also used : ResolvedChannel(org.atlasapi.channel.ResolvedChannel) Broadcast(org.atlasapi.content.Broadcast) ResolvedBroadcast(org.atlasapi.content.ResolvedBroadcast) ImmutableList(com.google.common.collect.ImmutableList) Alias(org.atlasapi.entity.Alias)

Example 2 with Broadcast

use of org.atlasapi.content.Broadcast in project atlas-deer by atlasapi.

the class NextBroadcastAnnotation method nextBroadcast.

private Iterable<Broadcast> nextBroadcast(Iterable<Broadcast> broadcasts) {
    DateTime now = clock.now();
    DateTime earliest = null;
    Builder<Broadcast> filteredBroadcasts = ImmutableSet.builder();
    for (Broadcast broadcast : broadcasts) {
        DateTime transmissionTime = broadcast.getTransmissionTime();
        if (transmissionTime.isAfter(now) && (earliest == null || transmissionTime.isBefore(earliest))) {
            earliest = transmissionTime;
            filteredBroadcasts = ImmutableSet.<Broadcast>builder().add(broadcast);
        } else if (transmissionTime.isEqual(earliest)) {
            filteredBroadcasts.add(broadcast);
        }
    }
    return filteredBroadcasts.build();
}
Also used : Broadcast(org.atlasapi.content.Broadcast) ResolvedBroadcast(org.atlasapi.content.ResolvedBroadcast) DateTime(org.joda.time.DateTime)

Example 3 with Broadcast

use of org.atlasapi.content.Broadcast in project atlas-deer by atlasapi.

the class ScheduleMergerImplTest method overlappingOverrideTruncatesExistingShowEndTime.

/*
    Overrides      ------
    Original    -----
     */
@Test
public void overlappingOverrideTruncatesExistingShowEndTime() {
    DateTime originalStart = DateTime.parse("2016-02-10T14:42:41.242Z");
    DateTime originalEnd = originalStart.plus(Duration.standardHours(2));
    DateTime overrideStart = originalStart.plus(Duration.standardHours(1));
    DateTime overrideEnd = overrideStart.plus(Duration.standardHours(2));
    Interval interval = new Interval(originalStart, overrideEnd);
    Broadcast originalBroadcast = new Broadcast(channel, originalStart, originalEnd);
    Broadcast overrideBroadcast = new Broadcast(channel, overrideStart, overrideEnd);
    Item originalItem = mock(Item.class, "originalItem");
    when(originalItem.copy()).thenReturn(originalItem);
    ChannelSchedule originalSchedule = new ChannelSchedule(channel, interval, ImmutableList.of(new ItemAndBroadcast(originalItem, originalBroadcast)));
    Item overrideItem = mock(Item.class, "overrideItem");
    when(overrideItem.copy()).thenReturn(overrideItem);
    ChannelSchedule overrideSchedule = new ChannelSchedule(channel, interval, ImmutableList.of(new ItemAndBroadcast(overrideItem, overrideBroadcast)));
    ChannelSchedule merged = merger.merge(originalSchedule, overrideSchedule);
    List<ItemAndBroadcast> entries = merged.getEntries();
    assertThat(entries.size(), is(2));
    ItemAndBroadcast truncatedOriginal = entries.get(0);
    Broadcast truncatedBroadcast = truncatedOriginal.getBroadcast();
    assertThat(truncatedBroadcast.getTransmissionTime(), is(originalStart));
    assertThat(truncatedBroadcast.getTransmissionEndTime(), is(overrideStart));
    ItemAndBroadcast insertedOverride = entries.get(1);
    Broadcast insertedBroadcast = insertedOverride.getBroadcast();
    assertThat(insertedBroadcast.getTransmissionTime(), is(overrideStart));
    assertThat(insertedBroadcast.getTransmissionEndTime(), is(overrideEnd));
}
Also used : Item(org.atlasapi.content.Item) Broadcast(org.atlasapi.content.Broadcast) ItemAndBroadcast(org.atlasapi.content.ItemAndBroadcast) ChannelSchedule(org.atlasapi.schedule.ChannelSchedule) DateTime(org.joda.time.DateTime) Interval(org.joda.time.Interval) ItemAndBroadcast(org.atlasapi.content.ItemAndBroadcast) Test(org.junit.Test)

Example 4 with Broadcast

use of org.atlasapi.content.Broadcast in project atlas-deer by atlasapi.

the class ScheduleMergerImplTest method emptyOverrideScheduleReturnsAllOriginalItems.

/*
    Overrides
    Original ------  --------
     */
@Test
public void emptyOverrideScheduleReturnsAllOriginalItems() {
    DateTime originalStart0 = DateTime.parse("2016-02-10T14:42:41.242Z");
    DateTime originalEnd0 = originalStart0.plus(Duration.standardHours(2));
    DateTime originalStart1 = originalEnd0.plus(Duration.standardHours(3));
    DateTime originalEnd1 = originalStart1.plus(Duration.standardHours(2));
    Interval interval = new Interval(originalStart0, originalEnd1);
    Broadcast overrideBroadcast0 = new Broadcast(channel, originalStart0, originalEnd0);
    Broadcast overrideBroadcast1 = new Broadcast(channel, originalStart1, originalEnd1);
    Item originalItem = mock(Item.class, "originalItem");
    when(originalItem.copy()).thenReturn(originalItem);
    ChannelSchedule originalSchedule = new ChannelSchedule(channel, interval, ImmutableList.of(new ItemAndBroadcast(originalItem, overrideBroadcast0), new ItemAndBroadcast(originalItem, overrideBroadcast1)));
    ChannelSchedule overrideSchedule = new ChannelSchedule(channel, interval, ImmutableList.of());
    ChannelSchedule merged = merger.merge(originalSchedule, overrideSchedule);
    List<ItemAndBroadcast> entries = merged.getEntries();
    assertThat(entries.size(), is(2));
    ItemAndBroadcast original0 = entries.get(0);
    Broadcast broadcast0 = original0.getBroadcast();
    assertThat(broadcast0.getTransmissionTime(), is(originalStart0));
    assertThat(broadcast0.getTransmissionEndTime(), is(originalEnd0));
    ItemAndBroadcast original1 = entries.get(1);
    Broadcast broadcast1 = original1.getBroadcast();
    assertThat(broadcast1.getTransmissionTime(), is(originalStart1));
    assertThat(broadcast1.getTransmissionEndTime(), is(originalEnd1));
}
Also used : Item(org.atlasapi.content.Item) Broadcast(org.atlasapi.content.Broadcast) ItemAndBroadcast(org.atlasapi.content.ItemAndBroadcast) ChannelSchedule(org.atlasapi.schedule.ChannelSchedule) DateTime(org.joda.time.DateTime) Interval(org.joda.time.Interval) ItemAndBroadcast(org.atlasapi.content.ItemAndBroadcast) Test(org.junit.Test)

Example 5 with Broadcast

use of org.atlasapi.content.Broadcast in project atlas-deer by atlasapi.

the class ScheduleMergerImplTest method overrideDeletesCompletelyContainedOriginalBetweenOtherOriginals.

/*
    Overrides      --------------
    Original   -----  ------  -------
     */
@Test
public void overrideDeletesCompletelyContainedOriginalBetweenOtherOriginals() {
    DateTime originalStart0 = DateTime.parse("2016-02-10T14:42:41.242Z");
    DateTime originalEnd0 = originalStart0.plus(Duration.standardHours(2));
    DateTime overrideStart = originalEnd0.minus(Duration.standardHours(1));
    DateTime overrideEnd = overrideStart.plus(Duration.standardHours(5));
    DateTime originalStart1 = overrideEnd.minus(Duration.standardHours(1));
    DateTime originalEnd1 = originalStart1.plus(Duration.standardHours(2));
    DateTime originalShadowedStart = originalEnd0.plus(Duration.standardHours(1));
    DateTime originalShadowedEnd = originalEnd1.minus(Duration.standardHours(1));
    Interval interval = new Interval(originalStart0, originalEnd1);
    Broadcast originalBroadcast0 = new Broadcast(channel, originalStart0, originalEnd0);
    Broadcast originalBroadcast1 = new Broadcast(channel, originalStart1, originalEnd1);
    Broadcast originalBroadcast2 = new Broadcast(channel, originalShadowedStart, originalShadowedEnd);
    Broadcast overrideBroadcast = new Broadcast(channel, overrideStart, overrideEnd);
    Item originalItem = mock(Item.class, "originalItem");
    when(originalItem.copy()).thenReturn(originalItem);
    when(originalItem.getId()).thenReturn(Id.valueOf(24));
    ChannelSchedule originalSchedule = new ChannelSchedule(channel, interval, ImmutableList.of(new ItemAndBroadcast(originalItem, originalBroadcast0), new ItemAndBroadcast(originalItem, originalBroadcast1), new ItemAndBroadcast(originalItem, originalBroadcast2)));
    Item overrideItem = mock(Item.class, "overrideItem");
    when(overrideItem.copy()).thenReturn(overrideItem);
    when(overrideItem.getId()).thenReturn(Id.valueOf(25));
    ChannelSchedule overrideSchedule = new ChannelSchedule(channel, interval, ImmutableList.of(new ItemAndBroadcast(overrideItem, overrideBroadcast)));
    ChannelSchedule merged = merger.merge(originalSchedule, overrideSchedule);
    List<ItemAndBroadcast> entries = merged.getEntries();
    assertThat(entries.size(), is(3));
    ItemAndBroadcast truncatedFirstOriginal = entries.get(0);
    Broadcast truncatedBroadcast = truncatedFirstOriginal.getBroadcast();
    assertThat(truncatedBroadcast.getTransmissionTime(), is(originalStart0));
    assertThat(truncatedBroadcast.getTransmissionEndTime(), is(overrideStart));
    ItemAndBroadcast insertedOverride = entries.get(1);
    Broadcast insertedBroadcast = insertedOverride.getBroadcast();
    assertThat(insertedBroadcast.getTransmissionTime(), is(overrideStart));
    assertThat(insertedBroadcast.getTransmissionEndTime(), is(overrideEnd));
    ItemAndBroadcast truncatedTailingOriginal = entries.get(2);
    Broadcast tailingBroadcast = truncatedTailingOriginal.getBroadcast();
    assertThat(tailingBroadcast.getTransmissionTime(), is(overrideEnd));
    assertThat(tailingBroadcast.getTransmissionEndTime(), is(originalEnd1));
}
Also used : Item(org.atlasapi.content.Item) Broadcast(org.atlasapi.content.Broadcast) ItemAndBroadcast(org.atlasapi.content.ItemAndBroadcast) ChannelSchedule(org.atlasapi.schedule.ChannelSchedule) DateTime(org.joda.time.DateTime) Interval(org.joda.time.Interval) ItemAndBroadcast(org.atlasapi.content.ItemAndBroadcast) Test(org.junit.Test)

Aggregations

Broadcast (org.atlasapi.content.Broadcast)113 Item (org.atlasapi.content.Item)90 Test (org.junit.Test)80 Interval (org.joda.time.Interval)67 DateTime (org.joda.time.DateTime)53 ItemAndBroadcast (org.atlasapi.content.ItemAndBroadcast)37 Id (org.atlasapi.entity.Id)22 ChannelSchedule (org.atlasapi.schedule.ChannelSchedule)22 Channel (org.atlasapi.channel.Channel)18 ImmutableList (com.google.common.collect.ImmutableList)17 Content (org.atlasapi.content.Content)15 Iterables (com.google.common.collect.Iterables)13 List (java.util.List)13 Publisher (org.atlasapi.media.entity.Publisher)13 EquivalenceGraph (org.atlasapi.equivalence.EquivalenceGraph)12 DateTimeZone (org.joda.time.DateTimeZone)12 ImmutableSet (com.google.common.collect.ImmutableSet)11 Futures (com.google.common.util.concurrent.Futures)11 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)10 WriteException (org.atlasapi.entity.util.WriteException)10