op.addParameter(Parameter.of(ParamsProperty.MODIFY_ACTION, new DocumentModifyAction( modifyHow, values, annotationName, elements, bundledAnnotations, useMarkup)));
/** * Constructor. * * @param method the method or operation to be executed. * See {@link OperationType}. * @param id the id of the request. * @param waveId the wave id to apply this operation to. * @param waveletId the wavelet id to apply this operation to. * @param blipId the blip id to apply this operation to. * @param params additional parameters for this operation. See * {@link ParamsProperty}. */ public OperationRequest(String method, String id, String waveId, String waveletId, String blipId, Parameter... params) { this.method = method; this.id = id; this.parameters = new HashMap<ParamsProperty, Object>(params.length + 3); setWaveId(waveId); setWaveletId(waveletId); setBlipId(blipId); for (Parameter parameter : params) { this.parameters.put(parameter.getKey(), parameter.getValue()); } }
Parameter.of(ParamsProperty.MODIFY_ACTION, new DocumentModifyAction(ModifyHow.UPDATE_ELEMENT, NO_VALUES, NO_ANNOTATION_KEY, updatedElementsIn, NO_BUNDLED_ANNOTATIONS, false)), Parameter.of(ParamsProperty.MODIFY_QUERY, new DocumentModifyQuery(ElementType.GADGET, ImmutableMap.of("url", gadgetUrl), 1)));
Parameter.of(ParamsProperty.MODIFY_ACTION, new DocumentModifyAction(ModifyHow.UPDATE_ELEMENT, NO_VALUES, NO_ANNOTATION_KEY, updatedElementsIn, NO_BUNDLED_ANNOTATIONS, false)), Parameter.of(ParamsProperty.MODIFY_QUERY, new DocumentModifyQuery(ElementType.GADGET, ImmutableMap.of("url", gadgetUrl), 1)));
operation.addParameter(Parameter.of(ParamsProperty.PROXYING_FOR, proxyForId));
public void testRemoveParticipant() throws Exception { OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ROBOT).getRoot(); String rootBlipId = ConversationUtil.getRootBlipId(conversation); // Confirm alex is not on wave prior to operation. Set<ParticipantId> participants = conversation.getParticipantIds(); assertFalse("Alex should not be a participant on wavelet prior to operation to add him.", participants.contains(ALEX)); OperationRequest operation = new OperationRequest(OperationType.WAVELET_ADD_PARTICIPANT_NEWSYNTAX.method(), OPERATION_ID, s(WAVE_ID), s(WAVELET_ID), rootBlipId, Parameter.of(ParamsProperty.PARTICIPANT_ID, ALEX.getAddress())); service.execute(operation, context, ROBOT); // Verify Alex is now a participant on the wave. participants = conversation.getParticipantIds(); assertTrue("Alex should now be a participant on the wavelet.", participants.contains(ALEX)); // Attempt to remove Alex. OperationRequest operation2 = operationRequest(OperationType.WAVELET_REMOVE_PARTICIPANT_NEWSYNTAX, OPERATION2_ID, rootBlipId, Parameter.of(ParamsProperty.PARTICIPANT_ID, ALEX.getAddress())); service.execute(operation2, context, ROBOT); // Verify Alex is no longer a participant on the wave. participants = conversation.getParticipantIds(); assertFalse("Alex should no longer be a participant on the wavelet.", participants.contains(ALEX)); }
/** * Validates the behavior when a caller invokes the DOCUMENT_APPEND_MARKUP * without actually passing in xml markup (so just the text). The behavior * should be to create a default wave line element, so the scenario is: * * input: "Hello World" * output: <line></line>Hello World */ public void testAppendLineMarkup() throws Exception { // Just insert text. should create <line></line>Text. String markup = NEW_BLIP_CONTENT; OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); // Append the text markup to the newly created blip. DocInitialization blipInitContent = new DocInitializationBuilder().build(); ConversationBlip markupBlip = conversation.getRootThread().appendBlip(blipInitContent); OperationRequest operation = operationRequest(OperationType.DOCUMENT_APPEND_MARKUP, markupBlip.getId(), Parameter.of(ParamsProperty.CONTENT, markup)); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse("LineMarkup generated error in service execution.", response.isError()); // The output should now include the default <line/> element. String lineContent = markupBlip.getContent().toXmlString(); assertTrue("Expected the blip to append the default wave <line/> element. " + "actual content: " + lineContent, lineContent.contains("<line/>"+markup)); }
public void testInsertInlineBlip() throws Exception { OperationContextImpl context = helper.getContext(); OpBasedWavelet wavelet = context.openWavelet(WAVE_ID, WAVELET_ID, ALEX); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); int insertAtApiLocation = 2; ApiView apiView = new ApiView(conversation.getRootThread().getFirstBlip().getContent(), wavelet); int insertAtXmlLocation = apiView.transformToXmlOffset(insertAtApiLocation); // Append the inline blip to the root blip String rootBlipId = ConversationUtil.getRootBlipId(conversation); OperationRequest operation = operationRequest(OperationType.DOCUMENT_INSERT_INLINE_BLIP, rootBlipId, Parameter.of(ParamsProperty.BLIP_DATA, blipData), Parameter.of(ParamsProperty.INDEX, insertAtApiLocation)); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse(response.isError()); ConversationBlip newBlip = checkAndGetNewBlip(context, conversation, response); Iterator<? extends LocatedReplyThread<? extends ObservableConversationThread>> it = conversation.getRootThread().getFirstBlip().locateReplyThreads().iterator(); LocatedReplyThread<? extends ObservableConversationThread> inlineReplyThread = it.next(); assertEquals("The inline reply was not located where specified", insertAtXmlLocation, inlineReplyThread.getLocation()); }
/** * Validates the behavior when a caller invokes the DOCUMENT_APPEND_MARKUP * without actually passing in xml markup (so just the text). The behavior * should be to create a default wave line element, so the scenario is: * * input: "Hello World" * output: <line></line>Hello World */ public void testAppendLineMarkup() throws Exception { // Just insert text. should create <line></line>Text. String markup = NEW_BLIP_CONTENT; OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); // Append the text markup to the newly created blip. DocInitialization blipInitContent = new DocInitializationBuilder().build(); ConversationBlip markupBlip = conversation.getRootThread().appendBlip(blipInitContent); OperationRequest operation = operationRequest(OperationType.DOCUMENT_APPEND_MARKUP, markupBlip.getId(), Parameter.of(ParamsProperty.CONTENT, markup)); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse("LineMarkup generated error in service execution.", response.isError()); // The output should now include the default <line/> element. String lineContent = markupBlip.getContent().toXmlString(); assertTrue("Expected the blip to append the default wave <line/> element. " + "actual content: " + lineContent, lineContent.contains("<line/>"+markup)); }
public void testRemoveParticipant() throws Exception { OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ROBOT).getRoot(); String rootBlipId = ConversationUtil.getRootBlipId(conversation); // Confirm alex is not on wave prior to operation. Set<ParticipantId> participants = conversation.getParticipantIds(); assertFalse("Alex should not be a participant on wavelet prior to operation to add him.", participants.contains(ALEX)); OperationRequest operation = new OperationRequest(OperationType.WAVELET_ADD_PARTICIPANT_NEWSYNTAX.method(), OPERATION_ID, s(WAVE_ID), s(WAVELET_ID), rootBlipId, Parameter.of(ParamsProperty.PARTICIPANT_ID, ALEX.getAddress())); service.execute(operation, context, ROBOT); // Verify Alex is now a participant on the wave. participants = conversation.getParticipantIds(); assertTrue("Alex should now be a participant on the wavelet.", participants.contains(ALEX)); // Attempt to remove Alex. OperationRequest operation2 = operationRequest(OperationType.WAVELET_REMOVE_PARTICIPANT_NEWSYNTAX, OPERATION2_ID, rootBlipId, Parameter.of(ParamsProperty.PARTICIPANT_ID, ALEX.getAddress())); service.execute(operation2, context, ROBOT); // Verify Alex is no longer a participant on the wave. participants = conversation.getParticipantIds(); assertFalse("Alex should no longer be a participant on the wavelet.", participants.contains(ALEX)); }
/** * Constructs an instance representing the search for element * {@code ElementType}, that has the properties specified in * {@code restrictions}. * * @param blip the blip to find {@code target} in. * @param target the element type to search. * @param maxResult the maximum number of results. * @param restrictions the additional properties filter that need to be * matched. * @return an instance of blip references. */ public static BlipContentRefs all(Blip blip, ElementType target, int maxResult, Restriction... restrictions) { Map<String, String> restrictionsAsMap = new HashMap<String, String>(restrictions.length); for (Restriction restriction : restrictions) { restrictionsAsMap.put(restriction.getKey(), restriction.getValue()); } return new BlipContentRefs(blip, new BlipIterator.ElementIterator(blip, target, restrictionsAsMap, maxResult), Parameter.of(ParamsProperty.MODIFY_QUERY, new DocumentModifyQuery(target, restrictionsAsMap, maxResult))); }
public void testAppendInlineBlip() throws Exception { OperationContextImpl context = helper.getContext(); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); // Append the inline blip to the root blip String rootBlipId = ConversationUtil.getRootBlipId(conversation); OperationRequest operation = operationRequest(OperationType.DOCUMENT_APPEND_INLINE_BLIP, rootBlipId, Parameter.of(ParamsProperty.BLIP_DATA, blipData)); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse(response.isError()); ConversationBlip newBlip = checkAndGetNewBlip(context, conversation, response); Iterator<? extends LocatedReplyThread<? extends ObservableConversationThread>> it = conversation.getRootThread().getFirstBlip().locateReplyThreads().iterator(); LocatedReplyThread<? extends ObservableConversationThread> inlineReplyThread = it.next(); // The inline reply thread should be located just after the last line // element Document doc = conversation.getRootThread().getFirstBlip().getContent(); Doc.E lastLine = DocHelper.getLastElementWithTagName(doc, LineContainers.LINE_TAGNAME); int lastLineLocation = doc.getLocation(Point.after(doc, lastLine)); assertEquals("The inline reply was not located just after the last line element", lastLineLocation, inlineReplyThread.getLocation()); }
/** * Inserts a new inline blip at a specified location. * * @param blip the blip to anchor this inline blip from. * @param position the position in the given blip to insert this new inline * blip. * @return an instance of {@link Blip} that represents the inline blip. */ public Blip insertInlineBlipToDocument(Blip blip, int position) { // Create a new thread. String tempBlipId = generateTempBlipId(blip.getWavelet()); Wavelet wavelet = blip.getWavelet(); BlipThread thread = new BlipThread(tempBlipId, position, new ArrayList<String>(), wavelet.getBlips()); // Add the new thread to the blip and wavelet. blip.addThread(thread); wavelet.addThread(thread); // Create a new blip in the new thread. Blip inlineBlip = newBlip(blip.getWavelet(), "", blip.getBlipId(), tempBlipId, thread.getId()); appendOperation(OperationType.DOCUMENT_INSERT_INLINE_BLIP, blip, Parameter.of(ParamsProperty.INDEX, position), Parameter.of(ParamsProperty.BLIP_DATA, inlineBlip.serialize())); return inlineBlip; }
@Override public OperationRequest deserialize(JsonElement json, Type type, JsonDeserializationContext ctx) throws JsonParseException { JsonObject jsonObject = json.getAsJsonObject(); JsonObject parameters = jsonObject.getAsJsonObject(RequestProperty.PARAMS.key()); OperationRequest request = new OperationRequest( jsonObject.get(RequestProperty.METHOD.key()).getAsString(), jsonObject.get(RequestProperty.ID.key()).getAsString(), getPropertyAsStringThenRemove(parameters, ParamsProperty.WAVE_ID), getPropertyAsStringThenRemove(parameters, ParamsProperty.WAVELET_ID), getPropertyAsStringThenRemove(parameters, ParamsProperty.BLIP_ID)); for (Entry<String, JsonElement> parameter : parameters.entrySet()) { ParamsProperty parameterType = ParamsProperty.fromKey(parameter.getKey()); if (parameterType != null) { Object object; if (parameterType == ParamsProperty.RAW_DELTAS) { object = ctx.deserialize(parameter.getValue(), GsonFactory.RAW_DELTAS_TYPE); } else { object = ctx.deserialize(parameter.getValue(), parameterType.clazz()); } request.addParameter(Parameter.of(parameterType, object)); } } return request; }
public void testInsertInlineBlip() throws Exception { OperationContextImpl context = helper.getContext(); OpBasedWavelet wavelet = context.openWavelet(WAVE_ID, WAVELET_ID, ALEX); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); int insertAtApiLocation = 2; ApiView apiView = new ApiView(conversation.getRootThread().getFirstBlip().getContent(), wavelet); int insertAtXmlLocation = apiView.transformToXmlOffset(insertAtApiLocation); // Append the inline blip to the root blip String rootBlipId = ConversationUtil.getRootBlipId(conversation); OperationRequest operation = operationRequest(OperationType.DOCUMENT_INSERT_INLINE_BLIP, rootBlipId, Parameter.of(ParamsProperty.BLIP_DATA, blipData), Parameter.of(ParamsProperty.INDEX, insertAtApiLocation)); service.execute(operation, context, ALEX); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertFalse(response.isError()); ConversationBlip newBlip = checkAndGetNewBlip(context, conversation, response); Iterator<? extends LocatedReplyThread<? extends ObservableConversationThread>> it = conversation.getRootThread().getFirstBlip().locateReplyThreads().iterator(); LocatedReplyThread<? extends ObservableConversationThread> inlineReplyThread = it.next(); assertEquals("The inline reply was not located where specified", insertAtXmlLocation, inlineReplyThread.getLocation()); }
public void testFetchWave() throws Exception { String message = "A message"; OperationRequest operation = operationRequest(OperationType.ROBOT_FETCH_WAVE, Parameter.of(ParamsProperty.MESSAGE, message)); OperationContextImpl context = helper.getContext(); WaveletProvider waveletProvider = helper.getWaveletProvider(); when(waveletProvider.checkAccessPermission(WAVELET_NAME, ALEX)).thenReturn(true); service.execute(operation, context, ALEX); ObservableConversation conversation = context.openConversation(WAVE_ID, WAVELET_ID, ALEX).getRoot(); JsonRpcResponse response = context.getResponse(OPERATION_ID); assertNotNull("expected a response", response); assertFalse("expected a success response", response.isError()); assertEquals("Expected the response to carry the message", message, response.getData().get(ParamsProperty.MESSAGE)); assertNotNull("Expected the response to carry a wavelet", response.getData().get(ParamsProperty.WAVELET_DATA)); assertEquals("Expected the response to carry root blip id", conversation.getRootThread().getFirstBlip().getId(), response.getData().get(ParamsProperty.BLIP_ID)); }