/** * Attempts to get a parameter, returns the {@code null} if not found. * * @param <T> type of class to cast to. * @param operation operation to extract property from. * @param key the key of the parameter. * @return specialized object after being serialized, or {@code null} if the * parameter could not be found. */ public static <T> T getOptionalParameter(OperationRequest operation, ParamsProperty key) { return OperationUtil.<T> getOptionalParameter(operation, key, null); }
@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); }
public void testGetOptionalParameter() throws Exception { String waveId = OperationUtil.getOptionalParameter(operation, ParamsProperty.WAVE_ID); assertEquals(s(WAVE_ID), waveId); assertNull("Non existing properties should return null when optional", OperationUtil.getOptionalParameter(operation, ParamsProperty.ANNOTATION)); String defaultValue = "b+1234"; String blipId = OperationUtil.getOptionalParameter(operation, ParamsProperty.BLIP_ID, defaultValue); assertSame("Default value should be returned when object does not exist", defaultValue, blipId); }
public void testGetOptionalParameter() throws Exception { String waveId = OperationUtil.getOptionalParameter(operation, ParamsProperty.WAVE_ID); assertEquals(s(WAVE_ID), waveId); assertNull("Non existing properties should return null when optional", OperationUtil.getOptionalParameter(operation, ParamsProperty.ANNOTATION)); String defaultValue = "b+1234"; String blipId = OperationUtil.getOptionalParameter(operation, ParamsProperty.BLIP_ID, defaultValue); assertSame("Default value should be returned when object does not exist", defaultValue, blipId); }
/** * Computes participant ID using optional {@link ParamsProperty.PROXYING_FOR} * parameter. * * @param operation the operation to be executed. * @param participant the base participant id. * @return new participant instance in the format * somebody+proxyFor@example.com. If proxyFor is null then just * returns unmodified participant. * @throws InvalidRequestException if participant address and/or proxyFor are * invalid. */ public static ParticipantId computeParticipant(OperationRequest operation, ParticipantId participant) throws InvalidRequestException { String proxyAddress = OperationUtil.getOptionalParameter(operation, ParamsProperty.PROXYING_FOR); try { return toProxyParticipant(participant, proxyAddress); } catch (InvalidParticipantAddress e) { throw new InvalidRequestException( participant.getAddress() + (proxyAddress != null ? "+" + proxyAddress : "" + " is not a valid participant address"), operation); } }
@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 { 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); } }
Range range = OperationUtil.getOptionalParameter(operation, ParamsProperty.RANGE); Integer index = OperationUtil.getOptionalParameter(operation, ParamsProperty.INDEX); DocumentModifyQuery query = OperationUtil.getOptionalParameter(operation, ParamsProperty.MODIFY_QUERY);
String message = OperationUtil.getOptionalParameter(operation, ParamsProperty.MESSAGE); WaveletCreatedEvent event = new WaveletCreatedEvent(null, null, participant.getAddress(), System.currentTimeMillis(),