@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); } }
/** * 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 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 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 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); } }
/** * Processes a {@link WaveletBlipCreatedEvent} and puts it into the context. * * @param operation the operation that has been performed * @param context the context of the operation. * @param participant the participant performing the operation. * @param conversation the conversation to which the new blip was added * @param newBlip the newly created blip. * @throws InvalidRequestException if the event could not be processed. */ private void processBlipCreatedEvent(OperationRequest operation, OperationContext context, ParticipantId participant, ObservableConversation conversation, ConversationBlip newBlip) throws InvalidRequestException { WaveletBlipCreatedEvent event = new WaveletBlipCreatedEvent(null, null, participant.getAddress(), System.currentTimeMillis(), ConversationUtil.getRootBlipId(conversation), newBlip.getId()); context.processEvent(operation, event); }
public void testContinueThread() throws Exception { OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); // Append a random blip to check that we actually append to the end of this // thread. conversation.getRootThread().appendBlip(); // Append to continue the thread of the root blip String rootBlipId = ConversationUtil.getRootBlipId(conversation); OperationRequest operation = operationRequest(OperationType.BLIP_CONTINUE_THREAD, rootBlipId, Parameter.of(ParamsProperty.BLIP_DATA, blipData)); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse(response.isError()); ConversationBlip newBlip = checkAndGetNewBlip(context, conversation, response); Iterator<? extends ObservableConversationBlip> it = conversation.getRootThread().getBlips().iterator(); it.next(); // skip, root it.next(); // skip, first reply assertEquals("New blip should be the third blip in the root thread", newBlip, it.next()); }
public void testContinueThread() throws Exception { OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); // Append a random blip to check that we actually append to the end of this // thread. conversation.getRootThread().appendBlip(); // Append to continue the thread of the root blip String rootBlipId = ConversationUtil.getRootBlipId(conversation); OperationRequest operation = operationRequest(OperationType.BLIP_CONTINUE_THREAD, rootBlipId, Parameter.of(ParamsProperty.BLIP_DATA, blipData)); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse(response.isError()); ConversationBlip newBlip = checkAndGetNewBlip(context, conversation, response); Iterator<? extends ObservableConversationBlip> it = conversation.getRootThread().getBlips().iterator(); it.next(); // skip, root it.next(); // skip, first reply assertEquals("New blip should be the third blip in the root thread", newBlip, it.next()); }
public void testInvalidParticipantAddress() throws Exception { OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ROBOT).getRoot(); String rootBlipId = ConversationUtil.getRootBlipId(conversation); OperationRequest operation = operationRequest(OperationType.WAVELET_ADD_PARTICIPANT_NEWSYNTAX, rootBlipId, Parameter.of(ParamsProperty.PARTICIPANT_ID, MALFORMED_ADDRESS)); try { service.execute(operation, context, ROBOT); fail("Addition of invalid particpant address should have generated error in service " + "execution."); } catch(InvalidRequestException e) { // Good. } } }
public void testInvalidParticipantAddress() throws Exception { OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ROBOT).getRoot(); String rootBlipId = ConversationUtil.getRootBlipId(conversation); OperationRequest operation = operationRequest(OperationType.WAVELET_ADD_PARTICIPANT_NEWSYNTAX, rootBlipId, Parameter.of(ParamsProperty.PARTICIPANT_ID, MALFORMED_ADDRESS)); try { service.execute(operation, context, ROBOT); fail("Addition of invalid particpant address should have generated error in service " + "execution."); } catch(InvalidRequestException e) { // Good. } } }
public void testAddThrowsOnDuplicateParticipant() throws Exception { OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ROBOT).getRoot(); String rootBlipId = ConversationUtil.getRootBlipId(conversation); // Confirm robot is on wave prior to operation to re-add it. Set<ParticipantId> participants = conversation.getParticipantIds(); assertTrue("Robot should be a participant on wavelet prior to test operation to add it.", participants.contains(ROBOT)); OperationRequest operation = operationRequest(OperationType.WAVELET_ADD_PARTICIPANT_NEWSYNTAX, rootBlipId, Parameter.of(ParamsProperty.PARTICIPANT_ID, ROBOT.getAddress())); try { service.execute(operation, context, ROBOT); fail("Duplicate add of participant should have generated error in service execution."); } catch(InvalidRequestException e) { // Good. } }
public void testRemoveThrowsOnNonWaveletParticipant() throws Exception { OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ROBOT).getRoot(); String rootBlipId = ConversationUtil.getRootBlipId(conversation); // Confirm alex is not on wave prior to operation. Set<ParticipantId> participants = conversation.getParticipantIds(); assertFalse("Alex should not be a participant on wavelet prior to operation to add him.", participants.contains(ALEX)); OperationRequest operation = operationRequest(OperationType.WAVELET_REMOVE_PARTICIPANT_NEWSYNTAX, rootBlipId, Parameter.of(ParamsProperty.PARTICIPANT_ID, ALEX.getAddress())); try { service.execute(operation, context, ROBOT); fail("Removal of non-participant should have generated error in service execution."); } catch(InvalidRequestException e) { // Good. } }
public void testAddThrowsOnDuplicateParticipant() throws Exception { OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ROBOT).getRoot(); String rootBlipId = ConversationUtil.getRootBlipId(conversation); // Confirm robot is on wave prior to operation to re-add it. Set<ParticipantId> participants = conversation.getParticipantIds(); assertTrue("Robot should be a participant on wavelet prior to test operation to add it.", participants.contains(ROBOT)); OperationRequest operation = operationRequest(OperationType.WAVELET_ADD_PARTICIPANT_NEWSYNTAX, rootBlipId, Parameter.of(ParamsProperty.PARTICIPANT_ID, ROBOT.getAddress())); try { service.execute(operation, context, ROBOT); fail("Duplicate add of participant should have generated error in service execution."); } catch(InvalidRequestException e) { // Good. } }
public void testRemoveThrowsOnNonWaveletParticipant() throws Exception { OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ROBOT).getRoot(); String rootBlipId = ConversationUtil.getRootBlipId(conversation); // Confirm alex is not on wave prior to operation. Set<ParticipantId> participants = conversation.getParticipantIds(); assertFalse("Alex should not be a participant on wavelet prior to operation to add him.", participants.contains(ALEX)); OperationRequest operation = operationRequest(OperationType.WAVELET_REMOVE_PARTICIPANT_NEWSYNTAX, rootBlipId, Parameter.of(ParamsProperty.PARTICIPANT_ID, ALEX.getAddress())); try { service.execute(operation, context, ROBOT); fail("Removal of non-participant should have generated error in service execution."); } catch(InvalidRequestException e) { // Good. } }
public void testAddParticipant() throws Exception { OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ROBOT).getRoot(); String rootBlipId = ConversationUtil.getRootBlipId(conversation); // Confirm alex is not on wave prior to operation. Set<ParticipantId> participants = conversation.getParticipantIds(); assertFalse("Alex should not be a participant on wavelet prior to operation to add him.", participants.contains(ALEX)); OperationRequest operation = operationRequest(OperationType.WAVELET_ADD_PARTICIPANT_NEWSYNTAX, rootBlipId, Parameter.of(ParamsProperty.PARTICIPANT_ID,ALEX.getAddress())); service.execute(operation, context, ROBOT); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse("Add Participant generated error in service execution.", response.isError()); // Verify Alex is now a participant on the wave. participants = conversation.getParticipantIds(); assertTrue("Alex should now be a participant on the wavelet.", participants.contains(ALEX)); }
public void testAddParticipant() throws Exception { OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ROBOT).getRoot(); String rootBlipId = ConversationUtil.getRootBlipId(conversation); // Confirm alex is not on wave prior to operation. Set<ParticipantId> participants = conversation.getParticipantIds(); assertFalse("Alex should not be a participant on wavelet prior to operation to add him.", participants.contains(ALEX)); OperationRequest operation = operationRequest(OperationType.WAVELET_ADD_PARTICIPANT_NEWSYNTAX, rootBlipId, Parameter.of(ParamsProperty.PARTICIPANT_ID,ALEX.getAddress())); service.execute(operation, context, ROBOT); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse("Add Participant generated error in service execution.", response.isError()); // Verify Alex is now a participant on the wave. participants = conversation.getParticipantIds(); assertTrue("Alex should now be a participant on the wavelet.", participants.contains(ALEX)); }
public void testDeleteBlip() throws Exception { OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); // Delete the root blip String rootBlipId = ConversationUtil.getRootBlipId(conversation); OperationRequest operation = operationRequest(OperationType.BLIP_DELETE, rootBlipId); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse(response.isError()); assertNull("Blip should have been deleted", conversation.getBlip(rootBlipId)); }
public void testDeleteBlip() throws Exception { OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); // Delete the root blip String rootBlipId = ConversationUtil.getRootBlipId(conversation); OperationRequest operation = operationRequest(OperationType.BLIP_DELETE, rootBlipId); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse(response.isError()); assertNull("Blip should have been deleted", conversation.getBlip(rootBlipId)); }
public void testCreateChild() throws Exception { OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); // Append a random blip to check that we actually make a new child blip conversation.getRootThread().appendBlip(); // Create a child to the rootblip String rootBlipId = ConversationUtil.getRootBlipId(conversation); OperationRequest operation = operationRequest(OperationType.BLIP_CREATE_CHILD, rootBlipId, Parameter.of(ParamsProperty.BLIP_DATA, blipData)); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse(response.isError()); ConversationBlip newBlip = checkAndGetNewBlip(context, conversation, response); Iterator<? extends ObservableConversationThread> it = conversation.getRootThread().getFirstBlip().getReplyThreads().iterator(); assertEquals("New blip should be the first blip in the first reply thread", it.next().getFirstBlip(), newBlip); }
public void testCreateChild() throws Exception { OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); // Append a random blip to check that we actually make a new child blip conversation.getRootThread().appendBlip(); // Create a child to the rootblip String rootBlipId = ConversationUtil.getRootBlipId(conversation); OperationRequest operation = operationRequest(OperationType.BLIP_CREATE_CHILD, rootBlipId, Parameter.of(ParamsProperty.BLIP_DATA, blipData)); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse(response.isError()); ConversationBlip newBlip = checkAndGetNewBlip(context, conversation, response); Iterator<? extends ObservableConversationThread> it = conversation.getRootThread().getFirstBlip().getReplyThreads().iterator(); assertEquals("New blip should be the first blip in the first reply thread", it.next().getFirstBlip(), newBlip); }