use of com.google.cloud.dialogflow.v2beta1.Document.KnowledgeType in project java-dialogflow by googleapis.
the class DocumentManagement method createDocument.
public static Document createDocument(String knowledgeBaseName, String displayName, String mimeType, String knowledgeType, String contentUri) throws IOException, ApiException, InterruptedException, ExecutionException, TimeoutException {
// Instantiates a client
try (DocumentsClient documentsClient = DocumentsClient.create()) {
Document document = Document.newBuilder().setDisplayName(displayName).setContentUri(contentUri).setMimeType(mimeType).addKnowledgeTypes(KnowledgeType.valueOf(knowledgeType)).build();
CreateDocumentRequest createDocumentRequest = CreateDocumentRequest.newBuilder().setDocument(document).setParent(knowledgeBaseName).build();
OperationFuture<Document, KnowledgeOperationMetadata> response = documentsClient.createDocumentAsync(createDocumentRequest);
Document createdDocument = response.get(180, TimeUnit.SECONDS);
System.out.format("Created Document:\n");
System.out.format(" - Display Name: %s\n", createdDocument.getDisplayName());
System.out.format(" - Knowledge ID: %s\n", createdDocument.getName());
System.out.format(" - MIME Type: %s\n", createdDocument.getMimeType());
System.out.format(" - Knowledge Types:\n");
for (KnowledgeType knowledgeTypeId : document.getKnowledgeTypesList()) {
System.out.format(" - %s \n", knowledgeTypeId.getValueDescriptor());
}
System.out.format(" - Source: %s \n", document.getContentUri());
return createdDocument;
}
}
Aggregations