use of org.atlasapi.content.v2.model.udt.PartialItemRef 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);
}
}
use of org.atlasapi.content.v2.model.udt.PartialItemRef 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.v2.model.udt.PartialItemRef 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()));
}
}
use of org.atlasapi.content.v2.model.udt.PartialItemRef in project atlas-deer by atlasapi.
the class ItemRefSerialization method serialize.
public PartialItemRef serialize(org.atlasapi.content.ItemRef itemRef) {
if (itemRef == null) {
return null;
}
PartialItemRef internal = new PartialItemRef();
Ref ref = new Ref();
Id id = itemRef.getId();
if (id != null) {
ref.setId(id.longValue());
}
Publisher source = itemRef.getSource();
if (source != null) {
ref.setSource(source.key());
}
internal.setSortKey(itemRef.getSortKey());
internal.setUpdated(toInstant(itemRef.getUpdated()));
if (itemRef instanceof EpisodeRef) {
internal.setType("episode");
} else if (itemRef instanceof FilmRef) {
internal.setType("film");
} else if (itemRef instanceof SongRef) {
internal.setType("song");
} else if (itemRef instanceof ClipRef) {
internal.setType("clip");
} else {
internal.setType("item");
}
return internal;
}
Aggregations