Search in sources :

Example 1 with RelationshipsQuery

use of org.hypertrace.entity.data.service.v1.RelationshipsQuery in project entity-service by hypertrace.

the class EntityDataServiceImpl method getRelationships.

@Override
public void getRelationships(RelationshipsQuery query, StreamObserver<EntityRelationship> responseObserver) {
    logQuery(query);
    Optional<String> tenantId = RequestContext.CURRENT.get().getTenantId();
    if (tenantId.isEmpty()) {
        responseObserver.onError(new ServiceException("Tenant id is missing in the request."));
        return;
    }
    org.hypertrace.core.documentstore.Query docStoreQuery = new org.hypertrace.core.documentstore.Query();
    List<Filter> filters = new ArrayList<>();
    filters.add(DocStoreConverter.getTenantIdEqFilter(tenantId.get()));
    if (query.getEntityRelationshipCount() > 0) {
        filters.add(new Filter(Filter.Op.IN, EntityServiceConstants.ENTITY_RELATIONSHIP_TYPE, query.getEntityRelationshipList()));
    }
    if (query.getFromEntityIdCount() > 0) {
        filters.add(new Filter(Filter.Op.IN, EntityServiceConstants.FROM_ENTITY_ID, query.getFromEntityIdList()));
    }
    if (query.getToEntityIdCount() > 0) {
        filters.add(new Filter(Filter.Op.IN, EntityServiceConstants.TO_ENTITY_ID, query.getToEntityIdList()));
    }
    if (!filters.isEmpty()) {
        if (filters.size() == 1) {
            docStoreQuery.setFilter(filters.get(0));
        } else {
            Filter f = new Filter();
            f.setOp(Filter.Op.AND);
            f.setChildFilters(filters.toArray(new Filter[] {}));
            docStoreQuery.setFilter(f);
        }
    }
    searchByQueryAndStreamRelationships(docStoreQuery, responseObserver, tenantId.get());
}
Also used : ServiceException(com.google.protobuf.ServiceException) Query(org.hypertrace.entity.data.service.v1.Query) RelationshipsQuery(org.hypertrace.entity.data.service.v1.RelationshipsQuery) Filter(org.hypertrace.core.documentstore.Filter) ArrayList(java.util.ArrayList)

Aggregations

ServiceException (com.google.protobuf.ServiceException)1 ArrayList (java.util.ArrayList)1 Filter (org.hypertrace.core.documentstore.Filter)1 Query (org.hypertrace.entity.data.service.v1.Query)1 RelationshipsQuery (org.hypertrace.entity.data.service.v1.RelationshipsQuery)1