OperationHandlerImpl implements OperationHandler { @Override public Optional<String> get(RestUri restUri, Optional<String> fieldSet, Optional<String> cluster) throws RestApiException { SyncSession syncSession = syncSessions.alloc(); Optional<String> route = cluster.isPresent() ? Optional.of(clusterDefToRoute(resolveClusterDef(cluster, clusterEnumerator.enumerateClusters()))) : Optional.empty(); setRoute(syncSession, route); try { DocumentId id = new DocumentId(restUri.generateFullId()); final Document document = syncSession.get(id, fieldSet.orElse(restUri.getDocumentType() + ":[document]"), DocumentProtocol.Priority.NORMAL_1); if (document == null) { return Optional.empty(); } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); JsonWriter jsonWriter = new JsonWriter(outputStream); jsonWriter.write(document); return Optional.of(outputStream.toString(StandardCharsets.UTF_8.name())); } catch (Exception e) { throw new RestApiException(Response.createErrorResponse(500, ExceptionUtils.getStackTraceAsString(e), restUri, RestUri.apiErrorCodes.UNSPECIFIED)); } finally { syncSessions.free(syncSession); } } OperationHandlerImpl(DocumentAccess documentAccess, ClusterEnumerator clusterEnumerator,
                                BucketSpaceResolver bucketSpaceResolver, MetricReceiver metricReceiver); @Override void shutdown(); static int getHTTPStatusCode(Set<Integer> errorCodes); @Override VisitResult visit(RestUri restUri, String documentSelection, VisitOptions options); @Override void put(RestUri restUri, FeedOperation data, Optional<String> route); @Override void update(RestUri restUri, FeedOperation data, Optional<String> route); @Override void delete(RestUri restUri, String condition, Optional<String> route); @Override Optional<String> get(RestUri restUri, Optional<String> fieldSet, Optional<String> cluster); @Override Optional<String> get(RestUri restUri, Optional<String> fieldSet); @Override Optional<String> get(RestUri restUri); static final int VISIT_TIMEOUT_MS; static final int WANTED_DOCUMENT_COUNT_UPPER_BOUND; static final int CONCURRENCY_UPPER_BOUND; }
@Test public void get_field_covers_all_fields_by_default() throws Exception { OperationHandlerImplFixture fixture = new OperationHandlerImplFixture(); OperationHandlerImpl handler = fixture.createHandler(); handler.get(dummyGetUri(), Optional.empty()); verify(fixture.mockSyncSession).get(any(), eq("document-type:[document]"), any()); }
@Test public void provided_get_fieldset_is_propagated_to_sync_session() throws Exception { OperationHandlerImplFixture fixture = new OperationHandlerImplFixture(); OperationHandlerImpl handler = fixture.createHandler(); handler.get(dummyGetUri(), Optional.of("donald,duck")); verify(fixture.mockSyncSession).get(any(), eq("donald,duck"), any()); }