use of org.hypertrace.entity.type.service.v2.EntityType in project java-dialogflow-cx by googleapis.
the class ITSystemTest method listEntityTypesTest.
@Test
public void listEntityTypesTest() {
ListEntityTypesRequest request = ListEntityTypesRequest.newBuilder().setParent(agentName).build();
Iterable<EntityType> entityTypes = entityTypesClient.listEntityTypes(request).iterateAll();
boolean isEntityTypeExists = false;
for (EntityType entityType : entityTypes) {
if (entityTypesName.equals(entityType.getName())) {
assertEntityTypesDetails(entityType);
isEntityTypeExists = true;
}
}
assertTrue(isEntityTypeExists);
}
use of org.hypertrace.entity.type.service.v2.EntityType in project java-dialogflow-cx by googleapis.
the class ITSystemTest method updateEntityTypeTest.
@Test
public void updateEntityTypeTest() {
EntityType entityType = EntityType.newBuilder().setName(entityTypesName).setKind(EntityType.Kind.KIND_LIST).setDisplayName(DISPLAY_NAME).setKindValue(2).build();
UpdateEntityTypeRequest updateEntityTypeRequest = UpdateEntityTypeRequest.newBuilder().setEntityType(entityType).build();
EntityType response = entityTypesClient.updateEntityType(updateEntityTypeRequest);
assertEquals(2, response.getKindValue());
}
use of org.hypertrace.entity.type.service.v2.EntityType in project entity-service by hypertrace.
the class EntityTypeServiceTest method testUpsertAndQueryEntityType.
@Test
public void testUpsertAndQueryEntityType() {
EntityType entityType1 = EntityType.newBuilder().setName("EntityType1").setTenantId(TENANT_ID).addAttributeType(AttributeType.newBuilder().setName("attr1").setIdentifyingAttribute(true).setValueKind(AttributeKind.TYPE_STRING).build()).addAttributeType(AttributeType.newBuilder().setName("someattr").setValueKind(AttributeKind.TYPE_STRING).build()).build();
EntityType entityType2 = EntityType.newBuilder().setName("EntityType2").setTenantId(TENANT_ID).addAttributeType(AttributeType.newBuilder().setName("attr2").setIdentifyingAttribute(true).setValueKind(AttributeKind.TYPE_INT64).build()).build();
client.upsertEntityType(TENANT_ID, entityType1);
client.upsertEntityType(TENANT_ID, entityType2);
List<EntityType> entityTypes = client.getAllEntityTypes(TENANT_ID);
Assertions.assertEquals(2, entityTypes.size());
Assertions.assertTrue(entityTypes.containsAll(List.of(entityType1, entityType2)));
entityTypes = client.queryEntityTypes(TENANT_ID, EntityTypeFilter.newBuilder().addName(entityType1.getName()).build());
Assertions.assertEquals(1, entityTypes.size());
Assertions.assertTrue(entityTypes.contains(entityType1));
}
use of org.hypertrace.entity.type.service.v2.EntityType in project entity-service by hypertrace.
the class EntityTypeServiceImpl method queryEntityTypes.
@Override
public void queryEntityTypes(EntityTypeFilter 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;
}
Iterator<Document> entityTypes = entityTypeCol.search(transform(tenantId.get(), request, true));
while (entityTypes.hasNext()) {
Document entityType = entityTypes.next();
EntityType.Builder builder = EntityType.newBuilder();
try {
PARSER.merge(entityType.toJson(), builder);
// Populate the tenant id field with the tenant id that's received for backward
// compatibility.
builder.setTenantId(tenantId.get());
} catch (InvalidProtocolBufferException e) {
LOG.error("Error processing entityType: {}", entityType.toJson(), e);
responseObserver.onError(e);
return;
}
responseObserver.onNext(builder.build());
}
responseObserver.onCompleted();
}
use of org.hypertrace.entity.type.service.v2.EntityType in project entity-service by hypertrace.
the class EntityTypeServiceImpl method queryEntityTypes.
@Override
public void queryEntityTypes(org.hypertrace.entity.type.service.v2.QueryEntityTypesRequest request, io.grpc.stub.StreamObserver<org.hypertrace.entity.type.service.v2.QueryEntityTypesResponse> responseObserver) {
Optional<String> tenantId = RequestContext.CURRENT.get().getTenantId();
if (tenantId.isEmpty()) {
responseObserver.onError(new ServiceException("Tenant id is missing in the request."));
return;
}
Iterator<Document> entityTypes = entityTypeCollection.search(transform(tenantId.get(), request.getNameList()));
List<EntityType> entityTypeList = new ArrayList<>();
while (entityTypes.hasNext()) {
String json = entityTypes.next().toJson();
try {
entityTypeList.add(EntityTypeDocument.fromJson(json).toProto());
} catch (JsonProcessingException e) {
LOGGER.warn("Failed to parse the EntityType json: {}", json, e);
responseObserver.onError(new RuntimeException("Error querying the entity types."));
return;
}
}
responseObserver.onNext(QueryEntityTypesResponse.newBuilder().addAllEntityType(entityTypeList).build());
responseObserver.onCompleted();
}
Aggregations