Search in sources :

Example 26 with EntityType

use of com.google.cloud.dialogflow.v2.EntityType in project entity-service by hypertrace.

the class EntityTypeDocumentTest method testProtoConversion.

@Test
public void testProtoConversion() {
    EntityType entityType = EntityType.newBuilder().setName("API").setAttributeScope("API").setIdAttributeKey("id").setNameAttributeKey("name").setTimestampAttributeKey("timestamp").addRequiredConditions(EntityFormationCondition.newBuilder().setRequiredKey("other")).build();
    Assertions.assertEquals(entityType, EntityTypeDocument.fromProto("testTenant", entityType).toProto());
}
Also used : EntityType(org.hypertrace.entity.type.service.v2.EntityType) Test(org.junit.jupiter.api.Test)

Example 27 with EntityType

use of com.google.cloud.dialogflow.v2.EntityType in project entity-service by hypertrace.

the class EntityTypeDocumentTest method testFromJsonMissingField.

@Test
public void testFromJsonMissingField() throws InvalidProtocolBufferException, JsonProcessingException {
    EntityType entityType = EntityType.newBuilder().setName("API").setAttributeScope("API").setIdAttributeKey("id").setNameAttributeKey("name").build();
    String entityTypeJson = JsonFormat.printer().print(entityType);
    Assertions.assertEquals(entityType, EntityTypeDocument.fromJson(entityTypeJson).toProto());
}
Also used : EntityType(org.hypertrace.entity.type.service.v2.EntityType) Test(org.junit.jupiter.api.Test)

Example 28 with EntityType

use of com.google.cloud.dialogflow.v2.EntityType in project entity-service by hypertrace.

the class EntityTypeServiceImpl method deleteEntityTypes.

@Override
public void deleteEntityTypes(EntityTypeFilter request, StreamObserver<Empty> responseObserver) {
    Optional<String> tenantId = RequestContext.CURRENT.get().getTenantId();
    if (tenantId.isEmpty()) {
        responseObserver.onError(new ServiceException("Tenant id is missing in the request."));
        return;
    }
    try {
        Iterator<Document> documents = entityTypeCol.search(transform(tenantId.get(), request, false));
        StreamSupport.stream(Spliterators.spliteratorUnknownSize(documents, 0), false).map(document -> {
            try {
                EntityType.Builder builder = EntityType.newBuilder();
                PARSER.merge(document.toJson(), builder);
                return builder;
            } catch (InvalidProtocolBufferException e) {
                LOG.warn(String.format("Error processing entityType: %s", document.toJson()), e);
                return null;
            }
        }).filter(Objects::nonNull).forEach(entityTypeBuilder -> entityTypeCol.delete(new SingleValueKey(tenantId.get(), entityTypeBuilder.getName())));
        responseObserver.onNext(Empty.newBuilder().build());
        responseObserver.onCompleted();
    } catch (Exception ex) {
        LOG.error("Error deleting entity types matching filter:{}", request);
        responseObserver.onError(ex);
    }
}
Also used : EntityType(org.hypertrace.entity.type.service.v1.EntityType) SingleValueKey(org.hypertrace.core.documentstore.SingleValueKey) ServiceException(com.google.protobuf.ServiceException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Document(org.hypertrace.core.documentstore.Document) JSONDocument(org.hypertrace.core.documentstore.JSONDocument) ServiceException(com.google.protobuf.ServiceException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) IOException(java.io.IOException)

Example 29 with EntityType

use of com.google.cloud.dialogflow.v2.EntityType in project entity-service by hypertrace.

the class EntityTypeServiceImpl method upsertEntityType.

@Override
public void upsertEntityType(EntityType request, StreamObserver<EntityType> responseObserver) {
    Optional<String> tenantId = RequestContext.CURRENT.get().getTenantId();
    if (tenantId.isEmpty()) {
        responseObserver.onError(new ServiceException("Tenant id is missing in the request."));
        return;
    }
    try {
        // TODO: Since we currently use the same object that's received in the request while
        // persisting in the doc store, we need to add tenantId explicitly here.
        // We need to split these objects later.
        EntityType newRequest = EntityType.newBuilder(request).setTenantId(tenantId.get()).build();
        entityTypeCol.upsert(new SingleValueKey(tenantId.get(), request.getName()), new JSONDocument(PROTO_PRINTER.print(newRequest)));
        responseObserver.onNext(newRequest);
        responseObserver.onCompleted();
    } catch (IOException ioe) {
        responseObserver.onError(new RuntimeException("Error upserting EntityType:" + request, ioe));
    }
}
Also used : EntityType(org.hypertrace.entity.type.service.v1.EntityType) SingleValueKey(org.hypertrace.core.documentstore.SingleValueKey) ServiceException(com.google.protobuf.ServiceException) JSONDocument(org.hypertrace.core.documentstore.JSONDocument) IOException(java.io.IOException)

Example 30 with EntityType

use of com.google.cloud.dialogflow.v2.EntityType in project entity-service by hypertrace.

the class EntityTypeCachingClientTest method supportsMultipleConcurrentCacheKeys.

@Test
void supportsMultipleConcurrentCacheKeys() throws Exception {
    EntityType defaultRetrieved = this.grpcTestContext.call(() -> this.typeClient.get("first").blockingGet());
    assertSame(this.type1, defaultRetrieved);
    verify(this.mockTypeService, times(1)).queryEntityTypes(any(), any());
    RequestContext otherMockContext = mock(RequestContext.class);
    when(otherMockContext.getTenantId()).thenReturn(Optional.of("other tenant"));
    Context otherGrpcContext = Context.current().withValue(RequestContext.CURRENT, otherMockContext);
    EntityType otherContextType = EntityType.newBuilder(this.type1).build();
    this.responseTypes = List.of(otherContextType);
    EntityType otherRetrieved = otherGrpcContext.call(() -> this.typeClient.get("first").blockingGet());
    assertSame(otherContextType, otherRetrieved);
    assertNotSame(defaultRetrieved, otherRetrieved);
    verify(this.mockTypeService, times(2)).queryEntityTypes(any(), any());
    verifyNoMoreInteractions(this.mockTypeService);
    assertSame(defaultRetrieved, this.grpcTestContext.call(() -> this.typeClient.get("first").blockingGet()));
    assertSame(otherRetrieved, otherGrpcContext.call(() -> this.typeClient.get("first").blockingGet()));
}
Also used : EntityType(org.hypertrace.entity.type.service.v2.EntityType) RequestContext(org.hypertrace.core.grpcutils.context.RequestContext) Context(io.grpc.Context) RequestContext(org.hypertrace.core.grpcutils.context.RequestContext) Test(org.junit.jupiter.api.Test)

Aggregations

EntityType (org.openstreetmap.osmosis.core.domain.v0_6.EntityType)12 Test (org.junit.Test)9 RelationMember (org.openstreetmap.osmosis.core.domain.v0_6.RelationMember)9 EntityType (com.google.cloud.dialogflow.cx.v3beta1.EntityType)4 ListEntityTypesPagedResponse (com.google.cloud.dialogflow.v2.EntityTypesClient.ListEntityTypesPagedResponse)4 AbstractMessage (com.google.protobuf.AbstractMessage)4 EntityType (org.hypertrace.entity.type.service.v1.EntityType)4 Test (org.junit.jupiter.api.Test)4 EntityType (com.google.cloud.dialogflow.v2.EntityType)3 ServiceException (com.google.protobuf.ServiceException)3 JSONDocument (org.hypertrace.core.documentstore.JSONDocument)3 EntityType (org.hypertrace.entity.type.service.v2.EntityType)3 Relation (org.openstreetmap.osmosis.core.domain.v0_6.Relation)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 Osmformat (crosby.binary.Osmformat)2 IOException (java.io.IOException)2 Document (org.hypertrace.core.documentstore.Document)2 SingleValueKey (org.hypertrace.core.documentstore.SingleValueKey)2 BeforeClass (org.junit.BeforeClass)2 Agent (com.google.cloud.dialogflow.cx.v3beta1.Agent)1