Package com.bazaarvoice.jolt.exception

Examples of com.bazaarvoice.jolt.exception.SpecException


        if ( operationNameObj == null ) {
            return null;
        }
        else if ( operationNameObj instanceof String) {
            if ( StringUtils.isBlank( (String) operationNameObj ) ) {
                throw new SpecException( "JOLT Chainr '" + ChainrEntry.OPERATION_KEY + "' should not be blank" + getErrorMessageIndexSuffix() );
            }
            return (String) operationNameObj;
        }
        else {
            throw new SpecException( "JOLT Chainr needs a '" + ChainrEntry.OPERATION_KEY + "' of type String" + getErrorMessageIndexSuffix() );
        }
    }
View Full Code Here


        try {
            Class opClass = Class.forName( operationClassName );

            if ( Chainr.class.isAssignableFrom( opClass ) ) {
                throw new SpecException( "Attempt to nest Chainr inside itself" + getErrorMessageIndexSuffix() );
            }

            if ( ! JoltTransform.class.isAssignableFrom( opClass ) )
            {
                throw new SpecException( "JOLT Chainr class:" + operationClassName + " does not implement the JoltTransform interface" + getErrorMessageIndexSuffix() );
            }

            @SuppressWarnings( "unchecked" ) // We know it is some type of Transform due to the check above
            Class<? extends JoltTransform> transformClass = (Class<? extends JoltTransform>) opClass;

            return transformClass;

        } catch ( ClassNotFoundException e ) {
            throw new SpecException( "JOLT Chainr could not find transform class:" + operationClassName + getErrorMessageIndexSuffix(), e );
        }
    }
View Full Code Here

     * @param chainrSpec Plain vanilla hydrated JSON representation of a Chainr spec .json file.
     */
    public ChainrSpec( Object chainrSpec ) {

        if ( !( chainrSpec instanceof List ) ) {
            throw new SpecException"JOLT Chainr expects a JSON array of objects - Malformed spec." );
        }

        @SuppressWarnings( "unchecked" ) // We know its a list due to the check above
        List<Object> operations = (List<Object>) chainrSpec;

        if ( operations.isEmpty() ) {
            throw new SpecException( "JOLT Chainr passed an empty JSON array.");
        }

        List<ChainrEntry> entries = new ArrayList<ChainrEntry>(operations.size());

        for ( int index = 0; index < operations.size(); index++ ) {
View Full Code Here

     */
    @Inject
    public CardinalityTransform( Object spec ) {

        if ( spec == null ){
            throw new SpecException( "CardinalityTransform expected a spec of Map type, got 'null'." );
        }
        if ( ! ( spec instanceof Map) ) {
            throw new SpecException( "CardinalityTransform expected a spec of Map type, got " + spec.getClass().getSimpleName() );
        }

        rootSpec = new CardinalityCompositeSpec( ROOT_KEY, (Map<String, Object>) spec );
    }
View Full Code Here

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

        if ( pathElements.size() != 1 ){
            throw new SpecException( "Shiftr 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

            return Arrays.<PathElement>asList( new DollarPathElement( key ) );
        }
        else if ( key.contains("[") ) {

            if ( StringUtils.countMatches( key, "[" ) != 1 || StringUtils.countMatches( key, "]" ) != 1 ) {
                throw new SpecException( "Invalid key:" + key + " has too many [] references.");
            }

            // is canonical array?
            if ( key.charAt( 0 ) == '[' && key.charAt( key.length() - 1 ) == ']') {
                return Arrays.<PathElement>asList( new ArrayPathElement( key ) );
            }

            // Split syntactic sugar of "photos[]" --> [ "photos", "[]" ]
            //  or                      "bob-&(3,1)-smith[&0]" --> [ "bob-&(3,1)-smith", "[&(0,0)]" ]

            String canonicalKey = key.replace( "[", ".[" );
            String[] subkeys = canonicalKey.split( "\\." );

            List<PathElement> subElements = parsesubkeys ); // at this point each sub key should be a valid key, so just recall parse

            for ( int index = 0; index < subElements.size() - 1; index++ ) {
                PathElement v = subElements.get( index );
                if ( v instanceof ArrayPathElement ) {
                    throw new SpecException( "Array [..] must be the last thing in the key, was:" + key );
                }
            }

            return subElements;
        }
        else if ( key.contains("&") ) {

            if ( key.contains("*") )
            {
                throw new SpecException("Can't mix * with & ) ");
            }
            return Arrays.<PathElement>asList( new AmpPathElement( key ) );
        }
        else if ( "*".equals( key ) ) {
            return Arrays.<PathElement>asList( new StarAllPathElement( key ) );
View Full Code Here

            // Do one pass of "instanceof" checks at construction time, rather than repeatedly at "runtime".
            boolean isTransform = joltTransform instanceof Transform;
            boolean isContextual = joltTransform instanceof ContextualTransform;

            if ( isContextual && isTransform ) {
                throw new SpecException( "JOLT Chainr - JoltTransform className:" + joltTransform.getClass().getCanonicalName() +
                        " implements both Transform and ContextualTransform, should only implement one of those interfaces." );
            }
            if ( ! isContextual && ! isTransform ) {
                throw new SpecException( "JOLT Chainr - Transform className:" + joltTransform.getClass().getCanonicalName() +
                        " should implement Transform or ContextualTransform." );
            }

            // We are optimizing given the assumption that Chainr objects will be built and then reused many times.
            // We want to have a single list of "transforms" that we can just blindly march through.
View Full Code Here

     */
    @Inject
    public Shiftr( Object spec ) {

        if ( spec == null ){
            throw new SpecException( "Shiftr expected a spec of Map type, got 'null'." );
        }
        if ( ! ( spec instanceof Map ) ) {
            throw new SpecException( "Shiftr expected a spec of Map type, got " + spec.getClass().getSimpleName() );
        }

        rootSpec = new ShiftrCompositeSpec( ROOT_KEY, (Map<String, Object>) spec );
    }
View Full Code Here

    private final RemovrCompositeSpec rootSpec;

    @Inject
    public Removr( Object spec ) {
        if ( spec == null ){
            throw new SpecException( "Removr expected a spec of Map type, got 'null'." );
        }
        if ( ! ( spec instanceof Map ) ) {
            throw new SpecException( "Removr expected a spec of Map type, got " + spec.getClass().getSimpleName() );
        }
        rootSpec = new RemovrCompositeSpec( ROOT_KEY, (Map<String, Object>) spec );
        this.spec = (Map<String, Object>) spec;
    }
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

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.