use of org.atlasapi.content.ContainerRef in project atlas-deer by atlasapi.
the class HierarchyWriter method writeEpisodeHierarchy.
private void writeEpisodeHierarchy(Episode episode, StatementRunner runner) {
EpisodeRef episodeRef = episode.toRef();
ContainerRef containerRef = episode.getContainerRef();
if (containerRef != null) {
addParent(episodeRef, containerRef, runner);
}
SeriesRef seriesRef = episode.getSeriesRef();
if (seriesRef != null) {
addParent(episodeRef, seriesRef, runner);
}
}
use of org.atlasapi.content.ContainerRef 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());
}
use of org.atlasapi.content.ContainerRef in project atlas-deer by atlasapi.
the class CqlContentStore method resolveContainer.
@Nullable
private Container resolveContainer(Content content) throws WriteException {
ContainerRef containerRef = null;
if (content instanceof Item) {
Item item = (Item) content;
containerRef = item.getContainerRef();
}
if (content instanceof Series) {
Series series = (Series) content;
containerRef = series.getBrandRef();
}
if (containerRef != null) {
try {
Optional<Content> container = resolveIds(ImmutableList.of(containerRef.getId())).get().getResources().first();
if (container.isPresent()) {
return (Container) container.get();
} else {
throw new WriteException(String.format("Failed to resolve container %s for %s", containerRef.getId(), content.getId()), new MissingResourceException(containerRef.getId()));
}
} catch (InterruptedException | ExecutionException e) {
throw new WriteException(String.format("Failed to retrieve container %s for %s seconds", containerRef.getId(), content.getId()), e);
}
}
return null;
}
use of org.atlasapi.content.ContainerRef in project atlas-deer by atlasapi.
the class CqlContentStore method updateWriteDates.
private List<Statement> updateWriteDates(Content content, DateTime now) {
content.setLastUpdated(now);
if (content.getFirstSeen() == null) {
content.setFirstSeen(now);
}
content.setThisOrChildLastUpdated(now);
List<Statement> result = Lists.newArrayList();
if (content instanceof Item) {
Item item = (Item) content;
ContainerRef container = item.getContainerRef();
if (container != null) {
result.add(accessor.setLastUpdated(container.getId().longValue(), now.toInstant()));
}
}
if (content instanceof Episode) {
Episode episode = (Episode) content;
SeriesRef series = episode.getSeriesRef();
if (series != null) {
result.add(accessor.setLastUpdated(series.getId().longValue(), now.toInstant()));
}
}
if (content instanceof Series) {
Series series = (Series) content;
BrandRef brand = series.getBrandRef();
if (brand != null) {
result.add(accessor.setLastUpdated(brand.getId().longValue(), now.toInstant()));
}
}
return result;
}
use of org.atlasapi.content.ContainerRef 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);
}
}
Aggregations