use of org.hypertrace.entity.data.service.v1.ByIdRequest in project entity-service by hypertrace.
the class EntityDataServiceImpl method delete.
/**
* Deletes an Entity by the EntityId and EntityType
*
* @param request ID of the entity to be deleted
* @param responseObserver Observer to be notified on about the Entity delete request
*/
@Override
public void delete(ByIdRequest request, StreamObserver<Empty> responseObserver) {
if (StringUtils.isEmpty(request.getEntityId())) {
LOG.info("{}. Invalid delete request:{}", request, ErrorMessages.ENTITY_ID_EMPTY);
responseObserver.onError(new RuntimeException(ErrorMessages.ENTITY_ID_EMPTY));
return;
}
Optional<String> tenantId = RequestContext.CURRENT.get().getTenantId();
if (tenantId.isEmpty()) {
responseObserver.onError(new ServiceException("Tenant id is missing in the request."));
return;
}
Optional<Entity> existingEntity = getExistingEntity(tenantId.get(), request.getEntityType(), request.getEntityId());
Key key = this.entityNormalizer.getEntityDocKey(tenantId.get(), request.getEntityType(), request.getEntityId());
if (entitiesCollection.delete(key)) {
responseObserver.onNext(Empty.newBuilder().build());
responseObserver.onCompleted();
existingEntity.ifPresent(entity -> entityChangeEventGenerator.sendDeleteNotification(RequestContext.CURRENT.get(), List.of(entity)));
} else {
responseObserver.onError(new RuntimeException("Could not delete the entity."));
}
}
use of org.hypertrace.entity.data.service.v1.ByIdRequest in project entity-service by hypertrace.
the class EntityDataServiceClient method getEnrichedEntityById.
@Nullable
@Override
public EnrichedEntity getEnrichedEntityById(String tenantId, String entityId) {
ByIdRequest byIdRequest = ByIdRequest.newBuilder().setEntityId(entityId).build();
EnrichedEntity entity = execute(tenantId, () -> blockingStub.getEnrichedEntityById(byIdRequest));
// Handle this here, so that callers can just do a null check
return entity.equals(EnrichedEntity.getDefaultInstance()) ? null : entity;
}
Aggregations