@Generated(value="by gapic-generator") @BetaApi public class DocumentsClient extends Object implements BackgroundResource
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
DocumentName name = DocumentName.of("[PROJECT]", "[KNOWLEDGE_BASE]", "[DOCUMENT]");
Document response = documentsClient.getDocument(name);
}
Note: close() needs to be called on the documentsClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of DocumentsSettings to create(). For example:
To customize credentials:
DocumentsSettings documentsSettings =
DocumentsSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
DocumentsClient documentsClient =
DocumentsClient.create(documentsSettings);
To customize the endpoint:
DocumentsSettings documentsSettings =
DocumentsSettings.newBuilder().setEndpoint(myEndpoint).build();
DocumentsClient documentsClient =
DocumentsClient.create(documentsSettings);
Modifier and Type | Class and Description |
---|---|
static class |
DocumentsClient.ListDocumentsFixedSizeCollection |
static class |
DocumentsClient.ListDocumentsPage |
static class |
DocumentsClient.ListDocumentsPagedResponse |
Modifier | Constructor and Description |
---|---|
protected |
DocumentsClient(DocumentsSettings settings)
Constructs an instance of DocumentsClient, using the given settings.
|
protected |
DocumentsClient(DocumentsStub stub) |
protected DocumentsClient(DocumentsSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") protected DocumentsClient(DocumentsStub stub)
public static final DocumentsClient create() throws IOException
IOException
public static final DocumentsClient create(DocumentsSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final DocumentsClient create(DocumentsStub stub)
public final DocumentsSettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public DocumentsStub getStub()
@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationsClient getOperationsClient()
public final DocumentsClient.ListDocumentsPagedResponse listDocuments(KnowledgeBaseName parent)
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
KnowledgeBaseName parent = KnowledgeBaseName.of("[PROJECT]", "[KNOWLEDGE_BASE]");
for (Document element : documentsClient.listDocuments(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent
- Required. The knowledge base to list all documents for. Format:
`projects/<Project ID>/knowledgeBases/<Knowledge Base ID>`.ApiException
- if the remote call failspublic final DocumentsClient.ListDocumentsPagedResponse listDocuments(String parent)
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
KnowledgeBaseName parent = KnowledgeBaseName.of("[PROJECT]", "[KNOWLEDGE_BASE]");
for (Document element : documentsClient.listDocuments(parent.toString()).iterateAll()) {
// doThingsWith(element);
}
}
parent
- Required. The knowledge base to list all documents for. Format:
`projects/<Project ID>/knowledgeBases/<Knowledge Base ID>`.ApiException
- if the remote call failspublic final DocumentsClient.ListDocumentsPagedResponse listDocuments(ListDocumentsRequest request)
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
KnowledgeBaseName parent = KnowledgeBaseName.of("[PROJECT]", "[KNOWLEDGE_BASE]");
ListDocumentsRequest request = ListDocumentsRequest.newBuilder()
.setParent(parent.toString())
.build();
for (Document element : documentsClient.listDocuments(request).iterateAll()) {
// doThingsWith(element);
}
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<ListDocumentsRequest,DocumentsClient.ListDocumentsPagedResponse> listDocumentsPagedCallable()
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
KnowledgeBaseName parent = KnowledgeBaseName.of("[PROJECT]", "[KNOWLEDGE_BASE]");
ListDocumentsRequest request = ListDocumentsRequest.newBuilder()
.setParent(parent.toString())
.build();
ApiFuture<ListDocumentsPagedResponse> future = documentsClient.listDocumentsPagedCallable().futureCall(request);
// Do something
for (Document element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final UnaryCallable<ListDocumentsRequest,ListDocumentsResponse> listDocumentsCallable()
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
KnowledgeBaseName parent = KnowledgeBaseName.of("[PROJECT]", "[KNOWLEDGE_BASE]");
ListDocumentsRequest request = ListDocumentsRequest.newBuilder()
.setParent(parent.toString())
.build();
while (true) {
ListDocumentsResponse response = documentsClient.listDocumentsCallable().call(request);
for (Document element : response.getDocumentsList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final Document getDocument(DocumentName name)
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
DocumentName name = DocumentName.of("[PROJECT]", "[KNOWLEDGE_BASE]", "[DOCUMENT]");
Document response = documentsClient.getDocument(name);
}
name
- Required. The name of the document to retrieve. Format `projects/<Project
ID>/knowledgeBases/<Knowledge Base ID>/documents/<Document ID>`.ApiException
- if the remote call failspublic final Document getDocument(String name)
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
DocumentName name = DocumentName.of("[PROJECT]", "[KNOWLEDGE_BASE]", "[DOCUMENT]");
Document response = documentsClient.getDocument(name.toString());
}
name
- Required. The name of the document to retrieve. Format `projects/<Project
ID>/knowledgeBases/<Knowledge Base ID>/documents/<Document ID>`.ApiException
- if the remote call failspublic final Document getDocument(GetDocumentRequest request)
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
DocumentName name = DocumentName.of("[PROJECT]", "[KNOWLEDGE_BASE]", "[DOCUMENT]");
GetDocumentRequest request = GetDocumentRequest.newBuilder()
.setName(name.toString())
.build();
Document response = documentsClient.getDocument(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<GetDocumentRequest,Document> getDocumentCallable()
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
DocumentName name = DocumentName.of("[PROJECT]", "[KNOWLEDGE_BASE]", "[DOCUMENT]");
GetDocumentRequest request = GetDocumentRequest.newBuilder()
.setName(name.toString())
.build();
ApiFuture<Document> future = documentsClient.getDocumentCallable().futureCall(request);
// Do something
Document response = future.get();
}
@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<Document,KnowledgeOperationMetadata> createDocumentAsync(KnowledgeBaseName parent, Document document)
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
KnowledgeBaseName parent = KnowledgeBaseName.of("[PROJECT]", "[KNOWLEDGE_BASE]");
Document document = Document.newBuilder().build();
Document response = documentsClient.createDocumentAsync(parent, document).get();
}
parent
- Required. The knowledge base to create a document for. Format:
`projects/<Project ID>/knowledgeBases/<Knowledge Base ID>`.document
- Required. The document to create.ApiException
- if the remote call fails@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<Document,KnowledgeOperationMetadata> createDocumentAsync(String parent, Document document)
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
KnowledgeBaseName parent = KnowledgeBaseName.of("[PROJECT]", "[KNOWLEDGE_BASE]");
Document document = Document.newBuilder().build();
Document response = documentsClient.createDocumentAsync(parent.toString(), document).get();
}
parent
- Required. The knowledge base to create a document for. Format:
`projects/<Project ID>/knowledgeBases/<Knowledge Base ID>`.document
- Required. The document to create.ApiException
- if the remote call fails@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<Document,KnowledgeOperationMetadata> createDocumentAsync(CreateDocumentRequest request)
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
KnowledgeBaseName parent = KnowledgeBaseName.of("[PROJECT]", "[KNOWLEDGE_BASE]");
Document document = Document.newBuilder().build();
CreateDocumentRequest request = CreateDocumentRequest.newBuilder()
.setParent(parent.toString())
.setDocument(document)
.build();
Document response = documentsClient.createDocumentAsync(request).get();
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call fails@BetaApi(value="The surface for use by generated code is not stable yet and may change in the future.") public final OperationCallable<CreateDocumentRequest,Document,KnowledgeOperationMetadata> createDocumentOperationCallable()
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
KnowledgeBaseName parent = KnowledgeBaseName.of("[PROJECT]", "[KNOWLEDGE_BASE]");
Document document = Document.newBuilder().build();
CreateDocumentRequest request = CreateDocumentRequest.newBuilder()
.setParent(parent.toString())
.setDocument(document)
.build();
OperationFuture<Document, KnowledgeOperationMetadata> future = documentsClient.createDocumentOperationCallable().futureCall(request);
// Do something
Document response = future.get();
}
public final UnaryCallable<CreateDocumentRequest,Operation> createDocumentCallable()
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
KnowledgeBaseName parent = KnowledgeBaseName.of("[PROJECT]", "[KNOWLEDGE_BASE]");
Document document = Document.newBuilder().build();
CreateDocumentRequest request = CreateDocumentRequest.newBuilder()
.setParent(parent.toString())
.setDocument(document)
.build();
ApiFuture<Operation> future = documentsClient.createDocumentCallable().futureCall(request);
// Do something
Operation response = future.get();
}
@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<Empty,KnowledgeOperationMetadata> deleteDocumentAsync(DocumentName name)
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
DocumentName name = DocumentName.of("[PROJECT]", "[KNOWLEDGE_BASE]", "[DOCUMENT]");
documentsClient.deleteDocumentAsync(name).get();
}
name
- Required. The name of the document to delete. Format: `projects/<Project
ID>/knowledgeBases/<Knowledge Base ID>/documents/<Document ID>`.ApiException
- if the remote call fails@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<Empty,KnowledgeOperationMetadata> deleteDocumentAsync(String name)
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
DocumentName name = DocumentName.of("[PROJECT]", "[KNOWLEDGE_BASE]", "[DOCUMENT]");
documentsClient.deleteDocumentAsync(name.toString()).get();
}
name
- Required. The name of the document to delete. Format: `projects/<Project
ID>/knowledgeBases/<Knowledge Base ID>/documents/<Document ID>`.ApiException
- if the remote call fails@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<Empty,KnowledgeOperationMetadata> deleteDocumentAsync(DeleteDocumentRequest request)
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
DocumentName name = DocumentName.of("[PROJECT]", "[KNOWLEDGE_BASE]", "[DOCUMENT]");
DeleteDocumentRequest request = DeleteDocumentRequest.newBuilder()
.setName(name.toString())
.build();
documentsClient.deleteDocumentAsync(request).get();
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call fails@BetaApi(value="The surface for use by generated code is not stable yet and may change in the future.") public final OperationCallable<DeleteDocumentRequest,Empty,KnowledgeOperationMetadata> deleteDocumentOperationCallable()
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
DocumentName name = DocumentName.of("[PROJECT]", "[KNOWLEDGE_BASE]", "[DOCUMENT]");
DeleteDocumentRequest request = DeleteDocumentRequest.newBuilder()
.setName(name.toString())
.build();
OperationFuture<Empty, KnowledgeOperationMetadata> future = documentsClient.deleteDocumentOperationCallable().futureCall(request);
// Do something
future.get();
}
public final UnaryCallable<DeleteDocumentRequest,Operation> deleteDocumentCallable()
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
DocumentName name = DocumentName.of("[PROJECT]", "[KNOWLEDGE_BASE]", "[DOCUMENT]");
DeleteDocumentRequest request = DeleteDocumentRequest.newBuilder()
.setName(name.toString())
.build();
ApiFuture<Operation> future = documentsClient.deleteDocumentCallable().futureCall(request);
// Do something
future.get();
}
@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<Document,KnowledgeOperationMetadata> updateDocumentAsync(Document document, FieldMask updateMask)
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
Document document = Document.newBuilder().build();
FieldMask updateMask = FieldMask.newBuilder().build();
Document response = documentsClient.updateDocumentAsync(document, updateMask).get();
}
document
- Required. The document to update.updateMask
- Optional. Not specified means `update all`. Currently, only `display_name`
can be updated, an InvalidArgument will be returned for attempting to update other fields.ApiException
- if the remote call fails@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<Document,KnowledgeOperationMetadata> updateDocumentAsync(Document document)
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
Document document = Document.newBuilder().build();
Document response = documentsClient.updateDocumentAsync(document).get();
}
document
- Required. The document to update.ApiException
- if the remote call fails@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<Document,KnowledgeOperationMetadata> updateDocumentAsync(UpdateDocumentRequest request)
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
Document document = Document.newBuilder().build();
UpdateDocumentRequest request = UpdateDocumentRequest.newBuilder()
.setDocument(document)
.build();
Document response = documentsClient.updateDocumentAsync(request).get();
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call fails@BetaApi(value="The surface for use by generated code is not stable yet and may change in the future.") public final OperationCallable<UpdateDocumentRequest,Document,KnowledgeOperationMetadata> updateDocumentOperationCallable()
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
Document document = Document.newBuilder().build();
UpdateDocumentRequest request = UpdateDocumentRequest.newBuilder()
.setDocument(document)
.build();
OperationFuture<Document, KnowledgeOperationMetadata> future = documentsClient.updateDocumentOperationCallable().futureCall(request);
// Do something
Document response = future.get();
}
public final UnaryCallable<UpdateDocumentRequest,Operation> updateDocumentCallable()
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
Document document = Document.newBuilder().build();
UpdateDocumentRequest request = UpdateDocumentRequest.newBuilder()
.setDocument(document)
.build();
ApiFuture<Operation> future = documentsClient.updateDocumentCallable().futureCall(request);
// Do something
Operation response = future.get();
}
@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<Document,KnowledgeOperationMetadata> reloadDocumentAsync(DocumentName name, GcsSource gcsSource)
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
DocumentName name = DocumentName.of("[PROJECT]", "[KNOWLEDGE_BASE]", "[DOCUMENT]");
GcsSource gcsSource = GcsSource.newBuilder().build();
Document response = documentsClient.reloadDocumentAsync(name, gcsSource).get();
}
name
- Required. The name of the document to reload. Format: `projects/<Project
ID>/knowledgeBases/<Knowledge Base ID>/documents/<Document ID>`gcsSource
- The path for a Cloud Storage source file for reloading document content. If
not provided, the Document's existing source will be reloaded.ApiException
- if the remote call fails@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<Document,KnowledgeOperationMetadata> reloadDocumentAsync(String name, GcsSource gcsSource)
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
DocumentName name = DocumentName.of("[PROJECT]", "[KNOWLEDGE_BASE]", "[DOCUMENT]");
GcsSource gcsSource = GcsSource.newBuilder().build();
Document response = documentsClient.reloadDocumentAsync(name.toString(), gcsSource).get();
}
name
- Required. The name of the document to reload. Format: `projects/<Project
ID>/knowledgeBases/<Knowledge Base ID>/documents/<Document ID>`gcsSource
- The path for a Cloud Storage source file for reloading document content. If
not provided, the Document's existing source will be reloaded.ApiException
- if the remote call fails@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<Document,KnowledgeOperationMetadata> reloadDocumentAsync(ReloadDocumentRequest request)
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
DocumentName name = DocumentName.of("[PROJECT]", "[KNOWLEDGE_BASE]", "[DOCUMENT]");
ReloadDocumentRequest request = ReloadDocumentRequest.newBuilder()
.setName(name.toString())
.build();
Document response = documentsClient.reloadDocumentAsync(request).get();
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call fails@BetaApi(value="The surface for use by generated code is not stable yet and may change in the future.") public final OperationCallable<ReloadDocumentRequest,Document,KnowledgeOperationMetadata> reloadDocumentOperationCallable()
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
DocumentName name = DocumentName.of("[PROJECT]", "[KNOWLEDGE_BASE]", "[DOCUMENT]");
ReloadDocumentRequest request = ReloadDocumentRequest.newBuilder()
.setName(name.toString())
.build();
OperationFuture<Document, KnowledgeOperationMetadata> future = documentsClient.reloadDocumentOperationCallable().futureCall(request);
// Do something
Document response = future.get();
}
public final UnaryCallable<ReloadDocumentRequest,Operation> reloadDocumentCallable()
Note: The `projects.agent.knowledgeBases.documents` resource is deprecated; only use `projects.knowledgeBases.documents`.
Sample code:
try (DocumentsClient documentsClient = DocumentsClient.create()) {
DocumentName name = DocumentName.of("[PROJECT]", "[KNOWLEDGE_BASE]", "[DOCUMENT]");
ReloadDocumentRequest request = ReloadDocumentRequest.newBuilder()
.setName(name.toString())
.build();
ApiFuture<Operation> future = documentsClient.reloadDocumentCallable().futureCall(request);
// Do something
Operation response = future.get();
}
public final void close()
close
in interface AutoCloseable
public void shutdown()
shutdown
in interface BackgroundResource
public boolean isShutdown()
isShutdown
in interface BackgroundResource
public boolean isTerminated()
isTerminated
in interface BackgroundResource
public void shutdownNow()
shutdownNow
in interface BackgroundResource
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
awaitTermination
in interface BackgroundResource
InterruptedException
Copyright © 2021 Google LLC. All rights reserved.