use of com.google.cloud.dialogflow.v2beta1.CreateDocumentRequest in project java-firestore by googleapis.
the class FirestoreClientTest method createDocumentTest.
@Test
public void createDocumentTest() throws Exception {
Document expectedResponse = Document.newBuilder().setName("name3373707").putAllFields(new HashMap<String, Value>()).setCreateTime(Timestamp.newBuilder().build()).setUpdateTime(Timestamp.newBuilder().build()).build();
mockFirestore.addResponse(expectedResponse);
CreateDocumentRequest request = CreateDocumentRequest.newBuilder().setParent("parent-995424086").setCollectionId("collectionId1636075609").setDocumentId("documentId-814940266").setDocument(Document.newBuilder().build()).setMask(DocumentMask.newBuilder().build()).build();
Document actualResponse = client.createDocument(request);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockFirestore.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateDocumentRequest actualRequest = ((CreateDocumentRequest) actualRequests.get(0));
Assert.assertEquals(request.getParent(), actualRequest.getParent());
Assert.assertEquals(request.getCollectionId(), actualRequest.getCollectionId());
Assert.assertEquals(request.getDocumentId(), actualRequest.getDocumentId());
Assert.assertEquals(request.getDocument(), actualRequest.getDocument());
Assert.assertEquals(request.getMask(), actualRequest.getMask());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.dialogflow.v2beta1.CreateDocumentRequest 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;
}
}
use of com.google.cloud.dialogflow.v2beta1.CreateDocumentRequest in project java-firestore by googleapis.
the class FirestoreClientTest method createDocumentExceptionTest.
@Test
public void createDocumentExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockFirestore.addException(exception);
try {
CreateDocumentRequest request = CreateDocumentRequest.newBuilder().setParent("parent-995424086").setCollectionId("collectionId1636075609").setDocumentId("documentId-814940266").setDocument(Document.newBuilder().build()).setMask(DocumentMask.newBuilder().build()).build();
client.createDocument(request);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.cloud.dialogflow.v2beta1.CreateDocumentRequest in project grpc-gcp-java by GoogleCloudPlatform.
the class CreateDocument method createDocumentCall.
public void createDocumentCall() {
System.out.println("\n:: Creating New Document ::\n");
FirestoreBlockingStub blockingStub = new GRPCFirebaseClientFactory().createFirebaseClient().getBlockingStub();
Scanner sc = new Scanner(System.in);
System.out.print("Enter Document Name: ");
String docName = sc.next();
HashMap<String, Value> fieldsMap;
MakeFieldsMap mfm = new MakeFieldsMap();
fieldsMap = mfm.makeFieldsMap();
Document newDoc = Document.newBuilder().putAllFields(fieldsMap).build();
CreateDocumentRequest createDocumentRequest = CreateDocumentRequest.newBuilder().setDocument(newDoc).setCollectionId("GrpcTestData").setParent("projects/firestoretestclient/databases/(default)/documents").setDocumentId(docName).build();
Document finishedDoc;
try {
finishedDoc = blockingStub.createDocument(createDocumentRequest);
} catch (Exception e) {
System.out.println("Error during call: " + e.getMessage() + e.getCause());
return;
}
DrawDocument dd = new DrawDocument();
dd.draw(finishedDoc);
Menu menu = new Menu();
menu.draw();
}
Aggregations