@Override public ObservableConversationView openConversation(WaveId waveId, WaveletId waveletId, ParticipantId participant) throws InvalidRequestException { WaveletName waveletName = WaveletName.of(waveId, waveletId); if (!openedConversations.containsKey(waveletName)) { openedConversations.put( waveletName, Maps.<ParticipantId, ObservableConversationView> newHashMap()); } Map<ParticipantId, ObservableConversationView> conversations = openedConversations.get(waveletName); if (!conversations.containsKey(participant)) { OpBasedWavelet wavelet = openWavelet(waveId, waveletId, participant); conversations.put(participant, conversationUtil.buildConversation(wavelet)); } return conversations.get(participant); }
@Override public void onParticipantRemoved(ParticipantId participant) { if (capabilities.containsKey(EventType.WAVELET_PARTICIPANTS_CHANGED)) { participantsRemoved.add(participant.getAddress()); } if (capabilities.containsKey(EventType.WAVELET_SELF_REMOVED) && participant.equals(robotId)) { String rootBlipId = ConversationUtil.getRootBlipId(conversation); WaveletSelfRemovedEvent event = new WaveletSelfRemovedEvent( null, null, deltaAuthor.getAddress(), deltaTimestamp, rootBlipId); addEvent(event, capabilities, rootBlipId, messages); } }
@Override protected void setUp() { MockitoAnnotations.initMocks(this); conversationUtil = new ConversationUtil(idGenerator); digester = new WaveDigester(conversationUtil); }
/** * Constructs a new {@link OperationServiceHelper} with a wavelet with the * name and participant that are passed in. * * @param waveletName the name of the empty wavelet to open in the context. * @param participant the participant that should be on that empty wavelet. */ public OperationServiceHelper(WaveletName waveletName, ParticipantId participant) { waveletProvider = mock(WaveletProvider.class); EventDataConverter converter = new EventDataConverterV22(); ObservableWaveletData waveletData = WaveletDataImpl.Factory.create(DOCUMENT_FACTORY).create( new EmptyWaveletSnapshot(waveletName.waveId, waveletName.waveletId, participant, HASH_FACTORY.createVersionZero(waveletName), 0L)); waveletData.addParticipant(participant); BasicWaveletOperationContextFactory CONTEXT_FACTORY = new BasicWaveletOperationContextFactory(participant); SilentOperationSink<WaveletOperation> executor = SilentOperationSink.Executor.<WaveletOperation, WaveletData>build(waveletData); OpBasedWavelet wavelet = new OpBasedWavelet(waveletData.getWaveId(), waveletData, CONTEXT_FACTORY, ParticipationHelper.DEFAULT, executor, SilentOperationSink.VOID); // Make a conversation with an empty root blip WaveletBasedConversation.makeWaveletConversational(wavelet); ConversationUtil conversationUtil = new ConversationUtil(FakeIdGenerator.create()); ObservableConversation conversation = conversationUtil.buildConversation(wavelet).getRoot(); conversation.getRootThread().appendBlip(); context = new OperationContextImpl(waveletProvider, converter, conversationUtil); context.putWavelet(waveletName.waveId, waveletName.waveletId, new RobotWaveletData(waveletData, HASH_FACTORY.createVersionZero(waveletName))); }
WaveletName waveletName = context.getConversationUtil().generateWaveletName(); RobotWaveletData newWavelet = createEmptyRobotWavelet(participant, waveletName); OpBasedWavelet opBasedWavelet = newWavelet.getOpBasedWavelet(participant); context.getConversationUtil().buildConversation(opBasedWavelet); ObservableConversationBlip rootBlip = conversation.getRoot().getRootThread().appendBlip();
@Override protected void setUp() throws Exception { conversationUtil = new ConversationUtil(FakeIdGenerator.create()); eventGenerator = new EventGenerator(ROBOT_NAME, conversationUtil); waveletData = WaveletDataImpl.Factory.create(DOCUMENT_FACTORY).create( new EmptyWaveletSnapshot(WAVELET_NAME.waveId, WAVELET_NAME.waveletId, ALEX, HASH_FACTORY.createVersionZero(WAVELET_NAME), 0L)); // Robot should be participant in snapshot before deltas // otherwise events will be filtered out. waveletData.addParticipant(ROBOT); waveletData.addParticipant(ALEX); waveletData.setVersion(1); SilentOperationSink<WaveletOperation> executor = SilentOperationSink.Executor.<WaveletOperation, WaveletData> build(waveletData); output = new CapturingOperationSink<WaveletOperation>(); wavelet = new OpBasedWavelet(waveletData.getWaveId(), waveletData, CONTEXT_FACTORY, ParticipationHelper.DEFAULT, executor, output); // Make a conversation and clear the sink WaveletBasedConversation.makeWaveletConversational(wavelet); conversationUtil.buildConversation(wavelet).getRoot().getRootThread().appendBlip(); output.clear(); }
/** * Returns the root conversation from the given wavelet. Or null if there is * none. * * @param wavelet the wavelet to get the conversation from. */ private ObservableConversation getRootConversation(ObservableWavelet wavelet) { if (!WaveletBasedConversation.waveletHasConversation(wavelet)) { // No conversation present, bail. return null; } ObservableConversation conversation = conversationUtil.buildConversation(wavelet).getRoot(); if (conversation.getRootThread().getFirstBlip() == null) { // No root blip is present, this will cause Robot API code // to fail when resolving the context of events. This might be fixed later // on by making changes to the ContextResolver. return null; } return conversation; } }
@Override public void onBlipDeleted(ObservableConversationBlip blip) { if (capabilities.containsKey(EventType.WAVELET_BLIP_REMOVED)) { String rootBlipId = ConversationUtil.getRootBlipId(conversation); WaveletBlipRemovedEvent event = new WaveletBlipRemovedEvent( null, null, deltaAuthor.getAddress(), deltaTimestamp, rootBlipId, blip.getId()); addEvent(event, capabilities, rootBlipId, messages); } }
@Override protected void setUp() throws Exception { conversationUtil = new ConversationUtil(FakeIdGenerator.create()); eventGenerator = new EventGenerator(ROBOT_NAME, conversationUtil); waveletData = WaveletDataImpl.Factory.create(DOCUMENT_FACTORY).create( new EmptyWaveletSnapshot(WAVELET_NAME.waveId, WAVELET_NAME.waveletId, ALEX, HASH_FACTORY.createVersionZero(WAVELET_NAME), 0L)); // Robot should be participant in snapshot before deltas // otherwise events will be filtered out. waveletData.addParticipant(ROBOT); waveletData.addParticipant(ALEX); waveletData.setVersion(1); SilentOperationSink<WaveletOperation> executor = SilentOperationSink.Executor.<WaveletOperation, WaveletData> build(waveletData); output = new CapturingOperationSink<WaveletOperation>(); wavelet = new OpBasedWavelet(waveletData.getWaveId(), waveletData, CONTEXT_FACTORY, ParticipationHelper.DEFAULT, executor, output); // Make a conversation and clear the sink WaveletBasedConversation.makeWaveletConversational(wavelet); conversationUtil.buildConversation(wavelet).getRoot().getRootThread().appendBlip(); output.clear(); }
@Override protected void setUp() { MockitoAnnotations.initMocks(this); conversationUtil = new ConversationUtil(idGenerator); digester = new WaveDigester(conversationUtil); }
public void testWaveletWithNoBlipsResultsInEmptyTitleAndNoBlips() { TestingWaveletData data = new TestingWaveletData(WAVE_ID, CONVERSATION_WAVELET_ID, PARTICIPANT, true); ObservableWaveletData observableWaveletData = data.copyWaveletData().get(0); ObservableWavelet wavelet = OpBasedWavelet.createReadOnly(observableWaveletData); ObservableConversationView conversation = conversationUtil.buildConversation(wavelet); SupplementedWave supplement = mock(SupplementedWave.class); when(supplement.isUnread(any(ConversationBlip.class))).thenReturn(true); Digest digest = digester.generateDigest(conversation, supplement, observableWaveletData); assertEquals("", digest.getTitle()); assertEquals(digest.getBlipCount(), 0); }
@Override public void onBlipAdded(ObservableConversationBlip blip) { if (capabilities.containsKey(EventType.WAVELET_BLIP_CREATED)) { String rootBlipId = ConversationUtil.getRootBlipId(conversation); WaveletBlipCreatedEvent event = new WaveletBlipCreatedEvent( null, null, deltaAuthor.getAddress(), deltaTimestamp, rootBlipId, blip.getId()); addEvent(event, capabilities, rootBlipId, messages); } }
@Override protected void setUp() { service = CreateWaveletService.create(); waveletProvider = mock(WaveletProvider.class); converter = mock(EventDataConverter.class); waveletData = mock(WaveletData.class); when(waveletData.getWaveId()).thenReturn(TEMP_WAVE_ID); when(waveletData.getWaveletId()).thenReturn(WAVELET_ID); when(waveletData.getRootBlipId()).thenReturn("b+root"); ConversationUtil conversationUtil = new ConversationUtil(FakeIdGenerator.create()); context = new OperationContextImpl(waveletProvider, converter, conversationUtil); operation = new OperationRequest(OperationType.ROBOT_CREATE_WAVELET.method(), OPERATION_ID, Parameter.of(ParamsProperty.WAVELET_DATA, waveletData), Parameter.of(ParamsProperty.MESSAGE, MESSAGE)); }
public void testWaveletWithNoBlipsResultsInEmptyTitleAndNoBlips() { TestingWaveletData data = new TestingWaveletData(WAVE_ID, CONVERSATION_WAVELET_ID, PARTICIPANT, true); ObservableWaveletData observableWaveletData = data.copyWaveletData().get(0); ObservableWavelet wavelet = OpBasedWavelet.createReadOnly(observableWaveletData); ObservableConversationView conversation = conversationUtil.buildConversation(wavelet); SupplementedWave supplement = mock(SupplementedWave.class); when(supplement.isUnread(any(ConversationBlip.class))).thenReturn(true); Digest digest = digester.generateDigest(conversation, supplement, observableWaveletData); assertEquals("", digest.getTitle()); assertEquals(digest.getBlipCount(), 0); }
/** * Generates the events that are collected over the span of one delta. */ public void deltaEnd() { if (!participantsAdded.isEmpty() || !participantsRemoved.isEmpty()) { String rootBlipId = ConversationUtil.getRootBlipId(conversation); WaveletParticipantsChangedEvent event = new WaveletParticipantsChangedEvent(null, null, deltaAuthor.getAddress(), deltaTimestamp, rootBlipId, participantsAdded, participantsRemoved); addEvent(event, capabilities, rootBlipId, messages); } clearOncePerDeltaCollectors(); deltaAuthor = null; deltaTimestamp = null; }
@Override protected void setUp() { service = CreateWaveletService.create(); waveletProvider = mock(WaveletProvider.class); converter = mock(EventDataConverter.class); waveletData = mock(WaveletData.class); when(waveletData.getWaveId()).thenReturn(TEMP_WAVE_ID); when(waveletData.getWaveletId()).thenReturn(WAVELET_ID); when(waveletData.getRootBlipId()).thenReturn("b+root"); ConversationUtil conversationUtil = new ConversationUtil(FakeIdGenerator.create()); context = new OperationContextImpl(waveletProvider, converter, conversationUtil); operation = new OperationRequest(OperationType.ROBOT_CREATE_WAVELET.method(), OPERATION_ID, Parameter.of(ParamsProperty.WAVELET_DATA, waveletData), Parameter.of(ParamsProperty.MESSAGE, MESSAGE)); }
public void testWaveletWithBlipsResultsInNonEmptyTitle() { TestingWaveletData data = new TestingWaveletData(WAVE_ID, CONVERSATION_WAVELET_ID, PARTICIPANT, true); String title = "title"; data.appendBlipWithText(title); ObservableWaveletData observableWaveletData = data.copyWaveletData().get(0); ObservableWavelet wavelet = OpBasedWavelet.createReadOnly(observableWaveletData); ObservableConversationView conversation = conversationUtil.buildConversation(wavelet); SupplementedWave supplement = mock(SupplementedWave.class); when(supplement.isUnread(any(ConversationBlip.class))).thenReturn(true); Digest digest = digester.generateDigest(conversation, supplement, observableWaveletData); assertEquals(title, digest.getTitle()); assertEquals(1, digest.getBlipCount()); }
@Override public void onParticipantAdded(ParticipantId participant) { if (capabilities.containsKey(EventType.WAVELET_PARTICIPANTS_CHANGED)) { boolean removedBefore = participantsRemoved.remove(participant.getAddress()); if (!removedBefore) { participantsAdded.add(participant.getAddress()); } } // This deviates from Google Wave production which always sends this // event, even if it wasn't present in your capabilities. if (capabilities.containsKey(EventType.WAVELET_SELF_ADDED) && participant.equals(robotId)) { // The robot has been added String rootBlipId = ConversationUtil.getRootBlipId(conversation); WaveletSelfAddedEvent event = new WaveletSelfAddedEvent( null, null, deltaAuthor.getAddress(), deltaTimestamp, rootBlipId); addEvent(event, capabilities, rootBlipId, messages); } }
when(waveViewProvider.retrievePerUserWaveView(SHARED_USER)).thenReturn(wavesViewUser3); ConversationUtil conversationUtil = new ConversationUtil(idGenerator); WaveDigester digester = new WaveDigester(conversationUtil);
public void testWaveletWithBlipsResultsInNonEmptyTitle() { TestingWaveletData data = new TestingWaveletData(WAVE_ID, CONVERSATION_WAVELET_ID, PARTICIPANT, true); String title = "title"; data.appendBlipWithText(title); ObservableWaveletData observableWaveletData = data.copyWaveletData().get(0); ObservableWavelet wavelet = OpBasedWavelet.createReadOnly(observableWaveletData); ObservableConversationView conversation = conversationUtil.buildConversation(wavelet); SupplementedWave supplement = mock(SupplementedWave.class); when(supplement.isUnread(any(ConversationBlip.class))).thenReturn(true); Digest digest = digester.generateDigest(conversation, supplement, observableWaveletData); assertEquals(title, digest.getTitle()); assertEquals(1, digest.getBlipCount()); }