Search in sources :

Example 1 with ByIdRequest

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."));
    }
}
Also used : EnrichedEntity(org.hypertrace.entity.data.service.v1.EnrichedEntity) Entity(org.hypertrace.entity.data.service.v1.Entity) ServiceException(com.google.protobuf.ServiceException) Key(org.hypertrace.core.documentstore.Key)

Example 2 with ByIdRequest

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;
}
Also used : ByIdRequest(org.hypertrace.entity.data.service.v1.ByIdRequest) EnrichedEntity(org.hypertrace.entity.data.service.v1.EnrichedEntity) Nullable(javax.annotation.Nullable)

Aggregations

EnrichedEntity (org.hypertrace.entity.data.service.v1.EnrichedEntity)2 ServiceException (com.google.protobuf.ServiceException)1 Nullable (javax.annotation.Nullable)1 Key (org.hypertrace.core.documentstore.Key)1 ByIdRequest (org.hypertrace.entity.data.service.v1.ByIdRequest)1 Entity (org.hypertrace.entity.data.service.v1.Entity)1