Search in sources :

Example 1 with TotalEntitiesRequest

use of org.hypertrace.entity.query.service.v1.TotalEntitiesRequest in project gateway-service by hypertrace.

the class EntityDataServiceEntityFetcher method getTotal.

@Override
public long getTotal(EntitiesRequestContext requestContext, EntitiesRequest entitiesRequest) {
    EntityQueryRequest.Builder builder = EntityQueryRequest.newBuilder().setEntityType(entitiesRequest.getEntityType()).setFilter(EntityServiceAndGatewayServiceConverter.convertToEntityServiceFilter(entitiesRequest.getFilter()));
    // add time filter for supported scope
    EntityServiceAndGatewayServiceConverter.addBetweenTimeFilter(entitiesRequest.getStartTimeMillis(), entitiesRequest.getEndTimeMillis(), attributeMetadataProvider, entitiesRequest, builder, requestContext);
    EntityQueryRequest entityQueryRequest = builder.build();
    TotalEntitiesRequest totalEntitiesRequest = TotalEntitiesRequest.newBuilder().setEntityType(entitiesRequest.getEntityType()).setFilter(entityQueryRequest.getFilter()).build();
    TotalEntitiesResponse response = entityQueryServiceClient.total(totalEntitiesRequest, requestContext.getHeaders());
    return response.getTotal();
}
Also used : TotalEntitiesRequest(org.hypertrace.entity.query.service.v1.TotalEntitiesRequest) EntityQueryRequest(org.hypertrace.entity.query.service.v1.EntityQueryRequest) TotalEntitiesResponse(org.hypertrace.entity.query.service.v1.TotalEntitiesResponse)

Example 2 with TotalEntitiesRequest

use of org.hypertrace.entity.query.service.v1.TotalEntitiesRequest in project entity-service by hypertrace.

the class EntityQueryServiceImpl method total.

@Override
public void total(TotalEntitiesRequest request, StreamObserver<TotalEntitiesResponse> responseObserver) {
    RequestContext requestContext = RequestContext.CURRENT.get();
    Optional<String> tenantId = requestContext.getTenantId();
    if (tenantId.isEmpty()) {
        responseObserver.onError(new ServiceException("Tenant id is missing in the request."));
        return;
    }
    // converting total entities request to entity query request
    EntityQueryRequest entityQueryRequest = EntityQueryRequest.newBuilder().setEntityType(request.getEntityType()).setFilter(request.getFilter()).build();
    // converting entity query request to entity data service query
    Query query = entityQueryConverter.convertToEDSQuery(requestContext, entityQueryRequest);
    // TODO: Replace to use the new org.hypertrace.core.documentstore.query.Query DTO
    long total = entitiesCollection.total(DocStoreConverter.transform(tenantId.get(), query, emptyList()));
    responseObserver.onNext(TotalEntitiesResponse.newBuilder().setTotal(total).build());
    responseObserver.onCompleted();
}
Also used : ServiceException(com.google.protobuf.ServiceException) Query(org.hypertrace.entity.data.service.v1.Query) RequestContext(org.hypertrace.core.grpcutils.context.RequestContext) EntityQueryRequest(org.hypertrace.entity.query.service.v1.EntityQueryRequest)

Aggregations

EntityQueryRequest (org.hypertrace.entity.query.service.v1.EntityQueryRequest)2 ServiceException (com.google.protobuf.ServiceException)1 RequestContext (org.hypertrace.core.grpcutils.context.RequestContext)1 Query (org.hypertrace.entity.data.service.v1.Query)1 TotalEntitiesRequest (org.hypertrace.entity.query.service.v1.TotalEntitiesRequest)1 TotalEntitiesResponse (org.hypertrace.entity.query.service.v1.TotalEntitiesResponse)1