Search in sources :

Example 6 with FeatureNotAvailableException

use of com.couchbase.client.core.error.FeatureNotAvailableException in project couchbase-jvm-clients by couchbase.

the class AsyncSearchIndexManager method analyzeDocument.

/**
 * Allows to see how a document is analyzed against a specific index.
 *
 * @param name the name of the search index.
 * @param document the document to analyze.
 * @return a {@link CompletableFuture} with analyzed document parts once complete.
 */
public CompletableFuture<List<JsonObject>> analyzeDocument(final String name, final JsonObject document, final AnalyzeDocumentOptions options) {
    notNullOrEmpty(name, "Search Index Name");
    notNull(document, "Document");
    return searchHttpClient.post(path(analyzeDocumentPath(name)), options.build()).trace(TracingIdentifiers.SPAN_REQUEST_MS_ANALYZE_DOCUMENT).json(Mapper.encodeAsBytes(document.toMap())).exec(core).exceptionally(throwable -> {
        if (throwable.getMessage().contains("Page not found")) {
            throw new FeatureNotAvailableException("Document analysis is not available on this server version!");
        } else if (throwable instanceof RuntimeException) {
            throw (RuntimeException) throwable;
        } else {
            throw new CouchbaseException("Failed to analyze search document", throwable);
        }
    }).thenApply(response -> {
        JsonNode rootNode = Mapper.decodeIntoTree(response.content());
        List<Map<String, Object>> analyzed = Mapper.convertValue(rootNode.get("analyzed"), new TypeReference<List<Map<String, Object>>>() {
        });
        return analyzed.stream().filter(Objects::nonNull).map(JsonObject::from).collect(Collectors.toList());
    });
}
Also used : AnalyzeDocumentOptions.analyzeDocumentOptions(com.couchbase.client.java.manager.search.AnalyzeDocumentOptions.analyzeDocumentOptions) HttpHeaderNames(com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpHeaderNames) GetSearchIndexOptions.getSearchIndexOptions(com.couchbase.client.java.manager.search.GetSearchIndexOptions.getSearchIndexOptions) Validators.notNull(com.couchbase.client.core.util.Validators.notNull) CouchbaseException(com.couchbase.client.core.error.CouchbaseException) RequestTarget(com.couchbase.client.core.msg.RequestTarget) TypeReference(com.couchbase.client.core.deps.com.fasterxml.jackson.core.type.TypeReference) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) JsonNode(com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode) TracingIdentifiers(com.couchbase.client.core.cnc.TracingIdentifiers) Map(java.util.Map) CoreHttpPath.path(com.couchbase.client.core.endpoint.http.CoreHttpPath.path) DropSearchIndexOptions.dropSearchIndexOptions(com.couchbase.client.java.manager.search.DropSearchIndexOptions.dropSearchIndexOptions) RequestSpan(com.couchbase.client.core.cnc.RequestSpan) GetAllSearchIndexesOptions.getAllSearchIndexesOptions(com.couchbase.client.java.manager.search.GetAllSearchIndexesOptions.getAllSearchIndexesOptions) CbTracing(com.couchbase.client.core.cnc.CbTracing) AllowQueryingSearchIndexOptions.allowQueryingSearchIndexOptions(com.couchbase.client.java.manager.search.AllowQueryingSearchIndexOptions.allowQueryingSearchIndexOptions) UTF_8(java.nio.charset.StandardCharsets.UTF_8) IndexNotFoundException(com.couchbase.client.core.error.IndexNotFoundException) Mapper(com.couchbase.client.core.json.Mapper) CoreHttpClient(com.couchbase.client.core.endpoint.http.CoreHttpClient) UrlQueryStringBuilder.urlEncode(com.couchbase.client.core.util.UrlQueryStringBuilder.urlEncode) FeatureNotAvailableException(com.couchbase.client.core.error.FeatureNotAvailableException) UpsertSearchIndexOptions.upsertSearchIndexOptions(com.couchbase.client.java.manager.search.UpsertSearchIndexOptions.upsertSearchIndexOptions) Collectors(java.util.stream.Collectors) Validators.notNullOrEmpty(com.couchbase.client.core.util.Validators.notNullOrEmpty) PauseIngestSearchIndexOptions.pauseIngestSearchIndexOptions(com.couchbase.client.java.manager.search.PauseIngestSearchIndexOptions.pauseIngestSearchIndexOptions) Objects(java.util.Objects) List(java.util.List) GetIndexedSearchIndexOptions.getIndexedSearchIndexOptions(com.couchbase.client.java.manager.search.GetIndexedSearchIndexOptions.getIndexedSearchIndexOptions) UnfreezePlanSearchIndexOptions.unfreezePlanSearchIndexOptions(com.couchbase.client.java.manager.search.UnfreezePlanSearchIndexOptions.unfreezePlanSearchIndexOptions) ResumeIngestSearchIndexOptions.resumeIngestSearchIndexOptions(com.couchbase.client.java.manager.search.ResumeIngestSearchIndexOptions.resumeIngestSearchIndexOptions) JsonObject(com.couchbase.client.java.json.JsonObject) FreezePlanSearchIndexOptions.freezePlanSearchIndexOptions(com.couchbase.client.java.manager.search.FreezePlanSearchIndexOptions.freezePlanSearchIndexOptions) Core(com.couchbase.client.core.Core) DisallowQueryingSearchIndexOptions.disallowQueryingSearchIndexOptions(com.couchbase.client.java.manager.search.DisallowQueryingSearchIndexOptions.disallowQueryingSearchIndexOptions) FeatureNotAvailableException(com.couchbase.client.core.error.FeatureNotAvailableException) CouchbaseException(com.couchbase.client.core.error.CouchbaseException) Objects(java.util.Objects) JsonNode(com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode) ArrayList(java.util.ArrayList) List(java.util.List) JsonObject(com.couchbase.client.java.json.JsonObject) Map(java.util.Map)

Example 7 with FeatureNotAvailableException

use of com.couchbase.client.core.error.FeatureNotAvailableException in project couchbase-jvm-clients by couchbase.

the class QueryIntegrationTest method preserveExpiryThrowsFeatureNotAvailable.

@Test
@IgnoreWhen(hasCapabilities = Capabilities.QUERY_PRESERVE_EXPIRY)
void preserveExpiryThrowsFeatureNotAvailable() {
    FeatureNotAvailableException ex = assertThrows(FeatureNotAvailableException.class, () -> cluster.query("select 1=1", queryOptions().preserveExpiry(true)));
    assertTrue(ex.getMessage().contains("Preserving expiry for the query service is not supported"));
}
Also used : FeatureNotAvailableException(com.couchbase.client.core.error.FeatureNotAvailableException) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

FeatureNotAvailableException (com.couchbase.client.core.error.FeatureNotAvailableException)7 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)3 Test (org.junit.jupiter.api.Test)3 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)2 CouchbaseBucketConfig (com.couchbase.client.core.config.CouchbaseBucketConfig)2 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)2 InsertRequest (com.couchbase.client.core.msg.kv.InsertRequest)2 CoreIntegrationTest (com.couchbase.client.core.util.CoreIntegrationTest)2 Core (com.couchbase.client.core.Core)1 CbTracing (com.couchbase.client.core.cnc.CbTracing)1 TracingIdentifiers (com.couchbase.client.core.cnc.TracingIdentifiers)1 BucketConfig (com.couchbase.client.core.config.BucketConfig)1 TypeReference (com.couchbase.client.core.deps.com.fasterxml.jackson.core.type.TypeReference)1 JsonNode (com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode)1 ByteBuf (com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)1 CompositeByteBuf (com.couchbase.client.core.deps.io.netty.buffer.CompositeByteBuf)1 HttpHeaderNames (com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpHeaderNames)1 CoreHttpClient (com.couchbase.client.core.endpoint.http.CoreHttpClient)1 CoreHttpPath.path (com.couchbase.client.core.endpoint.http.CoreHttpPath.path)1 IndexNotFoundException (com.couchbase.client.core.error.IndexNotFoundException)1