use of org.atlasapi.content.BroadcastRef in project atlas-deer by atlasapi.
the class AbstractScheduleStore method sendUpdateMessage.
private void sendUpdateMessage(Publisher source, List<ScheduleHierarchy> content, ScheduleBlocksUpdate update, Channel channel, Interval interval) throws WriteException {
try {
String messageId = UUID.randomUUID().toString();
Timestamp messageTimestamp = Timestamp.of(DateTime.now(DateTimeZones.UTC));
ScheduleRef updateRef = scheduleRef(content, channel, interval);
ImmutableSet<BroadcastRef> staleRefs = broadcastRefs(update.getStaleEntries());
ScheduleUpdateMessage message = new ScheduleUpdateMessage(messageId, messageTimestamp, new ScheduleUpdate(source, updateRef, staleRefs));
Id channelId = message.getScheduleUpdate().getSchedule().getChannel();
messageSender.sendMessage(message, Longs.toByteArray(channelId.longValue()));
} catch (MessagingException e) {
throw new WriteException(e);
}
}
use of org.atlasapi.content.BroadcastRef 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.BroadcastRef in project atlas-deer by atlasapi.
the class CassandraEquivalentScheduleStore method writeSchedule.
@Override
protected void writeSchedule(ScheduleUpdate update, Map<ScheduleRef.Entry, EquivalentScheduleEntry> content) throws WriteException {
DateTime now = clock.now();
ImmutableMultimap<LocalDate, BroadcastRow> currentBroadcastRows = resolveBroadcasts(update.getSource(), update.getSchedule().getChannel(), update.getSchedule().getInterval());
ImmutableList<EquivalentScheduleEntry> updateEntries = getEquivalentScheduleEntries(update.getSchedule(), content);
ImmutableSet<BroadcastRef> updateBroadcastRefs = updateEntries.stream().map(EquivalentScheduleEntry::getBroadcast).map(Broadcast::toRef).collect(MoreCollectors.toImmutableSet());
Set<BroadcastRow> staleBroadcasts = getStaleBroadcasts(updateBroadcastRefs, currentBroadcastRows);
List<Statement> deletes = deleteStatements(update.getSource(), update.getSchedule().getChannel(), staleBroadcasts);
log.info("Processing equivalent schedule update for {} {} {}: content: {}, " + "currentEntries:{}, update:{}, stale broadcasts from update:{}, " + "stale broadcasts:{}", update.getSource(), update.getSchedule().getChannel().longValue(), update.getSchedule().getInterval(), content, currentBroadcastRows.values().stream().map(BroadcastRow::toString).collect(Collectors.joining(",")), updateLog(updateBroadcastRefs), updateLog(update.getStaleBroadcasts()), staleBroadcasts.stream().map(BroadcastRow::toString).collect(Collectors.joining(",")));
ImmutableList<Statement> updates = updateEntries.stream().flatMap(entry -> statementsForEntry(update.getSource(), entry, now).stream()).collect(MoreCollectors.toImmutableList());
if (updates.isEmpty() && deletes.isEmpty()) {
return;
}
BatchStatement updateBatch = new BatchStatement();
updateBatch.addAll(Iterables.concat(updates, deletes));
try {
session.execute(updateBatch.setConsistencyLevel(write));
log.info("Processed equivalent schedule update for {} {} {}, updates: {}, " + "deletes: {}", update.getSource(), update.getSchedule().getChannel().longValue(), update.getSchedule().getInterval(), updates.size(), deletes.size());
} catch (NoHostAvailableException | QueryExecutionException e) {
throw new WriteException(e);
}
}
use of org.atlasapi.content.BroadcastRef in project atlas-deer by atlasapi.
the class CassandraEquivalentScheduleStore method getStaleBroadcasts.
private Set<BroadcastRow> getStaleBroadcasts(Set<BroadcastRef> updateBroadcastRefs, ImmutableMultimap<LocalDate, BroadcastRow> currentBroadcastRows) {
ImmutableMultimap<LocalDate, BroadcastRef> updateBroadcastsByDay = getBroadcastsByDay(updateBroadcastRefs);
ImmutableSet.Builder<BroadcastRow> staleBroadcasts = ImmutableSet.builder();
for (LocalDate day : currentBroadcastRows.keySet()) {
ImmutableCollection<BroadcastRow> currentBroadcastsInDay = currentBroadcastRows.get(day);
ImmutableSet<String> updateBroadcastIdsInDay = updateBroadcastsByDay.get(day).stream().map(BroadcastRef::getSourceId).collect(MoreCollectors.toImmutableSet());
ImmutableSet<BroadcastRow> staleBroadcastsInDay = currentBroadcastsInDay.stream().filter(broadcast -> !updateBroadcastIdsInDay.contains(broadcast.getBroadcastSourceId())).collect(MoreCollectors.toImmutableSet());
staleBroadcasts.addAll(staleBroadcastsInDay);
}
return staleBroadcasts.build();
}
use of org.atlasapi.content.BroadcastRef 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)))));
}
Aggregations