use of org.hypertrace.core.documentstore.Key in project entity-service by hypertrace.
the class EntityDataServiceImpl method upsertRelationships.
@Override
public void upsertRelationships(EntityRelationships request, StreamObserver<Empty> responseObserver) {
String tenantId = RequestContext.CURRENT.get().getTenantId().orElse(null);
if (tenantId == null) {
responseObserver.onError(new ServiceException("Tenant id is missing in the request."));
return;
}
Map<Key, Document> entityRelations = new HashMap<>();
try {
for (EntityRelationship relationship : request.getRelationshipList()) {
if (StringUtils.isEmpty(relationship.getFromEntityId()) || StringUtils.isEmpty(relationship.getToEntityId()) || StringUtils.isEmpty(relationship.getEntityRelationshipType())) {
LOG.warn("Invalid relationship upsert request:{}", relationship);
continue;
}
Document document = convertEntityRelationshipToDocument(tenantId, relationship);
Key key = new EntityRelationshipDocKey(tenantId, relationship.getEntityRelationshipType(), relationship.getFromEntityId(), relationship.getToEntityId());
entityRelations.put(key, document);
}
boolean status = relationshipsCollection.bulkUpsert(entityRelations);
if (status) {
responseObserver.onNext(Empty.newBuilder().build());
responseObserver.onCompleted();
} else {
responseObserver.onError(new RuntimeException("Could not bulk upsert relationships."));
}
} catch (IOException e) {
LOG.error("Failed to bulk upsert relationships.", e);
responseObserver.onError(e);
}
}
use of org.hypertrace.core.documentstore.Key in project entity-service by hypertrace.
the class EntityV2TypeDocKeyTest method usesAllFieldsInGeneratingString.
@Test
void usesAllFieldsInGeneratingString() {
Key key = new EntityV2TypeDocKey("AAA", "BBB", "CCC");
assertEquals("AAA:BBB:CCC", key.toString());
}
Aggregations