@Override public void onFailire(String message) { context.constructErrorResponse(operation, message); } });
@Override public void execute(OperationRequest operation, OperationContext context, ParticipantId participant) throws InvalidRequestException { if (OperationUtil.<Boolean>getOptionalParameter(operation, ParamsProperty.RETURN_WAVELET_IDS, false)) { ImmutableSet<WaveletId> waveletIds = context.getVisibleWaveletIds(operation, participant); Map<ParamsProperty, Object> data = ImmutableMap.<ParamsProperty, Object>of(ParamsProperty.WAVELET_IDS, waveletIds); context.constructResponse(operation, data); } else { OpBasedWavelet wavelet = context.openWavelet(operation, participant); ObservableConversation conversation = context.openConversation(operation, participant).getRoot(); EventMessageBundle messages = mapWaveletToMessageBundle(context.getConverter(), participant, wavelet, conversation); String rootBlipId = ConversationUtil.getRootBlipId(conversation); String message = OperationUtil.getOptionalParameter(operation, ParamsProperty.MESSAGE); WaveletFetchedEvent event = new WaveletFetchedEvent(null, null, participant.getAddress(), System.currentTimeMillis(), message, rootBlipId, messages.getWaveletData(), messages.getBlipData(), messages.getThreads()); context.processEvent(operation, event); } }
/** * Implementation for the {@link OperationType#BLIP_DELETE} method. It deletes * the blip specified in the operation. * * @param operation the operation to execute. * @param context the context of the operation. * @param participant the participant performing this operation. * @param conversation the conversation to operate on. * @throws InvalidRequestException if the operation fails to perform */ private void delete(OperationRequest operation, OperationContext context, ParticipantId participant, ObservableConversation conversation) throws InvalidRequestException { Preconditions.checkArgument( OperationUtil.getOperationType(operation) == OperationType.BLIP_DELETE, "Unsupported operation " + operation); String blipId = OperationUtil.getRequiredParameter(operation, ParamsProperty.BLIP_ID); context.getBlip(conversation, blipId).delete(); // report success. context.constructResponse(operation, Maps.<ParamsProperty, Object> newHashMap()); }
@Override public void execute( OperationRequest operation, OperationContext context, ParticipantId participant) throws InvalidRequestException { String title = OperationUtil.getRequiredParameter(operation, ParamsProperty.WAVELET_TITLE); ObservableConversation conversation = context.openConversation(operation, participant).getRoot(); String blipId = conversation.getRootThread().getFirstBlip().getId(); Document doc = context.getBlip(conversation, blipId).getContent(); TitleHelper.setExplicitTitle(doc, title); }
} catch (PersistenceException e) { LOG.severe("Failed to retreive account data for " + robotAccountId, e); context.constructErrorResponse(operation, "Unable to retrieve account data"); return; if (capabilities != null && capabilitiesHash.equals(capabilities.getCapabilitiesHash())) { context.constructResponse(operation, Maps.<ParamsProperty, Object> newHashMap()); return; } catch (CapabilityFetchException e) { LOG.fine("Unable to retrieve capabilities for " + account.getId(), e); context.constructErrorResponse(operation, "Unable to retrieve new capabilities"); return; } catch (PersistenceException e) { LOG.severe("Failed to update account data for " + robotAccountId, e); context.constructErrorResponse(operation, "Unable to update account data"); return; context.constructResponse(operation, Maps.<ParamsProperty, Object> newHashMap());
@Override public void execute( OperationRequest operation, OperationContext context, ParticipantId participant) { context.constructResponse(operation, Maps.<ParamsProperty, Object> newHashMap()); } }
OperationUtil.getRequiredParameter(operation, ParamsProperty.MODIFY_ACTION); OpBasedWavelet wavelet = context.openWavelet(operation, participant); ObservableConversation conversation = context.openConversation(operation, participant).getRoot(); Document doc = context.getBlip(conversation, blipId).getContent();
@Override public void execute(OperationRequest operation, OperationContext context, ParticipantId participant) throws InvalidRequestException { String modifyHow = OperationUtil.getRequiredParameter(operation, ParamsProperty.MODIFY_HOW); String blipId = OperationUtil.getOptionalParameter(operation, ParamsProperty.BLIP_ID); SupplementedWave supplement = buildSupplement(operation, context, participant); if (modifyHow.equals(ModifyHowType.MARK_AS_READ.getValue())) { if (blipId == null || blipId.isEmpty()) { supplement.markAsRead(); } else { ObservableConversation conversation = context.openConversation(operation, participant).getRoot(); ConversationBlip blip = conversation.getBlip(blipId); supplement.markAsRead(blip); } } else if (modifyHow.equals(ModifyHowType.MARK_AS_UNREAD.getValue())) { supplement.markAsUnread(); } else { throw new UnsupportedOperationException("Unsupported folder action: " + modifyHow); } // Construct empty response. Map<ParamsProperty, Object> data = Maps.newHashMap(); context.constructResponse(operation, data); } }
/** * Builds the supplement model for a wave. * * @param operation the operation. * @param context the operation context. * @param participant the viewer. * @return the wave supplement. * @throws InvalidRequestException if the wave id provided in the operation is * invalid. */ public static SupplementedWave buildSupplement(OperationRequest operation, OperationContext context, ParticipantId participant) throws InvalidRequestException { OpBasedWavelet wavelet = context.openWavelet(operation, participant); ConversationView conversationView = context.getConversationUtil().buildConversation(wavelet); // TODO (Yuri Z.) Find a way to obtain an instance of IdGenerator and use it // to create udwId. WaveletId udwId = IdUtil.buildUserDataWaveletId(participant); String waveIdStr = OperationUtil.getRequiredParameter(operation, ParamsProperty.WAVE_ID); WaveId waveId = null; try { waveId = ApiIdSerializer.instance().deserialiseWaveId(waveIdStr); } catch (InvalidIdException e) { throw new InvalidRequestException("Invalid WAVE_ID parameter: " + waveIdStr, operation, e); } OpBasedWavelet udw = context.openWavelet(waveId, udwId, participant); PrimitiveSupplement udwState = WaveletBasedSupplement.create(udw); SupplementedWave supplement = SupplementedWaveImpl.create(udwState, conversationView, participant, DefaultFollow.ALWAYS); return supplement; }
@Override public void execute(OperationRequest operation, OperationContext context, ParticipantId participant) throws InvalidRequestException { WaveId waveId; WaveletId waveletId; try { waveId = ApiIdSerializer.instance().deserialiseWaveId( OperationUtil.<String>getRequiredParameter(operation, ParamsProperty.WAVE_ID)); waveletId = ApiIdSerializer.instance().deserialiseWaveletId( OperationUtil.<String>getRequiredParameter(operation, ParamsProperty.WAVELET_ID)); } catch (InvalidIdException ex) { throw new InvalidRequestException("Invalid id", operation, ex); } WaveletName waveletName = WaveletName.of(waveId, waveletId); CommittedWaveletSnapshot snapshot = context.getWaveletSnapshot(waveletName, participant); WaveletSnapshot protoSnapshot = SnapshotSerializer.serializeWavelet(snapshot.snapshot, snapshot.snapshot.getHashedVersion()); WaveletSnapshotProtoImpl protoSnapshotImpl = new WaveletSnapshotProtoImpl(protoSnapshot); String jsonSnapshot = gson.toJson(protoSnapshotImpl.toGson(null, gson)); Map<ParamsProperty, Object> data = ImmutableMap.<ParamsProperty, Object> of(ParamsProperty.RAW_SNAPSHOT, jsonSnapshot); context.constructResponse(operation, data); }
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(); 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); ApiIdSerializer.instance().serialiseWaveId(waveletName.waveId), ApiIdSerializer.instance().serialiseWaveletId(waveletName.waveletId)); context.processEvent(operation, event);
/** * Implementation of the {@link OperationType#BLIP_CREATE_CHILD} method. It * appends a new reply thread to the blip specified in the operation. * * @param operation the operation to execute. * @param context the context of the operation. * @param participant the participant performing this operation. * @param conversation the conversation to operate on. * @throws InvalidRequestException if the operation fails to perform */ private void createChild(OperationRequest operation, OperationContext context, ParticipantId participant, ObservableConversation conversation) throws InvalidRequestException { Preconditions.checkArgument( OperationUtil.getOperationType(operation) == OperationType.BLIP_CREATE_CHILD, "Unsupported operation " + operation); BlipData blipData = OperationUtil.getRequiredParameter(operation, ParamsProperty.BLIP_DATA); String parentBlipId = OperationUtil.getRequiredParameter(operation, ParamsProperty.BLIP_ID); ConversationBlip parentBlip = context.getBlip(conversation, parentBlipId); ConversationBlip newBlip = parentBlip.addReplyThread().appendBlip(); context.putBlip(blipData.getBlipId(), newBlip); putContentForNewBlip(newBlip, blipData.getContent()); processBlipCreatedEvent(operation, context, participant, conversation, newBlip); }
OperationRequest operation, OperationContext context, ParticipantId participant) throws InvalidRequestException { OpBasedWavelet wavelet = context.openWavelet(operation, participant); ObservableConversationView conversationView = context.openConversation(operation, participant);
@Override public void execute( OperationRequest operation, OperationContext context, ParticipantId participant) throws InvalidRequestException { context.openWavelet(WAVE_ID, WAVELET_ID, ROBOT_PARTICIPANT).addParticipant(ALEX); } };
private void getDeltas(OperationContext context, WaveletName waveletName, ParticipantId participant, HashedVersion fromVersion, HashedVersion toVersion, RawDeltasListener listener) throws InvalidRequestException { final List<byte[]> deltaBytes = new LinkedList<byte[]>(); final AtomicReference<HashedVersion> version = new AtomicReference<HashedVersion>(); final AtomicInteger length = new AtomicInteger(0); context.getDeltas(waveletName, participant, fromVersion, toVersion, new Receiver<TransformedWaveletDelta>() { @Override public boolean put(TransformedWaveletDelta delta) { ProtocolWaveletDelta protoDelta = CoreWaveletOperationSerializer.serialize(delta); byte[] bytes = protoDelta.toByteArray(); deltaBytes.add(bytes); version.set(delta.getResultingVersion()); return length.addAndGet(bytes.length) < GET_HISTORY_BYTES_LENGTH_LIMIT; } }); listener.onSuccess(deltaBytes, CoreWaveletOperationSerializer.serialize(version.get()).toByteArray()); }
@Override public void execute(OperationRequest operation, OperationContext context, ParticipantId participant) throws InvalidRequestException { AttachmentId attachmentId; try { attachmentId = AttachmentId.deserialise(OperationUtil.<String>getRequiredParameter(operation, ParamsProperty.ATTACHMENT_ID)); } catch (InvalidIdException ex) { throw new InvalidRequestException("Invalid id", operation, ex); } AttachmentMetadata meta; byte[] data; try { meta = attachmentService.getMetadata(attachmentId); data = readInputStreamToBytes(attachmentService.getAttachment(attachmentId).getInputStream()); } catch (IOException ex) { LOG.info("Get attachment", ex); context.constructErrorResponse(operation, ex.toString()); return; } RawAttachmentData attachment = new RawAttachmentData(meta.getFileName(), meta.getCreator(), data); Map<ParamsProperty, Object> parameters = ImmutableMap.<ParamsProperty, Object> of(ParamsProperty.ATTACHMENT_DATA, attachment); context.constructResponse(operation, parameters); }
@Override public void onSuccess(List<byte[]> rawDeltas, byte[] rawTargetVersion) { Map<ParamsProperty, Object> data = ImmutableMap.<ParamsProperty, Object> of( ParamsProperty.RAW_DELTAS, rawDeltas, ParamsProperty.TARGET_VERSION, rawTargetVersion); context.constructResponse(operation, data); }
/** * Implementation of the {@link OperationType#BLIP_CONTINUE_THREAD} method. It * appends a new blip to the end of the thread of the blip specified in the * operation. * * @param operation the operation to execute. * @param context the context of the operation. * @param participant the participant performing this operation. * @param conversation the conversation to operate on. * @throws InvalidRequestException if the operation fails to perform */ private void continueThread(OperationRequest operation, OperationContext context, ParticipantId participant, ObservableConversation conversation) throws InvalidRequestException { Preconditions.checkArgument( OperationUtil.getOperationType(operation) == OperationType.BLIP_CONTINUE_THREAD, "Unsupported operation " + operation); BlipData blipData = OperationUtil.getRequiredParameter(operation, ParamsProperty.BLIP_DATA); String parentBlipId = OperationUtil.getRequiredParameter(operation, ParamsProperty.BLIP_ID); ConversationBlip parentBlip = context.getBlip(conversation, parentBlipId); ConversationBlip newBlip = parentBlip.getThread().appendBlip(); context.putBlip(blipData.getBlipId(), newBlip); putContentForNewBlip(newBlip, blipData.getContent()); processBlipCreatedEvent(operation, context, participant, conversation, newBlip); }
@Override public void execute( OperationRequest operation, OperationContext context, ParticipantId participant) throws InvalidRequestException { context.openWavelet(WAVE_ID, WAVELET_ID, ROBOT_PARTICIPANT).addParticipant(ALEX); } };
} catch (WaveServerException ex) { LOG.info("Get wavelet snapshot", ex); context.constructErrorResponse(operation, ex.toString()); return; context.constructErrorResponse(operation, error.toString()); return; } catch (WaveServerException ex) { LOG.info("Get wavelet snapshot", ex); context.constructErrorResponse(operation, ex.toString()); return; context.constructErrorResponse(operation, "Expected wavelet version " + delta.getHashedVersion().getVersion() + ", but current version is " + currentVersion + "." + "Possibly wavelet is modified during import."); context.constructResponse(operation, response);