use of org.hypertrace.entity.data.service.v1.AttributeValue in project entity-service by hypertrace.
the class DocStoreConverter method prepareRhsValueForSpecialValueListCase.
private static Object prepareRhsValueForSpecialValueListCase(AttributeValue attributeValue) {
org.hypertrace.entity.data.service.v1.AttributeValue.TypeCase typeCase = attributeValue.getTypeCase();
if (typeCase == TypeCase.VALUE) {
try {
JsonNode mapNode = OBJECT_MAPPER.readTree(JSONFORMAT_PRINTER.print(attributeValue));
Map map = OBJECT_MAPPER.convertValue(mapNode, Map.class);
return map;
} catch (JsonProcessingException | InvalidProtocolBufferException e) {
throw new RuntimeException(e);
}
} else {
// For now, just expecting VALUE type on the RHS
throw new UnsupportedOperationException(String.format("The RHS of filter for string array types can only be VALUE: %s", attributeValue));
}
}
use of org.hypertrace.entity.data.service.v1.AttributeValue in project entity-service by hypertrace.
the class DocStoreConverter method transform.
private static void transform(AttributeValue attributeValue, Filter filter, boolean isAttributeField) throws IOException {
switch(attributeValue.getTypeCase()) {
case VALUE:
{
Value value = attributeValue.getValue();
String fieldName = filter.getFieldName();
if (isAttributeField) {
fieldName = filter.getFieldName() + "." + "value" + "." + value.getTypeCase().name().toLowerCase();
}
filter.setFieldName(fieldName);
filter.setValue(getValue(value));
}
break;
case VALUE_LIST:
{
filter.setFieldName(createFieldNameForValueList(attributeValue, filter, isAttributeField));
if (filter.getOp().equals(Op.CONTAINS)) {
JsonNode mapNode = OBJECT_MAPPER.readTree(JSONFORMAT_PRINTER.print(attributeValue.getValue()));
Map map = OBJECT_MAPPER.convertValue(mapNode, Map.class);
filter.setValue(map);
} else if (filter.getOp().equals(Filter.Op.EQ)) {
List<Object> listNodes = new ArrayList<>();
for (AttributeValue v : attributeValue.getValueList().getValuesList()) {
listNodes.add(OBJECT_MAPPER.convertValue(OBJECT_MAPPER.readTree(JSONFORMAT_PRINTER.print(v)), Map.class));
}
filter.setValue(listNodes);
} else if (filter.getOp().equals(Op.IN)) {
List<Object> listNodes = new ArrayList<>();
for (AttributeValue v : attributeValue.getValueList().getValuesList()) {
listNodes.add(getValue(v.getValue()));
}
filter.setValue(listNodes);
} else {
throw new UnsupportedOperationException("Only CONTAINS, EQ and IN conditions supported for attribute values of type list");
}
}
break;
case VALUE_MAP:
{
if (filter.getOp().equals(Filter.Op.EQ)) {
String fieldName = filter.getFieldName();
if (isAttributeField) {
fieldName = filter.getFieldName() + "." + "valueMap";
}
filter.setFieldName(fieldName);
JsonNode mapNode = OBJECT_MAPPER.readTree(JSONFORMAT_PRINTER.print(attributeValue.getValueMap()));
Map map = OBJECT_MAPPER.convertValue(mapNode, Map.class);
filter.setValue(map);
} else {
throw new UnsupportedOperationException("Only EQ condition supported for attribute values of type map");
}
}
break;
}
}
use of org.hypertrace.entity.data.service.v1.AttributeValue in project entity-service by hypertrace.
the class DocStoreConverter method createNeqFilterForAttributeValue.
private static Filter createNeqFilterForAttributeValue(String fieldName, AttributeValue attributeValue) {
Filter f = new Filter();
f.setFieldName(fieldName);
f.setOp(Op.NEQ);
f.setValue(prepareRhsValueForSpecialValueListCase(attributeValue));
// Set child filters to empty array
f.setChildFilters(new Filter[] {});
return f;
}
use of org.hypertrace.entity.data.service.v1.AttributeValue in project entity-service by hypertrace.
the class EntityQueryServiceImpl method convertToJsonDocument.
@SneakyThrows
private JSONDocument convertToJsonDocument(LiteralConstant literalConstant) {
// Convert setAttribute LiteralConstant to AttributeValue. Need to be able to store an array
// literal constant as an array
AttributeValue attributeValue = EntityQueryConverter.convertToAttributeValue(literalConstant).build();
String jsonValue = PRINTER.print(attributeValue);
return new JSONDocument(jsonValue);
}
use of org.hypertrace.entity.data.service.v1.AttributeValue in project entity-service by hypertrace.
the class EdsCacheClientTest method testGetEnrichedEntityById.
@Test
public void testGetEnrichedEntityById() {
String tenantId = "tenant";
String enrichedEntityId = "enriched-12345";
Map<String, AttributeValue> identifyingAttributesMap = new HashMap<>();
identifyingAttributesMap.put("entity_name", AttributeValue.newBuilder().setValue(Value.newBuilder().setString("GET /products").build()).build());
identifyingAttributesMap.put("is_active", AttributeValue.newBuilder().setValue(Value.newBuilder().setBoolean(true).build()).build());
EnrichedEntity enrichedEntity = EnrichedEntity.newBuilder().setEntityId(enrichedEntityId).setEntityType("API").setEntityName("GET /products").putAllIdentifyingAttributes(identifyingAttributesMap).build();
when(entityDataServiceClient.getEnrichedEntityById(anyString(), anyString())).thenReturn(enrichedEntity);
edsCacheClient.getEnrichedEntityById(tenantId, enrichedEntityId);
edsCacheClient.getEnrichedEntityById(tenantId, enrichedEntityId);
verify(entityDataServiceClient, times(1)).getEnrichedEntityById("tenant", "enriched-12345");
}
Aggregations