@Override public void execute(OperationRequest operation, OperationContext context, ParticipantId participant) throws InvalidRequestException { FetchProfilesRequest request = OperationUtil.getRequiredParameter(operation, ParamsProperty.FETCH_PROFILES_REQUEST); List<String> requestAddresses = request.getParticipantIds(); List<ParticipantProfile> profiles = Lists.newArrayListWithCapacity(requestAddresses.size()); for (String address : requestAddresses) { ParticipantProfile participantProfile = profilesFetcher.fetchProfile(address); profiles.add(participantProfile); } FetchProfilesResult result = new FetchProfilesResult(profiles); Map<ParamsProperty, Object> data = ImmutableMap.<ParamsProperty, Object> of(ParamsProperty.FETCH_PROFILES_RESULT, result); context.constructResponse(operation, data); } }
public void testGetRequiredParameterThrowsInvalidRequestException() throws Exception { try { OperationUtil.getRequiredParameter(operation, ParamsProperty.ANNOTATION); fail("Expected InvalidRequestException"); } catch (InvalidRequestException e) { // expected } }
public void testGetRequiredParameterThrowsInvalidRequestException() throws Exception { try { OperationUtil.getRequiredParameter(operation, ParamsProperty.ANNOTATION); fail("Expected InvalidRequestException"); } catch (InvalidRequestException e) { // expected } }
@Override public OpBasedWavelet openWavelet(OperationRequest operation, ParticipantId participant) throws InvalidRequestException { try { WaveId waveId = ApiIdSerializer.instance().deserialiseWaveId( OperationUtil.<String>getRequiredParameter(operation, ParamsProperty.WAVE_ID)); WaveletId waveletId = ApiIdSerializer.instance().deserialiseWaveletId( OperationUtil.<String>getRequiredParameter(operation, ParamsProperty.WAVELET_ID)); return openWavelet(waveId, waveletId, participant); } catch (InvalidIdException e) { throw new InvalidRequestException("Invalid id", operation, e); } }
@Override public ObservableConversationView openConversation( OperationRequest operation, ParticipantId participant) throws InvalidRequestException { try { WaveId waveId = ApiIdSerializer.instance().deserialiseWaveId( OperationUtil.<String>getRequiredParameter(operation, ParamsProperty.WAVE_ID)); WaveletId waveletId = ApiIdSerializer.instance().deserialiseWaveletId( OperationUtil.<String>getRequiredParameter(operation, ParamsProperty.WAVELET_ID)); return openConversation(waveId, waveletId, participant); } catch (InvalidIdException e) { throw new InvalidRequestException("Invalid id", operation, e); } }
@Override public void execute( OperationRequest operation, OperationContext context, ParticipantId participant) throws InvalidRequestException { String query = OperationUtil.getRequiredParameter(operation, ParamsProperty.QUERY); int index = OperationUtil.getOptionalParameter(operation, ParamsProperty.INDEX, 0); int numResults = OperationUtil.getOptionalParameter( operation, ParamsProperty.NUM_RESULTS, DEFAULT_NUMBER_SEARCH_RESULTS); SearchResult result = search(participant, query, index, numResults); Map<ParamsProperty, Object> data = ImmutableMap.<ParamsProperty, Object> of(ParamsProperty.SEARCH_RESULTS, result); context.constructResponse(operation, data); }
/** * 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()); }
/** * Implementation for the {@link OperationType#DOCUMENT_APPEND_MARKUP} * method. It appends markup within 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 wavelet the wavelet to operate on. * @param conversation the conversation to operate on. * @throws InvalidRequestException if the operation fails to perform */ private void appendMarkup(OperationRequest operation, OperationContext context, ParticipantId participant, ObservableWavelet wavelet, ObservableConversation conversation) throws InvalidRequestException { Preconditions.checkArgument( OperationUtil.getOperationType(operation) == OperationType.DOCUMENT_APPEND_MARKUP, "Unsupported operation " + operation); String content = OperationUtil.getRequiredParameter(operation, ParamsProperty.CONTENT); String blipId = OperationUtil.getRequiredParameter(operation, ParamsProperty.BLIP_ID); ConversationBlip convBlip = context.getBlip(conversation, blipId); // Create builder from xml content. XmlStringBuilder markupBuilder = XmlStringBuilder.createFromXmlString(content); // Append the new markup to the blip doc. Document doc = convBlip.getContent(); LineContainers.appendLine(doc, markupBuilder); // Report success. context.constructResponse(operation, Maps.<ParamsProperty, Object> newHashMap()); }
private HashedVersion getVersionParameter(OperationRequest operation, ParamsProperty parameter) throws InvalidRequestException { byte[] bytes = OperationUtil.<byte[]>getRequiredParameter( operation, parameter); ProtocolHashedVersion protoVersion; try { protoVersion = ProtocolHashedVersion.parseFrom(bytes); } catch (InvalidProtocolBufferException ex) { throw new InvalidRequestException("Invalid version " + parameter.key(), operation, ex); } return CoreWaveletOperationSerializer.deserialize(protoVersion); } }
@Override public ImmutableSet<WaveletId> getVisibleWaveletIds(OperationRequest operation, ParticipantId participant) throws InvalidRequestException { Set<WaveletId> waveletIds = new HashSet<WaveletId>(); try { WaveId waveId = ApiIdSerializer.instance().deserialiseWaveId( OperationUtil.<String>getRequiredParameter(operation, ParamsProperty.WAVE_ID)); ImmutableSet<WaveletId> ids = waveletProvider.getWaveletIds(waveId); for (WaveletId waveletId: ids) { WaveletName waveletName = WaveletName.of(waveId, waveletId); if (waveletProvider.checkAccessPermission(waveletName, participant)) { waveletIds.add(waveletId); } } } catch (InvalidIdException ex) { throw new InvalidRequestException("Invalid id", operation, ex); } catch (WaveServerException e) { LOG.severe("Error of access to wave", e); } return ImmutableSet.copyOf(waveletIds); }
public void testGetRequiredParameter() throws Exception { String waveId = OperationUtil.getRequiredParameter(operation, ParamsProperty.WAVE_ID); assertEquals(s(WAVE_ID), waveId); }
public void testGetRequiredParameter() throws Exception { String waveId = OperationUtil.getRequiredParameter(operation, ParamsProperty.WAVE_ID); assertEquals(s(WAVE_ID), waveId); }
/** * 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); }
/** * 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 { 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); } }
@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); }
/** * Implementation for the {@link OperationType#WAVELET_APPEND_BLIP} method. It * appends a blip at the end of the root thread. * * @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 appendBlip(OperationRequest operation, OperationContext context, ParticipantId participant, ObservableConversation conversation) throws InvalidRequestException { Preconditions.checkArgument( OperationUtil.getOperationType(operation) == OperationType.WAVELET_APPEND_BLIP, "Unsupported operation " + operation); BlipData blipData = OperationUtil.getRequiredParameter(operation, ParamsProperty.BLIP_DATA); ObservableConversationBlip newBlip = conversation.getRootThread().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 { 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); }
@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); }
/** * 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; }