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);
}
}
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));
}
Aggregations