public void execute(OperationRequest operation, OperationContext context,
ParticipantId participant) throws InvalidRequestException {
// Get the conversation wavelet. If participant performing operation is not
// a member of wavelet, InvalidRequestException is thrown by this method.
ObservableConversation conversation =
context.openConversation(operation, participant).getRoot();
// Get participant operation is being performed on.
String paramParticipant =
OperationUtil.getRequiredParameter(operation, ParamsProperty.PARTICIPANT_ID);
ParticipantId targetParticipant;
try {
targetParticipant = ParticipantId.of(paramParticipant);
} catch (InvalidParticipantAddress e) {
String message = "Target ParticipantId " + paramParticipant + " is not " + "valid";
LOG.info(message);
throw new InvalidRequestException(message);
}
String rootBlipId = ConversationUtil.getRootBlipId(conversation);
// Create generic event (defined by operation type) that will be processed
// by the context.
Event event;
// Set up participant containers.
List<String> participantsAdded = Lists.newArrayList();
List<String> participantsRemoved = Lists.newArrayList();
OperationType type = OperationUtil.getOperationType(operation);
switch (type) {
case WAVELET_ADD_PARTICIPANT_NEWSYNTAX:
// Make sure targetParticipant is not already member.
if (conversation.getParticipantIds().contains(targetParticipant)) {
String message = targetParticipant.getAddress() + " is already a " + "member of wavelet";
LOG.info(message);
throw new InvalidRequestException(message, operation);
}
// Add participant to conversation and send event.
conversation.addParticipant(targetParticipant);
participantsAdded.add(targetParticipant.getAddress());
event =
new WaveletParticipantsChangedEvent(null, null, participant.getAddress(),
System.currentTimeMillis(), rootBlipId, participantsAdded, participantsRemoved);
break;
case WAVELET_REMOVE_PARTICIPANT_NEWSYNTAX:
// Make sure targetParticipant is already member.
if (!conversation.getParticipantIds().contains(targetParticipant)) {
// Not a member, throw invalid request.
String message = targetParticipant.getAddress() + " is not a " + "member of wavelet";
LOG.info(message);
throw new InvalidRequestException(message, operation);
}
// Remove participant and send event.
conversation.removeParticipant(targetParticipant);
participantsRemoved.add(targetParticipant.getAddress());
event =
new WaveletParticipantsChangedEvent(null, null, participant.getAddress(),
System.currentTimeMillis(), rootBlipId, participantsAdded, participantsRemoved);