Search in sources :

Example 1 with Ref

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

the class CqlContentStore method removeItemRefsFromContainers.

private Collection<? extends Statement> removeItemRefsFromContainers(Item item, ContainerRef... containerRefs) {
    ItemRef ref = item.toRef();
    ImmutableMap<ItemRef, Iterable<BroadcastRef>> upcoming = ImmutableMap.of(item.toRef(), item.getUpcomingBroadcastRefs());
    Set<Ref> upcomingSerialised = upcoming.keySet().stream().map(refTranslator::serialize).collect(MoreCollectors.toImmutableSet());
    ImmutableMap<ItemRef, Iterable<LocationSummary>> availableLocations = ImmutableMap.of(item.toRef(), item.getAvailableLocations());
    Set<Ref> availableLocationsSerialised = availableLocations.keySet().stream().map(refTranslator::serialize).collect(MoreCollectors.toImmutableSet());
    Ref itemRefKey = refTranslator.serialize(ref);
    return Arrays.stream(containerRefs).filter(Objects::nonNull).flatMap(containerRef -> Lists.newArrayList(accessor.removeItemRefsFromContainer(containerRef.getId().longValue(), ImmutableSet.of(itemRefKey), upcomingSerialised, availableLocationsSerialised), accessor.removeItemSummariesFromContainer(containerRef.getId().longValue(), ImmutableSet.of(itemRefKey))).stream()).collect(Collectors.toList());
}
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) ContainerRef(org.atlasapi.content.ContainerRef) BroadcastRef(org.atlasapi.content.BroadcastRef) SeriesRef(org.atlasapi.content.SeriesRef)

Example 2 with Ref

use of org.atlasapi.content.v2.model.udt.Ref 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 3 with Ref

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

the class RefSerialization method serialize.

public Ref serialize(ResourceRef ref) {
    Ref internal = new Ref();
    internal.setId(ref.getId().longValue());
    internal.setSource(ref.getSource().key());
    return internal;
}
Also used : ResourceRef(org.atlasapi.entity.ResourceRef) Ref(org.atlasapi.content.v2.model.udt.Ref)

Example 4 with Ref

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

the class SegmentRefSerialization method serialize.

public Ref serialize(SegmentRef segmentRef) {
    if (segmentRef == null) {
        return null;
    }
    Ref internal = new Ref();
    Id id = segmentRef.getId();
    if (id != null) {
        internal.setId(id.longValue());
    }
    Publisher source = segmentRef.getSource();
    if (source != null) {
        internal.setSource(source.key());
    }
    return internal;
}
Also used : SegmentRef(org.atlasapi.segment.SegmentRef) Ref(org.atlasapi.content.v2.model.udt.Ref) Id(org.atlasapi.entity.Id) Publisher(org.atlasapi.media.entity.Publisher)

Example 5 with Ref

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

the class EquivalenceRefSerialization method serialize.

public Ref serialize(EquivalenceRef equivalenceRef) {
    if (equivalenceRef == null) {
        return null;
    }
    Ref internal = new Ref();
    Id id = equivalenceRef.getId();
    if (id != null) {
        internal.setId(id.longValue());
    }
    Publisher source = equivalenceRef.getSource();
    if (source != null) {
        internal.setSource(source.key());
    }
    return internal;
}
Also used : EquivalenceRef(org.atlasapi.equivalence.EquivalenceRef) Ref(org.atlasapi.content.v2.model.udt.Ref) Id(org.atlasapi.entity.Id) Publisher(org.atlasapi.media.entity.Publisher)

Aggregations

Ref (org.atlasapi.content.v2.model.udt.Ref)10 Id (org.atlasapi.entity.Id)7 Publisher (org.atlasapi.media.entity.Publisher)5 BatchStatement (com.datastax.driver.core.BatchStatement)3 MoreCollectors (com.metabroadcast.common.stream.MoreCollectors)3 Collectors (java.util.stream.Collectors)3 StreamSupport (java.util.stream.StreamSupport)3 Nullable (javax.annotation.Nullable)3 PartialItemRef (org.atlasapi.content.v2.model.udt.PartialItemRef)3 SeriesRef (org.atlasapi.content.v2.model.udt.SeriesRef)3 MetricRegistry (com.codahale.metrics.MetricRegistry)2 MapStream (com.codepoetics.protonpack.maps.MapStream)2 ConsistencyLevel (com.datastax.driver.core.ConsistencyLevel)2 Session (com.datastax.driver.core.Session)2 Statement (com.datastax.driver.core.Statement)2 Mapper (com.datastax.driver.mapping.Mapper)2 MappingManager (com.datastax.driver.mapping.MappingManager)2 Function (com.google.common.base.Function)2 Optional (com.google.common.base.Optional)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2