Search in sources :

Example 26 with AttributeValue

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));
    }
}
Also used : AttributeValue(org.hypertrace.entity.data.service.v1.AttributeValue) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) JsonNode(com.fasterxml.jackson.databind.JsonNode) Map(java.util.Map) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TypeCase(org.hypertrace.entity.data.service.v1.AttributeValue.TypeCase)

Example 27 with 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;
    }
}
Also used : AttributeValue(org.hypertrace.entity.data.service.v1.AttributeValue) AttributeValue(org.hypertrace.entity.data.service.v1.AttributeValue) Value(org.hypertrace.entity.data.service.v1.Value) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 28 with AttributeValue

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;
}
Also used : Filter(org.hypertrace.core.documentstore.Filter) AttributeFilter(org.hypertrace.entity.data.service.v1.AttributeFilter)

Example 29 with AttributeValue

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);
}
Also used : AttributeValue(org.hypertrace.entity.data.service.v1.AttributeValue) JSONDocument(org.hypertrace.core.documentstore.JSONDocument) SneakyThrows(lombok.SneakyThrows)

Example 30 with AttributeValue

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");
}
Also used : AttributeValue(org.hypertrace.entity.data.service.v1.AttributeValue) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) EnrichedEntity(org.hypertrace.entity.data.service.v1.EnrichedEntity) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)39 Entity (org.hypertrace.entity.data.service.v1.Entity)37 AttributeValue (org.hypertrace.entity.data.service.v1.AttributeValue)24 AttributeValue (org.hypertrace.core.datamodel.AttributeValue)22 BackendInfo (org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo)20 Event (org.hypertrace.core.datamodel.Event)12 EnrichedEntity (org.hypertrace.entity.data.service.v1.EnrichedEntity)11 AttributeValue (com.google.devtools.cloudtrace.v2.AttributeValue)10 Test (org.junit.Test)10 HashMap (java.util.HashMap)9 ByTypeAndIdentifyingAttributes (org.hypertrace.entity.data.service.v1.ByTypeAndIdentifyingAttributes)9 TestUtil.buildAttributeValue (org.hypertrace.traceenricher.TestUtil.buildAttributeValue)7 Span (zipkin2.Span)7 AttributesExtractor.toAttributeValue (zipkin2.translation.stackdriver.AttributesExtractor.toAttributeValue)7 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Map (java.util.Map)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Span (com.google.devtools.cloudtrace.v2.Span)3 TruncatableString (com.google.devtools.cloudtrace.v2.TruncatableString)3