Search in sources :

Example 1 with org.atlasapi.content.v2.model.udt

use of org.atlasapi.content.v2.model.udt in project atlas-deer by atlasapi.

the class CqlContentStore method writeBroadcast.

@Override
public void writeBroadcast(ItemRef item, Optional<ContainerRef> containerRef, Optional<SeriesRef> seriesRef, Broadcast broadcast) {
    metricRegistry.meter(writeBroadcast + METER_CALLED).mark();
    try {
        BatchStatement batch = new BatchStatement();
        Instant now = clock.now().toInstant();
        org.atlasapi.content.v2.model.udt.Broadcast serialized = broadcastTranslator.serialize(broadcast);
        ImmutableMap<String, org.atlasapi.content.v2.model.udt.Broadcast> broadcasts = ImmutableMap.of(broadcast.getSourceId(), serialized);
        batch.add(accessor.addBroadcastToContent(item.getId().longValue(), broadcasts));
        batch.add(accessor.setLastUpdated(item.getId().longValue(), now));
        // item and return early
        if (broadcast.isActivelyPublished() && broadcast.isUpcoming()) {
            Ref ref = refTranslator.serialize(item);
            PartialItemRef itemRef = itemRefTranslator.serialize(item);
            Map<Ref, ItemRefAndBroadcastRefs> upcomingBroadcasts = ImmutableMap.of(ref, new ItemRefAndBroadcastRefs(itemRef, ImmutableList.of(broadcastRefTranslator.serialize(broadcast.toRef()))));
            if (containerRef.isPresent()) {
                long id = containerRef.get().getId().longValue();
                batch.add(accessor.addItemRefsToContainer(id, ImmutableMap.of(), upcomingBroadcasts, ImmutableMap.of()));
                batch.add(accessor.setLastUpdated(id, now));
            }
            if (seriesRef.isPresent()) {
                long id = seriesRef.get().getId().longValue();
                batch.add(accessor.addItemRefsToContainer(id, ImmutableMap.of(ref, itemRef), upcomingBroadcasts, ImmutableMap.of()));
                batch.add(accessor.setLastUpdated(id, now));
            }
        }
        session.execute(batch);
        sendMessages(ImmutableList.of(new ResourceUpdatedMessage(UUID.randomUUID().toString(), Timestamp.now(), item)));
    } catch (RuntimeException e) {
        metricRegistry.meter(writeBroadcast + METER_FAILURE).mark();
        Throwables.propagate(e);
    }
}
Also used : org.atlasapi.content.v2.model.udt(org.atlasapi.content.v2.model.udt) Instant(org.joda.time.Instant) ResourceUpdatedMessage(org.atlasapi.messaging.ResourceUpdatedMessage) org.atlasapi.content(org.atlasapi.content) ContainerRef(org.atlasapi.content.ContainerRef) BroadcastRef(org.atlasapi.content.BroadcastRef) SeriesRef(org.atlasapi.content.SeriesRef) Broadcast(org.atlasapi.content.Broadcast) BatchStatement(com.datastax.driver.core.BatchStatement)

Example 2 with org.atlasapi.content.v2.model.udt

use of org.atlasapi.content.v2.model.udt in project atlas-deer by atlasapi.

the class ItemSetter method deserialize.

public void deserialize(org.atlasapi.content.Content content, Content internal) {
    Item item = (Item) content;
    item.setContainerRef(containerRef.deserialize(internal.getContainerRef()));
    Boolean isLongForm = internal.getIsLongForm();
    if (isLongForm != null) {
        item.setIsLongForm(isLongForm);
    }
    item.setBlackAndWhite(internal.getBlackAndWhite());
    item = item.withSortKey(internal.getSortKey());
    Long duration = internal.getDuration();
    if (duration != null) {
        item.setDuration(new Duration(duration));
    }
    item.setContainerSummary(containerSummary.deserialize(internal.getContainerSummary()));
    Map<String, org.atlasapi.content.v2.model.udt.Broadcast> broadcasts = internal.getBroadcasts();
    if (broadcasts != null) {
        item.setBroadcasts(broadcasts.entrySet().stream().map(entry -> broadcast.deserialize(entry.getKey(), entry.getValue())).collect(Collectors.toSet()));
    }
    List<SegmentEvent> segmentEvents = internal.getSegmentEvents();
    if (segmentEvents != null) {
        item.setSegmentEvents(segmentEvents.stream().map(segmentEvent::deserialize).collect(Collectors.toList()));
    }
    Map<org.atlasapi.content.v2.model.udt.Restriction, UpdateTimes> restrictions = internal.getRestrictions();
    if (restrictions != null) {
        item.setRestrictions(restrictions.entrySet().stream().map(entry -> restriction.deserialize(entry.getValue(), entry.getKey())).collect(MoreCollectors.toImmutableSet()));
    }
}
Also used : UpdateTimes(org.atlasapi.content.v2.model.udt.UpdateTimes) Duration(org.joda.time.Duration) Item(org.atlasapi.content.Item) Broadcast(org.atlasapi.content.Broadcast) SegmentEvent(org.atlasapi.content.v2.model.udt.SegmentEvent)

Example 3 with org.atlasapi.content.v2.model.udt

use of org.atlasapi.content.v2.model.udt in project atlas-deer by atlasapi.

the class CqlContentStore method addItemRefsToContainers.

private List<Statement> addItemRefsToContainers(ImmutableList.Builder<ResourceUpdatedMessage> messages, Item item, ContainerRef containerRef, SeriesRef seriesRef) {
    List<Statement> result = Lists.newArrayList();
    ItemRef ref = item.toRef();
    ItemSummary summary = item.toSummary();
    PartialItemRef itemRef = itemRefTranslator.serialize(ref);
    Ref itemRefKey = refTranslator.serialize(ref);
    org.atlasapi.content.v2.model.udt.ItemSummary itemSummary = itemSummaryTranslator.serialize(summary);
    ImmutableMap<ItemRef, Iterable<BroadcastRef>> upcoming = ImmutableMap.of(item.toRef(), item.getUpcomingBroadcastRefs());
    Map<Ref, ItemRefAndBroadcastRefs> upcomingSerialised = MapStream.of(upcoming).mapEntries(refTranslator::serialize, vals -> new ItemRefAndBroadcastRefs(itemRef, StreamSupport.stream(vals.spliterator(), false).map(broadcastRefTranslator::serialize).collect(Collectors.toList()))).collect();
    ImmutableMap<ItemRef, Iterable<LocationSummary>> availableLocations = ImmutableMap.of(item.toRef(), item.getAvailableLocations());
    Map<Ref, ItemRefAndLocationSummaries> availableLocationsSerialised = MapStream.of(availableLocations).mapEntries(refTranslator::serialize, vals -> new ItemRefAndLocationSummaries(itemRef, StreamSupport.stream(vals.spliterator(), false).map(locationSummaryTranslator::serialize).collect(Collectors.toList()))).collect();
    if (containerRef != null) {
        result.add(accessor.addItemRefsToContainer(containerRef.getId().longValue(), ImmutableMap.of(itemRefKey, itemRef), upcomingSerialised, availableLocationsSerialised));
        if (seriesRef == null) {
            result.add(accessor.addItemSummariesToContainer(containerRef.getId().longValue(), ImmutableMap.of(itemRefKey, new ItemRefAndItemSummary(itemRef, itemSummary))));
        }
        messages.add(new ResourceUpdatedMessage(UUID.randomUUID().toString(), Timestamp.now(), containerRef));
    }
    if (seriesRef != null) {
        result.add(accessor.addItemRefsToContainer(seriesRef.getId().longValue(), ImmutableMap.of(itemRefKey, itemRef), upcomingSerialised, availableLocationsSerialised));
        result.add(accessor.addItemSummariesToContainer(seriesRef.getId().longValue(), ImmutableMap.of(itemRefKey, new ItemRefAndItemSummary(itemRef, itemSummary))));
        messages.add(new ResourceUpdatedMessage(UUID.randomUUID().toString(), Timestamp.now(), seriesRef));
    }
    return result;
}
Also used : org.atlasapi.content(org.atlasapi.content) Broadcast(org.atlasapi.content.Broadcast) MissingResourceException(org.atlasapi.entity.util.MissingResourceException) LoggerFactory(org.slf4j.LoggerFactory) Resolved(org.atlasapi.entity.util.Resolved) MappingManager(com.datastax.driver.mapping.MappingManager) ConsistencyLevel(com.datastax.driver.core.ConsistencyLevel) Optional(com.google.common.base.Optional) Session(com.datastax.driver.core.Session) ContainerRef(org.atlasapi.content.ContainerRef) com.google.common.collect(com.google.common.collect) IdGenerator(com.metabroadcast.common.ids.IdGenerator) BatchStatement(com.datastax.driver.core.BatchStatement) Longs(com.google.common.primitives.Longs) Function(com.google.common.base.Function) OptionalMap(com.metabroadcast.common.collect.OptionalMap) Collectors(java.util.stream.Collectors) Promise(com.metabroadcast.promise.Promise) MoreCollectors(com.metabroadcast.common.stream.MoreCollectors) Statement(com.datastax.driver.core.Statement) ContainerSummary(org.atlasapi.content.ContainerSummary) java.util(java.util) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Clock(com.metabroadcast.common.time.Clock) Description(org.atlasapi.content.v2.model.udt.Description) ImmutableOptionalMap(com.metabroadcast.common.collect.ImmutableOptionalMap) Timestamp(com.metabroadcast.common.time.Timestamp) LocationSummary(org.atlasapi.content.LocationSummary) EquivalenceGraph(org.atlasapi.equivalence.EquivalenceGraph) MapStream(com.codepoetics.protonpack.maps.MapStream) StreamSupport(java.util.stream.StreamSupport) BroadcastRef(org.atlasapi.content.BroadcastRef) SeriesRef(org.atlasapi.content.SeriesRef) org.atlasapi.content.v2.model.udt(org.atlasapi.content.v2.model.udt) WriteResult(org.atlasapi.entity.util.WriteResult) org.atlasapi.content.v2.serialization(org.atlasapi.content.v2.serialization) Nullable(javax.annotation.Nullable) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) DateTime(org.joda.time.DateTime) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Throwables(com.google.common.base.Throwables) Id(org.atlasapi.entity.Id) ResourceUpdatedMessage(org.atlasapi.messaging.ResourceUpdatedMessage) ItemSummary(org.atlasapi.content.ItemSummary) ExecutionException(java.util.concurrent.ExecutionException) Futures(com.google.common.util.concurrent.Futures) EquivalenceGraphStore(org.atlasapi.equivalence.EquivalenceGraphStore) Mapper(com.datastax.driver.mapping.Mapper) MessageSender(com.metabroadcast.common.queue.MessageSender) Instant(org.joda.time.Instant) WriteException(org.atlasapi.entity.util.WriteException) org.atlasapi.content.v2.model.udt(org.atlasapi.content.v2.model.udt) BatchStatement(com.datastax.driver.core.BatchStatement) Statement(com.datastax.driver.core.Statement) ResourceUpdatedMessage(org.atlasapi.messaging.ResourceUpdatedMessage) ItemSummary(org.atlasapi.content.ItemSummary) ContainerRef(org.atlasapi.content.ContainerRef) BroadcastRef(org.atlasapi.content.BroadcastRef) SeriesRef(org.atlasapi.content.SeriesRef)

Example 4 with org.atlasapi.content.v2.model.udt

use of org.atlasapi.content.v2.model.udt in project atlas-deer by atlasapi.

the class BroadcastRefSerialization method serialize.

public BroadcastRef serialize(org.atlasapi.content.BroadcastRef broadcastRef) {
    if (broadcastRef == null) {
        return null;
    }
    BroadcastRef internal = new BroadcastRef();
    internal.setSourceId(broadcastRef.getSourceId());
    Id channelId = broadcastRef.getChannelId();
    if (channelId != null) {
        internal.setChannelId(channelId.longValue());
    }
    Interval transmissionInterval = broadcastRef.getTransmissionInterval();
    if (transmissionInterval != null) {
        org.atlasapi.content.v2.model.udt.Interval interval = new org.atlasapi.content.v2.model.udt.Interval();
        interval.setStart(transmissionInterval.getStart().toInstant());
        interval.setEnd(transmissionInterval.getEnd().toInstant());
        internal.setInterval(interval);
    }
    return internal;
}
Also used : BroadcastRef(org.atlasapi.content.v2.model.udt.BroadcastRef) Id(org.atlasapi.entity.Id) Interval(org.joda.time.Interval)

Example 5 with org.atlasapi.content.v2.model.udt

use of org.atlasapi.content.v2.model.udt in project atlas-deer by atlasapi.

the class ContainerSetter method deserialize.

public void deserialize(org.atlasapi.content.Content content, org.atlasapi.content.v2.model.Content internal) {
    Container container = (Container) content;
    Map<Ref, PartialItemRef> itemRefs = internal.getItemRefs();
    if (itemRefs != null) {
        container.setItemRefs(itemRefs.entrySet().stream().map(entry -> itemRef.deserialize(entry.getKey(), entry.getValue())).collect(Collectors.toList()));
    }
    Map<Ref, ItemRefAndBroadcastRefs> internalUpcomingContent = internal.getUpcomingContent();
    if (internalUpcomingContent != null) {
        Map<org.atlasapi.content.ItemRef, Iterable<org.atlasapi.content.BroadcastRef>> upcomingContent = internalUpcomingContent.entrySet().stream().collect(MoreCollectors.toImmutableMap(entry -> {
            Ref ref = entry.getKey();
            ItemRefAndBroadcastRefs broadcasts = entry.getValue();
            return itemRef.deserialize(ref, broadcasts.getItemRef());
        }, entry -> entry.getValue().getBroadcastRefs().stream().map(broadcastRef::deserialize).collect(MoreCollectors.toImmutableList())));
        container.setUpcomingContent(upcomingContent);
    }
    Map<Ref, ItemRefAndLocationSummaries> internalAvailableContent = internal.getAvailableContent();
    if (internalAvailableContent != null) {
        Map<org.atlasapi.content.ItemRef, Iterable<org.atlasapi.content.LocationSummary>> availableContent = internalAvailableContent.entrySet().stream().collect(MoreCollectors.toImmutableMap(entry -> {
            Ref ref = entry.getKey();
            ItemRefAndLocationSummaries locations = entry.getValue();
            return itemRef.deserialize(ref, locations.getItemRef());
        }, entry -> entry.getValue().getLocationSummaries().stream().map(locationSummary::deserialize).collect(MoreCollectors.toImmutableList())));
        container.setAvailableContent(availableContent);
    }
    Map<Ref, ItemRefAndItemSummary> itemSummaries = internal.getItemSummaries();
    if (itemSummaries != null) {
        container.setItemSummaries(itemSummaries.entrySet().stream().map(entry -> {
            Ref ref = entry.getKey();
            ItemRefAndItemSummary summaryWithRef = entry.getValue();
            ItemSummary summary = summaryWithRef.getSummary();
            return itemSummary.deserialize(ref, summaryWithRef.getItemRef(), summary);
        }).collect(MoreCollectors.toImmutableList()));
    }
}
Also used : ItemRefAndBroadcastRefs(org.atlasapi.content.v2.model.udt.ItemRefAndBroadcastRefs) ItemRefAndLocationSummaries(org.atlasapi.content.v2.model.udt.ItemRefAndLocationSummaries) ItemRefAndItemSummary(org.atlasapi.content.v2.model.udt.ItemRefAndItemSummary) PartialItemRef(org.atlasapi.content.v2.model.udt.PartialItemRef) Container(org.atlasapi.content.Container) ItemRefSerialization(org.atlasapi.content.v2.serialization.ItemRefSerialization) Collectors(java.util.stream.Collectors) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Content(org.atlasapi.content.v2.model.Content) ItemSummary(org.atlasapi.content.v2.model.udt.ItemSummary) LocationSummarySerialization(org.atlasapi.content.v2.serialization.LocationSummarySerialization) RefSerialization(org.atlasapi.content.v2.serialization.RefSerialization) Map(java.util.Map) MoreCollectors(com.metabroadcast.common.stream.MoreCollectors) StreamSupport(java.util.stream.StreamSupport) ItemSummarySerialization(org.atlasapi.content.v2.serialization.ItemSummarySerialization) Ref(org.atlasapi.content.v2.model.udt.Ref) BroadcastRefSerialization(org.atlasapi.content.v2.serialization.BroadcastRefSerialization) PartialItemRef(org.atlasapi.content.v2.model.udt.PartialItemRef) ItemRefAndItemSummary(org.atlasapi.content.v2.model.udt.ItemRefAndItemSummary) ItemSummary(org.atlasapi.content.v2.model.udt.ItemSummary) Container(org.atlasapi.content.Container) PartialItemRef(org.atlasapi.content.v2.model.udt.PartialItemRef) Ref(org.atlasapi.content.v2.model.udt.Ref) ItemRefAndItemSummary(org.atlasapi.content.v2.model.udt.ItemRefAndItemSummary) ItemRefAndLocationSummaries(org.atlasapi.content.v2.model.udt.ItemRefAndLocationSummaries) PartialItemRef(org.atlasapi.content.v2.model.udt.PartialItemRef) ItemRefAndBroadcastRefs(org.atlasapi.content.v2.model.udt.ItemRefAndBroadcastRefs)

Aggregations

Broadcast (org.atlasapi.content.Broadcast)3 BatchStatement (com.datastax.driver.core.BatchStatement)2 MoreCollectors (com.metabroadcast.common.stream.MoreCollectors)2 Collectors (java.util.stream.Collectors)2 StreamSupport (java.util.stream.StreamSupport)2 org.atlasapi.content (org.atlasapi.content)2 BroadcastRef (org.atlasapi.content.BroadcastRef)2 ContainerRef (org.atlasapi.content.ContainerRef)2 Id (org.atlasapi.entity.Id)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 MapStream (com.codepoetics.protonpack.maps.MapStream)1 ConsistencyLevel (com.datastax.driver.core.ConsistencyLevel)1 Session (com.datastax.driver.core.Session)1 Statement (com.datastax.driver.core.Statement)1 Mapper (com.datastax.driver.mapping.Mapper)1 MappingManager (com.datastax.driver.mapping.MappingManager)1 Function (com.google.common.base.Function)1 Optional (com.google.common.base.Optional)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Throwables (com.google.common.base.Throwables)1