com.bazaarvoice.jolt.SpecDriven Java Examples

The following examples show how to use com.bazaarvoice.jolt.SpecDriven. 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: TraversalBuilder.java    From jolt with Apache License 2.0 6 votes vote down vote up
public <T extends PathEvaluatingTraversal> T build( Object rawObj ) {

        if ( ! ( rawObj instanceof String ) ) {
            throw new SpecException( "Invalid spec, RHS should be a String or array of Strings. Value in question : " + rawObj );
        }

        // Prepend "root" to each output path.
        // This is needed for the "identity" transform, eg if we are just supposed to put the input into the output
        //  what key do we put it under?
        String outputPathStr = (String) rawObj;
        if ( StringTools.isBlank( outputPathStr ) ) {
            outputPathStr = SpecDriven.ROOT_KEY;
        }
        else {
            outputPathStr = SpecDriven.ROOT_KEY + "." + outputPathStr;
        }

        return buildFromPath( outputPathStr );
    }
 
Example #2
Source File: TransformFactory.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static JoltTransform getCustomTransform(final ClassLoader classLoader, final String customTransformType, final Object specJson) throws Exception {
    final Class clazz = classLoader.loadClass(customTransformType);
    if(SpecDriven.class.isAssignableFrom(clazz)){
        final Constructor constructor = clazz.getConstructor(Object.class);
        return (JoltTransform)constructor.newInstance(specJson);

    }else{
        return (JoltTransform)clazz.newInstance();
    }
}
 
Example #3
Source File: TransformFactory.java    From nifi with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static JoltTransform getCustomTransform(final ClassLoader classLoader, final String customTransformType, final Object specJson) throws Exception {
    final Class clazz = classLoader.loadClass(customTransformType);
    if(SpecDriven.class.isAssignableFrom(clazz)){
        final Constructor constructor = clazz.getConstructor(Object.class);
        return (JoltTransform)constructor.newInstance(specJson);

    }else{
        return (JoltTransform)clazz.newInstance();
    }
}
 
Example #4
Source File: TransformFactory.java    From nifi with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static JoltTransform getCustomTransform(final ClassLoader classLoader, final String customTransformType, final Object specJson) throws Exception {
    final Class clazz = classLoader.loadClass(customTransformType);
    if(SpecDriven.class.isAssignableFrom(clazz)){
        final Constructor constructor = clazz.getConstructor(Object.class);
        return (JoltTransform)constructor.newInstance(specJson);

    }else{
        return (JoltTransform)clazz.newInstance();
    }
}
 
Example #5
Source File: ChainrEntry.java    From jolt with Apache License 2.0 5 votes vote down vote up
/**
 * Process an element from the Chainr Spec into a ChainrEntry class.
 * This method tries to validate the syntax of the Chainr spec, whereas
 * the ChainrInstantiator deals with loading the Transform classes.
 *
 * @param chainrEntryObj the unknown Object from the Chainr list
 * @param index the index of the chainrEntryObj, used in reporting errors
 */
public ChainrEntry( int index, Object chainrEntryObj, ClassLoader classLoader ) {

    if ( ! (chainrEntryObj instanceof Map ) ) {
        throw new SpecException( "JOLT ChainrEntry expects a JSON map - Malformed spec" + getErrorMessageIndexSuffix() );
    }

    @SuppressWarnings( "unchecked" ) // We know it is a Map due to the check above
    Map<String,Object> chainrEntryMap = (Map<String, Object>) chainrEntryObj;

    this.index = index;

    String opString = extractOperationString( chainrEntryMap );

    if ( opString == null ) {
        throw new SpecException( "JOLT Chainr 'operation' must implement Transform or ContextualTransform" + getErrorMessageIndexSuffix() );
    }

    if ( STOCK_TRANSFORMS.containsKey( opString ) ) {
        operationClassName = STOCK_TRANSFORMS.get( opString );
    }
    else {
        operationClassName = opString;
    }

    joltTransformClass = loadJoltTransformClass( classLoader );

    spec = chainrEntryMap.get( ChainrEntry.SPEC_KEY );

    isSpecDriven = SpecDriven.class.isAssignableFrom( joltTransformClass );
    if ( isSpecDriven && ! chainrEntryMap.containsKey( SPEC_KEY ) ) {
        throw new SpecException( "JOLT Chainr - Transform className:" + joltTransformClass.getName() + " requires a spec" + getErrorMessageIndexSuffix() );
    }
}
 
Example #6
Source File: KeyOrderingTest.java    From jolt with Apache License 2.0 5 votes vote down vote up
@Test(dataProvider = "shiftrKeyOrderingTestCases" )
public void testKeyOrdering( String testName, Map<String,Object> spec, List<String> expectedOrder ) {

    ShiftrCompositeSpec root = new ShiftrCompositeSpec( SpecDriven.ROOT_KEY, spec );

    for ( int index = 0; index < expectedOrder.size(); index++) {
        String expected = expectedOrder.get( index );
        Assert.assertEquals( expected, root.getComputedChildren().get( index ).pathElement.getCanonicalForm(), testName );
    }
}