Search in sources :

Example 1 with OptionalMap

use of com.metabroadcast.common.collect.OptionalMap in project atlas-deer by atlasapi.

the class AbstractEquivalentContentStore method updateContent.

@Override
public final void updateContent(Id contentId) throws WriteException {
    metricRegistry.meter(updateContent + METER_CALLED).mark();
    try {
        lock.lock(contentId);
        Content content = resolveId(contentId);
        ImmutableList<Id> ids = ImmutableList.of(contentId);
        ListenableFuture<OptionalMap<Id, EquivalenceGraph>> graphs = graphStore.resolveIds(ids);
        Optional<EquivalenceGraph> possibleGraph = get(graphs).get(content.getId());
        EquivalenceGraph graph;
        if (possibleGraph.isPresent()) {
            graph = possibleGraph.get();
            update(graph, content);
        } else {
            graph = EquivalenceGraph.valueOf(content.toRef());
            update(graph, content);
        }
        sendEquivalentContentChangedMessage(content, graph);
    } catch (MessagingException | InterruptedException e) {
        metricRegistry.meter(updateContent + METER_FAILURE).mark();
        throw new WriteException("Updating " + contentId, e);
    } finally {
        lock.unlock(contentId);
    }
}
Also used : WriteException(org.atlasapi.entity.util.WriteException) MessagingException(com.metabroadcast.common.queue.MessagingException) OptionalMap(com.metabroadcast.common.collect.OptionalMap) Id(org.atlasapi.entity.Id) EquivalenceGraph(org.atlasapi.equivalence.EquivalenceGraph)

Example 2 with OptionalMap

use of com.metabroadcast.common.collect.OptionalMap in project atlas-deer by atlasapi.

the class CassandraEquivalenceGraphStoreIT method testCreatingEquivalences.

@Test
public void testCreatingEquivalences() throws Exception {
    ResourceRef subject = new BrandRef(Id.valueOf(1), Publisher.BBC);
    BrandRef equiv = new BrandRef(Id.valueOf(2), Publisher.PA);
    Set<ResourceRef> assertedAdjacents = ImmutableSet.<ResourceRef>of(equiv);
    Set<Publisher> sources = ImmutableSet.of(Publisher.BBC, Publisher.PA);
    store.updateEquivalences(subject, assertedAdjacents, sources);
    ListenableFuture<OptionalMap<Id, EquivalenceGraph>> resolveIds = store.resolveIds(ImmutableList.of(Id.valueOf(1)));
    OptionalMap<Id, EquivalenceGraph> graphs = Futures.get(resolveIds, ResolveException.class);
    EquivalenceGraph graph = graphs.get(Id.valueOf(1)).get();
    assertTrue(graph.getAdjacents(Id.valueOf(1)).getOutgoingEdges().contains(equiv));
    assertTrue(graph.getAdjacents(Id.valueOf(2)).getIncomingEdges().contains(subject));
}
Also used : OptionalMap(com.metabroadcast.common.collect.OptionalMap) ResourceRef(org.atlasapi.entity.ResourceRef) BrandRef(org.atlasapi.content.BrandRef) Publisher(org.atlasapi.media.entity.Publisher) Id(org.atlasapi.entity.Id) Test(org.junit.Test)

Aggregations

OptionalMap (com.metabroadcast.common.collect.OptionalMap)2 Id (org.atlasapi.entity.Id)2 MessagingException (com.metabroadcast.common.queue.MessagingException)1 BrandRef (org.atlasapi.content.BrandRef)1 ResourceRef (org.atlasapi.entity.ResourceRef)1 WriteException (org.atlasapi.entity.util.WriteException)1 EquivalenceGraph (org.atlasapi.equivalence.EquivalenceGraph)1 Publisher (org.atlasapi.media.entity.Publisher)1 Test (org.junit.Test)1