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());
}
Aggregations