use of org.atlasapi.content.v2.model.udt.Ref 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.v2.model.udt.Ref 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.Ref in project atlas-deer by atlasapi.
the class RefSerialization method serialize.
public Ref serialize(ResourceRef ref) {
Ref internal = new Ref();
internal.setId(ref.getId().longValue());
internal.setSource(ref.getSource().key());
return internal;
}
use of org.atlasapi.content.v2.model.udt.Ref in project atlas-deer by atlasapi.
the class SegmentRefSerialization method serialize.
public Ref serialize(SegmentRef segmentRef) {
if (segmentRef == null) {
return null;
}
Ref internal = new Ref();
Id id = segmentRef.getId();
if (id != null) {
internal.setId(id.longValue());
}
Publisher source = segmentRef.getSource();
if (source != null) {
internal.setSource(source.key());
}
return internal;
}
use of org.atlasapi.content.v2.model.udt.Ref in project atlas-deer by atlasapi.
the class EquivalenceRefSerialization method serialize.
public Ref serialize(EquivalenceRef equivalenceRef) {
if (equivalenceRef == null) {
return null;
}
Ref internal = new Ref();
Id id = equivalenceRef.getId();
if (id != null) {
internal.setId(id.longValue());
}
Publisher source = equivalenceRef.getSource();
if (source != null) {
internal.setSource(source.key());
}
return internal;
}
Aggregations