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