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);
}
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;
}
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);
}
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);
}
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);
}
Aggregations