Search in sources :

Example 1 with ItemSummary

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

the class ExtendedDescriptionAnnotation method write.

@Override
public void write(Content desc, FieldWriter writer, OutputContext ctxt) throws IOException {
    writer.writeList("genres", "genre", desc.getGenres(), ctxt);
    writer.writeField("presentation_channel", desc.getPresentationChannel());
    writer.writeField("priority", desc.getPriority() != null ? desc.getPriority().getPriority() : null);
    if (ctxt.getActiveAnnotations().contains(Annotation.PRIORITY_REASONS)) {
        if (desc.getPriority() != null && desc.getPriority().getReasons() != null) {
            writer.writeObject(priorityReasonsWriter, desc.getPriority().getReasons(), ctxt);
        } else {
            writer.writeObject(priorityReasonsWriter, null, ctxt);
        }
    }
    writer.writeField("short_description", desc.getShortDescription());
    writer.writeField("medium_description", desc.getMediumDescription());
    writer.writeField("long_description", desc.getLongDescription());
    writer.writeList(releaseDateWriter, desc.getReleaseDates(), ctxt);
    if (desc instanceof Item) {
        Item item = (Item) desc;
        writer.writeField("black_and_white", item.getBlackAndWhite());
        writer.writeField("schedule_only", item.isScheduleOnly());
        writer.writeList(restrictionWriter, item.getRestrictions(), ctxt);
    }
    if (desc instanceof Container) {
        Container container = (Container) desc;
        ImmutableSet<Certificate> childCerts = container.getItemSummaries().stream().map(ItemSummary::getCertificates).filter(Optional::isPresent).map(Optional::get).flatMap(Collection::stream).collect(MoreCollectors.toImmutableSet());
        writer.writeList(certificateWriter, Sets.union(desc.getCertificates(), childCerts), ctxt);
    } else {
        writer.writeList(certificateWriter, desc.getCertificates(), ctxt);
    }
    writer.writeList(languageWriter, desc.getLanguages(), ctxt);
    writer.writeList("countries_of_origin", "country", desc.getCountriesOfOrigin(), ctxt);
    if (desc instanceof Film) {
        Film film = (Film) desc;
        writer.writeList(subtitleWriter, film.getSubtitles(), ctxt);
    }
}
Also used : Item(org.atlasapi.content.Item) Container(org.atlasapi.content.Container) Optional(java.util.Optional) Film(org.atlasapi.content.Film) ItemSummary(org.atlasapi.content.ItemSummary) Certificate(org.atlasapi.content.Certificate)

Example 2 with ItemSummary

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

the class CqlContentGenerator method setContainerFields.

private static void setContainerFields(Container container) {
    setContentFields(container);
    container.setItemRefs(ImmutableList.of(new ItemRef(Id.valueOf(8775), Publisher.BT, "sort key", DateTime.now(DateTimeZone.UTC))));
    container.setUpcomingContent(ImmutableMap.of(new ItemRef(Id.valueOf(221), Publisher.BT, "sort key", DateTime.now(DateTimeZone.UTC)), ImmutableList.of(new BroadcastRef("source id", Id.valueOf(32199), new Interval(DateTime.now(DateTimeZone.UTC).minusHours(2), DateTime.now(DateTimeZone.UTC))))));
    container.setAvailableContent(ImmutableMap.of(new ItemRef(Id.valueOf(23087), Publisher.BT, "sort key", DateTime.now(DateTimeZone.UTC)), ImmutableList.of(new LocationSummary(Boolean.TRUE, "uri", DateTime.now(DateTimeZone.UTC).minusHours(1), DateTime.now(DateTimeZone.UTC)))));
    container.setItemSummaries(ImmutableList.of(new ItemSummary(new ItemRef(Id.valueOf(32), Publisher.BT, "sort key", DateTime.now(DateTimeZone.UTC)), "title", "description", "image", 2015, ImmutableList.of(new Certificate("class", Countries.GB)))));
}
Also used : LocationSummary(org.atlasapi.content.LocationSummary) ItemRef(org.atlasapi.content.ItemRef) BroadcastRef(org.atlasapi.content.BroadcastRef) ItemSummary(org.atlasapi.content.ItemSummary) Interval(org.joda.time.Interval) Certificate(org.atlasapi.content.Certificate)

Example 3 with ItemSummary

use of org.atlasapi.content.ItemSummary 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 ItemSummary

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

the class SubItemSummariesAnnotations method write.

@Override
public void write(Content entity, FieldWriter writer, OutputContext ctxt) throws IOException {
    if (entity instanceof Container) {
        Container container = (Container) entity;
        Integer offset = 0;
        Integer limit = Integer.MAX_VALUE;
        String offsetStr = ctxt.getRequest().getParameter(SUB_ITEM_OFFSET);
        if (!Strings.isNullOrEmpty(offsetStr)) {
            offset = Integer.valueOf(offsetStr);
        }
        String limitStr = ctxt.getRequest().getParameter(SUB_ITEM_LIMIT);
        if (!Strings.isNullOrEmpty(limitStr)) {
            limit = Integer.valueOf(limitStr);
        }
        String orderingStr = ctxt.getRequest().getParameter(SUB_ITEMS_ORDERING);
        Ordering<ItemSummary> ordering = Ordering.natural().onResultOf((ItemSummary summary) -> summary.getItemRef().getSortKey()).nullsLast();
        /* Item refs by default are ordered reverse lexicographically,
                so to reverse that ordering through the API is to simply leave it alone here */
        if (Strings.isNullOrEmpty(orderingStr) || !REVERSE.equalsIgnoreCase(orderingStr)) {
            ordering = ordering.reverse();
        }
        ImmutableList<ItemSummary> summaries = ordering.immutableSortedCopy(container.getItemSummaries()).stream().skip(offset).limit(limit).collect(MoreCollectors.toImmutableList());
        writer.writeList(subItemSummaryListWriter, summaries, ctxt);
    }
}
Also used : Container(org.atlasapi.content.Container) ItemSummary(org.atlasapi.content.ItemSummary)

Example 5 with ItemSummary

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

the class HashValueExtractorTest method setContainerFields.

private void setContainerFields(Container container) {
    ItemRef itemRef = new ItemRef(Id.valueOf(10L), Publisher.METABROADCAST, "sort", DateTime.now());
    container.setItemRefs(ImmutableSet.of(itemRef));
    container.setUpcomingContent(ImmutableMap.of(itemRef, ImmutableSet.of(new BroadcastRef("id", Id.valueOf(1L), new Interval(DateTime.now(), DateTime.now().plusDays(1))))));
    container.setAvailableContent(ImmutableMap.of(itemRef, ImmutableSet.of(new LocationSummary(true, "uri", DateTime.now().minusDays(1), DateTime.now().plusDays(1)))));
    container.setItemSummaries(ImmutableList.of(new ItemSummary(itemRef, "title", "description", "image", 2000, ImmutableSet.of(new Certificate("18", Countries.GB)))));
}
Also used : LocationSummary(org.atlasapi.content.LocationSummary) ItemRef(org.atlasapi.content.ItemRef) BroadcastRef(org.atlasapi.content.BroadcastRef) ItemSummary(org.atlasapi.content.ItemSummary) Interval(org.joda.time.Interval) Certificate(org.atlasapi.content.Certificate)

Aggregations

ItemSummary (org.atlasapi.content.ItemSummary)6 Certificate (org.atlasapi.content.Certificate)4 BroadcastRef (org.atlasapi.content.BroadcastRef)3 Container (org.atlasapi.content.Container)3 ItemRef (org.atlasapi.content.ItemRef)3 LocationSummary (org.atlasapi.content.LocationSummary)3 Interval (org.joda.time.Interval)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 MapStream (com.codepoetics.protonpack.maps.MapStream)1 BatchStatement (com.datastax.driver.core.BatchStatement)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 com.google.common.collect (com.google.common.collect)1