/** * 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); }
/** * @see #blindWavelet(WaveId, WaveletId, String, Map) * * @param threads a collection of threads that belong to this wavelet. */ public Wavelet blindWavelet(WaveId waveId, WaveletId waveletId, String proxyForId, Map<String, Blip> blips, Map<String, BlipThread> threads) { Util.checkIsValidProxyForId(proxyForId); Map<String, String> roles = new HashMap<String, String>(); return new Wavelet(waveId, waveletId, null, new BlipThread("", -1, new ArrayList<String>(), blips), Collections.<String>emptySet(), roles, blips, threads, new OperationQueue(proxyForId)); }
/** * 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); }
/** * @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); }
/** * 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); }
/** * Exports attachment. * * @param attachmentId the id of attachment. * @param rpcServerUrl the URL of the JSON-RPC request handler. * @return the data of attachment. * @throws IOException if there is a problem fetching the wavelet. */ public RawAttachmentData exportAttachment(AttachmentId attachmentId, String rpcServerUrl) throws IOException { OperationQueue opQueue = new OperationQueue(); opQueue.exportAttachment(attachmentId); Map<ParamsProperty, Object> response = makeSingleOperationRpc(opQueue, rpcServerUrl); return (RawAttachmentData)response.get(ParamsProperty.ATTACHMENT_DATA); }
/** * Requests SearchResult for a query. * * @param query the query to execute. * @param index the index from which to return results. * @param numresults the number of results to return. * @param rpcServerUrl the active gateway. * * @throws IOException if remote server returns error. */ public SearchResult search(String query, Integer index, Integer numResults, String rpcServerUrl) throws IOException { OperationQueue opQueue = new OperationQueue(); opQueue.search(query, index, numResults); Map<ParamsProperty, Object> response = makeSingleOperationRpc(opQueue, rpcServerUrl); return (SearchResult) response.get(ParamsProperty.SEARCH_RESULTS); }
/** * Retrieves wavelets ids of the specified wave. * * @param waveId the id of the wave. * @param rpcServerUrl the URL of the JSON-RPC request handler. * @return list of wavelets ids. * @throws IOException if there is a problem fetching the wavelet. */ public List<WaveletId> retrieveWaveletIds(WaveId waveId, String rpcServerUrl) throws IOException { OperationQueue opQueue = new OperationQueue(); opQueue.retrieveWaveletIds(waveId); Map<ParamsProperty, Object> response = makeSingleOperationRpc(opQueue, rpcServerUrl); @SuppressWarnings("unchecked") List<WaveletId> list = (List<WaveletId>)response.get(ParamsProperty.WAVELET_IDS); return list; }
/** * 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); }
@Override protected void setUp() throws Exception { wavelet = mock(Wavelet.class); when(wavelet.getOperationQueue()).thenReturn(new OperationQueue()); when(wavelet.getWaveId()).thenReturn(WaveId.of("example.com", "wave1")); when(wavelet.getWaveletId()).thenReturn(WaveletId.of("example.com", "wavelet1")); }
@Override protected void setUp() throws Exception { wavelet = mock(Wavelet.class); when(wavelet.getBlips()).thenReturn(blips); when(wavelet.getOperationQueue()).thenReturn(new OperationQueue()); when(wavelet.getWaveId()).thenReturn(WaveId.of("example.com", "wave1")); when(wavelet.getWaveletId()).thenReturn(WaveletId.of("example.com", "wavelet1")); when(wavelet.getThread(anyString())).thenReturn(new BlipThread("rootThread", -1, Lists.newArrayList(ROOT_BLIP_ID, CHILD_BLIP_ID), blips)); }
@Override protected void setUp() throws Exception { wavelet = mock(Wavelet.class); when(wavelet.getOperationQueue()).thenReturn(new OperationQueue()); when(wavelet.getWaveId()).thenReturn(WaveId.of("example.com", "wave1")); when(wavelet.getWaveletId()).thenReturn(WaveletId.of("example.com", "wavelet1")); }
@Override protected void setUp() throws Exception { wavelet = mock(Wavelet.class); when(wavelet.getBlips()).thenReturn(blips); when(wavelet.getOperationQueue()).thenReturn(new OperationQueue()); when(wavelet.getWaveId()).thenReturn(WaveId.of("example.com", "wave1")); when(wavelet.getWaveletId()).thenReturn(WaveletId.of("example.com", "wavelet1")); when(wavelet.getThread(anyString())).thenReturn(new BlipThread("rootThread", -1, Lists.newArrayList(ROOT_BLIP_ID, CHILD_BLIP_ID), blips)); }
/** * 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; }
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()); } }
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()); } }
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)); }
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 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 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)); }