Search in sources :

Example 11 with JoltTransform

use of com.bazaarvoice.jolt.JoltTransform in project nifi by apache.

the class TestTransformFactory method testGetModifierOverwriteTransform.

@Test
public void testGetModifierOverwriteTransform() throws Exception {
    final String cardrSpec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformFactory/modifierOverwriteSpec.json")));
    JoltTransform transform = TransformFactory.getTransform(getClass().getClassLoader(), "jolt-transform-modify-overwrite", JsonUtils.jsonToObject(cardrSpec));
    assertTrue(transform instanceof Modifier.Overwritr);
}
Also used : JoltTransform(com.bazaarvoice.jolt.JoltTransform) Modifier(com.bazaarvoice.jolt.Modifier) Test(org.junit.Test)

Example 12 with JoltTransform

use of com.bazaarvoice.jolt.JoltTransform in project nifi by apache.

the class JoltTransformJSON method getTransform.

private JoltTransform getTransform(final ProcessContext context, final FlowFile flowFile) throws Exception {
    final String specString;
    if (context.getProperty(JOLT_SPEC).isSet() && !StringUtils.isEmpty(context.getProperty(JOLT_SPEC).getValue())) {
        specString = context.getProperty(JOLT_SPEC).evaluateAttributeExpressions(flowFile).getValue();
    } else {
        specString = null;
    }
    // Get the transform from our cache, if it exists.
    JoltTransform transform = null;
    synchronized (this) {
        transform = transformCache.get(specString);
    }
    if (transform != null) {
        return transform;
    }
    // If no transform for our spec, create the transform.
    final Object specJson;
    if (context.getProperty(JOLT_SPEC).isSet() && !SORTR.getValue().equals(context.getProperty(JOLT_TRANSFORM).getValue())) {
        specJson = JsonUtils.jsonToObject(specString, DEFAULT_CHARSET);
    } else {
        specJson = null;
    }
    if (CUSTOMR.getValue().equals(context.getProperty(JOLT_TRANSFORM).getValue())) {
        transform = TransformFactory.getCustomTransform(customClassLoader, context.getProperty(CUSTOM_CLASS).getValue(), specJson);
    } else {
        transform = TransformFactory.getTransform(customClassLoader, context.getProperty(JOLT_TRANSFORM).getValue(), specJson);
    }
    // value from the cache.
    synchronized (this) {
        final JoltTransform existingTransform = transformCache.get(specString);
        if (existingTransform == null) {
            transformCache.put(specString, transform);
        } else {
            transform = existingTransform;
        }
    }
    return transform;
}
Also used : JoltTransform(com.bazaarvoice.jolt.JoltTransform)

Example 13 with JoltTransform

use of com.bazaarvoice.jolt.JoltTransform in project nifi by apache.

the class TestTransformFactory method testGetShiftTransform.

@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);
}
Also used : JoltTransform(com.bazaarvoice.jolt.JoltTransform) Shiftr(com.bazaarvoice.jolt.Shiftr) Test(org.junit.Test)

Example 14 with JoltTransform

use of com.bazaarvoice.jolt.JoltTransform in project nifi by apache.

the class TestTransformFactory method testGetRemoveTransform.

@Test
public void testGetRemoveTransform() throws Exception {
    final String removrSpec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformFactory/removrSpec.json")));
    JoltTransform transform = TransformFactory.getTransform(getClass().getClassLoader(), "jolt-transform-remove", JsonUtils.jsonToObject(removrSpec));
    assertTrue(transform instanceof Removr);
}
Also used : JoltTransform(com.bazaarvoice.jolt.JoltTransform) Removr(com.bazaarvoice.jolt.Removr) Test(org.junit.Test)

Example 15 with JoltTransform

use of com.bazaarvoice.jolt.JoltTransform in project nifi by apache.

the class TestTransformFactory method testGetModifierDefineTransform.

@Test
public void testGetModifierDefineTransform() throws Exception {
    final String cardrSpec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformFactory/modifierDefineSpec.json")));
    JoltTransform transform = TransformFactory.getTransform(getClass().getClassLoader(), "jolt-transform-modify-define", JsonUtils.jsonToObject(cardrSpec));
    assertTrue(transform instanceof Modifier.Definr);
}
Also used : JoltTransform(com.bazaarvoice.jolt.JoltTransform) Modifier(com.bazaarvoice.jolt.Modifier) Test(org.junit.Test)

Aggregations

JoltTransform (com.bazaarvoice.jolt.JoltTransform)15 Test (org.junit.Test)10 Modifier (com.bazaarvoice.jolt.Modifier)3 CardinalityTransform (com.bazaarvoice.jolt.CardinalityTransform)1 Chainr (com.bazaarvoice.jolt.Chainr)1 Defaultr (com.bazaarvoice.jolt.Defaultr)1 Removr (com.bazaarvoice.jolt.Removr)1 Shiftr (com.bazaarvoice.jolt.Shiftr)1 Sortr (com.bazaarvoice.jolt.Sortr)1 SpecException (com.bazaarvoice.jolt.exception.SpecException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 POST (javax.ws.rs.POST)1