*/
@Override
public void execute(
OperationRequest operation, OperationContext context, ParticipantId participant)
throws InvalidRequestException {
WaveletData waveletData =
OperationUtil.getRequiredParameter(operation, ParamsProperty.WAVELET_DATA);
// The loop validates the addresses present in the wavelet data before
// creating a new wavelet.
List<ParticipantId> participants = Lists.newArrayList(participant);
for (String address : waveletData.getParticipants()) {
try {
participants.add(ParticipantId.of(address));
} catch (InvalidParticipantAddress e) {
throw new InvalidRequestException(
address + " is not a valid participant address", operation);
}
}
WaveletName waveletName = context.getConversationUtil().generateWaveletName();
RobotWaveletData newWavelet = createEmptyRobotWavelet(participant, waveletName);
OpBasedWavelet opBasedWavelet = newWavelet.getOpBasedWavelet(participant);
WaveletBasedConversation.makeWaveletConversational(opBasedWavelet);
ObservableConversationView conversation =
context.getConversationUtil().buildConversation(opBasedWavelet);
ObservableConversationBlip rootBlip = conversation.getRoot().getRootThread().appendBlip();
for (ParticipantId newParticipant : participants) {
opBasedWavelet.addParticipant(newParticipant);
}
// Store the temporary id of the wavelet and rootblip so that future
// operations can reference it.
try {
WaveId waveId = ApiIdSerializer.instance().deserialiseWaveId(waveletData.getWaveId());
WaveletId waveletId =
ApiIdSerializer.instance().deserialiseWaveletId(waveletData.getWaveletId());
context.putWavelet(waveId, waveletId, newWavelet);
} catch (InvalidIdException e) {
throw new InvalidRequestException("Invalid id", operation, e);
}
context.putBlip(waveletData.getRootBlipId(), rootBlip);
String message = OperationUtil.getOptionalParameter(operation, ParamsProperty.MESSAGE);
WaveletCreatedEvent event =
new WaveletCreatedEvent(null, null, participant.getAddress(), System.currentTimeMillis(),
rootBlip.getId(), message,