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);
}
}
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)))));
}
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;
}
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);
}
}
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)))));
}
Aggregations