Package com.bazaarvoice.jolt.exception

Examples of com.bazaarvoice.jolt.exception.SpecException


        specialChild = null;

        // self check
        if ( pathElement instanceof AtPathElement ) {
            throw new SpecException( "@ CardinalityTransform key, can not have children." );
        }

        List<CardinalitySpec> children = createChildren( spec );

        if ( children.isEmpty() ) {
            throw new SpecException( "Shift CardinalitySpec format error : CardinalitySpec line with empty {} as value is not valid." );
        }

        for ( CardinalitySpec child : children ) {
            literals.put( child.pathElement.getRawKey(), child );

            if ( child.pathElement instanceof LiteralPathElement ) {
                literals.put( child.pathElement.getRawKey(), child );
            }
            // special is it is "@"
            else if ( child.pathElement instanceof AtPathElement ) {
                if ( child instanceof CardinalityLeafSpec ) {
                    specialChild = (CardinalityLeafSpec) child;
                } else {
                    throw new SpecException( "@ CardinalityTransform key, can not have children." );
                }
            } else {   // star
                computed.add( child );
            }
        }
View Full Code Here


        Map<String, ShiftrSpec> literals = new HashMap<String, ShiftrSpec>();
        ArrayList<ShiftrSpec> computed = new ArrayList<ShiftrSpec>();

        // self check
        if ( pathElement instanceof AtPathElement ) {
            throw new SpecException( "@ Shiftr key, can not have children." );
        }
        if ( pathElement instanceof DollarPathElement ) {
            throw new SpecException( "$ Shiftr key, can not have children." );
        }

        List<ShiftrSpec> children = createChildren( spec );

        if ( children.isEmpty() ) {
            throw new SpecException( "Shift ShiftrSpec format error : ShiftrSpec line with empty {} as value is not valid." );
        }

        for ( ShiftrSpec child : children ) {
            if ( child.pathElement instanceof LiteralPathElement ) {
                literals.put( child.pathElement.getRawKey(), child );
View Full Code Here

    public CardinalitySpec( String rawJsonKey ) {
        List<PathElement> pathElements = parse( rawJsonKey );

        if ( pathElements.size() != 1 ){
            throw new SpecException( "CardinalityTransform invalid LHS:" + rawJsonKey + " can not contain '.'" );
        }

        PathElement pe =  pathElements.get( 0 );
        if ( ! ( pe instanceof MatchablePathElement ) ) {
            throw new SpecException( "Spec LHS key=" + rawJsonKey + " is not a valid LHS key." );
        }

        this.pathElement = (MatchablePathElement) pe;
    }
View Full Code Here

public class AtPathElement extends BasePathElement implements MatchablePathElement {
    public AtPathElement( String key ) {
        super(key);

        if ( ! "@".equals( key ) ) {
            throw new SpecException( "'References Input' key '@', can only be a single '@'.  Offending key : " + key );
        }
    }
View Full Code Here

            for ( Object dotNotation : rhsList ) {
                writers.add( parseOutputDotNotation( dotNotation ) );
            }
        }
        else {
            throw new SpecException( "Invalid Shiftr spec RHS.  Should be map, string, or array of strings.  Spec in question : " + rhs );
        }

        shiftrWriters = Collections.unmodifiableList( writers );
    }
View Full Code Here

    }

    private static ShiftrWriter parseOutputDotNotation( Object rawObj ) {

        if ( ! ( rawObj instanceof String ) ) {
            throw new SpecException( "Invalid Shiftr 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?
View Full Code Here

    protected abstract char getToken();

    public BasePathReference( String refStr ) {

        if ( refStr == null || refStr.length() == 0 || getToken() != refStr.charAt( 0 ) ) {
            throw new SpecException( "Invalid reference key=" + refStr + " either blank or doesn't start with correct character=" + getToken() );
        }

        int pathIndex = 0;

        try {
            if ( refStr.length() > 1 ) {

                String meat = refStr.substring( 1 );

                pathIndex = Integer.parseInt( meat );
            }
        }
        catch( NumberFormatException nfe ) {
            throw new SpecException( "Unable to parse '" + getToken() + "' reference key:" + refStr, nfe );
        }

        if ( pathIndex < 0 ) {
            throw new SpecException( "Reference:" + refStr + " can not have a negative value."  );
        }

        this.pathIndex = pathIndex;
    }
View Full Code Here

    protected abstract char getToken();

    public BasePathAndGroupReference( String refStr ) {

        if ( refStr == null || refStr.length() == 0 || getToken() != refStr.charAt( 0 ) ) {
            throw new SpecException( "Invalid reference key=" + refStr + " either blank or doesn't start with correct character=" + getToken() );
        }

        int pI = 0;
        int kG = 0;

        try {
            if ( refStr.length() > 1 ) {

                String meat = refStr.substring( 1 );

                if( meat.length() >= 3 && meat.startsWith( "(" ) && meat.endsWith( ")" ) ) {

                    // "&(1,2)" -> "1,2".split( "," ) -> String[] { "1", "2" }    OR
                    // "&(3)"   -> "3".split( "," ) -> String[] { "3" }

                    String parenMeat = meat.substring( 1, meat.length() -1 );
                    String[] intStrs = parenMeat.split( "," );
                    if ( intStrs.length > 2 ) {
                        throw new SpecException( "Invalid Reference=" + refStr );
                    }

                    pI = Integer.parseInt( intStrs[0] );
                    if ( intStrs.length == 2 ) {
                        kG = Integer.parseInt( intStrs[1] );
                    }
                }
                else {   // &2
                    pI = Integer.parseInt( meat );
                }
            }
        }
        catch( NumberFormatException nfe ) {
            throw new SpecException( "Unable to parse '" + getToken() + "' reference key:" + refStr, nfe );
        }

        if ( pI < 0 || kG < 0 ) {
            throw new SpecException( "Reference:" + refStr + " can not have a negative value."  );
        }

        pathIndex = pI;
        keyGroup = kG;
    }
View Full Code Here

                    return (JoltTransform) constructor.newInstance( spec );

                } catch ( NoSuchMethodException nsme ) {
                    // This means the transform class "violated" the SpecTransform marker interface
                    throw new SpecException( "JOLT Chainr encountered an exception constructing SpecTransform className:" + transformClass.getCanonicalName() +
                            ".  Specifically, no single arg constructor found" + entry.getErrorMessageIndexSuffix(), nsme );
                }
            }
            else {
                // The opClass is just a Transform, so just create a newInstance of it.
                return transformClass.newInstance();
            }
        } catch ( Exception e ) {
            // FYI 3 exceptions are known to be thrown here
            // IllegalAccessException, InvocationTargetException, InstantiationException
            throw new SpecException( "JOLT Chainr encountered an exception constructing Transform className:"
                    + transformClass.getCanonicalName() + entry.getErrorMessageIndexSuffix(), e );
        }
    }
View Full Code Here

     * @param index the index of the chainrEntryObj, used in reporting errors
     */
    public ChainrEntry( int index, Object chainrEntryObj ) {

        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( ChainrEntry.OPERATION_KEY, 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();

        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.getCanonicalName() + " requires a spec" + getErrorMessageIndexSuffix() );
        }
    }
View Full Code Here

TOP

Related Classes of com.bazaarvoice.jolt.exception.SpecException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.