/** * @see #newWave(String, Set, String) * * @param msg the message that will be passed back to the robot when * WAVELET_CREATED event is fired as a result of this operation. */ public Wavelet newWave(String domain, Set<String> participants, String msg, String proxyForId) { Util.checkIsValidProxyForId(proxyForId); return new OperationQueue(proxyForId).createWavelet(domain, participants, msg); }
/** * Replies to the conversation in this wavelet. * * @param initialContent the initial content of the reply. * @return an instance of {@link Blip} that represents a transient version of * the reply. * * @throws IllegalArgumentException if {@code initialContent} does not start * with a newline character. */ public Blip reply(String initialContent) { if (initialContent == null || !initialContent.startsWith("\n")) { throw new IllegalArgumentException("Initial content should start with a newline character"); } return operationQueue.appendBlipToWavelet(this, initialContent); }
/** * Requests a snapshot of the specified wave. * * @param waveId the id of the wave that should be fetched. * @param waveletId the wavelet id that should be fetched. */ public void fetchWavelet(WaveId waveId, WaveletId waveletId) { appendOperation(OperationType.ROBOT_FETCH_WAVE, waveId, waveletId, null); }
/** * Imports attachment. * * @param waveId the id of the wave to import. * @param waveletId the id of the wavelet to import. * @param attachmentId the id of attachment. * @param attachmentData the data of attachment. * @param rpcServerUrl the URL of the JSON-RPC request handler. * @throws IOException if there is a problem fetching the wavelet. */ public void importAttachment(WaveId waveId, WaveletId waveletId, AttachmentId attachmentId, RawAttachmentData attachmentData, String rpcServerUrl) throws IOException { OperationQueue opQueue = new OperationQueue(); opQueue.importAttachment(waveId, waveletId, attachmentId, attachmentData); makeSingleOperationRpc(opQueue, rpcServerUrl); }
/** * Exports wavelet deltas history. * * @param waveId the id of the wave to export. * @param waveletId the id of the wavelet to export. * @param rpcServerUrl the URL of the JSON-RPC request handler. * @return WaveletSnapshot in Json. * @throws IOException if there is a problem fetching the wavelet. */ public String exportRawSnapshot(WaveId waveId, WaveletId waveletId, String rpcServerUrl) throws IOException { OperationQueue opQueue = new OperationQueue(); opQueue.exportSnapshot(waveId, waveletId); Map<ParamsProperty, Object> response = makeSingleOperationRpc(opQueue, rpcServerUrl); return (String)response.get(ParamsProperty.RAW_SNAPSHOT); }
public void testProxyFor() throws Exception { OperationQueue queue = new OperationQueue(); queue.createWavelet("google.com", Collections.<String>emptySet()); OperationQueue proxyingForQueue = queue.proxyFor("foo"); assertEquals(1, proxyingForQueue.getPendingOperations().size()); proxyingForQueue.setTitleOfWavelet(wavelet, "My title"); List<OperationRequest> ops = proxyingForQueue.getPendingOperations(); assertEquals(2, ops.size()); assertEquals(OperationType.ROBOT_CREATE_WAVELET.method(), ops.get(0).getMethod()); assertNull(ops.get(0).getParameter(ParamsProperty.PROXYING_FOR)); assertEquals(OperationType.WAVELET_SET_TITLE.method(), ops.get(1).getMethod()); assertEquals("foo", ops.get(1).getParameter(ParamsProperty.PROXYING_FOR)); OperationQueue nonProxyingForQueue = proxyingForQueue.proxyFor(null); nonProxyingForQueue.fetchWavelet(WaveId.of("example.com", "wave2"), WaveletId.of("example.com", "wavelet2")); ops = nonProxyingForQueue.getPendingOperations(); assertEquals(3, ops.size()); assertNull(ops.get(2).getParameter(ParamsProperty.PROXYING_FOR)); }
public void testSubmitWith() throws Exception { OperationQueue queue = new OperationQueue(); queue.createWavelet("example.com", Collections.<String>emptySet()); OperationQueue queue2 = new OperationQueue(); queue2.setTitleOfWavelet(wavelet, "My title"); queue2.submitWith(queue); List<OperationRequest> ops = queue.getPendingOperations(); assertEquals(2, ops.size()); assertEquals(OperationType.ROBOT_CREATE_WAVELET.method(), ops.get(0).getMethod()); assertEquals(OperationType.WAVELET_SET_TITLE.method(), ops.get(1).getMethod()); assertEquals(queue.getPendingOperations(), queue2.getPendingOperations()); }
public void testSearchWithNoMatchShouldNotGenerateOperation() { Blip blip = newBlip("\nFoo bar.", Collections.<Annotation>emptyList()); blip.all(":(").replace(":)"); assertEquals(0, wavelet.getOperationQueue().getPendingOperations().size()); }
public void testSubmit() throws Exception { HttpFetcher fetcher = mock(HttpFetcher.class); when(fetcher.execute(any(HttpMessage.class), anyMapOf(String.class, Object.class))) .thenReturn(new HttpResponse("POST", new URL("http://foo.google.com"), 0, new ByteArrayInputStream("[{\"id\":\"op1\",\"data\":{}}]".getBytes()))); MockRobot robot = new MockRobot(); robot.setupOAuth("consumerKey", "consumerSecret", "http://gmodules.com/api/rpc"); WaveService service = new WaveService(fetcher, robot.computeHash()); service.setupOAuth("consumerKey", "consumerSecret", "http://gmodules.com/api/rpc"); OperationQueue opQueue = new OperationQueue(); opQueue.appendOperation(OperationType.ROBOT_NOTIFY, Parameter.of(ParamsProperty.CAPABILITIES_HASH, "123")); Wavelet wavelet = mock(Wavelet.class); when(wavelet.getOperationQueue()).thenReturn(opQueue); assertEquals(1, opQueue.getPendingOperations().size()); robot.submit(wavelet, "http://gmodules.com/api/rpc", service); assertEquals(0, opQueue.getPendingOperations().size()); verify(fetcher, times(1)).execute(any(HttpMessage.class), anyMapOf(String.class, Object.class)); }
/** * Appends a blip to a wavelet. * * @param wavelet the wavelet to append the new blip to. * @param initialContent the initial content of the new blip. * @return an instance of {@link Blip} that represents the new blip. */ public Blip appendBlipToWavelet(Wavelet wavelet, String initialContent) { Blip newBlip = newBlip(wavelet, initialContent, null, generateTempBlipId(wavelet), wavelet.getRootThread().getId()); appendOperation(OperationType.WAVELET_APPEND_BLIP, wavelet, Parameter.of(ParamsProperty.BLIP_DATA, newBlip.serialize())); return newBlip; }
@Override public void remove() { if (removeCalled) { throw new IllegalStateException("remove() has been called after the last call to next()."); } if (currentTag == null) { throw new IllegalStateException("Please call next() first before calling remove()."); } removeCalled = true; operationQueue.modifyTagOfWavelet(wavelet, currentTag, "remove"); storeIterator.remove(); } }
public void testCreateChildOfBlip() throws Exception { Blip blip = mock(Blip.class); when(blip.getBlipId()).thenReturn("blip1"); when(blip.getWavelet()).thenReturn(wavelet); Map<String, Blip> blips = new HashMap<String, Blip>(); blips.put("blip1", blip); when(wavelet.getBlip("blip1")).thenReturn(blip); when(wavelet.getBlips()).thenReturn(blips); OperationQueue queue = new OperationQueue(); Blip newBlip = queue.createChildOfBlip(blip); assertEquals(blip.getBlipId(), newBlip.getParentBlipId()); assertEquals(blip, newBlip.getParentBlip()); assertEquals(2, blips.size()); } }
/** * Creates a view of this {@link OperationQueue} with the proxying for set to * the given id. * * This method returns a new instance of an operation queue that shares the * operation list, but has a different {@link #proxyForId} set so when the * robot uses this new queue, subsequent operations will be sent out with the * {@code proxying_for} field set. * * @param proxyForId the proxying information. * @return a view of this {@link OperationQueue} with the proxying information * set. */ public OperationQueue proxyFor(String proxyForId) { return new OperationQueue(pendingOperations, proxyForId); }
/** * Fetches multiple profiles using Data API. */ private FetchProfilesResult fetchProfilesFromService(ParticipantId user, List<String> addresses) { OperationQueue opQueue = new OperationQueue(); FetchProfilesRequest request = new FetchProfilesRequest(addresses); opQueue.fetchProfiles(request); OperationContextImpl context = new OperationContextImpl(waveletProvider, converterManager.getEventDataConverter(ProtocolVersion.DEFAULT), conversationUtil); OperationRequest operationRequest = opQueue.getPendingOperations().get(0); String opId = operationRequest.getId(); OperationUtil.executeOperation(operationRequest, operationRegistry, context, user); JsonRpcResponse jsonRpcResponse = context.getResponses().get(opId); FetchProfilesResult profileResults = (FetchProfilesResult) jsonRpcResponse.getData().get(ParamsProperty.FETCH_PROFILES_RESULT); return profileResults; }
throws IOException { Util.checkIsValidProxyForId(proxyForId); OperationQueue opQueue = new OperationQueue(proxyForId); opQueue.fetchWavelet(waveId, waveletId); opQueue.clear(); WaveletData waveletData = (WaveletData) response.get(ParamsProperty.WAVELET_DATA); Map<String, Blip> blips = new HashMap<String, Blip>();
/** * Performs search using Data API. */ protected SearchResult performSearch(SearchRequest searchRequest, ParticipantId user) { OperationQueue opQueue = new OperationQueue(); opQueue.search(searchRequest.getQuery(), searchRequest.getIndex(), searchRequest.getNumResults()); OperationContextImpl context = new OperationContextImpl(waveletProvider, converterManager.getEventDataConverter(ProtocolVersion.DEFAULT), conversationUtil); LOG.fine( "Performing query: " + searchRequest.getQuery() + " [" + searchRequest.getIndex() + ", " + (searchRequest.getIndex() + searchRequest.getNumResults()) + "]"); OperationRequest operationRequest = opQueue.getPendingOperations().get(0); String opId = operationRequest.getId(); OperationUtil.executeOperation(operationRequest, operationRegistry, context, user); JsonRpcResponse jsonRpcResponse = context.getResponses().get(opId); SearchResult searchResult = (SearchResult) jsonRpcResponse.getData().get(ParamsProperty.SEARCH_RESULTS); return searchResult; } }
public void testDeleteByBlipId() throws Exception { assertEquals(1, wavelet.getBlips().size()); assertEquals("blip1", wavelet.getBlips().entrySet().iterator().next().getKey()); wavelet.delete("blip1"); assertEquals(0, wavelet.getBlips().size()); verify(opQueue).deleteBlip(wavelet, "blip1"); }
/** * Returns a view of this blip that will proxy for the specified id. * * A shallow copy of the current blip is returned with the {@code proxyingFor} * field set. Any modifications made to this copy will be done using the * {@code proxyForId}, i.e. the {@code robot+<proxyForId>@appspot.com} address * will be used. * * @param proxyForId the id to proxy. Please note that this parameter should * be properly encoded to ensure that the resulting participant id is * valid (see {@link Util#checkIsValidProxyForId(String)} for more * details). * @return a shallow copy of this blip with the proxying information set. */ public Blip proxyFor(String proxyForId) { Util.checkIsValidProxyForId(proxyForId); OperationQueue proxiedOperationQueue = operationQueue.proxyFor(proxyForId); return new Blip(this, proxiedOperationQueue); }
/** * Processes the incoming HTTP request that contains the event bundle. * * @param req the HTTP request. * @param resp the HTTP response. */ private void processRpc(HttpServletRequest req, HttpServletResponse resp) { // Deserialize and process the incoming events. EventMessageBundle events = null; try { events = deserializeEvents(req); } catch (IOException e) { resp.setStatus(HttpURLConnection.HTTP_INTERNAL_ERROR); return; } // Append robot.notifyCapabilitiesHash operation before processing the // events. OperationQueue operationQueue = events.getWavelet().getOperationQueue(); operationQueue.notifyRobotInformation(WaveService.PROTOCOL_VERSION, version); // Call the robot event handlers. processEvents(events); // Serialize the operations. serializeOperations(operationQueue.getPendingOperations(), resp); operationQueue.clear(); }
/** * Imports deltas to wavelet. * * @param waveId the id of the wave to import. * @param waveletId the id of the wavelet to import. * @param history the history of deltas. * @param rpcServerUrl the URL of the JSON-RPC request handler. * @return the version from which importing started. * @throws IOException if there is a problem fetching the wavelet. */ public long importRawDeltas(WaveId waveId, WaveletId waveletId, List<byte[]> history, String rpcServerUrl) throws IOException { OperationQueue opQueue = new OperationQueue(); opQueue.importRawDeltas(waveId, waveletId, history); Map<ParamsProperty, Object> response = makeSingleOperationRpc(opQueue, rpcServerUrl); return (Long)response.get(ParamsProperty.IMPORTED_FROM_VERSION); }