@Override public void onDocumentChanged(DocumentChangedEvent event) { Blip blip = event.getBlip(); String modifiedBy = event.getModifiedBy(); CommandLine commandLine = null; try { commandLine = preprocessCommand(blip.getContent()); } catch (IllegalArgumentException e) { appendLine(blip, e.getMessage()); } if (commandLine != null) { if (commandLine.hasOption("help") // Or if only options. || (commandLine.getArgs().length - commandLine.getOptions().length <= 1)) { appendLine(blip, getFullDescription()); } else { String robotMessage = maybeExecuteCommand(commandLine, modifiedBy); appendLine(blip, robotMessage); } } }
@Override public void onDocumentChanged(DocumentChangedEvent e) { calledEvents.add(e.getType()); } }
public void testGenerateDocumentChangedEvent() throws Exception { ConversationBlip rootBlip = conversationUtil.buildConversation(wavelet).getRoot().getRootThread().getFirstBlip(); XmlStringBuilder builder = XmlStringBuilder.createText("some random content"); LineContainers.appendToLastLine(rootBlip.getContent(), builder); EventMessageBundle messages = generateAndCheckEvents(EventType.DOCUMENT_CHANGED); assertEquals("Expected one event", 1, messages.getEvents().size()); // Can not check the blip id because it is not accessible, however the line // here below will confirm that there was actually a real // DocumentChangedEvent put into the message bundle. DocumentChangedEvent event = DocumentChangedEvent.as(messages.getEvents().get(0)); assertEquals(ALEX.getAddress(), event.getModifiedBy()); }
@SuppressWarnings("unchecked") public void testProcessSendsBundleAndCallsOperationsApplicator() throws Exception { EventMessageBundle messages = new EventMessageBundle(ROBOT_NAME.toEmailAddress(), ""); messages.addEvent(new DocumentChangedEvent(null, null, ALEX.getAddress(), 0L, "b+1234")); when(eventGenerator.generateEvents( any(WaveletAndDeltas.class), anyMap(), any(EventDataConverter.class))).thenReturn(messages); OperationRequest op = new OperationRequest("wavelet.fetch", "op1"); List<OperationRequest> ops = Collections.singletonList(op); when(connector.sendMessageBundle( any(EventMessageBundle.class), eq(robot), any(ProtocolVersion.class))).thenReturn(ops); enqueueEmptyWavelet(); robot.run(); verify(connector).sendMessageBundle( any(EventMessageBundle.class), eq(robot), any(ProtocolVersion.class)); verify(operationApplicator).applyOperations( eq(ops), any(ReadableWaveletData.class), any(HashedVersion.class), eq(INITIALIZED_ACCOUNT)); }
break; case DOCUMENT_CHANGED: onDocumentChanged(DocumentChangedEvent.as(event)); break; case FORM_BUTTON_CLICKED:
@Capability(contexts = {Context.SELF, Context.SIBLINGS}) @Override public void onDocumentChanged(DocumentChangedEvent event) { Blip blip = event.getBlip(); if (!isShadowBlip(blip)) { createOrUpdateShadowBlip(blip); } }
public void testGenerateDocumentChangedEvent() throws Exception { ConversationBlip rootBlip = conversationUtil.buildConversation(wavelet).getRoot().getRootThread().getFirstBlip(); XmlStringBuilder builder = XmlStringBuilder.createText("some random content"); LineContainers.appendToLastLine(rootBlip.getContent(), builder); EventMessageBundle messages = generateAndCheckEvents(EventType.DOCUMENT_CHANGED); assertEquals("Expected one event", 1, messages.getEvents().size()); // Can not check the blip id because it is not accessible, however the line // here below will confirm that there was actually a real // DocumentChangedEvent put into the message bundle. DocumentChangedEvent event = DocumentChangedEvent.as(messages.getEvents().get(0)); assertEquals(ALEX.getAddress(), event.getModifiedBy()); }
@SuppressWarnings("unchecked") public void testProcessSendsBundleAndCallsOperationsApplicator() throws Exception { EventMessageBundle messages = new EventMessageBundle(ROBOT_NAME.toEmailAddress(), ""); messages.addEvent(new DocumentChangedEvent(null, null, ALEX.getAddress(), 0L, "b+1234")); when(eventGenerator.generateEvents( any(), anyMap(), any())).thenReturn(messages); OperationRequest op = new OperationRequest("wavelet.fetch", "op1"); List<OperationRequest> ops = Collections.singletonList(op); when(connector.sendMessageBundle( any(EventMessageBundle.class), eq(robot), any(ProtocolVersion.class))).thenReturn(ops); enqueueEmptyWavelet(); robot.run(); verify(connector).sendMessageBundle( any(EventMessageBundle.class), eq(robot), any(ProtocolVersion.class)); verify(operationApplicator).applyOperations( eq(ops), any(ReadableWaveletData.class), any(HashedVersion.class), eq(INITIALIZED_ACCOUNT)); }
&& !documentChangedEventGenerated && !gadgetStateChangeEvent) { DocumentChangedEvent apiEvent = new DocumentChangedEvent(null, null, deltaAuthor.getAddress(), deltaTimestamp, blip.getId()); addEvent(apiEvent, capabilities, blip.getId(), messages);
@Override public void onDocumentChanged(DocumentChangedEvent e) { calledEvents.add(e.getType()); } }
waveletData.addParticipant("foo@google.com"); BlipSubmittedEvent event1 = new BlipSubmittedEvent(null, null, "foo@test.com", 1l, "blip1"); DocumentChangedEvent event2 = new DocumentChangedEvent(null, null, "foo@test.com", 1l, "blip1"); WaveletTagsChangedEvent event3 = new WaveletTagsChangedEvent(null, null, "foo@test.com", 1l, "blip1");
@Override public void onDocumentChanged(DocumentChangedEvent e) { calledEvents.add(e.getType()); }
waveletData.addParticipant("foo@google.com"); BlipSubmittedEvent event1 = new BlipSubmittedEvent(null, null, "foo@test.com", 1l, "blip1"); DocumentChangedEvent event2 = new DocumentChangedEvent(null, null, "foo@test.com", 1l, "blip1"); WaveletTagsChangedEvent event3 = new WaveletTagsChangedEvent(null, null, "foo@test.com", 1l, "blip1");
@Override public void onDocumentChanged(DocumentChangedEvent e) { calledEvents.add(e.getType()); }