com.bazaarvoice.jolt.Shiftr Java Examples

The following examples show how to use com.bazaarvoice.jolt.Shiftr. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransformFactory.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
public static JoltTransform getTransform(final ClassLoader classLoader,final String transformType, final Object specJson) throws Exception {

        if (transformType.equals("jolt-transform-default")) {
            return new Defaultr(specJson);
        } else if (transformType.equals("jolt-transform-shift")) {
            return new Shiftr(specJson);
        } else if (transformType.equals("jolt-transform-remove")) {
            return new Removr(specJson);
        } else if (transformType.equals("jolt-transform-card")) {
            return new CardinalityTransform(specJson);
        } else if(transformType.equals("jolt-transform-sort")){
            return new Sortr();
        } else if(transformType.equals("jolt-transform-modify-default")){
          return new Modifier.Defaultr(specJson);
        } else if(transformType.equals("jolt-transform-modify-overwrite")){
            return new Modifier.Overwritr(specJson);
        } else if(transformType.equals("jolt-transform-modify-define")){
            return new Modifier.Definr(specJson);
        } else{
            return new Chainr(getChainrJoltTransformations(classLoader,specJson));
        }

    }
 
Example #2
Source File: KafkaPlugin.java    From hawkular-alerts with Apache License 2.0 6 votes vote down vote up
protected String transform(Action a) {
    String spec = a.getProperties().get(PROP_TRANSFORM);
    if (spec == null || spec.isEmpty()) {
        return JsonUtil.toJson(a.getEvent());
    }
    try {
        Shiftr transformer = new Shiftr(JsonUtil.fromJson(spec, Map.class));
        Map<String, Object> eventMap = JsonUtil.getMap(a.getEvent());
        String timestampPattern = a.getProperties().get(PROP_TIMESTAMP_PATTERN);
        if (!isEmpty(timestampPattern)) {
            transformTimestamp(timestampPattern, eventMap);
        }
        return JsonUtil.toJson(transformer.transform(eventMap));
    } catch (Exception e) {
        log.warnf("Plugin kafka can not apply spec [%s]", spec);
        return JsonUtil.toJson(a.getEvent());
    }
}
 
Example #3
Source File: ElasticsearchPlugin.java    From hawkular-alerts with Apache License 2.0 6 votes vote down vote up
protected String transform(Action a) {
    String spec = a.getProperties().get(PROP_TRANSFORM);
    if (spec == null || spec.isEmpty()) {
        return JsonUtil.toJson(a.getEvent());
    }
    try {
        Shiftr transformer = new Shiftr(JsonUtil.fromJson(spec, Map.class));
        Map<String, Object> eventMap = JsonUtil.getMap(a.getEvent());
        String timestampPattern = a.getProperties().get(PROP_TIMESTAMP_PATTERN);
        if (!isEmpty(timestampPattern)) {
            transformTimestamp(timestampPattern, eventMap);
        }
        return JsonUtil.toJson(transformer.transform(eventMap));
    } catch (Exception e) {
        log.warnf("Plugin elasticsearch can not apply spec [%s]", spec);
        return JsonUtil.toJson(a.getEvent());
    }
}
 
Example #4
Source File: TransformFactory.java    From nifi with Apache License 2.0 6 votes vote down vote up
public static JoltTransform getTransform(final ClassLoader classLoader,final String transformType, final Object specJson) throws Exception {

        if (transformType.equals("jolt-transform-default")) {
            return new Defaultr(specJson);
        } else if (transformType.equals("jolt-transform-shift")) {
            return new Shiftr(specJson);
        } else if (transformType.equals("jolt-transform-remove")) {
            return new Removr(specJson);
        } else if (transformType.equals("jolt-transform-card")) {
            return new CardinalityTransform(specJson);
        } else if(transformType.equals("jolt-transform-sort")){
            return new Sortr();
        } else if(transformType.equals("jolt-transform-modify-default")){
          return new Modifier.Defaultr(specJson);
        } else if(transformType.equals("jolt-transform-modify-overwrite")){
            return new Modifier.Overwritr(specJson);
        } else if(transformType.equals("jolt-transform-modify-define")){
            return new Modifier.Definr(specJson);
        } else{
            return new Chainr(getChainrJoltTransformations(classLoader,specJson));
        }

    }
 
Example #5
Source File: TransformFactory.java    From nifi with Apache License 2.0 6 votes vote down vote up
public static JoltTransform getTransform(final ClassLoader classLoader,final String transformType, final Object specJson) throws Exception {

        if (transformType.equals("jolt-transform-default")) {
            return new Defaultr(specJson);
        } else if (transformType.equals("jolt-transform-shift")) {
            return new Shiftr(specJson);
        } else if (transformType.equals("jolt-transform-remove")) {
            return new Removr(specJson);
        } else if (transformType.equals("jolt-transform-card")) {
            return new CardinalityTransform(specJson);
        } else if(transformType.equals("jolt-transform-sort")){
            return new Sortr();
        } else if(transformType.equals("jolt-transform-modify-default")){
          return new Modifier.Defaultr(specJson);
        } else if(transformType.equals("jolt-transform-modify-overwrite")){
            return new Modifier.Overwritr(specJson);
        } else if(transformType.equals("jolt-transform-modify-define")){
            return new Modifier.Definr(specJson);
        } else{
            return new Chainr(getChainrJoltTransformations(classLoader,specJson));
        }

    }
 
Example #6
Source File: ShiftrUnitTest.java    From jolt with Apache License 2.0 5 votes vote down vote up
@Test(dataProvider = "shiftrTestCases")
public void shiftrUnitTest(String testName, Map<String, Object> spec, Map<String, Object> data, Map<String, Object> expected) throws Exception {

    Shiftr shiftr = new Shiftr( spec );
    Object actual = shiftr.transform( data );

    JoltTestUtil.runDiffy( testName, expected, actual );
}
 
Example #7
Source File: TestTransformFactory.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetShiftTransform() throws Exception{
    final String shiftrSpec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformFactory/shiftrSpec.json")));
    JoltTransform transform = TransformFactory.getTransform(getClass().getClassLoader(), "jolt-transform-shift",JsonUtils.jsonToObject(shiftrSpec));
    assertTrue(transform instanceof Shiftr);
}
 
Example #8
Source File: TestTransformFactory.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetShiftTransform() throws Exception {
    final String shiftrSpec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformFactory/shiftrSpec.json")));
    JoltTransform transform = TransformFactory.getTransform(getClass().getClassLoader(), "jolt-transform-shift", JsonUtils.jsonToObject(shiftrSpec));
    assertTrue(transform instanceof Shiftr);
}
 
Example #9
Source File: TestTransformFactory.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetShiftTransform() throws Exception{
    final String shiftrSpec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformFactory/shiftrSpec.json")));
    JoltTransform transform = TransformFactory.getTransform(getClass().getClassLoader(), "jolt-transform-shift",JsonUtils.jsonToObject(shiftrSpec));
    assertTrue(transform instanceof Shiftr);
}
 
Example #10
Source File: ShiftrUnitTest.java    From jolt with Apache License 2.0 4 votes vote down vote up
@Test(dataProvider = "badSpecs", expectedExceptions = SpecException.class)
public void failureUnitTest(String testName, Object spec) {
    new Shiftr( spec );
}