Search in sources :

Example 1 with CreateDocumentRequest

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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) CreateDocumentRequest(com.google.firestore.v1.CreateDocumentRequest) Document(com.google.firestore.v1.Document) Test(org.junit.Test)

Example 2 with CreateDocumentRequest

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;
    }
}
Also used : KnowledgeOperationMetadata(com.google.cloud.dialogflow.v2beta1.KnowledgeOperationMetadata) CreateDocumentRequest(com.google.cloud.dialogflow.v2beta1.CreateDocumentRequest) Document(com.google.cloud.dialogflow.v2beta1.Document) KnowledgeType(com.google.cloud.dialogflow.v2beta1.Document.KnowledgeType) DocumentsClient(com.google.cloud.dialogflow.v2beta1.DocumentsClient)

Example 3 with CreateDocumentRequest

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.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) CreateDocumentRequest(com.google.firestore.v1.CreateDocumentRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 4 with CreateDocumentRequest

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();
}
Also used : GRPCFirebaseClientFactory(org.roguewave.grpc.util.GRPCFirebaseClientFactory) Scanner(java.util.Scanner) FirestoreBlockingStub(com.google.firestore.v1beta1.FirestoreGrpc.FirestoreBlockingStub) CreateDocumentRequest(com.google.firestore.v1beta1.CreateDocumentRequest) MakeFieldsMap(org.roguewave.grpc.util.gfx.MakeFieldsMap) Value(com.google.firestore.v1beta1.Value) Menu(org.roguewave.grpc.util.gfx.Menu) DrawDocument(org.roguewave.grpc.util.gfx.DrawDocument) Document(com.google.firestore.v1beta1.Document) DrawDocument(org.roguewave.grpc.util.gfx.DrawDocument)

Aggregations

CreateDocumentRequest (com.google.firestore.v1.CreateDocumentRequest)2 Test (org.junit.Test)2 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)1 CreateDocumentRequest (com.google.cloud.dialogflow.v2beta1.CreateDocumentRequest)1 Document (com.google.cloud.dialogflow.v2beta1.Document)1 KnowledgeType (com.google.cloud.dialogflow.v2beta1.Document.KnowledgeType)1 DocumentsClient (com.google.cloud.dialogflow.v2beta1.DocumentsClient)1 KnowledgeOperationMetadata (com.google.cloud.dialogflow.v2beta1.KnowledgeOperationMetadata)1 Document (com.google.firestore.v1.Document)1 CreateDocumentRequest (com.google.firestore.v1beta1.CreateDocumentRequest)1 Document (com.google.firestore.v1beta1.Document)1 FirestoreBlockingStub (com.google.firestore.v1beta1.FirestoreGrpc.FirestoreBlockingStub)1 Value (com.google.firestore.v1beta1.Value)1 AbstractMessage (com.google.protobuf.AbstractMessage)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 HashMap (java.util.HashMap)1 Scanner (java.util.Scanner)1 GRPCFirebaseClientFactory (org.roguewave.grpc.util.GRPCFirebaseClientFactory)1 DrawDocument (org.roguewave.grpc.util.gfx.DrawDocument)1 MakeFieldsMap (org.roguewave.grpc.util.gfx.MakeFieldsMap)1