/** * Checks that a conversation is accessible by examining some state. */ protected static void assertConversationAccessible(Conversation conversation) { conversation.getAnchor(); assertThreadAccessible(conversation.getRootThread()); }
@Override public ConversationBlip getBlip(Conversation conversation, String blipId) throws InvalidRequestException { // We might need to look up the blip id for new blips. String actualBlipId = blipId.startsWith(TEMP_ID_MARKER) ? tempBlipIdMap.get(blipId) : blipId; ConversationBlip blip = conversation.getBlip(actualBlipId); if (blip == null) { throw new InvalidRequestException( "Blip with id " + blipId + " does not exist or has been deleted"); } return blip; }
@Override public String render(Conversation conversation, String participants, String thread) { return "Conversation [ id: " + conversation.getId() + "; participants: " + participants + "; thread: " + thread + " ]"; }
/** * Checks that a conversation is unusable by attempting mutation. */ protected static void assertConversationUnusable(Conversation conversation) { try { conversation.setAnchor(null); fail("Expected conversation to be unusable"); } catch (IllegalStateException expected) { } try { conversation.getRootThread().appendBlip(); fail("Expected conversation items to be unusable"); } catch (IllegalStateException expected) { } }
/** * A breadth-first iterator over blips in a conversation. Deleted blips are * skipped, but non-deleted descendant blips are included. */ public static Iterable<ConversationBlip> breadthFirst(Conversation conversation) { return breadthFirst(conversation.getRootThread()); }
void populate(ConversationBlip blip, FakeBlipView blipUi) { for (ThreadBuilder threadBuilder : unanchored) { ConversationThread thread = blip.addReplyThread(); threadBuilder.populate(thread, blipUi.insertDefaultAnchorBefore(null, thread).getThread()); } for (ThreadBuilder threadBuilder : anchored) { ConversationThread thread = blip.addReplyThread(blip.getContent().size() - 1); FakeAnchor anchor = blipUi.insertDefaultAnchorBefore(null, thread); FakeInlineThreadView threadUi = anchor.getThread(); threadBuilder.populate(thread, threadUi); anchor.detach(threadUi); blipUi.getMeta().createInlineAnchorBefore(null, thread).attach(threadUi); } for (ConversationBuilder conversationBuilder : privates) { Conversation conversation = wave.createConversation(); conversation.setAnchor(blip.getConversation().createAnchor(blip)); assert conversation.hasAnchor(); conversationBuilder.populate( conversation, blipUi.insertConversationBefore(null, conversation)); } }
for (Map.Entry<String, Set<Context>> entry : eventMessageBundle.getRequiredBlips().entrySet()) { Set<Context> contextSet = entry.getValue(); ConversationBlip requiredBlip = conversation.getBlip(entry.getKey()); if (contextSet.contains(Context.ALL)) { ContextResolver.addAllBlipsToEventMessages( ConversationBlip rootBlip = conversation.getRootThread().getFirstBlip(); if (rootBlip != requiredBlip) { ContextResolver.addBlipToEventMessages(
@Override public boolean isExplicitParticipant() { for (Conversation w : view.getConversations()) { if (w.getParticipantIds().contains(viewer)) { return true; } } return false; } }
/** * Finds the main conversation in a wave. The main conversation is defined as * the root if there is one, or the first unanchored conversation otherwise. */ public static Conversation getMainConversation(ConversationView view) { Conversation root = view.getRoot(); if (root == null) { for (Conversation curr : view.getConversations()) { if (!curr.hasAnchor()) { root = curr; break; } } } return root; } }
/** @return the structure of a conversations in {@code wave}. */ public static ConversationStructure of(ConversationView wave) { IdentityMap<ConversationBlip, Collection<Conversation>> anchoring = null; Collection<Conversation> unanchored = null; Conversation mainConversation = getMainConversation(wave); for (Conversation conversation : wave.getConversations()) { if (conversation == mainConversation) { continue; } Anchor anchor = conversation.getAnchor(); ConversationBlip blip = anchor != null ? anchor.getBlip() : null; if (blip != null) { addLazily((anchoring = createIfNull(anchoring)), blip, conversation); } else { (unanchored = createIfNull(unanchored)).add(conversation); } } if (anchoring == null) { anchoring = CollectionUtils.emptyIdentityMap(); } if (unanchored == null) { unanchored = Collections.emptySet(); } return new ConversationStructure(anchoring, unanchored, mainConversation); }
public TestingWaveletData( WaveId waveId, WaveletId waveletId, ParticipantId author, boolean isConversational) { waveletData = new WaveletDataImpl(waveletId, author, 1234567890, 0, HashedVersion.unsigned(0), 0, waveId, BasicFactories.observablePluggableMutableDocumentFactory()); userWaveletData = new WaveletDataImpl(WaveletId.of("example.com", "user+foo@example.com"), author, 1234567890, 0, HashedVersion.unsigned(0), 0, waveId, BasicFactories.observablePluggableMutableDocumentFactory()); OpBasedWavelet wavelet = new OpBasedWavelet(waveId, waveletData, new BasicWaveletOperationContextFactory(author), ParticipationHelper.DEFAULT, SilentOperationSink.Executor.<WaveletOperation, WaveletData>build(waveletData), SilentOperationSink.VOID); ReadOnlyWaveView waveView = new ReadOnlyWaveView(waveId); waveView.addWavelet(wavelet); if (isConversational) { ConversationView conversationView = WaveBasedConversationView.create(waveView, FakeIdGenerator.create()); WaveletBasedConversation.makeWaveletConversational(wavelet); conversation = conversationView.getRoot(); conversation.addParticipant(author); } else { conversation = null; } waveViewData = WaveViewDataImpl.create(waveId, ImmutableList.of(waveletData, userWaveletData)); }
void apply(Conversation conversation) { apply(conversation.getRootThread()); }
void populate(ConversationBlip blip, FakeBlipView blipUi) { for (ThreadBuilder threadBuilder : unanchored) { ConversationThread thread = blip.addReplyThread(); threadBuilder.populate(thread, blipUi.insertDefaultAnchorBefore(null, thread).getThread()); } for (ThreadBuilder threadBuilder : anchored) { ConversationThread thread = blip.addReplyThread(blip.getContent().size() - 1); FakeAnchor anchor = blipUi.insertDefaultAnchorBefore(null, thread); FakeInlineThreadView threadUi = anchor.getThread(); threadBuilder.populate(thread, threadUi); anchor.detach(threadUi); blipUi.getMeta().createInlineAnchorBefore(null, thread).attach(threadUi); } for (ConversationBuilder conversationBuilder : privates) { Conversation conversation = wave.createConversation(); conversation.setAnchor(blip.getConversation().createAnchor(blip)); assert conversation.hasAnchor(); conversationBuilder.populate( conversation, blipUi.insertConversationBefore(null, conversation)); } }
/** * Checks that a conversation is unusable by attempting mutation. */ protected static void assertConversationUnusable(Conversation conversation) { try { conversation.setAnchor(null); fail("Expected conversation to be unusable"); } catch (IllegalStateException expected) { } try { conversation.getRootThread().appendBlip(); fail("Expected conversation items to be unusable"); } catch (IllegalStateException expected) { } }
@Override public String render(Conversation conversation, StringMap<String> participants) { StringBuilder r = new StringBuilder("Participants ["); for (ParticipantId participant : conversation.getParticipantIds()) { r.append(" "); r.append(participants.get(participant.getAddress())); } r.append(" ]"); return r.toString(); }
public TestingWaveletData( WaveId waveId, WaveletId waveletId, ParticipantId author, boolean isConversational) { waveletData = new WaveletDataImpl(waveletId, author, 1234567890, 0, HashedVersion.unsigned(0), 0, waveId, BasicFactories.observablePluggableMutableDocumentFactory()); userWaveletData = new WaveletDataImpl(WaveletId.of("example.com", "user+foo@example.com"), author, 1234567890, 0, HashedVersion.unsigned(0), 0, waveId, BasicFactories.observablePluggableMutableDocumentFactory()); OpBasedWavelet wavelet = new OpBasedWavelet(waveId, waveletData, new BasicWaveletOperationContextFactory(author), ParticipationHelper.DEFAULT, SilentOperationSink.Executor.<WaveletOperation, WaveletData>build(waveletData), SilentOperationSink.VOID); ReadOnlyWaveView waveView = new ReadOnlyWaveView(waveId); waveView.addWavelet(wavelet); if (isConversational) { ConversationView conversationView = WaveBasedConversationView.create(waveView, FakeIdGenerator.create()); WaveletBasedConversation.makeWaveletConversational(wavelet); conversation = conversationView.getRoot(); conversation.addParticipant(author); } else { conversation = null; } waveViewData = WaveViewDataImpl.create(waveId, ImmutableList.of(waveletData, userWaveletData)); }
/** * Returns the blip id of the first blip in the root thread. * * @param conversation the conversation to get the blip id from. */ public static String getRootBlipId(Conversation conversation) { ConversationBlip rootBlip = conversation.getRootThread().getFirstBlip(); return (rootBlip != null) ? rootBlip.getId() : ""; } }
/** * Checks that a conversation is accessible by examining some state. */ protected static void assertConversationAccessible(Conversation conversation) { conversation.getAnchor(); assertThreadAccessible(conversation.getRootThread()); }
@Override public String render(Conversation conversation, String participants, String thread) { return "Conversation [ id: " + conversation.getId() + "; participants: " + participants + "; thread: " + thread + " ]"; }
public void testPutNonTemporaryBlip() throws Exception { // Non temporary blip is ignored Conversation conversation = mock(Conversation.class); ConversationBlip blip = mock(ConversationBlip.class); String blipId = "b+1234"; when(blip.getId()).thenReturn(blipId); when(conversation.getBlip(blipId)).thenReturn(blip); operationContext.putBlip(blip.getId(), blip); assertEquals(operationContext.getBlip(conversation, blipId), blip); }