Search in sources :

Example 21 with FieldTransformer

use of org.apache.metron.common.configuration.FieldTransformer in project metron by apache.

the class ParserConfigFunctions method pruneEmptyStellarTransformers.

private static void pruneEmptyStellarTransformers(SensorParserConfig config) {
    List<FieldTransformer> toRemove = new ArrayList<>();
    List<FieldTransformer> fieldTransformations = config.getFieldTransformations();
    for (FieldTransformer transformer : fieldTransformations) {
        if (transformer.getFieldTransformation().getClass().getName().equals(FieldTransformations.STELLAR.getMappingClass().getName()) && transformer.getConfig().isEmpty()) {
            toRemove.add(transformer);
        }
    }
    for (FieldTransformer t : toRemove) {
        fieldTransformations.remove(t);
    }
}
Also used : FieldTransformer(org.apache.metron.common.configuration.FieldTransformer) ArrayList(java.util.ArrayList)

Example 22 with FieldTransformer

use of org.apache.metron.common.configuration.FieldTransformer in project metron by apache.

the class StellarServiceImplTest method applyTransformationsShouldProperlyTransformData.

@Test
public void applyTransformationsShouldProperlyTransformData() {
    SensorParserConfig sensorParserConfig = new SensorParserConfig();
    FieldTransformer fieldTransformater = new FieldTransformer();
    fieldTransformater.setOutput("url_host");
    fieldTransformater.setTransformation("STELLAR");
    fieldTransformater.setConfig(new LinkedHashMap<String, Object>() {

        {
            put("url_host", "TO_LOWER(URL_TO_HOST(url))");
        }
    });
    sensorParserConfig.setFieldTransformations(ImmutableList.of(fieldTransformater));
    SensorParserContext sensorParserContext = new SensorParserContext();
    sensorParserContext.setSensorParserConfig(sensorParserConfig);
    sensorParserContext.setSampleData(new HashMap<String, Object>() {

        {
            put("url", "https://caseystella.com/blog");
        }
    });
    Map<String, Object> results = stellarService.applyTransformations(sensorParserContext);
    assertEquals(2, results.size());
    assertEquals("https://caseystella.com/blog", results.get("url"));
    assertEquals("caseystella.com", results.get("url_host"));
}
Also used : SensorParserContext(org.apache.metron.rest.model.SensorParserContext) FieldTransformer(org.apache.metron.common.configuration.FieldTransformer) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) Test(org.junit.jupiter.api.Test)

Aggregations

FieldTransformer (org.apache.metron.common.configuration.FieldTransformer)22 SensorParserConfig (org.apache.metron.common.configuration.SensorParserConfig)20 JSONObject (org.json.simple.JSONObject)19 Test (org.junit.jupiter.api.Test)18 HashMap (java.util.HashMap)2 ArrayList (java.util.ArrayList)1 SensorParserContext (org.apache.metron.rest.model.SensorParserContext)1