@Override public void execute( OperationRequest operation, OperationContext context, ParticipantId participant) { context.constructResponse(operation, Maps.<ParamsProperty, Object> newHashMap()); } }
@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); }
@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); } }
@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()); }
@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); } }
public void testFetchProfilesServiceWorks() throws InvalidRequestException { service.execute(operation, context, ParticipantId.ofUnsafe(ADDRESS)); verify(context).constructResponse(eq(operation), argThat(matchesFetchResult(ADDRESS, NAME, PROFILE_URL, IMAGE_URL))); }
public void testFetchProfilesServiceWorks() throws InvalidRequestException { service.execute(operation, context, ParticipantId.ofUnsafe(ADDRESS)); verify(context).constructResponse(eq(operation), argThat(matchesFetchResult(ADDRESS, NAME, PROFILE_URL, IMAGE_URL))); }
/** * 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()); }
public void testSimpleProfilesFetcherWorks() throws InvalidRequestException { service = new FetchProfilesService(FetchProfilesService.ProfilesFetcher.SIMPLE_PROFILES_FETCHER); service.execute(operation, context, ParticipantId.ofUnsafe(ADDRESS)); verify(context).constructResponse(eq(operation), argThat(matchesFetchResult(ADDRESS, NAME, PROFILE_URL, IMAGE_URL))); }
public void testSimpleProfilesFetcherWorks() throws InvalidRequestException { service = new FetchProfilesService(FetchProfilesService.ProfilesFetcher.SIMPLE_PROFILES_FETCHER); service.execute(operation, context, ParticipantId.ofUnsafe(ADDRESS)); verify(context).constructResponse(eq(operation), argThat(matchesFetchResult(ADDRESS, NAME, PROFILE_URL, IMAGE_URL))); }
public void testSearchWrapsSearchProvidersResult() throws InvalidRequestException { String title = "title"; SearchResult.Digest digest = new Digest(title, "", WAVE_ID.serialise(), ImmutableList.of(PARTICIPANT.getAddress(), OTHER_PARTICIPANT.getAddress()), -1L, -1L, 1, 1); String query = "in:inbox"; SearchResult searchResult = new SearchResult(query); searchResult.addDigest(digest); when(searchProvider.search(USER, query, 0, 10)).thenReturn(searchResult); service.execute(operation, context, USER); verify(context).constructResponse( eq(operation), argThat(matchesSearchResult("in:inbox", WAVE_ID, "title", PARTICIPANT, ImmutableSet.of( PARTICIPANT, OTHER_PARTICIPANT), 1, 1))); }
public void testSearchWrapsSearchProvidersResult() throws InvalidRequestException { String title = "title"; SearchResult.Digest digest = new Digest(title, "", WAVE_ID.serialise(), ImmutableList.of(PARTICIPANT.getAddress(), OTHER_PARTICIPANT.getAddress()), -1L, -1L, 1, 1); String query = "in:inbox"; SearchResult searchResult = new SearchResult(query); searchResult.addDigest(digest); when(searchProvider.search(USER, query, 0, 10)).thenReturn(searchResult); service.execute(operation, context, USER); verify(context).constructResponse( eq(operation), argThat(matchesSearchResult("in:inbox", WAVE_ID, "title", PARTICIPANT, ImmutableSet.of( PARTICIPANT, OTHER_PARTICIPANT), 1, 1))); }
@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 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); }
if (capabilities != null && capabilitiesHash.equals(capabilities.getCapabilitiesHash())) { context.constructResponse(operation, Maps.<ParamsProperty, Object> newHashMap()); return; context.constructResponse(operation, Maps.<ParamsProperty, Object> newHashMap());
@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); } }
service.execute(operation, context, USER); verify(context).constructResponse( eq(operation), argThat(new BaseMatcher<Map<ParamsProperty, Object>>() { @SuppressWarnings("unchecked")
service.execute(operation, context, USER); verify(context).constructResponse( eq(operation), argThat(new BaseMatcher<Map<ParamsProperty, Object>>() { @SuppressWarnings("unchecked")
context.constructResponse(operation, response);