Search in sources :

Example 1 with ContentEquivalenceAssertionMessage

use of org.atlasapi.messaging.v3.ContentEquivalenceAssertionMessage in project atlas-deer by atlasapi.

the class ContentEquivalenceAssertionLegacyTransformer method transform.

public EquivalenceAssertionMessage transform(ContentEquivalenceAssertionMessage leg) {
    String mid = leg.getMessageId();
    Timestamp ts = leg.getTimestamp();
    ResourceRef subj = LegacyTransformer.resourceRef(leg.getEntityId(), leg.getEntitySource(), leg.getEntityType(), leg.getTimestamp());
    Set<ResourceRef> adjacents = toResourceRef(leg);
    Set<Publisher> srcs = ImmutableSet.copyOf(Iterables.transform(leg.getSources(), Publisher.FROM_KEY));
    return new EquivalenceAssertionMessage(mid, ts, subj, adjacents, srcs);
}
Also used : EquivalenceAssertionMessage(org.atlasapi.messaging.EquivalenceAssertionMessage) ContentEquivalenceAssertionMessage(org.atlasapi.messaging.v3.ContentEquivalenceAssertionMessage) ResourceRef(org.atlasapi.entity.ResourceRef) Publisher(org.atlasapi.media.entity.Publisher) Timestamp(com.metabroadcast.common.time.Timestamp)

Example 2 with ContentEquivalenceAssertionMessage

use of org.atlasapi.messaging.v3.ContentEquivalenceAssertionMessage in project atlas-deer by atlasapi.

the class ContentEquivalenceAssertionLegacyTransformer method toResourceRef.

protected Set<ResourceRef> toResourceRef(ContentEquivalenceAssertionMessage leg) {
    if (leg.getAdjacent() == null || leg.getAdjacent().isEmpty()) {
        return ImmutableSet.of();
    }
    DateTime madeUpUpdatedTime = new DateTime(leg.getTimestamp().millis(), UTC);
    ImmutableSet.Builder<ResourceRef> resourceRefs = ImmutableSet.builder();
    for (AdjacentRef adjacentRef : leg.getAdjacent()) {
        resourceRefs.add(LegacyTransformer.toResourceRef(ID_CODEC.decode(adjacentRef.getId()).longValue(), Publisher.fromKey(adjacentRef.getSource()).requireValue(), adjacentRef.getType(), madeUpUpdatedTime));
    }
    return resourceRefs.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) ResourceRef(org.atlasapi.entity.ResourceRef) DateTime(org.joda.time.DateTime) AdjacentRef(org.atlasapi.messaging.v3.ContentEquivalenceAssertionMessage.AdjacentRef)

Example 3 with ContentEquivalenceAssertionMessage

use of org.atlasapi.messaging.v3.ContentEquivalenceAssertionMessage in project atlas-deer by atlasapi.

the class ContentEquivalenceAssertionLegacyTransformerTest method testDeSerializesContentEquivalenceAssertionMessage.

@Test
public void testDeSerializesContentEquivalenceAssertionMessage() {
    // given
    ImmutableList<AdjacentRef> adjs = ImmutableList.of(new AdjacentRef("cf2", "item", Publisher.PA.key()));
    Set<String> srcs = toKeys(Publisher.all());
    ContentEquivalenceAssertionMessage msg = new ContentEquivalenceAssertionMessage("1", Timestamp.of(1L), "cyp", "item", "bbc.co.uk", adjs, srcs);
    // when
    EquivalenceAssertionMessage transformed = transformer.transform(msg);
    // then
    assertThat(transformed.getMessageId(), is(msg.getMessageId()));
    assertThat(transformed.getTimestamp(), is(msg.getTimestamp()));
    assertThat(transformed.getSubject().getId().longValue(), is(SubstitutionTableNumberCodec.lowerCaseOnly().decode(msg.getEntityId()).longValue()));
    assertThat(transformed.getSubject().getSource().toString(), is(msg.getEntitySource()));
    assertThat(transformed.getSubject().getResourceType(), is(ResourceType.CONTENT));
    assertThat(toKeys(transformed.getPublishers()), is(msg.getSources()));
    assertThat(Iterables.getOnlyElement(transformed.getAssertedAdjacents()).getId().longValue(), is(SubstitutionTableNumberCodec.lowerCaseOnly().decode(Iterables.getOnlyElement(adjs).getId()).longValue()));
    assertThat(Iterables.getOnlyElement(transformed.getAssertedAdjacents()).getSource().key(), is(Iterables.getOnlyElement(adjs).getSource()));
    assertThat(Iterables.getOnlyElement(transformed.getAssertedAdjacents()), instanceOf(ItemRef.class));
}
Also used : EquivalenceAssertionMessage(org.atlasapi.messaging.EquivalenceAssertionMessage) ContentEquivalenceAssertionMessage(org.atlasapi.messaging.v3.ContentEquivalenceAssertionMessage) ContentEquivalenceAssertionMessage(org.atlasapi.messaging.v3.ContentEquivalenceAssertionMessage) ItemRef(org.atlasapi.content.ItemRef) AdjacentRef(org.atlasapi.messaging.v3.ContentEquivalenceAssertionMessage.AdjacentRef) Test(org.junit.Test)

Example 4 with ContentEquivalenceAssertionMessage

use of org.atlasapi.messaging.v3.ContentEquivalenceAssertionMessage in project atlas-persistence by atlasapi.

the class ContentEquivalenceAssertionMessageTest method prepareMessage.

private ContentEquivalenceAssertionMessage prepareMessage() {
    Set<String> srcs = Sets.newHashSet(Publisher.BBC.key(), Publisher.ITV.key());
    List<AdjacentRef> adjacent = Lists.newArrayList(new AdjacentRef("cyp", "episode", Publisher.PA.key()), new AdjacentRef("dms", "item", Publisher.ITV.key()));
    return new ContentEquivalenceAssertionMessage("1", Timestamp.of(1), "cf2", "episode", "bbc.co.uk", adjacent, srcs);
}
Also used : AdjacentRef(org.atlasapi.messaging.v3.ContentEquivalenceAssertionMessage.AdjacentRef)

Example 5 with ContentEquivalenceAssertionMessage

use of org.atlasapi.messaging.v3.ContentEquivalenceAssertionMessage in project atlas-deer by atlasapi.

the class WorkersModule method createLegacyContentEquivalenceUpdatingWorker.

private Worker<ContentEquivalenceAssertionMessage> createLegacyContentEquivalenceUpdatingWorker(String workerName) {
    ContentEquivalenceAssertionLegacyTransformer transformer = new ContentEquivalenceAssertionLegacyTransformer();
    ContentEquivalenceUpdatingWorker worker = ContentEquivalenceUpdatingWorker.create(persistence.getContentEquivalenceGraphStore(), explicitEquivalenceMigrator(), WORKER_METRIC_PREFIX + workerName + ".", metricsModule.metrics(), createRateLimiter(contentEquivalenceGraphChangesMaxMessagesPerSecond));
    return (ContentEquivalenceAssertionMessage message) -> worker.process(transformer.transform(message));
}
Also used : ContentEquivalenceAssertionLegacyTransformer(org.atlasapi.system.bootstrap.workers.ContentEquivalenceAssertionLegacyTransformer) ContentEquivalenceAssertionMessage(org.atlasapi.messaging.v3.ContentEquivalenceAssertionMessage)

Aggregations

ContentEquivalenceAssertionMessage (org.atlasapi.messaging.v3.ContentEquivalenceAssertionMessage)3 AdjacentRef (org.atlasapi.messaging.v3.ContentEquivalenceAssertionMessage.AdjacentRef)3 ResourceRef (org.atlasapi.entity.ResourceRef)2 EquivalenceAssertionMessage (org.atlasapi.messaging.EquivalenceAssertionMessage)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Timestamp (com.metabroadcast.common.time.Timestamp)1 ItemRef (org.atlasapi.content.ItemRef)1 Publisher (org.atlasapi.media.entity.Publisher)1 ContentEquivalenceAssertionLegacyTransformer (org.atlasapi.system.bootstrap.workers.ContentEquivalenceAssertionLegacyTransformer)1 DateTime (org.joda.time.DateTime)1 Test (org.junit.Test)1