Search in sources :

Example 16 with JSONDocument

use of org.hypertrace.core.documentstore.JSONDocument in project entity-service by hypertrace.

the class DocumentConverterTest method testConvert.

@Test
void testConvert() throws IOException, ConversionException {
    final String json = new String(getClass().getClassLoader().getResourceAsStream("response/nested_document.json").readAllBytes());
    final Document document = new JSONDocument(json);
    final ResultSetMetadata resultSetMetadata = ResultSetMetadata.newBuilder().addColumnMetadata(ColumnMetadata.newBuilder().setColumnName("tenantId")).addColumnMetadata(ColumnMetadata.newBuilder().setColumnName("entityId")).addColumnMetadata(ColumnMetadata.newBuilder().setColumnName("Entity.status")).addColumnMetadata(ColumnMetadata.newBuilder().setColumnName("attributes.something")).addColumnMetadata(ColumnMetadata.newBuilder().setColumnName("attributes.updated_time")).addColumnMetadata(ColumnMetadata.newBuilder().setColumnName("attributes.address_map")).addColumnMetadata(ColumnMetadata.newBuilder().setColumnName("attributes.valueMap")).addColumnMetadata(ColumnMetadata.newBuilder().setColumnName("attributes.nonExisting")).addColumnMetadata(ColumnMetadata.newBuilder().setColumnName("attributes.valueList")).addColumnMetadata(ColumnMetadata.newBuilder().setColumnName("attributes.emptyMap")).addColumnMetadata(ColumnMetadata.newBuilder().setColumnName("attributes.emptyMapNested")).addColumnMetadata(ColumnMetadata.newBuilder().setColumnName("attributes.emptyList")).addColumnMetadata(ColumnMetadata.newBuilder().setColumnName("attributes.emptyListNested")).build();
    final Row expectedRow = Row.newBuilder().addColumn(Value.newBuilder().setValueType(STRING).setString("tenant-1")).addColumn(Value.newBuilder().setValueType(STRING).setString("0215f3f6-55eb-4d95-a116-60f2962528ef")).addColumn(Value.newBuilder().setValueType(STRING).setString("Red Shift")).addColumn(Value.newBuilder().setValueType(BOOL).setBoolean(true)).addColumn(Value.newBuilder().setValueType(LONG_ARRAY).addAllLongArray(List.of(1643702835L, 1643702900L))).addColumn(Value.newBuilder().setValueType(STRING_MAP).putAllStringMap(Map.of("galaxy", "Milky Way", "planet", "Mars"))).addColumn(Value.newBuilder().setValueType(STRING).setString("The Future is Red!")).addColumn(Value.getDefaultInstance()).addColumn(Value.newBuilder().setValueType(INT_ARRAY).addAllIntArray(List.of(2016, 2037, 2122))).addColumn(Value.newBuilder().setValueType(STRING_MAP).build()).addColumn(Value.newBuilder().setValueType(STRING_MAP).build()).addColumn(Value.newBuilder().setValueType(STRING_ARRAY).build()).addColumn(Value.newBuilder().setValueType(STRING_ARRAY).build()).build();
    final Row actualRow = documentConverter.convertToRow(document, resultSetMetadata);
    assertEquals(expectedRow, actualRow);
}
Also used : ResultSetMetadata(org.hypertrace.entity.query.service.v1.ResultSetMetadata) JSONDocument(org.hypertrace.core.documentstore.JSONDocument) Row(org.hypertrace.entity.query.service.v1.Row) Document(org.hypertrace.core.documentstore.Document) JSONDocument(org.hypertrace.core.documentstore.JSONDocument) Test(org.junit.jupiter.api.Test)

Example 17 with JSONDocument

use of org.hypertrace.core.documentstore.JSONDocument in project entity-service by hypertrace.

the class EntityTypeServiceImpl method upsertEntityType.

@Override
public void upsertEntityType(EntityType request, StreamObserver<EntityType> responseObserver) {
    Optional<String> tenantId = RequestContext.CURRENT.get().getTenantId();
    if (tenantId.isEmpty()) {
        responseObserver.onError(new ServiceException("Tenant id is missing in the request."));
        return;
    }
    try {
        // TODO: Since we currently use the same object that's received in the request while
        // persisting in the doc store, we need to add tenantId explicitly here.
        // We need to split these objects later.
        EntityType newRequest = EntityType.newBuilder(request).setTenantId(tenantId.get()).build();
        entityTypeCol.upsert(new SingleValueKey(tenantId.get(), request.getName()), new JSONDocument(PROTO_PRINTER.print(newRequest)));
        responseObserver.onNext(newRequest);
        responseObserver.onCompleted();
    } catch (IOException ioe) {
        responseObserver.onError(new RuntimeException("Error upserting EntityType:" + request, ioe));
    }
}
Also used : EntityType(org.hypertrace.entity.type.service.v1.EntityType) SingleValueKey(org.hypertrace.core.documentstore.SingleValueKey) ServiceException(com.google.protobuf.ServiceException) JSONDocument(org.hypertrace.core.documentstore.JSONDocument) IOException(java.io.IOException)

Aggregations

JSONDocument (org.hypertrace.core.documentstore.JSONDocument)17 Document (org.hypertrace.core.documentstore.Document)10 Test (org.junit.jupiter.api.Test)10 SingleValueKey (org.hypertrace.core.documentstore.SingleValueKey)9 Collection (org.hypertrace.core.documentstore.Collection)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 MongoCollection (com.mongodb.client.MongoCollection)4 Query (org.hypertrace.core.documentstore.Query)4 ResultSetChunk (org.hypertrace.entity.query.service.v1.ResultSetChunk)4 ServiceException (com.google.protobuf.ServiceException)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Entity (org.hypertrace.entity.data.service.v1.Entity)3 EntityQueryRequest (org.hypertrace.entity.query.service.v1.EntityQueryRequest)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 BulkUpdateRequest (org.hypertrace.core.documentstore.BulkUpdateRequest)2 BulkUpdateResult (org.hypertrace.core.documentstore.BulkUpdateResult)2 Filter (org.hypertrace.core.documentstore.Filter)2